MODx.panel.Messages=function(A){A=A||{};Ext.applyIf(A,{id:"modx-panel-message",url:MODx.config.connectors_url+"security/message.php",layout:"fit",bodyStyle:"background: none;",border:false,items:[{html:"<h2>"+_("messages")+"</h2>",id:"modx-messages-header",cls:"modx-page-header",border:false,autoHeight:true,anchor:"100%"},MODx.getPageStructure([{title:_("messages"),bodyStyle:"padding: 15px;",id:"modx-messages-tab",autoHeight:true,items:[{html:"",id:"modx-messages-msg",border:false},{xtype:"modx-grid-message",user:A.user,preventRender:true}]}],{border:true,defaults:{bodyStyle:"padding: 15px; "}})]});MODx.panel.Messages.superclass.constructor.call(this,A);};Ext.extend(MODx.panel.Messages,MODx.Panel);Ext.reg("modx-panel-messages",MODx.panel.Messages);MODx.grid.Message=function(A){A=A||{};this.exp=new Ext.grid.RowExpander({tpl:new Ext.Template('<span style="float: right;">',"<i>"+_("sent_by")+": {sender_name} <br />"+_("sent_on")+": {postdate}</i><br /><br />","</span>","<h3>{subject}</h3>","<p>{message}</p>")});this.exp.on("expand",this.read,this);Ext.applyIf(A,{title:_("messages"),id:"modx-grid-message",url:MODx.config.connectors_url+"security/message.php",fields:["id","type","subject","message","sender","recipient","private","date_sent","read","sender_name","menu"],autosave:true,paging:true,plugins:this.exp,columns:[this.exp,{header:_("id"),dataIndex:"id",width:60},{header:_("sender"),dataIndex:"sender_name",width:120},{header:_("subject"),dataIndex:"subject",width:200},{header:_("date_sent"),dataIndex:"date_sent",width:150},{header:_("read"),dataIndex:"read",width:100,editor:{xtype:"combo-boolean",renderer:"boolean"},editable:false}],tbar:[{text:_("message_new"),scope:this,handler:{xtype:"modx-window-message-create",blankValues:true}}]});MODx.grid.Message.superclass.constructor.call(this,A);};Ext.extend(MODx.grid.Message,MODx.grid.Grid,{read:function(E,D,A,B){var C=D.data;if(C.read){return false;}MODx.Ajax.request({url:this.config.url,params:{action:"read",id:C.id},listeners:{success:{fn:function(G){var F=this.getStore().getAt(B);F.set("read",true);F.commit();this.exp.expandRow(B);},scope:this}}});},markUnread:function(A,B){var C=this.getSelectionModel().getSelected();MODx.Ajax.request({url:this.config.url,params:{action:"unread",id:C.data.id},listeners:{success:{fn:function(D){C.set("read",false);C.commit();},scope:this}}});}});Ext.reg("modx-grid-message",MODx.grid.Message);MODx.window.CreateMessage=function(A){A=A||{};Ext.applyIf(A,{title:_("message_create"),url:MODx.config.connectors_url+"security/message.php",action:"create",fields:[{xtype:"combo",fieldLabel:_("recipient_type"),name:"type",hiddenName:"type",store:new Ext.data.SimpleStore({fields:["type","disp"],data:[["user",_("user")],["usergroup",_("usergroup")],["role",_("role")],["all",_("all")]]}),mode:"local",triggerAction:"all",displayField:"disp",valueField:"type",editable:false,value:"user",listeners:{select:{fn:this.showRecipient,scope:this}},anchor:"90%"},{xtype:"modx-combo-user",id:"mc-recipient-user",fieldLabel:_("user"),allowBlank:true,anchor:"90%"},{xtype:"modx-combo-usergroup",id:"mc-recipient-usergroup",fieldLabel:_("usergroup"),allowBlank:true,anchor:"90%"},{xtype:"modx-combo-role",id:"mc-recipient-role",fieldLabel:_("role"),allowBlank:true,anchor:"90%"},{xtype:"hidden",id:"mc-recipient-all",name:"all",fieldLabel:_("all"),value:"all"},{xtype:"textfield",fieldLabel:_("subject"),name:"subject",maxLength:255,anchor:"90%"},{xtype:"textarea",fieldLabel:_("message"),name:"message",anchor:"90%",grow:true}],listeners:{show:{fn:this.initRecipient,scope:this}}});MODx.window.CreateMessage.superclass.constructor.call(this,A);this.on("show",function(){this.fp.getForm().findField("type").fireEvent("select");},this);};Ext.extend(MODx.window.CreateMessage,MODx.Window,{tps:["user","usergroup","role","all"],initRecipient:function(){for(var A=1;A<this.tps.length;A++){var B=this.fp.getForm().findField("mc-recipient-"+this.tps[A]);if(B){this.hideField(B);}}},showRecipient:function(B,G,D){for(var A=0;A<this.tps.length;A++){var F=this.fp.getForm().findField("mc-recipient-"+this.tps[A]);if(F){this.hideField(F);}}var E=G?G.data.type:"user";var C=this.fp.getForm().findField("mc-recipient-"+E);if(C){this.showField(C);}}});Ext.reg("modx-window-message-create",MODx.window.CreateMessage);