app.js
35.8 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 a=Ext.get(Ext.query("div.x-msg-error")),b=Ext.get(Ext.query("div.x-msg-trace"));if(b.first().getHeight()+a.first().getHeight()>this.body.getHeight()){b.first().setHeight(this.body.getHeight()-a.first().getHeight())}}},showInfo:function(a){Ext.Msg.show(Ext.apply({autoScroll:true,title:"Info",msg:"",icon:Ext.Msg.INFO,buttons:Ext.Msg.OK},a||{}))},showError:function(a){if(Ext.isObject(a.msg)){if(a.msg.tpl){if(Ext.isArray(a.msg.tpl)||Ext.isString(a.msg.tpl)){a.msg=new Ext.XTemplate(Ext.isArray(a.msg.tpl)?a.msg.tpl.join(""):a.msg.tpl).apply(a.msg.data||{})}else{if(a.msg.tpl.isTemplate){a.msg=a.msg.tpl.apply(a.msg.data||{})}}}else{if(a.msg.error){a.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 == '->'\">{class}->{function}()</tpl>",'<tpl if="args && args.length > 0"><div><b>Arguments:</b> {[ Ext.encode(values.args) ]}</div></tpl>',"</div>","</tpl></div>","</tpl>").apply(a.msg.error)}}}Ext.Msg.show(Ext.apply({autoScroll:true,title:"Error",msg:"",icon:Ext.Msg.ERROR,buttons:Ext.Msg.OK},a||{}))}});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 a=[];Ext.iterate(arguments,function(b){this.push(b)},a);a=a.join("/");a.replace(/^[\/\\]+/,"");return[this.getBaseUrl(),"/index.php/",a].join("")},onComplete:function(f){var d=this,c=f.options,a,i,b;try{a=d.parseStatus(f.xhr.status)}catch(h){a={success:false,isException:false}}i=a.success;if(i){b=d.createResponse(f);d.fireEvent("requestcomplete",d,b,c);Ext.callback(c.success,c.scope,[b,c])}else{if(a.isException||f.aborted||f.timedout){b=d.createException(f)}else{b=d.createResponse(f)}if(Ext.isEmpty(d.getGuest())&&(b.status!=404||b.status!=500)){d.setGuest(true)}else{if(c.proxy&&c.proxy.isProxy){var g=b.responseText?Ext.decode(b.responseText):{};Ext.Msg.showError({title:g.error.title||"Error",msg:{error:g.error},buttons:Ext.Msg.OK})}else{d.fireEvent("requestexception",d,b,c)}Ext.callback(c.failure,c.scope,[b,c])}}if(!Ext.isDefined(d.isGuest)){Ext.callback(c.callback,c.scope,[c,i,b])}delete d.requests[f.id];return b}});Ext.override(Ext.Toolbar,{getValues:function(){var b={},a=this.query("searchfield,textfield,numberfield,checkbox,radio,combo");Ext.each(a,function(c){this[c.name||c.itemId||c.getId()]=c.getValue()},b);return b}});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(d,c){var b=this.getValue();if(c.getKey()===c.ENTER){if(Ext.isFunction(this.handler)){this.handler()}else{if(Ext.isString(this.handler)){var a=this.up("toolbar").query("#"+this.handler);if(a.length>0&&a[0].getXType()=="button"){a[0].fireEvent("click",a[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(a){if(Ext.getBody().getHeight()>500){a.setHeight(Ext.getBody().getHeight()-150)}}},items:[{xtype:"grid",border:false,viewConfig:{plugins:{ptype:"gridviewdragdrop"},listeners:{beforedrop:function(c,e,d,a,b){Ext.each(e.records,function(f){if(f.get("alias")!=this.groupName){f.set("alias",this.groupName);f.save({action:"update",scope:this,failure:function(g){g.store.reload()}})}},{data:e,groupName:this.getFeature("alias-groups").getGroupName(c),model:d})}}},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(a){if(Ext.getBody().getHeight()>500){a.setHeight(Ext.getBody().getHeight()-150)}}},items:[{xtype:"grid",border:false,listeners:{edit:function(a,b){if(b.originalValue==b.value){return}b.record.save({action:"update",scope:b,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(a){if(a==1){return"Yes"}return"No"}},{header:"IMAP",dataIndex:"imap",editor:{xtype:"combo",valueField:"id",displayField:"name",triggerAction:"all",editable:false,store:"Choice"},renderer:function(a){if(a==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(a){if(Ext.getBody().getHeight()>500){a.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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(b){var b=b||{property:"id",value:null},a=-1;if((a=this.find(b.property,b.value,0,false,true,true))>-1){return this.getAt(a)}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(g,a,h,i,f,j,b){if(f.getTarget(".x-ibtn-edit")){var d=j.store.getAt(h);var c=this.getController("Taskpanel").addProgram({name:"user"});c.setTitle("User: "+d.get("name"));c.down("form").getForm().loadRecord(d)}if(f.getTarget(".x-ibtn-delete")){var d=j.store.getAt(h);Ext.Msg.confirm("Info","Press Yes to conform remove action",function(e){if(e==="yes"){this.record.destroy({scope:this,success:function(){this.store.remove(this.record)}})}},{store:j.store,record:d})}},showForm:function(a){this.getController("Taskpanel").addProgram({name:"user",title:"New User"})},onSearch:function(a){this.getUsersList().getStore().reload({params:a.up("toolbar").getValues()})}});Ext.define("MyMA.controller.ProgramMenu",{extend:"Ext.app.Controller",init:function(){this.control({"programmenu > menu":{click:this.LaunchProgram}})},LaunchProgram:function(b,a){if(a.itemId=="logout"){this.getController("Viewport").Logout()}else{this.getController("Taskpanel").addProgram({name:a.widgetName,title:a.text})}}});Ext.define("MyMA.controller.Program",{extend:"Ext.app.Controller",stores:["Programs"],refs:[{selector:"taskpanel",ref:"taskPanel"}],init:function(){var a={};Ext.each(this.refs,function(b){this.control[b.selector]={beforeclose:this.me.programStop,hide:this.me.programState,show:this.me.programState,minimize:this.me.programMinimize}},{control:a,me:this});this.control(a)},registerControl:function(a){var a=a||null,b={};if(!a){return}b[a]={beforeclose:this.programStop,hide:this.programState,show:this.programState,minimize:this.programMinimize};this.control(b)},programMinimize:function(b){var a;if(!(a=this.getStore("Programs").getProccess({property:"item",value:b.getId()}))){return false}this.getTaskPanel().items.get(a.get("control")).toggle(false);b.hide();this.programState(b)},programState:function(c,b){var a;if(!(a=this.getStore("Programs").getProccess({property:"item",value:c.getId()}))){return false}a.set("state",c.isHidden()?"hide":"show")},programStop:function(b,a){var a=a||Ext.undefined;if(!a.data){(a=this.getStore("Programs").getProccess({property:"item",value:b.getId()}))}if(b.animateTarget){b.animateTarget=null}if(a&&a.data){this.getTaskPanel().items.get(a.get("control")).destroy();this.getStore("Programs").remove(a)}}});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(a){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 a=this.getAuthPanel().down("form").getForm();if(a.isValid()){a.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(a){this.isGuest=Ext.isBoolean(a)?a:true;if(this.isGuest&&!this.getAuthPanel()){this.getView("Authorize").create()}},successLogin:function(a,b){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(a){var b=this.getAliasWindow().down("form").getForm(),c=b.getValues().id||null;if(!b.isValid()){return false}b.submit({url:Ext.Ajax.getRestUrl("api","alias",c),clientValidation:true,method:c>0?"PUT":"POST",scope:{controller:this,win:this.getAliasWindow()},success:this.onSuccessSubmit,failure:this.onFailSubmit})},onSuccessSubmit:function(a,b){this.win.close();this.controller.getController("Aliases").getStore("Aliases").reload({params:{start:0}});Ext.Msg.showInfo({msg:"Data saved"})},onFailSubmit:function(a,c){try{var b=Ext.decode(c.response.responseText);throw (b)}catch(d){Ext.Msg.showError({msg:d})}}});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(a){var b=this.getUserWindow().down("form").getForm(),c=b.getValues().id||null;if(!b.isValid()){return false}b.submit({url:Ext.Ajax.getRestUrl("api","user",c),clientValidation:true,method:c>0?"PUT":"POST",params:Ext.applyIf(Ext.copyTo({},b.getValues(),"smtp,imap,manager"),{smtp:0,imap:0,manager:0}),scope:{controller:this,win:this.getUserWindow()},success:this.onSuccessSubmit,failure:this.onFailSubmit})},onSuccessSubmit:function(a,b){this.win.close();this.controller.getController("Users").getStore("Users").reload({params:{start:0}});Ext.Msg.showInfo({msg:"Data saved"})},onFailSubmit:function(a,c){try{var b=Ext.decode(c.response.responseText);throw (b)}catch(d){Ext.Msg.showError({msg:d})}}});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(g,a,h,i,f,j,b){if(f.getTarget(".x-ibtn-edit")){var d=j.store.getAt(h);var c=this.getController("Taskpanel").addProgram({name:"alias"});c.setTitle("Alias: "+d.get("alias"));c.down("form").getForm().loadRecord(d)}if(f.getTarget(".x-ibtn-delete")){var d=j.store.getAt(h);Ext.Msg.confirm("Info","Press Yes to confirm remove action",function(e){if(e==="yes"){this.record.destroy({scope:this,success:function(){this.store.remove(this.record)}})}},{store:j.store,record:d})}},showForm:function(a){this.getController("Taskpanel").addProgram({name:"alias",title:"New Alias"})},onSearch:function(a){this.getAliasesList().getStore().reload({params:a.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(b,g,i,d,h,f,c){if(h.getTarget(".x-ibtn-delete")){var a=f.store.getAt(i);Ext.Msg.confirm("Info","Press Yes to confirm remove action",function(e){if(e==="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:f.store,record:a})}},addRecord:function(a){this.getTransportsList().getStore().insert(0,this.getTransportsList().getStore().model.create({id:0,domain:null,transport:"virtual"}))},onSearch:function(a){this.getTransportsList().getStore().reload({params:a.up("toolbar").getValues()})},onEditAction:function(a,b){b.record.save({scope:b,success:function(c){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(g){var g=g||{name:null},c=this.getStore("Programs"),b,f;if(!(b=c.getProccess({property:"name",value:g.name}))){try{var f=Ext.widget(g.name),d=(c.max("id")||0)+1}catch(h){return false}var a=this.getTaskPanel().add({xtype:"button",ui:"program-button",height:28,text:g.title||f.title,enableToggle:true,pressed:true,programId:d});b=c.add({id:d,title:g.title||f.title,name:g.name,state:"show",item:f.getId(),control:a.getId()})[0];this.getController("Program").registerControl(g.name);f.animateTarget=a.getId();f.setTitle(g.title);f.show()}else{this.getTaskPanel().items.get(b.get("control")).toggle(true);if((f=Ext.getCmp(b.get("item")))){f.show()}}return f?f:null},callRef:function(a){var d=this;try{for(var b=0,c=this.refs.length;b<c;b++){if(this.refs[b]["selector"]==a){return d["get"+Ext.String.capitalize(this.refs[b]["ref"])]()}}}catch(f){}return null},programState:function(b){var c=this.getStore("Programs"),a,d;if(!(a=c.getProccess({property:"id",value:b.programId}))){return false}if((d=Ext.getCmp(a.get("item")))){d[a.get("state")=="show"?"hide":"show"]()}},closeAll:function(){this.getStore("Programs").each(function(a){if((widget=Ext.getCmp(a.get("item")))){widget.hide();this.getTaskPanel().items.get(a.get("control")).destroy()}},this)}});Ext.application({name:"MyMA",controllers:["Viewport","ProgramMenu","Taskpanel","Program","Users","User","Aliases","Alias","Transports"],enableQuickTips:true});