(function(){"use strict";var e={canExport:true,canSaveSnapshot:true};var t=u8.session.webConfigValues.get("Query.Parameters");if(t){if(t.indexOf("DisableExport")>=0){e.canExport=false}if(t.indexOf("DisableSaveResult")>=0){e.canSaveSnapshot=false}}e.countRecords=u8.session.webConfigValues.getInt("Query.CountRecords",0);var s=u8.session.webConfigValues.get("UpdateServer.RepID");e.canRunInBackground=!!s;u8.services.ready("queries",function(){$.extend(u8.services.queries.commands,{"Query/CountRows":{execute:function(e,t,s){if(!this.query){return}this.query.execute({countRows:true})},queryState:function(t,s,u){u.visible=e.countRecords?true:false;u.disabled=!(this.query&&this.query.canExecute())}},"Query/Execute":{execute:function(e,t,s){if(!this.query){return}this.query.execute()},queryState:function(e,t,s){var u=u8.session.webConfigValues.getInt("Query.Rights");if(u===u8.Crm.Queries.rightsFlags.disabled){s.disabled=true}else{s.disabled=!(this.query&&this.query.canExecute())}}},Save:{execute:function(e,t,s){if(!this.query){return}u8.services.queries.save(this.query,{uri:null})}},"Action/Delete":{execute:function(e,t,s){if(!this.query){return}if(this.query.infoAreaId){u8.services.queries.filters.delete_({infoAreaId:this.query.infoAreaId,name:this.query.name,queryLookupScope:this.query.queryLookupScope})}else{u8.services.queries.deleteQuery({name:this.query.name,queryLookupScope:this.query.queryLookupScope})}},queryState:function(e,t,s){s.disabled=!(this.query&&this.query.canDelete())}},"Query/RunInBackground":{execute:function(e,t,s){var u=this.query;if(!(u&&u.canExecute())){return}u8.services.queries.executeInBackground({query:u,options:s.commandArguments})},queryState:function(t,s,u){var r=u8.session.webConfigValues.getInt("Query.Rights");if(r==u8.Crm.Queries.rightsFlags.disabled){u.disabled=true}else{u.disabled=!(this.query&&this.query.canExecute())}u.visible=e.canRunInBackground;u.stopPropagation=true}},"Query/SaveResultSet":{execute:function(e,t,s){var u=this.query||this.resultSet.getOwner()&&this.resultSet.getOwner().query;if(!u){return}u8.services.queries.snapshots.save({query:u})},queryState:function(t,s,u){u.visible=e.canSaveSnapshot;if(u.visible){u.disabled=!this.resultSet||this.resultSet.isEmpty()}u.stopPropagation=true}},Export:{execute:function(e,t,s){if(!this.query){s.stopPropagation=false;return}var u=s.commandArguments,r=u8.services.reporting.createReport({elWindow:this.elWindow,action:u.report||s.action});u=$.extend({},u,{report:r});u8.services.queries.executeExport({query:this.query,options:u,noUi:s.noUi||true})},queryState:function(t,s,u){if(!this.query){return}u.visible=!!(e.canExport&&this.query.canExecute());if(u.visible){u.disabled=u.needsResultSet===false?false:!this.resultSet||this.resultSet.isEmpty()}u.stopPropagation=true}},"Query/SendToReps":{execute:function(e,t,s){var u=this.query||s.commandArguments;var r=$.extend({},s.commandArguments,this.query&&{name:u.name,uri:u.uri?u.uri:null,queryLookupScope:u.queryLookupScope});u8.services.queries.sendToReps(r)},queryState:function(e,t,s){var u=this.query||s.commandArguments;s.disabled=!u||!u.name}}});$.extend(u8.services.queries.snapshots.commands,{Export:{execute:function(e,t,s){$assert(this.snapshot,"Cannot export without a query result snapshot!");var u=s.commandArguments,r=u8.services.reporting.createReport({elWindow:this.elWindow,action:u.report||s.action});u=$.extend({},u,{report:r});u8.services.queries.snapshots.executeExport($.extend(u,{snapshot:this.snapshot}))},queryState:function(t,s,u){u.visible=e.canExport&&this.snapshot;if(u.visible){if(!this.resultSet||this.resultSet.isEmpty()||!u8.isValidRecordUid(this.snapshot.uid)){u.disabled=true;u.stopPropagation=true}}else{u.stopPropagation=true}}},"QueryResultSnapshots/MarkRowMarked":{execute:function(e,t,s){var u=s.marked||false,r=this;u8.services.queries.snapshots.setRowMarked(s.uid,u,function(){r.snapshot.update()})}},"QueryResultSnapshots/MarkRowDone":{execute:function(e,t,s){var u=s.done||false,r=this;u8.services.queries.snapshots.setRowDone(s.uid,u,function(){r.snapshot.update()})}},"QueryResultSnapshots/SetRowPriority":{execute:function(e,t,s){var u=s.priority||0,r=this;u8.services.queries.snapshots.setRowPriority(s.uid,u,function(){r.snapshot.update()})}}})})})();