dojo.provide("parus.balanceReportRecalculateValuesDialog");dojo.require("dijit.Dialog");dojo.require("dijit.form.Button");dojo.require("parus.parus8");dojo.require("parus.dialog");dojo.declare("parus.balanceReportRecalculateValuesDialog",[parus.Dialog],{noGrid:false,rn:null,isSubReport:false,applyProgressLabel:"Рассчитываются значения показателей...",onShow:function(){var a=this.getDefaultCalculationTypeValue();this.recalculateTypeEdit.attr("value",a.CALCTYPECODE);this.calculateResultSubReportsCheckBox.attr("checked",a.CALCRESULTS)},getDefaultCalculationTypeValue:function(){var g={CALCTYPECODE:"",CALCRESULTS:false};if(!this.rn){var f=parus.balance.primaryMasterGrid;if(this.isSubReport){f=parus.balance.primaryDetailGrid}var e=f.store;var d=f.selection.getSelectedIndex();var c=f.getItem(d);this.rn=e.getValue(c,"RN")}if(this.rn||f.selection.getSelectedCount()==1){var b="getReportDefaultsRecalculateType";if(this.isSubReport){b="getSubReportDefaultsRecalculateType"}var a=parus.database.execute(b,{RN:this.rn});if(a){g={CALCTYPECODE:parus.parus8.nodeField(parus.parus8.rowNodes(a)[0],"CALCTYPECODE"),CALCRESULTS:parus.parus8.nodeField(parus.parus8.rowNodes(a)[0],"CALCRESULTS")=="1"}}}return g},onApply:function(){var b="recalculateReportValues";var f=this.noGrid?null:parus.balance.primaryMasterGrid;if(this.isSubReport){b="recalculateSubReportValues";f=this.noGrid?null:parus.balance.primaryDetailGrid}if(f){var e=f.store;var d=!this.isSubReport;var c=(this.calculateResultSubReportsCheckBox.checked?1:0);var a=this.recalculateTypeEdit.value;parus.progressDialog.iterateOverGrid(this.applyProgressLabel,f,function(g){parus.database.execute(b,{RN:e.getValue(g,"RN"),RESCOUNT:c,CALCTYPE_CODE:a})},function(){parus.balance.refreshGrid(f,"RN",e.getValue(f.selection.getFirstSelected(),"RN"));if(d){parus.balance.refreshGrid(parus.balance.primaryDetailGrid,"RN",parus.balance.primaryDetailGrid.store.getValue(parus.balance.primaryDetailGrid.selection.getFirstSelected(),"RN"))}});return true}else{if(this.rn){parus.database.execute(b,{RN:this.rn,RESCOUNT:(this.calculateResultSubReportsCheckBox.checked?1:0),CALCTYPE_CODE:this.recalculateTypeEdit.value});if(f){parus.balance.refreshGrid(f,"RN",this.rn)}}}if(!this.isSubReport&&f){parus.balance.refreshGrid(parus.balance.primaryDetailGrid,"RN",parus.balance.primaryDetailGrid.store.getValue(parus.balance.primaryDetailGrid.selection.getFirstSelected(),"RN"))}return true},show:function(){if(parus.parus8.optionValue("Balance_ShowCalculationParamsForm")!="0"){return this.inherited(arguments)}else{if(this.noGrid){var a=new parus.progressDialog({message:this.applyProgressLabel});a.show();setTimeout(dojo.hitch(this,function(){this.onShow();this.applied=true;this.onApply();a.close();a.destroyRecursive();this.onClose()}),1000)}else{return(new parus.confirmationDialog({message:"Пересчитать значения "+(this.isSubReport?"подотчета":"отчета")+"?",onApply:dojo.hitch(this,function(){var b=new parus.progressDialog({message:this.applyProgressLabel});b.show();setTimeout(dojo.hitch(this,function(){this.onShow();this.applied=true;this.onApply();b.close();b.destroyRecursive();this.onClose()}),1000);return true}),onClose:dojo.hitch(this,this.onClose)})).show()}}}});