var adhocControls={};adhocControls={CONTROLS_LOCATION:"filtersMainTableICCell",filterSaveAsCheckbox:null,controlsController:null,hideDialog:null,lastSelection:{controlsData:null,saveAsDefault:null},initialize:function(o){if("true"===hasVisibleInputControls&&$(ControlsBase.INPUT_CONTROLS_DIALOG)){this.controlsController=new JRS.Controls.Controller({reportUri:Report.reportUnitURI});var t="#"+ControlsBase.INPUT_CONTROLS_FORM+" .sub.header";if(jQuery("#"+ControlsBase.INPUT_CONTROLS_DIALOG).length>0&&(t="#"+ControlsBase.INPUT_CONTROLS_DIALOG+" .sub.header"),this.viewModel=this.controlsController.getViewModel(),this.viewModel.reloadContainer(),this.controlsController.fetchControlsStructure(o.adhocParameters,!0).always(function(){var o=adhocControls.viewModel;o.areAllControlsValid()&&"true"!==reportForceControlsOnStart?adhocControls.forceFiltersFromControls():adhocControls.launchDialog()}),this.filterSaveAsCheckbox=jQuery("#filterssaveasdefault"),0===this.filterSaveAsCheckbox.length)throw Error("Can't find filter save as default");adhocControls.setSaveAsDefaultCheckbox(o.isSaveParametersAsDefault);var e={"button#ok":this.applyFilters.curry(!0),"button#cancel":this.cancel,"button#reset":this.reset,"button#apply":this.applyFilters.curry(!1)};this._dialog=new ControlDialog(e)}},launchDialog:function(){"true"===hasVisibleInputControls&&(adhocControls._dialog.show(),enableSelection(adhocControls._dialog._dom),adhocControls.setFocusOnFirstInputControl())},applyFilters:function(o){adhocControls.hideDialog=o,adhocControls.isSelectionChanged()?adhocControls.controlsController.validate().then(function(t){t&&(adhocControls.forceFiltersFromControls(),o&&adhocControls.closeDialog())}):adhocControls.viewModel.areAllControlsValid()&&o&&adhocControls.closeDialog()},reset:function(){adhocControls.controlsController.reset(),adhocControls.setSaveAsDefaultCheckbox(!0)},cancel:function(){adhocControls.closeDialog(),adhocControls.isSelectionChanged()&&adhocControls.restoreDialogLastSelection()},forceFiltersFromControls:function(){var o,t=adhocControls.getControlsSelection(),e=adhocControls.isSaveAsDefaultCheckbox();e&&(o={filterssaveasdefault:"on"}),adhocControls.forceFilterAction(ControlsBase.buildSelectedDataUri(t,o)),adhocControls.saveDialogLastSelection(t,e)},closeDialog:function(){adhocControls._dialog.hide()},leaveAdhoc:function(){document.location=buildActionUrl({_flowId:"homeFlow"})},refreshAdhocDesigner:function(){var o=function(o){localContext.standardOpCallback(o),adhocDesigner.filtersController.setFilters(o,{reset:!0})};designerBase.sendRequest("co_loadState",[],o)},requestFilterAction:function(o,t,e,l){var n={_flowId:"adhocAjaxFilterDialogFlow",clientKey:clientKey,decorate:"no"};n[t]="true";var r=buildActionUrl(n),s=Object.extend({postData:l,callback:o,mode:AjaxRequester.prototype.EVAL_JSON,errorHandler:baseErrorHandler},e);ajaxTargettedUpdate(r,s)},setFilters:function(o){adhocControls.requestFilterAction(o,"setFilters")},forceFilterAction:function(o){adhocControls.requestFilterAction(function(o){"success"===o&&(adhocControls.refreshAdhocDesigner(),adhocControls.hideDialog&&adhocControls.closeDialog())},"setFilters",null,o)},setFocusOnFirstInputControl:function(){if("undefined"!=typeof firstInputControlName&&firstInputControlName){var o=$(firstInputControlName);o&&o.focus()}},isSelectionChanged:function(){return JRS.Controls.ViewModel.isSelectionChanged(adhocControls.getControlsLastSelection(),adhocControls.getControlsSelection())||adhocControls.getSaveAsDefaultCheckboxLastValue()!=adhocControls.isSaveAsDefaultCheckbox()},setSaveAsDefaultCheckbox:function(o){o?adhocControls.filterSaveAsCheckbox.prop("checked",!0):adhocControls.filterSaveAsCheckbox.removeAttr("checked")},isSaveAsDefaultCheckbox:function(){return adhocControls.filterSaveAsCheckbox.is(":checked")},getControlsSelection:function(){return adhocControls.viewModel.get("selection")},restoreDialogLastSelection:function(){adhocControls.controlsController.update(adhocControls.lastSelection.controlsData),adhocControls.setSaveAsDefaultCheckbox(adhocControls.lastSelection.saveAsDefault)},saveDialogLastSelection:function(o,t){adhocControls.lastSelection.controlsData=o,adhocControls.lastSelection.saveAsDefault=t},getControlsLastSelection:function(){return adhocControls.lastSelection.controlsData},getSaveAsDefaultCheckboxLastValue:function(){return adhocControls.lastSelection.saveAsDefault}};