Ext.define("Portlet",{alias:"widget.portlet",ui:"eg-x-panel",bodyPadding:10,extend:"Ext.panel.Panel",initComponent:function(){var a=this;a.callParent();},onRender:function(){if(!Ext.isEmpty(Ext.getCmp(this.id+"-toolbar"))){this.mon(this.el,"mouseover",function(){Ext.getCmp(this.id+"-toolbar").show();
},this.el);this.mon(this.el,"mouseout",function(){Ext.getCmp(this.id+"-toolbar").hide();},this.el);}this.callParent();}});var $activeScroll=false,$scrollInterval,deferTimeout;Ext.define("utilities.gridstackPanel",{extend:"Ext.container.Container",alias:"widget.gridstackpanel",closeAction:"destroy",autoScroll:true,scroll:true,padding:"10 5 10 5",flex:1,getDragPositions:Ext.emptyFn,getResizePositions:Ext.emptyFn,config:{data:[],},constructor:function(a){this.initConfig(a);
this.callParent(arguments);},resizeWidget:true,gridstackColumns:12,id:"gridstackpanel",frame:false,widgetConfigObj:{},tpl:'<div class="grid-stack  grid-stack-12"><tpl for="."><div class="grid-stack-item {widgetType}"   data-gs-no-resize={noResize}  id= {id}   data-gs-id={id} data-gs-x="{x}" data-gs-y="{y}" data-gs-width="{width}" data-gs-height="{height}"><div class="grid-stack-item-content bord" id= "{id}_inner"></div></div></tpl></div>',initComponent:function(){var a=this;
var b=a.data;if(a.data.length==0){a.update("");}a.on("boxready",function(){a.loadgridStackAPI(b);},a);a.on("resize",a.windowResize,a);a.callParent();},gridStackData:function(b){var a=this;a.data.push(b);},loadgridStackAPI:function(d){var b=this,c=(Math.round(b.getHeight()/12)-10),a={verticalMargin:10,width:12,height:0,acceptWidgets:".grid-stack-item",animate:false,resizable:{scroll:true,handles:"se , sw"},draggable:{scroll:true,handle:".x-panel-header, .textWidgetDrag"}};
gridStackObj=$(".grid-stack").gridstack(a);b.loadPanel(d);b.widgetResize();b.widgetDrag();b.widgetAdded();b.widgetRemoved();b.widgetChanges();return gridStackObj;},setPanelResize:function(a){Ext.defer(function(){var b=a.target.id;if(b!=null&&b.indexOf("_outer")>-1){b=b.substring(0,b.indexOf("_outer"));
}var c={width:$("#"+b+"_inner").outerWidth(true),height:$("#"+b+"_inner").outerHeight(true)};Ext.getCmp(b).setSize(c);Ext.getCmp(b).doComponentLayout();},500);},widgetDrag:function(){var a=this;$(".grid-stack").on("dragstop",function(d,e){var c=this;var b=d.target;a.getDragPositions();});},widgetResize:function(){var a=this;
var b='<div class="empty" style="height:90px; visibility: hidden">emptyWidget</div>';$(".grid-stack").on("resize",function(e,f){$("iframe").css("pointer-events","none");a.setPanelResize(e);var d=e.target.id;if(d!=null&&d.indexOf("_outer")>-1){d=d.substring(0,d.indexOf("_outer"));}var c=Ext.getCmp(d);
c.isWidgetResizeInProgress=true;if((f.position.top+f.size.height)>($("#gridstackpanelObj").scrollTop()+$("#gridstackpanelObj").height()-30)){if($activeScroll===false){$activeScroll=true;$scrollInterval=setInterval(function(){if(($(f.element[0]).offset().top+$(f.element[0]).height())>($("#gridstackpanelObj").scrollTop()+$("#gridstackpanelObj").height())){$("#gridstackpanelObj").stop().animate({scrollTop:$("#gridstackpanelObj").scrollTop()+10},100);
$(".empty").remove();$("#gridstackpanelObj").append(b);}else{if(typeof node!=="undefined"){a.gridStackObjRef().update(e.target.id,node.x,node.y,node.el.css("width"),500);}}},150);}$(".empty").remove();$("#gridstackpanelObj").append(b);$("#gridstackpanelObj").stop().animate({scrollTop:$("#gridstackpanelObj").scrollTop()+40},100);
if(deferTimeout){clearTimeout(deferTimeout);}}else{$("#gridstackpanelObj").stop();}}).on("resizeStart",function(e,f){var d=e.target.id;if(d!=null&&d.indexOf("_outer")>-1){d=d.substring(0,d.indexOf("_outer"));}var c=Ext.getCmp(d);c.isWidgetResizeInProgress=true;}).on("resizestop",function(d,j){$activeScroll=false;
clearInterval($scrollInterval);deferTimeout=Ext.defer(function(){$(".empty").remove();},2000);deferTimeout;a.setPanelResize(d);a.getResizePositions(d);if(($("#"+e+".dofontsize").size)&&($("#"+e+".dofontsize_2").size)){var i=d.target;var o=j.size;maxSize=70;minSize=30;maxSize2=60;minSize2=40;var n=(o.width*o.height)/1300;
if(n>maxSize){n=maxSize;}if(n<minSize){n=minSize;}var l=d.target.id;if(l!=null&&l.indexOf("_outer")>-1){l=l.substring(0,l.indexOf("_outer"));}var g=Ext.getCmp(l);var m=g.measureValue;var c=0;if(!Ext.isEmpty(m)){c=m.length;}if(c>=7){n=(o.width*o.height)/1300;if(n>maxSize){n=70;}}if(c<=6){n=(o.width*o.height)/1000;
if(n>maxSize){n=70;}}if(c<=5){n=(o.width*o.height)/800;if(n>maxSize){n=70;}}if(c<=4){n=(o.width*o.height)/700;if(n>maxSize){n=70;}}var f=(o.width*o.height)/10000;if(f>maxSize2){f=maxSize2;}if(f<minSize2){f=minSize2;}var h=f-10;if(g.isString){if(n>=25){var k=(n/2);if(k>35){n=35;}else{if(k>30){n=30;}else{n=25;
}}}}var e=$(i)[0].id;$("#"+e+" .dofontsize").css("font-size",n+"px");$("#"+e+" .dofontsize").css("line-height",n+"px");$("#"+e+" .dofontsize_2").css("font-size",f+"px");$("#"+e+" .dofontsize_2").css("line-height",(h+10)+"px");}$("iframe").css("pointer-events","auto");});},loadPortletToolbarItems:function(a){var b=this;
b.portlettoolbarItems.length=0;switch(a.widgetType){case"Gauge Meter":b.portlettoolbarItems.push({xtype:"button",ui:"xx",text:"x",handler:function(){this.up("panel").close();}});break;}},portlettoolbarItems:[],portlet:function(f,e,a,d,d){var c=this;if($("#noData")){$("#noData").remove();}var g,b;if(Ext.isArray(f)){b=f;
}else{b=[];b.push(f);}_.each(b,function(l){var j=l.id,i=l.id+"_inner",k=Ext.get(i).getWidth(),h=Ext.get(i).getHeight();c.loadPortletToolbarItems(l);g=Ext.create("Portlet",{closeAction:"destroy",title:l.widgetType,renderTo:i,relationTo:l.id,id:j,width:k,height:h,layout:{type:"vbox",align:"stretch"},tools:[{xtype:"toolbar",margin:0,padding:0,hidden:true,id:j+"-toolbar",ui:"plain",items:c.portlettoolbarItems}],listeners:{"beforeclose":function(m){if(m.panelClose){m.panelClose=false;
return true;}Ext.Msg.show({title:"Close confirmation",msg:"Really close?",buttons:Ext.Msg.YESNO,callback:function(n){if("yes"===n){m.panelClose=true;c._removeWidget(g.relationTo);}}});return false;}}});});return g;},loadPanel:function(c){var b=this;for(var a in c){if(c[a].hasOwnProperty("id")){Ext.suspendLayouts();
b.portlet(c[a],"addWidget","","","");Ext.resumeLayouts(true);}else{throw"No id is given in the data";}}},gridStackObjRef:function(){var b=this,a=$(".grid-stack").data("gridstack");return a;},windowResize:function(){var a=this;_.map($(".grid-stack > .grid-stack-item:visible"),function(g){if(!Ext.isEmpty(g)){g=$(g);
var h=g.data("_gridstack_node"),f=h.id;if(f!=null&&f.indexOf("_outer")>-1){f=f.substring(0,f.indexOf("_outer"));}var c=$("#"+f+"_inner"),e=c.outerWidth(true),b=c.outerHeight(true),d={width:e,height:b};if(!Ext.isEmpty(Ext.getCmp(f))){Ext.getCmp(f).setSize(d);Ext.getCmp(f).doComponentLayout();}}},a);},defaultConfigWidget:{x:0,y:0,width:2,height:2,autoPosition:false,minWidth:undefined,maxWidth:undefined,minHeight:undefined,maxHeight:undefined,id:Ext.id(),noResize:false},_loadData:function(e){var c=this;
c.gridStackObjRef().removeAll();var b=GridStackUI.Utils.sort(e);var d,a;_.each(b,function(g){var h=g.id;var f=h+"_inner";c.gridStackObjRef().addWidget($('<div class="grid-stack-item '+g.widgetType+'"   data-gs-no-resize="'+g.noResize+'"  id= "'+h+'"   data-gs-id="'+h+'"  ><div class="grid-stack-item-content bord" id= "'+f+'"></div></div>'),g.x,g.y,g.width,g.height);
},this);c.gridStackData(e);c.portlet(e,"addWidget","","","");},moveWidgets:function(c,a){var b=this,c=GridStackUI.Utils.sort(c,1,b.getWidth());gridstackobj=b.gridStackObjRef();gridstackobj.batchUpdate();$.each(c,function(d,e){el=$("#"+e.id);});gridstackobj.commit();},_gridStackSetColumn:function(b){var c=this,a=c.gridStackObjRef();
c.gridstackColumns=b;a.setGridWidth(b,false);},_updateWidgets:function(d,b){var c=this,a=c.gridStackObjRef();$(".grid-stack").each(function(){var e=$(this).data("gridstack");c.moveWidgets(d,b);});},_addWidget:function(f,e,j,g,g){var i=this,h=i.gridStackObjRef(),d=i.defaultConfigWidget;var a=Ext.applyIf(arguments[0],i.defaultConfigWidget);
var k=a.id+"_outer";var b=a.id+"_inner";var c=$('<div class="grid-stack-item"><div class="grid-stack-item-content"  id="'+b+'"></div></div>');if(typeof a.x!="undefined"){c.attr("data-gs-x",a.x);}if(typeof a.y!="undefined"){c.attr("data-gs-y",a.y);}if(typeof a.width!="undefined"){c.attr("data-gs-width",a.width);
}if(typeof a.height!="undefined"){c.attr("data-gs-height",a.height);}if(typeof a.autoPosition!="undefined"){c.attr("data-gs-auto-position",a.autoPosition?"yes":null);}if(typeof a.minWidth!="undefined"){c.attr("data-gs-min-width",a.minWidth);}if(typeof a.maxWidth!="undefined"){c.attr("data-gs-max-width",a.maxWidth);
}if(typeof a.minHeight!="undefined"){c.attr("data-gs-min-height",a.minHeight);}if(typeof a.maxHeight!="undefined"){c.attr("data-gs-max-height",a.maxHeight);}if(a.noResize){c.attr("data-gs-no-resize",a.noResize);}if(typeof a.id!="undefined"){c.attr("data-gs-id",k);}if(typeof a.id!="undefined"){c.attr("id",k);
}if(typeof e!="undefined"){c.attr("action",e);}if(typeof j!="undefined"){c.attr("widgetTitle",j);}if(typeof g!="undefined"){c.attr("imgIcon",g);}if(typeof a.internalId!="undefined"){c.attr("internalId",a.internalId);}c.data("internalId",a.internalId);i.widgetConfigObj[k]=a;h.addWidget(c);i.gridStackData(a);
},counter:0,widgetAdded:function(){var b=this,a=b.gridStackObjRef(),c=b.defaultConfigWidget;$(".grid-stack").on("added",function(j,f){for(var g=0;g<f.length;g++){var k=$("#"+f[0].id).attr("action");var d=$("#"+f[0].id).attr("widgetTitle");var h=$("#"+f[0].id).attr("imgIcon");var e=f[0];if(b.widgetConfigObj!=null&&b.widgetConfigObj.hasOwnProperty(f[0].id)){e=b.widgetConfigObj[f[0].id];
}f[0].id=f[g].id.replace("_outer","");b.portlet(e,k,d,h,h);}});},widgetRemoved:function(){var a=this;a.removedItems=[],gridStackObj=a.gridStackObjRef();$(".grid-stack").on("removed",function(d,b){for(var c=0;c<b.length;c++){Ext.destroy(Ext.getCmp(b[0].id));a.removedItems.push(b[0]);}});},widgetChanges:function(){var a=this;
$(".grid-stack").on("change",function(c,b){Ext.defer(function(){a.windowResize();},500);});},_removeWidget:function(c){var e=this,b=e.gridStackObjRef(),a=$("#"+c+"_outer"),d=Ext.getCmp(c).getEl();d.ghost("t",{duration:200});b.removeWidget(a,true);},_removeAllWidget:function(){var c=this,b=c.gridStackObjRef();
for(var a in c.data){if(!Ext.isEmpty(Ext.getCmp(c.data[a].id))){Ext.destroy(Ext.getCmp(c.data[a].id));c.data.length=0;}}b.removeAll();},_serialization:function(){var b=this,a=b.gridStackObjRef();b.data=_.map($(".grid-stack > .grid-stack-item:visible"),function(d){d=$(d);var e=d.data("_gridstack_node");
var c=d.attr("id");if(c!=null&&c.indexOf("_outer")>0){c=c.substring(0,c.indexOf("_outer"));}return{dataX:e.x,dataY:e.y,dataWidth:e.width,dataHeight:e.height,id:c};},b);return b.data;},getTBPanelPositions:function(){var g=this;var j="";var f=g._serialization();for(var c in f){var d=f[c];var b=d.dataX;
var a=d.dataY;var i=d.dataWidth;var h=d.dataHeight;var e=d.id;if(e!=null&&e.indexOf("_outer")>0){e=e.substring(0,e.indexOf("_outer"));}j+="|"+e+":"+b+","+a+","+i+","+h;}if(j!=null&&j.indexOf("|")==0){j=j.substring(1);}return j;},_serializationStr:function(){var c=this,a=c.gridStackObjRef();c.data=_.map($(".grid-stack > .grid-stack-item:visible"),function(j){j=$(j);
var k=j.data("_gridstack_node");var l=j.attr("id");if(l!=null&&l.indexOf("_outer")>0){l=l.substring(0,l.indexOf("_outer"));}var h=300;var i=180;var g=l+":"+j[0].dataset["gsX"]+","+j[0].dataset["gsY"]+","+j[0].dataset["gsWidth"]+","+j[0].dataset["gsHeight"]+","+j[0].offsetWidth+","+j[0].offsetHeight;return g;
},c);if(c.data!=null&&c.data.length>0){var f=[];f=c.data;var d="";for(var b in f){var e=f[b];d+="|"+e;}}if(d!=null&&d.indexOf("|")==0){d=d.substring(1);}return d;},_gridstackDestroy:function(){gridStackObjRef.destroy();}});