dojo.provide("parus.balanceReportAttachedDocumentsDialog");dojo.require("dijit.Dialog");dojo.require("dijit.form.Button");dojo.require("dojox.grid.DataGrid");dojo.require("parus.parus8");dojo.require("parus.gridData");dojo.require("parus.dialog");dojo.require("parus.balanceReportAttachedDocumentActionDialog");dojo.declare("parus.balanceReportAttachedDocumentsDialog",[parus.Dialog],{rn:null,unitcode:"BalanceReports",postCreate:function(){this.inherited(arguments);this.docsGrid.attr("store",this.docsGridStore());this.docsGrid.setQuery(this.docsGrid.query);this.docsGridPopupMenu.bindDomNode(this.docsGrid.viewsNode);parus.balance._createActionsButton(this.docsGridPopupMenu,this.docsGridHeaderPane);var a=parus.userdata.get(this.declaredClass);if(a){parus.gridSettingsDialog.mergeGridSettings(this.docsGrid,a.gridSettings);parus.gridSettingsDialog.mergeColorConditions(this.docsGrid,a.colorConditions);parus.gridSettingsDialog.mergeMenuSettings(this.docsGridPopupMenu,a.actionSettings,a.userProcsActions,a.userReportsActions,a.userAppsActions);parus.gridSettingsDialog.mergeFilterBar(this.docsGrid,a.showFilterBar,a.filterValues,a.sortInfo)}},docsGridStore:function(){return parus.gridData({queryid:"AttachedDocuments",onGetConditions:dojo.hitch(this,function(a){return{RN:this.rn,UNITCODE:this.unitcode}}),onComplete:dojo.hitch(this,function(b,a){if((a.length>0)&&!this.docsGrid.selection.getSelectedCount()){this.docsGrid.selection.select(0);this.docsGrid.autoSelected=true}})})},refresh:function(){var c=this.docsGrid;var b=c.selection.getSelectedIndex();var a=c.getItem(b);parus.balance.refreshGrid(c,"RN",c.store.getValue(a,"RN"))},insertFile:function(){(new parus.balanceReportAttachedDocumentActionDialog({title:"Присоединенные документы: Добавление",grid:this.docsGrid,prn:this.rn,unitcode:this.unitcode})).show()},updateFile:function(){var b=this.docsGrid;var a=b.selection.getSelectedIndex();var c=b.getItem(a);(new parus.balanceReportAttachedDocumentActionDialog({title:"Присоединенные документы: Исправление",grid:this.docsGrid,prn:this.rn,rn:b.store.getValue(c,"RN"),docCode:b.store.getValue(c,"CODE"),docType:b.store.getValue(c,"FILE_TYPE_CODE"),catalog:b.store.getValue(c,"CATALOG"),note:b.store.getValue(c,"NOTE"),unitcode:this.unitcode})).show()},deleteFile:function(){(new parus.confirmationDialog({message:"Удалить запись (записи)?",onApply:dojo.hitch(this,function(){var b=this.docsGrid;var a=b.selection.getFirstSelected();for(var c=0;c<b.selection.getSelectedCount();c++){parus.database.execute("DeleteAttachedDocument",{RN:b.store.getValue(a,"RN")});a=b.selection.getNextSelected(a)}parus.balance.refreshGrid(b,"RN",b.store.getValue(b.selection.getFirstSelected(),"RN"));return true})})).show()},downloadFile:function(){var b=this.docsGrid;var a=b.selection.getFirstSelected();for(var c=0;c<b.selection.getSelectedCount();c++){parus.balance.downloadAttachedFile(b.store.getValue(a,"RN"));a=b.selection.getNextSelected(a)}},insertFiles:function(){if(parus.parus8._themeEditorMode){alert("В режиме редактирования схемы это действие невозможно.");return}if(!parus.parus8.optionValue("BalanceOnlineCacheContractorDictValues")){parus.parus8.errorMessage("В настройках системы не задан тип присоединенного документа по умолчанию.");return}var b=document.createElement("form");b.method="POST";b.encoding="multipart/form-data";b.action=parus.database.getLoadAttachedDocumentsUrl();var a=document.createElement("input");a.type="hidden";a.name="prn";a.value=this.rn;b.appendChild(a);var a=document.createElement("input");a.type="hidden";a.name="unitcode";a.value=this.unitcode;b.appendChild(a);var a=document.createElement("input");a.type="file";a.name="filedata";a.multiple=true;a.onchange=dojo.hitch(this,function(){if(!a.files.length){document.body.removeChild(b);return}var c=new parus.progressDialog({message:"Загружаются файлы..."});c.show();dojo.xhrGet({url:"../.system/session.xml?filedata=",handleAs:"xml",sync:false,preventCache:true,load:dojo.hitch(this,function(d){dojo.io.iframe.send({method:"POST",form:b,handleAs:(dojo.isIE>=10)?"html":"xml",handle:dojo.hitch(this,function(f,e){document.body.removeChild(b);if(!dojo.isIE){f.normalize()}if(f.documentElement.nodeName=="error"){parus.parus8.errorMessage(parus.parus8.nodeField(f.documentElement,"message"));f=null}c.close();c.destroyRecursive();this.refresh()})});return(d)})})});b.appendChild(a);document.body.appendChild(b);a.click()}});