Ext.define("KSWN.meta.holidayLoad.Model",{extend:"Ext.data.Model",statics:{createModel:function(){const period=new KSWN.core.date.Period,{holidayLoadFTPAddress:holidayLoadFTPAddress}=KSWN.Constant,{beginDate:beginDate,endDate:endDate}=period.getYearPeriod();return new KSWN.meta.holidayLoad.Model({ftpAddress:holidayLoadFTPAddress,beginDate:beginDate,endDate:endDate})}},fields:[{name:"loadType",type:"int"},{name:"file"},{name:"uploadedFileId",type:"string"},{name:"uploadedFileName",type:"string"},{name:"ftpAddress",type:"string"},{name:"beginDate",allowNull:!1,type:"date",convert:date=>date&&Ext.Date.clearTime(date)},{name:"endDate",allowNull:!1,type:"date",convert:date=>date&&Ext.Date.clearTime(date)}],isLoadFromFtp:function(){return 0===this.data.loadType},isLoadFromFile:function(){return 1===this.data.loadType},isLoadFromDates:function(){return 2===this.data.loadType},validate:function(){const{ftpAddress:ftpAddress,file:file,beginDate:beginDate,endDate:endDate}=this.data;let error;return this.isLoadFromFile()&&!file&&(error=KSWN.Locale.failnevibran),this.isLoadFromFtp()&&!ftpAddress&&(error=KSWN.Locale.neukazanputkfailu),this.isLoadFromDates()&&(beginDate&&endDate?beginDate-endDate>0?error=KSWN.Locale.dataokonchaniyanemozhetbitmenshedatanachala:endDate-beginDate<0&&(error=KSWN.Locale.datanachalanemozhetbitbolshedatiokonchaniya):error=KSWN.Locale.neukazanidati),error||!0},doImport:async function(view){await this.beforeImport();const params=this.getImportParams();return await Ajax({url:"HolidayLoad/Import",mask:{id:view,text:KSWN.Locale.vipolnyaetsyaimport},params:params})},beforeImport:async function(){this.isLoadFromFile()&&await this.uploadFile()},getImportParams:function(){return _.pick(this.data,["loadType","beginDate","endDate","uploadedFileId","uploadedFileName","ftpAddress"])},uploadFile:async function(){const{file:file}=this.data;if(!file)return!1;const res=await KSWN.util.FileUtils.AsyncUploadFileFine({files:[file]});if(!res)return!1;const{uuid:uuid,name:name}=_.head(res);this.set({uploadedFileId:uuid,uploadedFileName:name})}}),Ext.define("KSWN.meta.holidayLoad.ViewController",{extend:"Ext.app.ViewController",alias:"controller.ks-meta-holidayload",init:function(){const model=KSWN.meta.holidayLoad.Model.createModel();this.getViewModel().set({model:model})},onFileInputChange:function(field){const model=this.getViewModel().get("model"),file=_.get(field,"fileInputEl.dom.files[0]",null);model.set({file:file})},okBtnClick:async function(){const EU=KSWN.ExtUtils,view=this.getView(),{objx:objx}=view,model=this.getViewModel().get("model"),validateResult=model.validate();if(!0!==validateResult)return EU.Alert("#msg#"+validateResult);const importResult=await model.doImport(view);if(!importResult||objx.containerMain.destroyed)return;EU.ShowProtocol({hres:importResult});const{Links:Links}=importResult;objx.Refresh&&_.size(Links)>0&&objx.Refresh(Links),view.destroy()},cancelBtnClick:function(){this.getView().destroy()}}),Ext.define("KSWN.meta.holidayLoad.ViewModel",{extend:"Ext.app.ViewModel",alias:"viewmodel.ks-meta-holidayload",data:{model:null},stores:{loadTypesStore:{data:[{text:KSWN.Locale.ftpserver,value:0},{text:KSWN.Locale.izfaila,value:1},{text:KSWN.Locale.subbotiivoskresenyazaperoid,value:2}]}}}),Ext.define("KSWN.meta.holidayLoad.Window",{extend:"Ext.window.Window",statics:{showImportWindow:function(objx){new KSWN.meta.holidayLoad.Window({xtype:"ks-meta-holidayload-window",objx:objx})}},xtype:"ks-meta-holidayload-window",viewModel:"ks-meta-holidayload",controller:"ks-meta-holidayload",layout:{type:"vbox",align:"stretch"},iconCls:"ks-icon-calendar",title:KSWN.Locale.importnerabochikhdnei,width:450,autoShow:!0,modal:!0,bodyPadding:8,defaults:{labelWidth:180},items:[{xtype:"ks-defaultcombobox",fieldLabel:KSWN.Locale.tipimporta,margin:"0 0 16 0",bind:{store:"{loadTypesStore}",value:"{model.loadType}"}},{xtype:"container",layout:"fit",border:1,bodyPadding:4,defaults:{labelWidth:180,format:"d.m.Y"},items:[{xtype:"textfield",fieldLabel:KSWN.Locale.adresdlyazagruzki,bind:{value:"{model.ftpAddress}",hidden:"{ model.loadType !== 0 }"}},{xtype:"fileuploadfield",reference:"fileInput",fieldLabel:KSWN.Locale.putkfailu,listeners:{change:"onFileInputChange"},bind:{hidden:"{ model.loadType !== 1 }"}},{xtype:"fieldcontainer",fieldLabel:KSWN.Locale.subbotiivoskresenyazaperiod,labelAlign:"top",margin:0,padding:0,layout:{type:"hbox",align:"center"},defaults:{labelWidth:25,format:"d.m.Y",flex:1,margin:0,padding:0},bind:{hidden:"{ model.loadType !== 2 }"},items:[{xtype:"datefield",fieldLabel:"c",margin:"0 10 0 0",bind:{value:"{model.beginDate}",maxValue:"{model.endDate}"}},{xtype:"datefield",fieldLabel:KSWN.Locale.po,bind:{value:"{model.endDate}",minValue:"{model.beginDate}"}}]}]}],buttons:[{text:"OK",handler:"okBtnClick"},{text:KSWN.Locale.otmena,handler:"cancelBtnClick"}]});