(function(){"use strict";var e;var t={outputFields:null,isNew:false,isFinalPage:false,startPage:0,filterNode:null};page.commandBindings=$.extend(page.commandBindings,{Apply:v,Cancel:g,Next:m,Back:p});var i=u8.session.webConfigValues.getBoolean("Query.HideSystemFields");var a="<div class='u8-popup-sizer u8-main u8-vstack spaced' style='width: 400px;'>"+"<div class='u8-page-validationsummary'></div>"+"<div>${teaser}</div>"+"<div style='position: relative; min-height: 300px;'>"+"{{FieldListBox(list)}}"+"</div>"+"<div class='u8-buttons nowrap'>"+'{{Button({ textId: "TXT_button_text_17", command:"Next" })}}'+'{{Button({ textId: "TXT_button_text_10", isCancel: true, command:"Cancel" })}}'+"</div>"+"</div>";var r="<div class='u8-main u8-vstack spaced u8-popup-sizer' style='display: inline-block; min-width: 400px'>"+"<div class='u8-page-validationsummary dense'></div>"+"{{FilterNodeEditor(editor)}}"+"<div class='u8-buttons nowrap'>"+"{{if canBack}}"+'{{Button({ textId: "TXT_button_text_1", command:"Back" })}}'+"{{/if}}"+'{{Button({ textId: "TXT_button_text_11", isDefault: true, command:"Apply" })}}'+'{{Button({ textId: "TXT_button_text_10", isCancel: true, command:"Cancel" })}}'+"</div>"+"</div>";page.using={texts:["XSelFilter_Text","XSelFilterField_text","calendar_text","save_text","button_text","XSelFieldsTexts","error_text"],types:["FilterNodeEditor","Schema.UI"]};page.onLoad=function(){e=u8.Base.Widgets.Popup.getFromElement(document.body);var i=this.url.get("Mode");t.adapter=e["queryeditor.adapter"];if(i=="Add"){t.isNew=true;t.filterNode=null}else{t.isNew=false;t.filterNode=t.adapter.node}var a=t.adapter.getQueryNode();$assert(a,"No query node is associated with the query editor adapter!");t.queryNode=a;t.infoAreaId=t.queryNode.infoAreaId;u8.using({schema:t.infoAreaId},l)};function l(){var e=u8.services.schema.getInfoArea(t.infoAreaId);t.infoAreaLabel=e.label;if(t.isNew&&!t.outputFields){u8.services.queries.getOutputFieldsForInfoArea(t.infoAreaId,function(e){t.outputFields=e;if(typeof e=="object"){t.outputFields=u8.tools.clone(e)}d()})}else{d()}}function d(){if(t.filterNode){var e,i=t.filterNode;if(!i.isLeaf()){e=-1}else if(i.lValue&&i.lValue["function"]=="COUNT"){e=u8.Crm.Schema.VirtualFieldId.NumberOfRecords}else{e=i.lValue.fieldId}y(e)}if(t.isNew){o()}else{f()}}function o(){t.isFinalPage=false;var e=n();T(e.title,{template:a,data:e})}function n(){var e={id:"fields",parent:page,infoAreaId:t.infoAreaId,onSelect:s,filter:u,fieldIds:t.outputFields,settingsName:"QueryFilter",autoFocus:true,autoLayout:"fill",dataTypes:"CDKXLFSBT"};if(t.adapter.isFilter){e.__isFilter=t.adapter.isFilter}else if(t.adapter.isAdvancedFilter){e.dataTypes="LFS";if(!u8.session.webConfigValues.getBoolean("Query.ShowVirtualFields")){e.additionalFields=[{id:u8.Crm.Schema.VirtualFieldId.NumberOfRecords,label:$t("TXT_XSelDefineText_39"),dataType:$t("TXT_XSelFilterField_text_8")}]}}return{list:e,title:$t("TXT_XSelFilterField_text_0")+"  "+t.infoAreaLabel,teaser:"TXT_XSelFilter_Text_58".format({1:t.infoAreaLabel})}}function s(e,t){y(e.getValue());f()}function u(e){if(!(e.rights&u8.Crm.Schema.RightsMask.View)){return false}if((!u8.session.webConfigValues.getBoolean("Query.ShowVirtualFields")||i)&&e.category==u8.Crm.Schema.FieldCategory.VirtualCore){return false}if(e.category==u8.Crm.Schema.FieldCategory.WebCustomField){return false}return true}function f(){t.isFinalPage=true;var e=c();T(e.title,{template:r,data:e})}function c(){var e="TXT_XSelFilter_Text_46".format({1:t.fieldLabel,2:t.infoAreaLabel});return{title:e,canBack:t.isNew,editor:{id:"editor",model:{infoAreaId:t.infoAreaId,fieldId:t.fieldId,filterNode:t.filterNode,isFilter:t.adapter.isFilter,isAdvancedFilter:t.adapter.isAdvancedFilter,parentNode:t.adapter.parentNode,getCombinedValues:t.adapter.getCombinedValues},onLayoutChange:F}}}function p(){o()}function m(){var e=$widget("fields");if(!e){return}var t=e.getValue();if(typeof t=="undefined"){return}y(t);f()}function v(){_()}function g(){if(t.adapter){t.adapter.cancel()}e.close()}function F(){e.autoSizeAndPosition()}function _(){var i={};var a=$widget("editor");if(!a||!a.apply(i)){if(i.error){page.notify(i.error.message,i.sourceWidget)}return}var r=a.model;var l=r.filterNode;if(t.isNew){t.adapter.addNode(l,{parentOperator:r.parentOperator})}else{t.adapter.updateNode(l)}e.close()}function T(t,i){e.setTitle(t);page.children.removeWhere(function(e){return!u8.tools.isInstanceOfClass(e,"Tooltip")});$("#contents").utml($.extend({},i,{itemOptions:{parent:page}}),function(){u8.tools.ready(true,page,function(){e.autoSizeAndPosition().show()})})}function y(e){t.fieldId=e;if(e==u8.Crm.Schema.VirtualFieldId.NumberOfRecords){t.fieldLabel=$t("TXT_XSelDefineText_39")}else{var i=u8.services.schema.getField(t.infoAreaId,e);t.fieldLabel=i.label}if(t.adapter.isAdvancedFilter){t.fieldLabel=$t("TXT_XSelDefineText_40")+" ("+t.fieldLabel+")"}}})();