dojo.provide("parus.balanceReportDigitalSignaturesDialog");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.digitalSignature");dojo.declare("parus.balanceReportDigitalSignaturesDialog",[parus.Dialog],{rn:null,unitCode:null,postCreate:function(){this.inherited(arguments);var b=dojo.clone(this.signaturesGrid.structure);dojo.forEach(b[0].cells[0],dojo.hitch(this,function(c){if(c.field=="SIGN_STATE"){c.formatter=this.formatSignState}else{if(c.field=="STRUCT_STATE"){c.formatter=this.formatStructureState}}}));this.signaturesGrid.attr("structure",b);this.signaturesGrid.attr("store",this.signaturesGridStore());this.signaturesGrid.setQuery(this.signaturesGrid.query);this.signaturesPopupMenu.bindDomNode(this.signaturesGrid.viewsNode);parus.balance._createActionsButton(this.signaturesPopupMenu,this.signaturesGridHeaderPane);var a=parus.userdata.get(this.declaredClass);if(a){parus.gridSettingsDialog.mergeGridSettings(this.signaturesGrid,a.gridSettings);parus.gridSettingsDialog.mergeColorConditions(this.signaturesGrid,a.colorConditions);parus.gridSettingsDialog.mergeMenuSettings(this.signaturesPopupMenu,a.actionSettings,a.userProcsActions,a.userReportsActions,a.userAppsActions)}},destroy:function(){this.inherited(arguments)},signaturesGridStore:function(){return parus.gridData({queryid:"DigitalSignatures",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.signaturesGrid.selection.getSelectedCount()){this.signaturesGrid.selection.select(0);this.signaturesGrid.autoSelected=true}})})},checkSign:function(){var h=this.signaturesGrid;var f=h.store;var c=h.selection.getFirstSelected();var m=[];for(var a=0;a<h.selection.getSelectedCount();a++){var l=h.store.getValue(c,"RN");var k=h.store.getValue(c,"SIMPLESIGN")=="1";var j=parus.database.execute("VerifySign",{RN:l,DOCUMENT:this.rn,UNITCODE:this.unitCode});if(j){var g=parus.parus8.nodeField(parus.parus8.rowNodes(j)[0],"STRUCT_CHANGED");var e=h.store.findIndex("RN",l);if(e>=0){var d=h.getItem(e);if(k){d.setAttribute("formatSignState","Не проверялась")}else{m.push({rn:l,data:parus.parus8.nodeField(parus.parus8.rowNodes(j)[0],"clobDOC_DATA"),signedData:parus.parus8.nodeField(parus.parus8.rowNodes(j)[0],"clobSIGN"),structChanged:g})}var b="";switch(g){case"0":b="Не изменена";break;case"1":b="Изменена";break;case"2":b="Не используется";break}d.setAttribute("formatStructureState",b)}}c=h.selection.getNextSelected(c)}h.setQuery(h.query);parus.digitalSignature.checkPlugin().then(dojo.hitch(this,function(){parus.digitalSignature.checkSign(m).then(dojo.hitch(this,function(i){dojo.forEach(i,function(p){var o=h.store.findIndex("RN",p.rn);if(o>=0){var n=h.getItem(o);n.setAttribute("formatSignState",p.checkResult?"Проверена":p.checkError)}});h.setQuery(h.query)}),function(i){this.close();parus.parus8.errorMessage(i)})}),function(i){parus.parus8.errorMessage(i)})},formatSignState:function(b,a,d){var c=d.grid.getItem(a);return c.getAttribute("formatSignState")||"Не определено"},formatStructureState:function(d,c,b){var a=b.grid.getItem(c);return a.getAttribute("formatStructureState")||"Не определено"}});