app.js 36 KB
Ext.override(Ext.Msg,{onShow:function(){this.callParent(arguments);this.center();if(!Ext.isEmpty(Ext.query("div.x-msg-trace"))&&!Ext.isEmpty(Ext.query("div.x-msg-error"))){var d=Ext.get(Ext.query("div.x-msg-error")),c=Ext.get(Ext.query("div.x-msg-trace"));if(c.first().getHeight()+d.first().getHeight()>this.body.getHeight()){c.first().setHeight(this.body.getHeight()-d.first().getHeight());}}},showInfo:function(b){Ext.Msg.show(Ext.apply({autoScroll:true,title:"Info",msg:"",icon:Ext.Msg.INFO,buttons:Ext.Msg.OK},b||{}));},showError:function(b){if(Ext.isObject(b.msg)){if(b.msg.tpl){if(Ext.isArray(b.msg.tpl)||Ext.isString(b.msg.tpl)){b.msg=new Ext.XTemplate(Ext.isArray(b.msg.tpl)?b.msg.tpl.join(""):b.msg.tpl).apply(b.msg.data||{});}else{if(b.msg.tpl.isTemplate){b.msg=b.msg.tpl.apply(b.msg.data||{});}}}else{if(b.msg.error){b.msg=new Ext.XTemplate('<div class="x-msg-error">','<tpl if="code">Error code: {code}<br/></tpl>','<tpl if="type">Error type: {type}<br/></tpl>','Message: <tpl if="message">{message}</tpl><tpl if="!values.message">Unknown error</tpl><br>','<tpl if="file">File: {file}<br/></tpl>','<tpl if="line">Line: {line}<br/></tpl>',"</div>",'<tpl if="traces">','<div class="x-msg-trace"><tpl for="traces">','({line}) {file}: <div class="x-msg-trace-detail">',"<tpl if=\"type == '-&gt;'\">{class}-&gt;{function}()</tpl>",'<tpl if="args && args.length &gt; 0"><div><b>Arguments:</b> {[ Ext.encode(values.args) ]}</div></tpl>',"</div>","</tpl></div>","</tpl>").apply(b.msg.error);}}}Ext.Msg.show(Ext.apply({autoScroll:true,title:"Error",msg:"",icon:Ext.Msg.ERROR,buttons:Ext.Msg.OK},b||{}));}});Ext.override(Ext.data.Connection,{url:".",timeout:380000,setGuest:Ext.emptyFn,getGuest:Ext.emptyFn,getBaseUrl:function(){if(!Ext.isDefined(this.baseUrl)){this.baseUrl=(Ext.query("meta[name=application-url]")[0]||{content:"."}).content;this.baseUrl.replace(/[\/\\]+$/,"");this.url=this.baseUrl;}return this.url;},getRestUrl:function(){var b=[];Ext.iterate(arguments,function(a){this.push(a);},b);b=b.join("/");b.replace(/^[\/\\]+/,"");return[this.getBaseUrl(),"/index.php/",b].join("");},onComplete:function(k){var l=this,m=k.options,o,p,n;try{o=l.parseStatus(k.xhr.status);}catch(e){o={success:false,isException:false};}p=o.success;if(p){n=l.createResponse(k);l.fireEvent("requestcomplete",l,n,m);Ext.callback(m.success,m.scope,[n,m]);}else{if(o.isException||k.aborted||k.timedout){n=l.createException(k);}else{n=l.createResponse(k);}if(Ext.isEmpty(l.getGuest())&&(n.status!=404||n.status!=500)){l.setGuest(true);}else{if(m.proxy&&m.proxy.isProxy){var j=n.responseText?Ext.decode(n.responseText):{};Ext.Msg.showError({title:j.error.title||"Error",msg:{error:j.error},buttons:Ext.Msg.OK});}else{l.fireEvent("requestexception",l,n,m);}Ext.callback(m.failure,m.scope,[n,m]);}}if(!Ext.isDefined(l.isGuest)){Ext.callback(m.callback,m.scope,[m,p,n]);}delete l.requests[k.id];return n;}});Ext.override(Ext.Toolbar,{getValues:function(){var c={},d=this.query("searchfield,textfield,numberfield,checkbox,radio,combo");Ext.each(d,function(a){this[a.name||a.itemId||a.getId()]=a.getValue();},c);return c;}});Ext.define("Ext.form.SearchField",{extend:"Ext.form.field.Text",alias:"widget.searchfield",enableKeyEvents:true,handler:null,initComponent:function(){this.callParent();if(!Ext.isEmpty(this.handler)){this.on("specialkey",this.checkEnterKey,this);}},checkEnterKey:function(e,f){var g=this.getValue();if(f.getKey()===f.ENTER){if(Ext.isFunction(this.handler)){this.handler();}else{if(Ext.isString(this.handler)){var h=this.up("toolbar").query("#"+this.handler);if(h.length>0&&h[0].getXType()=="button"){h[0].fireEvent("click",h[0]);}}}}}});Ext.define("MyMA.view.ProgramMenu",{extend:"Ext.Button",alias:"widget.programmenu",text:"Menu",height:30,ui:"program-menu",menu:[{text:"Users",widgetName:"users"},{text:"Aliases",widgetName:"aliases"},{text:"Transports",widgetName:"transports"},"-",{text:"Logout",itemId:"logout"}]});Ext.define("MyMA.view.Taskpanel",{extend:"Ext.Toolbar",alias:"widget.taskpanel",ui:"programbar",height:28,style:{border:0,padding:0},autoScroll:true,items:[]});Ext.define("MyMA.view.Aliases",{extend:"Ext.window.Window",alias:"widget.aliases",layout:"fit",minimizable:true,constrainHeader:true,closeAction:"destroy",width:900,listeners:{render:function(b){if(Ext.getBody().getHeight()>500){b.setHeight(Ext.getBody().getHeight()-150);}}},items:[{xtype:"grid",border:false,viewConfig:{plugins:{ptype:"gridviewdragdrop"},listeners:{beforedrop:function(g,j,f,i,h){Ext.each(j.records,function(a){if(a.get("alias")!=this.groupName){a.set("alias",this.groupName);a.save({action:"update",scope:this,failure:function(b){b.store.reload();}});}},{data:j,groupName:this.getFeature("alias-groups").getGroupName(g),model:f});}}},tbar:[{xtype:"button",itemId:"addrecord",iconCls:"x-ibtn-add",text:"New Item"},{xtype:"tbseparator",width:5},{xtype:"searchfield",handler:"search",name:"query"},{xtype:"tbspacer",width:5},{xtype:"button",itemId:"search",text:"Search"}],bbar:{xtype:"pagingtoolbar",displayInfo:true,store:"Aliases"},features:[{ftype:"grouping",id:"alias-groups",groupHeaderTpl:"Group: {name} ({rows.length})",startCollapsed:false}],selModel:{selType:"rowmodel"},columns:[{xtype:"actioncolumn",width:30,items:[{getClass:function(){return"x-ibtn-edit x-ibtn-def";}}]},{header:"ID",dataIndex:"id",width:40},{header:"Recipient",dataIndex:"recipient",flex:1},{header:"Alias",hidden:true,dataIndex:"alias"},{header:"Comment",dataIndex:"comment",flex:1},{xtype:"actioncolumn",width:30,items:[{getClass:function(){return"x-ibtn-delete x-ibtn-def";}}]}],selType:"rowmodel",multiSelect:true,store:"Aliases"}]});Ext.define("MyMA.view.Alias",{extend:"Ext.window.Window",alias:"widget.alias",layout:"fit",title:"Alias",width:400,constrainHeader:true,closeAction:"destroy",buttons:[{xtype:"button",itemId:"savedata",text:"Save",scope:this}],items:[{xtype:"form",frame:true,monitorValid:true,defaults:{xtype:"textfield",anchor:"100%",allowBlank:false},items:[{xtype:"hidden",name:"id"},{fieldLabel:"Alias",name:"alias",vtype:"email"},{fieldLabel:"Recipient",name:"recipient",vtype:"email"},{fieldLabel:"Comment",xtype:"textarea",name:"comment"}]}]});Ext.define("MyMA.view.Users",{extend:"Ext.window.Window",alias:"widget.users",layout:"fit",minimizable:true,constrainHeader:true,closeAction:"destroy",width:900,listeners:{render:function(b){if(Ext.getBody().getHeight()>500){b.setHeight(Ext.getBody().getHeight()-150);}}},items:[{xtype:"grid",border:false,listeners:{edit:function(d,c){if(c.originalValue==c.value){return;}c.record.save({action:"update",scope:c,success:function(){this.record.commit();}});}},tbar:[{xtype:"button",iconCls:"x-ibtn-add",itemId:"addrecord",text:"New Item"},{xtype:"tbseparator",width:5},{xtype:"searchfield",handler:"search",name:"query"},{xtype:"tbspacer",width:5},{xtype:"button",itemId:"search",text:"Search"}],bbar:{xtype:"pagingtoolbar",displayInfo:true,store:"Users"},plugins:[Ext.create("Ext.grid.plugin.CellEditing",{clicksToEdit:1})],selModel:{selType:"cellmodel"},columns:[{xtype:"actioncolumn",width:30,items:[{getClass:function(){return"x-ibtn-edit x-ibtn-def";}}]},{header:"ID",dataIndex:"id",width:40},{header:"Name",dataIndex:"name",editor:{xtype:"textfield"},flex:1},{header:"Login",dataIndex:"login",width:120},{header:"Password",hidden:true,dataIndex:"passwd"},{header:"uid",dataIndex:"uid",width:40},{header:"gid",dataIndex:"gid",width:40},{header:"Mail directory",dataIndex:"maildir"},{header:"SMTP",dataIndex:"smtp",editor:{xtype:"combo",valueField:"id",displayField:"name",triggerAction:"all",editable:false,store:"Choice"},renderer:function(b){if(b==1){return"Yes";}return"No";}},{header:"IMAP",dataIndex:"imap",editor:{xtype:"combo",valueField:"id",displayField:"name",triggerAction:"all",editable:false,store:"Choice"},renderer:function(b){if(b==1){return"Yes";}return"No";}},{header:"Quota",dataIndex:"quota",editor:{xtype:"numberfield",allowDecimal:false}},{xtype:"actioncolumn",width:30,items:[{getClass:function(){return"x-ibtn-delete x-ibtn-def";}}]}],store:"Users"}]});Ext.define("MyMA.view.User",{extend:"Ext.window.Window",alias:"widget.user",layout:"fit",title:"User",width:400,constrainHeader:true,closeAction:"destroy",buttons:[{xtype:"button",itemId:"savedata",text:"Save",scope:this}],items:[{xtype:"form",frame:true,monitorValid:true,defaults:{xtype:"textfield",anchor:"100%",allowBlank:false},items:[{xtype:"hidden",name:"id"},{xtype:"checkbox",fieldLabel:"Manager",name:"manager",inputValue:1},{xtype:"checkbox",fieldLabel:"SMTP",name:"smtp",inputValue:1},{xtype:"checkbox",fieldLabel:"IMAP",name:"imap",inputValue:1},{fieldLabel:"Name",name:"name"},{fieldLabel:"Login",name:"login",vtype:"email"},{fieldLabel:"Password",name:"passwd"},{xtype:"numberfield",allowDecimal:false,fieldLabel:"UID",name:"uid",anchor:"50%",value:8},{xtype:"numberfield",allowDecimal:false,fieldLabel:"GID",name:"gid",anchor:"50%",value:12},{fieldLabel:"Mail directory",name:"maildir"},{xtype:"numberfield",name:"quota",allowDecimal:false,fieldLabel:"Quota",anchor:"60%",value:100000000}]}]});Ext.define("MyMA.view.Viewport",{extend:"Ext.container.Viewport",requires:["MyMA.view.ProgramMenu","MyMA.view.Taskpanel","MyMA.view.Users","MyMA.view.Aliases"],layout:"fit",statics:{ready:false},items:{xtype:"panel",layout:"fit",border:false,dockedItems:[{dock:"top",xtype:"toolbar",height:30,ui:"programbar-panel",items:[{xtype:"programmenu",width:100},"-",{xtype:"taskpanel",flex:1}]}],items:[{xtype:"panel",border:false,ui:"desk-panel",bodyCls:"x-desk-panel-bg",layout:{type:"fit"}}]}});Ext.define("MyMA.view.Authorize",{extend:"Ext.Window",alias:"widget.authorize",layout:"fit",autoShow:true,layout:"fit",width:350,closable:false,constrain:true,draggable:false,resizable:false,modal:true,cls:"x-window-authbaner",dockedItems:[{dock:"top",xtype:"toolbar",ui:"authform-baner",height:43,html:"{LOGIN @ MAIL . PANEL }"}],items:[{xtype:"form",url:"index.php",monitorValid:true,frame:false,border:false,defaults:{anchor:"100%"},buttons:[{text:"Login"}],items:[{fieldLabel:"Login",xtype:"textfield",allowBlank:false,name:"login"},{fieldLabel:"Password",xtype:"textfield",name:"pass",inputType:"password"}]}]});Ext.define("MyMA.view.Transports",{extend:"Ext.window.Window",alias:"widget.transports",layout:"fit",minimizable:true,constrainHeader:true,closeAction:"destroy",width:900,listeners:{render:function(b){if(Ext.getBody().getHeight()>500){b.setHeight(Ext.getBody().getHeight()-150);}}},items:[{xtype:"grid",border:false,tbar:[{xtype:"button",itemId:"addrecord",iconCls:"x-ibtn-add",text:"New Item"},{xtype:"tbseparator",width:5},{xtype:"searchfield",handler:"search",name:"query"},{xtype:"tbspacer",width:5},{xtype:"button",itemId:"search",text:"Search"}],bbar:{xtype:"pagingtoolbar",displayInfo:true,store:"Transports"},columns:[{header:"ID",dataIndex:"id",width:40},{header:"Domain",dataIndex:"domain",editor:{xtype:"textfield",allowBlank:false},flex:1},{header:"Transport",dataIndex:"transport"},{xtype:"actioncolumn",width:30,items:[{getClass:function(){return"x-ibtn-delete x-ibtn-def";}}]}],selType:"rowmodel",plugins:[Ext.create("Ext.grid.plugin.RowEditing",{clicksToEdit:1})],store:"Transports"}]});Ext.define("MyMA.model.Users",{extend:"Ext.data.Model",fields:[{name:"id",type:"int"},{name:"name",type:"string"},{name:"login",type:"string"},{name:"passwd",type:"string"},{name:"uid",type:"int",defaultValue:8},{name:"gid",type:"int",defaultValue:12},{name:"maildir",type:"string"},{name:"smtp",type:"int"},{name:"imap",type:"int"},{name:"quota",type:"int",defaultValue:10000000},{name:"manager",type:"int"}],validations:[{type:"format",field:"maildir",matcher:/^\/[a-z]\.ru\/[a-z_0-9]\/Maildir\/$/}],proxy:{type:"rest",url:Ext.Ajax.getRestUrl("api/user"),reader:{type:"json",root:"results"},writer:{type:"json",allowSingle:true}}});Ext.define("MyMA.model.Brief",{extend:"Ext.data.Model",fields:["id","name"],proxy:{type:"memory",reader:{type:"json",root:"results"}}});Ext.define("MyMA.model.Aliases",{extend:"Ext.data.Model",fields:[{name:"id",type:"int"},{name:"alias",type:"string"},{name:"recipient",type:"string"},{name:"comment",type:"string"}],proxy:{type:"rest",url:Ext.Ajax.getRestUrl("api","alias"),reader:{type:"json",root:"results",totalProperty:"total"},writer:{type:"json",allowSingle:true}}});Ext.define("MyMA.model.Transports",{extend:"Ext.data.Model",fields:[{name:"id",type:"int"},{name:"domain",type:"string"},{name:"transport",type:"string"}],proxy:{type:"rest",url:Ext.Ajax.getRestUrl("api","transport"),reader:{type:"json",root:"results",totalProperty:"total"},writer:{type:"json",allowSingle:true}}});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Transports",{extend:"Ext.data.Store",requires:"MyMA.model.Transports",model:"MyMA.model.Transports",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.store.Users",{extend:"Ext.data.Store",requires:"MyMA.model.Users",model:"MyMA.model.Users",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Programs",{extend:"Ext.data.ArrayStore",fields:["id","name","state","item","title","control"],data:[],getProccess:function(c){var c=c||{property:"id",value:null},d=-1;if((d=this.find(c.property,c.value,0,false,true,true))>-1){return this.getAt(d);}return null;}});Ext.define("MyMA.store.Aliases",{extend:"Ext.data.Store",requires:"MyMA.model.Aliases",model:"MyMA.model.Aliases",groupField:"alias",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Transports",{extend:"Ext.data.Store",requires:"MyMA.model.Transports",model:"MyMA.model.Transports",remoteSort:true,pageSize:100});Ext.define("MyMA.store.Choice",{extend:"Ext.data.Store",requires:"MyMA.model.Brief",model:"MyMA.model.Brief",data:[{id:0,name:"No"},{id:1,name:"Yes"}]});Ext.define("MyMA.controller.Users",{extend:"Ext.app.Controller",stores:["Users","Choice"],views:["Users","User"],refs:[{selector:"users > grid",ref:"usersList"},{selector:"users",ref:"usersWindow"}],init:function(){this.control({"users > grid > toolbar > #addrecord":{click:this.showForm},"users > grid > toolbar > #search":{click:this.onSearch},"users actioncolumn":{click:this.onActionColumn}});},onActionColumn:function(m,r,l,k,n,e,q){if(n.getTarget(".x-ibtn-edit")){var o=e.store.getAt(l);var p=this.getController("Taskpanel").addProgram({name:"user"});p.setTitle("User: "+o.get("name"));p.down("form").getForm().loadRecord(o);}if(n.getTarget(".x-ibtn-delete")){var o=e.store.getAt(l);Ext.Msg.confirm("Info","Press Yes to conform remove action",function(a){if(a==="yes"){this.record.destroy({scope:this,success:function(){this.store.remove(this.record);}});}},{store:e.store,record:o});}},showForm:function(b){this.getController("Taskpanel").addProgram({name:"user",title:"New User"});},onSearch:function(b){this.getUsersList().getStore().reload({params:b.up("toolbar").getValues()});}});Ext.define("MyMA.controller.ProgramMenu",{extend:"Ext.app.Controller",init:function(){this.control({"programmenu > menu":{click:this.LaunchProgram}});},LaunchProgram:function(c,d){if(d.itemId=="logout"){this.getController("Viewport").Logout();}else{this.getController("Taskpanel").addProgram({name:d.widgetName,title:d.text});}}});Ext.define("MyMA.controller.Program",{extend:"Ext.app.Controller",stores:["Programs"],refs:[{selector:"taskpanel",ref:"taskPanel"}],init:function(){var b={};Ext.each(this.refs,function(a){this.control[a.selector]={beforeclose:this.me.programStop,hide:this.me.programState,show:this.me.programState,minimize:this.me.programMinimize};},{control:b,me:this});this.control(b);},registerControl:function(d){var d=d||null,c={};if(!d){return;}c[d]={beforeclose:this.programStop,hide:this.programState,show:this.programState,minimize:this.programMinimize};this.control(c);},programMinimize:function(c){var d;if(!(d=this.getStore("Programs").getProccess({property:"item",value:c.getId()}))){return false;}this.getTaskPanel().items.get(d.get("control")).toggle(false);c.hide();this.programState(c);},programState:function(e,f){var d;if(!(d=this.getStore("Programs").getProccess({property:"item",value:e.getId()}))){return false;}d.set("state",e.isHidden()?"hide":"show");},programStop:function(c,d){var d=d||Ext.undefined;if(!d.data){(d=this.getStore("Programs").getProccess({property:"item",value:c.getId()}));}if(c.animateTarget){c.animateTarget=null;}if(d&&d.data){this.getTaskPanel().items.get(d.get("control")).destroy();this.getStore("Programs").remove(d);}}});Ext.define("MyMA.controller.Viewport",{extend:"Ext.app.Controller",views:["Viewport","Authorize"],refs:[{selector:"viewport",ref:"appView"},{selector:"authorize",ref:"authPanel"},{selector:"authorize > form",ref:"authForm"}],isGuest:Ext.undefined,init:function(b){Ext.override(Ext.data.Connection,{setGuest:Ext.Function.bind(this.setGuest,this),getGuest:Ext.Function.bind(this.getGuest,this)});this.control({"authorize > form > toolbar > button":{click:this.Authorize}});this.Authorize();},Authorize:function(){if(this.getAuthPanel()){var b=this.getAuthPanel().down("form").getForm();if(b.isValid()){b.submit({url:Ext.Ajax.getRestUrl("api","login","authorize",0),method:"PUT",clientValidation:true,scope:this,success:this.successLogin});}}else{Ext.Ajax.request({url:Ext.Ajax.getRestUrl("api","login"),scope:this,callback:function(){if(!this.isGuest&&!this.getAppView()){this.setGuest(false);this.getView("Viewport").create();}}});}},getGuest:function(){return this.isGuest;},setGuest:function(b){this.isGuest=Ext.isBoolean(b)?b:true;if(this.isGuest&&!this.getAuthPanel()){this.getView("Authorize").create();}},successLogin:function(d,c){this.getAuthPanel().close();if(!this.getAppView()){this.getView("Viewport").create();}},Logout:function(){Ext.Ajax.request({url:Ext.Ajax.getRestUrl("api","login","logout",0),method:"PUT",scope:this,callback:function(){if(this.getAppView()){this.getController("Taskpanel").closeAll();this.getAppView().destroy();}this.setGuest(this,true);}});}});Ext.define("MyMA.controller.Alias",{extend:"Ext.app.Controller",views:["Alias"],refs:[{selector:"alias",ref:"aliasWindow"}],init:function(){this.control({"alias > toolbar > #savedata":{click:this.saveData}});},saveData:function(d){var f=this.getAliasWindow().down("form").getForm(),e=f.getValues().id||null;if(!f.isValid()){return false;}f.submit({url:Ext.Ajax.getRestUrl("api","alias",e),clientValidation:true,method:e>0?"PUT":"POST",scope:{controller:this,win:this.getAliasWindow()},success:this.onSuccessSubmit,failure:this.onFailSubmit});},onSuccessSubmit:function(d,c){this.win.close();this.controller.getController("Aliases").getStore("Aliases").reload({params:{start:0}});Ext.Msg.showInfo({msg:"Data saved"});},onFailSubmit:function(h,f){try{var g=Ext.decode(f.response.responseText);throw (g);}catch(e){Ext.Msg.showError({msg:e});}}});Ext.define("MyMA.controller.User",{extend:"Ext.app.Controller",views:["User"],refs:[{selector:"user",ref:"userWindow"}],init:function(){this.control({"user > toolbar > #savedata":{click:this.saveData}});},saveData:function(d){var f=this.getUserWindow().down("form").getForm(),e=f.getValues().id||null;if(!f.isValid()){return false;}f.submit({url:Ext.Ajax.getRestUrl("api","user",e),clientValidation:true,method:e>0?"PUT":"POST",params:Ext.applyIf(Ext.copyTo({},f.getValues(),"smtp,imap,manager"),{smtp:0,imap:0,manager:0}),scope:{controller:this,win:this.getUserWindow()},success:this.onSuccessSubmit,failure:this.onFailSubmit});},onSuccessSubmit:function(d,c){this.win.close();this.controller.getController("Users").getStore("Users").reload({params:{start:0}});Ext.Msg.showInfo({msg:"Data saved"});},onFailSubmit:function(h,f){try{var g=Ext.decode(f.response.responseText);throw (g);}catch(e){Ext.Msg.showError({msg:e});}}});Ext.define("MyMA.controller.Aliases",{extend:"Ext.app.Controller",stores:["Aliases"],views:["Aliases","Alias"],refs:[{selector:"aliases > grid",ref:"aliasesList"}],init:function(){this.control({"aliases > grid > toolbar > #addrecord":{click:this.showForm},"aliases > grid > toolbar > #search":{click:this.onSearch},"aliases actioncolumn":{click:this.onActionColumn}});},onActionColumn:function(m,r,l,k,n,e,q){if(n.getTarget(".x-ibtn-edit")){var o=e.store.getAt(l);var p=this.getController("Taskpanel").addProgram({name:"alias"});p.setTitle("Alias: "+o.get("alias"));p.down("form").getForm().loadRecord(o);}if(n.getTarget(".x-ibtn-delete")){var o=e.store.getAt(l);Ext.Msg.confirm("Info","Press Yes to confirm remove action",function(a){if(a==="yes"){this.record.destroy({scope:this,success:function(){this.store.remove(this.record);}});}},{store:e.store,record:o});}},showForm:function(b){this.getController("Taskpanel").addProgram({name:"alias",title:"New Alias"});},onSearch:function(b){this.getAliasesList().getStore().reload({params:b.up("toolbar").getValues()});}});Ext.define("MyMA.controller.Transports",{extend:"Ext.app.Controller",stores:["Transports"],views:["Transports"],refs:[{selector:"transports > grid",ref:"transportsList"}],init:function(){this.control({"transports > grid > toolbar > #addrecord":{click:this.addRecord},"transports > grid > toolbar > #search":{click:this.onSearch},"transports actioncolumn":{click:this.onActionColumn},"transports > grid":{edit:this.onEditAction}});},onActionColumn:function(m,j,p,l,e,k,n){if(e.getTarget(".x-ibtn-delete")){var o=k.store.getAt(p);Ext.Msg.confirm("Info","Press Yes to confirm remove action",function(a){if(a==="yes"){if(!this.record.get("id")){this.store.remove(this.record);}else{this.record.destroy({scope:this,success:function(){this.store.remove(this.record);}});}}},{store:k.store,record:o});}},addRecord:function(b){this.getTransportsList().getStore().insert(0,this.getTransportsList().getStore().model.create({id:0,domain:null,transport:"virtual"}));},onSearch:function(b){this.getTransportsList().getStore().reload({params:b.up("toolbar").getValues()});},onEditAction:function(d,c){c.record.save({scope:c,success:function(a){this.store.reload();}});}});Ext.define("MyMA.controller.Taskpanel",{extend:"Ext.app.Controller",stores:["Programs"],refs:[{selector:"taskpanel",ref:"taskPanel"}],init:function(){this.control({"taskpanel > button":{toggle:this.programState}});},addProgram:function(n){var n=n||{name:null},j=this.getStore("Programs"),k,e;if(!(k=j.getProccess({property:"name",value:n.name}))){try{var e=Ext.widget(n.name),i=(j.max("id")||0)+1;}catch(m){return false;}var l=this.getTaskPanel().add({xtype:"button",ui:"program-button",height:28,text:n.title||e.title,enableToggle:true,pressed:true,programId:i});k=j.add({id:i,title:n.title||e.title,name:n.name,state:"show",item:e.getId(),control:l.getId()})[0];this.getController("Program").registerControl(n.name);e.animateTarget=l.getId();e.setTitle(n.title);e.show();}else{this.getTaskPanel().items.get(k.get("control")).toggle(true);if((e=Ext.getCmp(k.get("item")))){e.show();}}return e?e:null;},callRef:function(i){var e=this;try{for(var h=0,g=this.refs.length;h<g;h++){if(this.refs[h]["selector"]==i){return e["get"+Ext.String.capitalize(this.refs[h]["ref"])]();}}}catch(j){}return null;},programState:function(g){var f=this.getStore("Programs"),h,e;if(!(h=f.getProccess({property:"id",value:g.programId}))){return false;}if((e=Ext.getCmp(h.get("item")))){e[h.get("state")=="show"?"hide":"show"]();}},closeAll:function(){this.getStore("Programs").each(function(b){if((widget=Ext.getCmp(b.get("item")))){widget.hide();this.getTaskPanel().items.get(b.get("control")).destroy();}},this);}});Ext.application({name:"MyMA",controllers:["Viewport","ProgramMenu","Taskpanel","Program","Users","User","Aliases","Alias","Transports"],enableQuickTips:true});