//>>built
define("mill/olap/cubeView",["dijit/layout/BorderContainer","dijit/form/ToggleButton","dijit/form/Select","mill/mill"],function(){window.mill||(mill={});mill.olap||dojo.mixin(mill,{olap:{}});dojo.declare("mill.olap.cubeView",[dijit.layout.BorderContainer],{rttiManager:null,cubeName:null,cubeID:null,gutters:!1,design:"headline",style:"width:100%;height:100%;margin:0;overflow:hidden",headerPane:null,gridPane:null,_startedUp:!1,_rendering:!1,cubeDescription:null,valuesClassName:null,horizontalDimension:null,
verticalDimension:null,calculation:null,dimensionValues:null,measures:null,dimensionNames:null,measureNames:null,measureDescriptions:null,allDimensionValues:null,startup:function(d){if(!this._startedUp)if(this.dimensionValues={},this.allDimensionValues=[],this.measures={},this.dimensionNames={},this.measureNames={},this.measureDescriptions={},mill.queryCursor({headers:{"Disable-Basic-Auth":"yes"},handler:this.rttiManager.handle,fetchAll:!0,className:"TCube",sync:!0,query:[{part:0,name:"ID"},{part:0,
name:"Name"},{part:0,name:"Description"},{part:0,name:"ValuesClass$N"},{part:0,name:"IsAccessible"},{part:1,name:this.cubeID?"ID":"Name",value:this.cubeID||this.cubeName}],load:dojo.hitch(this,function(a){(a=a.documentElement.childNodes[0])&&"1"==mill.fieldValue(a,"IsAccessible")&&(this.cubeID=mill.fieldValue(a,"ID"),this.cubeName=mill.fieldValue(a,"Name"),this.cubeDescription=mill.fieldValue(a,"Description"),this.valuesClassName=mill.fieldValue(a,"ValuesClass-N"))})}),this.cubeID&&this.cubeName){var e=
[],b=[],f=[];(new dojo.DeferredList([mill.queryCursor({headers:{"Disable-Basic-Auth":"yes"},handler:this.rttiManager.handle,fetchAll:!0,className:"TCubeDimension",sync:!1,query:[{part:0,name:"ID"},{part:0,name:"Description"},{part:0,name:"PropertyName"},{part:2,name:"Description"},{part:1,name:"Master",value:this.cubeID}],fetched:function(a){e.push(a)}}),mill.queryCursor({headers:{"Disable-Basic-Auth":"yes"},handler:this.rttiManager.handle,fetchAll:!0,className:"TCubeDimensionValue",sync:!1,query:[{part:0,
name:"ID"},{part:0,name:"Description"},{part:0,name:"Master"},{part:0,name:"Parent"},{part:2,name:"Position"},{part:1,name:"Cube",value:this.cubeID}],fetched:dojo.hitch(this,function(a){this.allDimensionValues.push(a)})}),mill.queryCursor({headers:{"Disable-Basic-Auth":"yes"},handler:this.rttiManager.handle,fetchAll:!0,className:"TCubeMeasure",sync:!1,query:[{part:0,name:"ID"},{part:0,name:"Description"},{part:0,name:"PropertyName"},{part:2,name:"Description"},{part:1,name:"Master",value:this.cubeID}],
fetched:function(a){b.push(a)}}),mill.queryCursor({headers:{"Disable-Basic-Auth":"yes"},handler:this.rttiManager.handle,fetchAll:!0,className:"TCubeCalculation",sync:!1,query:[{part:0,name:"ID"},{part:0,name:"Description"},{part:2,name:"Completed",special:"desc"},{part:1,name:"Completed",value:"*"},{part:1,name:"Master",value:this.cubeID}],fetched:function(a){f.push(a)}})])).addCallback(dojo.hitch(this,function(){var a=[];a.push("\x3ch1\x3e"+this.cubeDescription+"\x3c/h1\x3e");a.push("\x3ctable\x3e");
a.push('\x3ctr style\x3d"display:'+(1>=f.length?"none":"")+'" \x3e');a.push("\x3ctd\x3e");a.push(dojo.i18n.getLocalization("mill","resources").forStatus+"\x26#160;\x26#160;\x26#160;");a.push("\x3c/td\x3e");a.push("\x3ctd\x3e");a.push("\x3cdiv");a.push(' data-dojo-type\x3d"dijit.form.Select"');a.push(' data-dojo-props\x3d\'style:"width:100%", onChange: function(){dijit.byId("'+this.id+"\")._calculationChanged(this.value)}'");a.push("\x3e");dojo.forEach(f,dojo.hitch(this,function(c){this.calculation||
(this.calculation=mill.fieldValue(c,"ID"));a.push('\x3cspan data-dojo-value\x3d"'+mill.fieldValue(c,"ID")+'"\x3e\x3cb style\x3d"color: #3E62A2"\x3e'+mill.fieldValue(c,"Description")+"\x3c/b\x3e\x3c/span\x3e")}));a.push("\x3c/div\x3e");a.push("\x3c/td\x3e");a.push("\x3c/tr\x3e");dojo.forEach(e,dojo.hitch(this,function(c){this.horizontalDimension?this.verticalDimension||(this.verticalDimension=mill.fieldValue(c,"ID")):this.horizontalDimension=mill.fieldValue(c,"ID");this.dimensionNames[mill.fieldValue(c,
"ID")]=mill.fieldValue(c,"PropertyName");a.push("\x3ctr\x3e");a.push("\x3ctd\x3e");a.push(mill.fieldValue(c,"Description")+":\x26#160;\x26#160;\x26#160;");a.push("\x3c/td\x3e");a.push("\x3ctd\x3e");a.push("\x3cdiv");a.push(' data-dojo-type\x3d"dijit.form.Select"');a.push(' data-dojo-props\x3d\'style:"width:100%", id:"'+this.id+"_dimensionSelect_"+mill.fieldValue(c,"ID")+'", onChange: function(){dijit.byId("'+this.id+'")._dimensionValueChanged("'+mill.fieldValue(c,"ID")+"\", this.value)}'");a.push("\x3e");
a.push("\x3c/div\x3e");a.push("\x3c/td\x3e");a.push("\x3ctd\x3e");a.push('\x3cbutton dojoType\x3d"dijit.form.ToggleButton"');a.push(" label\x3d\"\x3cdiv style\x3d'width:12px;height:12px;background-image:url("+dojo.moduleUrl("mill","olap/verticalDimension.png")+");overflow:hidden'\x3e\x26#160;\x3c/div\x3e\"");a.push("  onClick\x3d\"dijit.byId('"+this.id+"')._toVerticalDimension('"+mill.fieldValue(c,"ID")+"')\"");a.push('  checked\x3d"'+(this.verticalDimension==mill.fieldValue(c,"ID")?"true":"false")+
'"');a.push(' id\x3d"'+this.id+"_toVerticalButton_"+mill.fieldValue(c,"ID")+'"');a.push("/\x3e");a.push('\x3cbutton dojoType\x3d"dijit.form.ToggleButton"');a.push(" label\x3d\"\x3cdiv style\x3d'width:12px;height:12px;background-image:url("+dojo.moduleUrl("mill","olap/horizontalDimension.png")+");overflow:hidden'\x3e\x26#160;\x3c/div\x3e\"");a.push("  onClick\x3d\"dijit.byId('"+this.id+"')._toHorizontalDimension('"+mill.fieldValue(c,"ID")+"')\"");a.push('  checked\x3d"'+(this.horizontalDimension==
mill.fieldValue(c,"ID")?"true":"false")+'"');a.push(' id\x3d"'+this.id+"_toHorizontalButton_"+mill.fieldValue(c,"ID")+'"');a.push("/\x3e");a.push("\x3c/td\x3e");a.push("\x3c/tr\x3e")}));a.push('\x3ctr style\x3d"display:'+(1>=b.length?"none":"")+'"\x3e');a.push("\x3ctd\x3e");a.push(dojo.i18n.getLocalization("mill","resources").rates+"\x26#160;\x26#160;\x26#160;");a.push("\x3c/td\x3e");a.push("\x3ctd\x3e");dojo.forEach(b,dojo.hitch(this,function(c){this.measures[mill.fieldValue(c,"ID")]=!0;this.measureNames[mill.fieldValue(c,
"ID")]=mill.fieldValue(c,"PropertyName");this.measureDescriptions[mill.fieldValue(c,"ID")]=mill.fieldValue(c,"Description");a.push('\x3cinput dojoType\x3d"dijit.form.CheckBox"');a.push("  onClick\x3d\"dijit.byId('"+this.id+"')._measureChanged('"+mill.fieldValue(c,"ID")+"', this.attr('checked'))\"");a.push(' id\x3d"'+this.id+"_measureCheckBox_"+mill.fieldValue(c,"ID")+'"');a.push('checked\x3d"true"');a.push("/\x3e");a.push("\x26#160;");a.push('\x3cb style\x3d"color:#3E62A2"\x3e');a.push(mill.fieldValue(c,
"Description"));a.push("\x3c/b\x3e");a.push("\x26#160;")}));a.push("\x3c/td\x3e");a.push("\x3c/tr\x3e");a.push("\x3c/table\x3e");a.push('\x3cdiv style\x3d"margin-top:10px;"\x3e');a.push('\x3cdiv dojoType\x3d"dijit.form.Button"');a.push('showLabel\x3d"false"');a.push("onClick\x3d\"dijit.byId('"+this.id+"')._toExcel('.xls')\"");a.push('iconClass\x3d"CExcelImageIndex"\x3e');a.push("\x3c/div\x3e");a.push('\x3cdiv dojoType\x3d"dijit.form.Button"');a.push('showLabel\x3d"false"');a.push("onClick\x3d\"dijit.byId('"+
this.id+"')._toExcel('.pdf')\"");a.push('iconClass\x3d"CPDFImageIndex"\x3e');a.push("\x3c/div\x3e");a.push('\x3cdiv dojoType\x3d"dijit.form.Button"');a.push('showLabel\x3d"false"');a.push("onClick\x3d\"dijit.byId('"+this.id+"')._toExcel('.html')\"");a.push('iconClass\x3d"CHTMLDocumentImageIndex"\x3e');a.push("\x3c/div\x3e");a.push("\x3c/div\x3e");this.headerPane=new dijit.layout.ContentPane({region:"top"});this.addChild(this.headerPane);this.gridPane=new dijit.layout.ContentPane({region:"center",
style:"overflow:scroll"});this.addChild(this.gridPane);dojo.place(a.join(""),this.headerPane.containerNode,"only");dojo.parser.parse(this.headerPane.containerNode);this._startedUp=!0;this._checkDimensionValues(this.calculation);this._render();d&&d()}))}else alert(dojo.i18n.getLocalization("mill","resources").youHaveNotAccess)},_checkDimensionValues:function(d){if(d){var e={};mill.queryCursor({headers:{"Disable-Basic-Auth":"yes"},handler:this.rttiManager.handle,fetchAll:!0,className:"TCubeDimensionValue",
sync:!0,query:[{part:0,name:"ID"},{part:1,name:"Cube",value:this.cubeID},{part:0,name:"HasValues",value:"TCubeDimensionValue.HasValues",special:"22",context:[{name:"Calculation",domain:"TCubeCal\u0441ulation required domain",value:d}]}],fetched:function(b){"0"==mill.fieldValue(b,"HasValues")&&(e[mill.fieldValue(b,"ID")]=!0)},load:dojo.hitch(this,function(b){for(var f in this.dimensionNames){var a=dijit.byId(this.id+"_dimensionSelect_"+f),c=[{label:'\x3cb style\x3d"color: #3E62A2"\x3e(\u0412\u0441\u0435)\x3c/b\x3e',
value:""}],r=this;(function(t,u,p){var k=arguments.callee;dojo.forEach(r.allDimensionValues,function(g){mill.fieldValue(g,"Master")!=t||mill.fieldValue(g,"Parent")!=u||e[mill.fieldValue(g,"ID")]||(c.push({value:mill.fieldValue(g,"ID"),label:'\x3cb style\x3d"margin-left:'+10*p+'px"\x3e'+mill.fieldValue(g,"Description")+"\x3c/b\x3e"}),k(t,mill.fieldValue(g,"ID"),p+1))})})(f,"",0);a.attr("options",c);a.attr("value","")}return b})})}},_calculationChanged:function(d){this.calculation=d;this._checkDimensionValues(d);
this._render()},_dimensionValueChanged:function(d,e){this.dimensionValues[d]=e;this._render()},_toVerticalDimension:function(d){this.horizontalDimension==d&&(this.horizontalDimension=this.verticalDimension);this.dimensionValues[d]=null;this.verticalDimension=d;this._render()},_toHorizontalDimension:function(d){this.verticalDimension==d&&(this.verticalDimension=this.horizontalDimension);this.dimensionValues[d]=null;this.horizontalDimension=d;this._render()},_measureChanged:function(d,e){this.measures[d]=
!!e;this._render()},_formatToggleButton:function(d){dojo.query(".dijitButtonNode",d.domNode).style({backgroundImage:d.checked?"url()":"",backgroundColor:d.checked?"#FFFFFF":""})},_renderControls:function(){for(var d in this.dimensionNames){var e=dijit.byId(this.id+"_toVerticalButton_"+d);e.attr("checked",d==this.verticalDimension);this._formatToggleButton(e);e=dijit.byId(this.id+"_toHorizontalButton_"+d);e.attr("checked",d==this.horizontalDimension);this._formatToggleButton(e);e=dijit.byId(this.id+
"_dimensionSelect_"+d);d==this.verticalDimension||d==this.horizontalDimension?(e.attr("disabled",!0),e.attr("value","")):e.attr("disabled",!1)}d=0;for(var b in this.measures)this.measures[b]&&d++;for(b in this.measures)e=dijit.byId(this.id+"_measureCheckBox_"+b),e.attr("disabled",1>=d&&e.attr("checked"))},_render:function(){if(!this._rendering){this._rendering=!0;this._renderControls();var d=[{part:0,name:"Hierarchical"},{part:0,name:"Status$N"},{part:1,name:"Calculation",value:this.calculation}],
e;for(e in this.dimensionNames)e==this.verticalDimension||e==this.horizontalDimension?d.push({part:0,name:this.dimensionNames[e]}):d.push({part:1,name:this.dimensionNames[e],value:this.dimensionValues[e]||"!*"});for(var b in this.measures)this.measures[b]&&d.push({part:0,name:this.measureNames[b]});var f=[];mill.queryCursor({headers:{"Disable-Basic-Auth":"yes"},handler:this.rttiManager.handle,fetchAll:!0,className:this.valuesClassName,sync:!1,query:d,fetched:function(a){f.push(a)},load:dojo.hitch(this,
function(a){var c=dojo.place(this._buildDimensionTable(this.horizontalDimension,this.verticalDimension),this.gridPane.containerNode,"only"),r=0,t;for(t in this.measures)this.measures[t]&&r++;a=dojo.clone(this.dimensionNames);delete a[this.horizontalDimension];delete a[this.verticalDimension];for(var u in this.dimensionValues)this.dimensionValues[u]&&delete a[u];var p=0;for(u in a)p++;dojo.forEach(f,dojo.hitch(this,function(k){var g=mill.fieldValue(k,this.dimensionNames[this.horizontalDimension]),
m=mill.fieldValue(k,this.dimensionNames[this.verticalDimension]),q=m?dojo.query("TR#"+this.id+"_"+m,c)[0]:c.rows[c.rows.length-1];q.style.display="";var v=g?dojo.query("TD#"+this.id+"_"+g,c.rows[0])[0]:c.rows[0].cells[c.rows[0].cells.length-1];dojo.forEach(c.rows,function(w){w.cells[v.cellIndex].style.display=""});q=q.cells[v.cellIndex];var h=[],l=["olapValue"];"1"==mill.fieldValue(k,"Hierarchical")&&l.push("olapHierarchical");g&&m||l.push("olapDimensionSummaryValue");h.push('\x3cdiv class\x3d"'+
l.join(" ")+'"\x3e');p&&h.push("\x3ca href\x3d\"javascript:dijit.byId('"+this.id+"')._details("+(g?"'"+g+"'":"null")+","+(m?"'"+m+"'":"null")+')"\x3e');if(1>=r)for(var n in this.measures)this.measures[n]&&(h.push('\x3cspan style\x3d"color:black"\x3e'+this.formatValue(mill.fieldValue(k,this.measureNames[n]),g,m)+"\x3c/span\x3e"),l=(l=k.getElementsByTagName(this.measureNames[n])[0])?l.getAttribute("type"):"","int"==l||"dbl"==l)&&(q.align="right");else{for(n in this.measures)this.measures[n]&&(h.push("\x3cdiv\x3e"),
h.push('\x3cspan class\x3d"olapMeasureTitle"\x3e'+this.measureDescriptions[n]+':\x26#160;\x3c/span\x3e\x3cspan style\x3d"color:black"\x3e'+this.formatValue(mill.fieldValue(k,this.measureNames[n]),g,m)+"\x3c/span\x3e"),h.push("\x3c/div\x3e"));q.align="right"}p&&h.push("\x3c/a\x3e");h.push("\x3c/div\x3e");dojo.place(h.join(""),q,"only")}));this._rendering=!1})})}},_buildDimensionTable:function(d,e){var b=[];b.push('\x3ctable cellspacing\x3d"0" cellpadding\x3d"0"\x3e');var f=[],a=[];dojo.forEach(dijit.byId(this.id+
"_dimensionSelect_"+d).options,dojo.hitch(this,function(c){c.value&&f.push({id:c.value,label:c.label})}));dojo.forEach(dijit.byId(this.id+"_dimensionSelect_"+e).options,dojo.hitch(this,function(c){c.value&&a.push({id:c.value,label:c.label})}));b.push("\x3ctr\x3e");b.push("\x3ctd\x3e");b.push("\x3c/td\x3e");dojo.forEach(f,dojo.hitch(this,function(c){b.push('\x3ctd class\x3d"olapDimensionHeaderCell" style\x3d"display:none" align\x3d"center" valign\x3d"center" id\x3d"'+this.id+"_"+c.id+'"\x3e');b.push('\x3cdiv class\x3d"olapDimensionHeader"\x3e');
b.push(c.label);b.push("\x3c/div\x3e");b.push("\x3c/td\x3e")}));b.push('\x3ctd  class\x3d"olapDimensionHeaderCell" align\x3d"center" valign\x3d"center" \x3e');b.push('\x3cb class\x3d"olapDimensionSummaryHeader"\x3e'+dojo.i18n.getLocalization("mill","resources").total+"\x3c/b\x3e");b.push("\x3c/td\x3e");b.push("\x3c/tr\x3e");dojo.forEach(a,dojo.hitch(this,function(c){b.push('\x3ctr  style\x3d"display:none"  id\x3d"'+this.id+"_"+c.id+'"\x3e');b.push('\x3ctd class\x3d"olapDimensionHeaderCell"\x3e');
b.push('\x3cdiv class\x3d"olapDimensionHeader"\x3e');b.push(c.label);b.push("\x3c/div\x3e");b.push("\x3c/td\x3e");dojo.forEach(f,dojo.hitch(this,function(r){b.push('\x3ctd  class\x3d"olapValueCell" style\x3d"display:none" \x3e');b.push("\x26#160;");b.push("\x3c/td\x3e")}));b.push('\x3ctd class\x3d"olapDimensionSummaryCell"\x3e');b.push("\x26#160;");b.push("\x3c/td\x3e");b.push("\x3c/tr\x3e")}));b.push("\x3ctr\x3e");b.push('\x3ctd class\x3d"olapDimensionHeaderCell"\x3e');b.push('\x3cb class\x3d"olapDimensionSummaryHeader"\x3e'+
dojo.i18n.getLocalization("mill","resources").total+"\x3c/b\x3e");b.push("\x3c/td\x3e");dojo.forEach(f,dojo.hitch(this,function(c){b.push('\x3ctd  class\x3d"olapDimensionSummaryCell" style\x3d"display:none" \x3e');b.push("\x26#160;");b.push("\x3c/td\x3e")}));b.push('\x3ctd class\x3d"olapDimensionSummaryCell"\x3e');b.push("\x26#160;");b.push("\x3c/td\x3e");b.push("\x3c/tr\x3e");b.push("\x3c/table\x3e");return b.join("")},_toExcel:function(d){var e=[],b=[],f;for(f in this.dimensionNames)f!=this.verticalDimension&&
f!=this.horizontalDimension&&b.push(f+"\x3d"+(this.dimensionValues[f]||"!*"));for(var a in this.measures)this.measures[a]&&e.push(a);mill.executeExcelTemplate({handler:this.rttiManager.handle,className:"TCube",templateName:"Values",fileName:this.cubeDescription+d,extension:d,params:{ID:this.cubeID,Calculation:this.calculation,HorizontalDimension:this.horizontalDimension,VerticalDimension:this.verticalDimension,MeasuresList:e.join(";"),Filters:b.join(";")}})},_details:function(d,e){var b=dojo.clone(this.dimensionNames);
delete b[this.horizontalDimension];delete b[this.verticalDimension];for(var f in this.dimensionValues)this.dimensionValues[f]&&delete b[f];if(d)for(f in b){this.dimensionValues[this.horizontalDimension]=d;var a=dijit.byId(this.id+"_dimensionSelect_"+this.horizontalDimension);this._rendering=!0;a.attr("value",d);this._rendering=!1;this.horizontalDimension=f;delete b[f];break}if(e)for(f in b){this.dimensionValues[this.verticalDimension]=e;a=dijit.byId(this.id+"_dimensionSelect_"+this.verticalDimension);
this._rendering=!0;a.attr("value",e);this._rendering=!1;this.verticalDimension=f;delete b[f];break}this._render()},formatValue:function(d,e,b){return d||"\x3ci\x3e"+dojo.i18n.getLocalization("mill","resources").defaultNoValue+"\x3c/i\x3e"}})});