(function(){"use strict";var e={designerDataModel:false,designerProcessesAndRoles:false,designerCatalogs:false,designerFixedCatalogs:false};page.using={texts:["net_designer_client_texts"],processes:e};var a=u8.Base.Model.define("syncByCode,allCatalogs,catalogType,catalogsModel,catalogsAreLoaded,tab,onlyTmp,updateProcesses,updateRoles");var t;var s=function(){function a(e){var a={pageSize:25,hasRowCheck:true,columns:[{label:"#",dataKey:"catalogNr",width:50,sortFn:u8.services.schema.createComparer("L").ascending},{label:$t("TXT_net_designer_client_texts_2"),dataKey:"title"},{label:$t("TXT_net_designer_client_texts_3"),dataKey:"parent"},{label:$t("TXT_net_designer_client_texts_4"),dataKey:"state",width:100,cellRenderer:function(e,a){var t=a.cellData;a.elCell.innerHTML=t=="Full"?"<strong>"+t+"</strong>":t}},{label:$t("TXT_net_designer_client_texts_5"),dataKey:"lastSynchDate",width:150,sortFn:u8.services.schema.createComparer("D").ascending,cellFormatter:function(e){return u8.services.typeConverter.dateToString(e,"Date Time")}},{label:$t("TXT_net_designer_client_texts_6"),dataKey:"usageCount",width:100,sortFn:u8.services.schema.createComparer("L").ascending},{label:$t("TXT_net_designer_client_texts_7"),dataKey:"valuesInDatabase",width:100,sortFn:u8.services.schema.createComparer("L").ascending}],rowActionCount:0,rowDefaults:{actions:[{selectOnClick:true}]},selectionMode:"multi"};var t=s(e);var r=new u8.Base.Widgets.GridModel(a);r.setData(t,{createRows:true});return r}function s(e){var a=[],t=e;for(var s=0;s<t.length;s++){var r=t[s];var n="";if(r.parentCatalogNr){n=(r.parentCatalogName||"?")+" (#"+r.parentCatalogNr+")"}var o;if(r.catalogInDatabase){if(r.lastSynchDate){o=$t("TXT_net_designer_client_texts_8")}else{o=$t("TXT_net_designer_client_texts_9")}}else if(r.lastSynchDate){o=$t("TXT_net_designer_client_texts_10")}else{o=$t("TXT_net_designer_client_texts_11")}a.push({catalogNr:r.catalogNr,title:r.catalogName,parent:n,state:o,lastSynchDate:r.lastSynchDate,usageCount:r.usageCount,valuesInDatabase:r.valuesInDatabase})}return a}function r(){var e=t.catalogsModel;return e.grepRows(u8._.attr("isChecked"),function(a,t){var s=e.getRowData(t);return s.catalogNr})}function n(e){var a=s(e);t.catalogsModel.setData(a,{createRows:true});t.catalogsModel.update()}function l(){t.catalogsState="loading";u8.request("DesignerChannel.GetCatalogs",{request:{allCatalogs:t.allCatalogs,fixed:t.catalogType=="X"}},function(e,a){t.catalogsState="loaded";var s=a.response&&a.response.catalogs||[];n(s)})}function i(){o();var e={catalogNrs:r(),fixed:t.catalogType=="X",syncMode:t.syncByCode?3:0};var a=$widget("form").busy({delay:0});u8.request("DesignerChannel.UpdateCatalogs",{request:e},function(e,t){a.hide();if(t.error){return}var s=t.response&&t.response.catalogs||[];l(s)})}return{apply:i,load:l,create:function(t){t.catalogType=e.designerCatalogs?"K":"X";t.catalogsModel=a([]);t.catalogsState=null}}}();var r=function(){return{apply:function(){o();var e={upgradeProcesses:t.updateProcesses,upgradeRoles:t.updateRoles,onlyTMPTables:t.onlyTmp};var a=$widget("form").busy({delay:0});u8.request("DesignerChannel.UpdateProcesses",{request:e},function(e,t){a.hide();if(t.error){return}o(t.response&&t.response.protocol)})},create:function(e){e.updateProcesses=true;e.updateRoles=true}}}();var n=function(){return{apply:function(){o();var e={onlyTMPTables:t.onlyTmp};var a=$widget("form").busy({delay:0});u8.request("DesignerChannel.UpdateDatabaseSchema",{request:e},function(e,t){a.hide();if(t.error){return}o(t.response&&t.response.protocol)})},create:function(e){e.onlyTmp=false}}}();function o(e){e=e||{};var a=e.lines||[];var t="";for(var s=0;s<a.length;s++){t+=u8.Base.Html.escape(a[s])+"<br>"}$("#protocol").html(t)}function l(e,a){if(a.propertyName=="tab"&&a.value=="catalogs"&&!t.catalogsState){s.load()}else if(a.propertyName=="allCatalogs"||a.propertyName=="catalogType"){s.load()}}page.onLoad=function(){t=new a;s.create(t);r.create(t);n.create(t);t.bind("PropertyChange",l);t.tab="catalogs";$("#form").widget("Form",{parent:page,commandBindings:{ApplyCatalogs:s.apply,ApplyProcesses:r.apply,ApplyDataModel:n.apply},formName:"DesignerMaintenance",context:t,isDefault:true,onPreCreate:function(a){var t=a.widgets;var s=t.tabsPanel.options.items;if(!e.designerCatalogs&&!e.designerFixedCatalogs){s.removeWhere(u8._.eq("value","catalogs"))}if(!e.designerDataModel){s.removeWhere(u8._.eq("value","datamodel"))}if(!e.designerProcessesAndRoles){s.removeWhere(u8._.eq("value","processes"))}if(!s.length){t.root={type:"Message",options:{severity:200,text:$t("TXT_net_designer_client_texts_14"),buttons:null}};return}if(!e.designerCatalogs||!e.designerFixedCatalogs){t.catalogsPanel.options.items.removeWhere(u8._.eq("widget","catalogTypesPanel"))}}})}})();