Check and uncheck the checkbox needs to reload the search item

I’m having the search column with checkbox along with folder names. when I click the checkbox of corresponding folder, it will show their items. As well as when I click on multiple checkbox it will show their corresponding items. But when I uncheck the folder, the corresponding items doesn’t remove. So I need the hard reload or refresh when I check or uncheck the checkbox or need to clear the cache for every check or uncheck.

Checkbox: Core.component.Checkbox.extend({
    click: function () {
        var ret=null;
        var nav = this.get("controller").get('selectedNavigator');
        ret = this._super.apply(this, arguments);
        var states=null;
        Ember.run.schedule('sync', this, function () {
            Ember.run.schedule('render', this, function () {
                states = this.get('parentView.itemStates');
                var values =  Object.keys(states).filter(function (key) {
                    if(states[key]){

                    return states[key];}
                    else{return;}
                });
                if (values.length === 0) {
                    Core.Action('core:contentHome', {});
                } else {
                    this.set('parentView.model.values',values);
                    nav.publish();
                }
            });
        });
        return ret;
    }
}),

In that code, states[key] defining the items get true if it checked and items get false if it unchecked and nav.publish(); defining to show the items of checked.

publish: function () {
					var currentResultSet = this.get('resultSet'),
					    ctl = this.get('controller'),
						form = ctl.get('formModel'),
						resultSet,
						data = form.sleep(2000);
					if (Object.keys(data).length === 0) {
						Core.view.Menu.create({
							anchor: $('*[data-class-name="Core.Tab.Content.Controller.NavigationRefresh"]'),
							model: [
								Core.model.Menu.Item.create({
									label: "Please select something to search.",
									icon: 'dialog_warning'
								})
							]
						}).show();
						return;
					}
					resultSet = form.send();
					ctl.set('loadState', 'loading');
					ctl.set('resultSet', Core.model.BlankResultSet.create({
						loadState: 'loading',
						tabContext: Ember.get(form, 'resultSet.tabContext')
					}));
					resultSet.fail(function (err) {
						ctl.set('loadState', 'loaded');
						console.log(currentResultSet);
						ctl.set('resultSet', currentResultSet);
					}).always(function () {
						ctl.set('loadState', 'loaded');
					});
				},

Please provide suggestion on this.

Everything I said here applies equally well to this post.

Did you try to use any of my suggestions from that reply? You’re going to keep having painful bugs with the kind of code you’re showing here. You need to refactor little by little into cleaner patterns. There is no good reason to extend Checkbox to do what you’re doing.

2 Likes