MailTemplateList.php
[Pman.Core] / Pman.Dialog.CoreMailingListMessage.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.CoreMailingListMessage = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             listeners : {
34                 show : function (_self)
35                 {
36                     
37                     _self.layout.getRegion('center').showPanel(0);
38                     var w = Roo.lib.Dom.getViewWidth();\r
39                     var h = Roo.lib.Dom.getViewHeight();    \r    this.resizeTo(w-50, h-50);\r
40                     this.center();\r    
41                     var ew = Math.max(250, w-320);\r
42                     var eh = Math.max(250, h-350) ;\r
43                     var e = _this.dialog.layout.getRegion('east');
44                     if (e.visible) {
45                         e.hide();
46                     }
47                     
48                     var el = _self.getEl();
49                     var elw = el.dom.clientWidth;
50                     
51                     var bdtext = _this.form.findField('bodytext');
52                     var ptext = _this.form.findField('plaintext');
53                     if(bdtext.resizeEl){
54                         bdtext.width = elw-100;
55                         bdtext.resizeEl.resizeTo.defer(110, bdtext.resizeEl,[ bdtext.width, bdtext.height  ] );
56                         ptext.setSize(bdtext.width , bdtext.height);
57                     }
58                     
59                 }
60             },
61             closable : true,
62             collapsible : false,
63             height : 500,
64             modal : true,
65             resizable : true,
66             title : "Edit / Create Message",
67             width : 800,
68             items : [
69                 {
70                     xtype: 'NestedLayoutPanel',
71                     xns: Roo,
72                     autoScroll : false,
73                     fitContainer : true,
74                     fitToFrame : true,
75                     region : 'center',
76                     toolbar : {
77                         xtype: 'Toolbar',
78                         xns: Roo,
79                         items : [
80                             {
81                                 xtype: 'Button',
82                                 xns: Roo.Toolbar,
83                                 text : "Import",
84                                 menu : {
85                                     xtype: 'Menu',
86                                     xns: Roo.menu,
87                                     items : [
88                                         {
89                                             xtype: 'Item',
90                                             xns: Roo.menu,
91                                             listeners : {
92                                                 click : function (_self, e)
93                                                 {
94                                                     Pman.Dialog.CoreImportUrl.show({
95                                                         target : '/Crm/ImportHtml.php'
96                                                     }, function(data) {
97                                                         if  (data) {
98                                                           //  Roo.log(data);
99                                                             _this.form.findField('bodytext').setValue(data);
100                                                         }
101                                                     });
102                                                 }
103                                             },
104                                             text : "URL"
105                                         },
106                                         {
107                                             xtype: 'Item',
108                                             xns: Roo.menu,
109                                             listeners : {
110                                                 click : function (_self, e)
111                                                 {
112                                                     Pman.Dialog.Image.show({
113                                                         _url : baseURL + '/Crm/ImportHtml.php'
114                                                     }, function(data) {
115                                                         if  (data) {
116                                                             _this.form.findField('bodytext').setValue(data);
117                                                         }
118                                                     });
119                                                 }
120                                             },
121                                             text : "Html File"
122                                         }
123                                     ]
124                                 }
125                             },
126                             {
127                                 xtype: 'Button',
128                                 xns: Roo.Toolbar,
129                                 text : "Use template",
130                                 menu : {
131                                     xtype: 'Menu',
132                                     xns: Roo.menu,
133                                     items : [
134                                         {
135                                             xtype: 'Item',
136                                             xns: Roo.menu,
137                                             listeners : {
138                                                 click : function (_self, e)
139                                                 {
140                                                 
141                                                     var l = document.location;
142                                                     new Pman.Request({
143                                                 
144                                                         url : baseURL + '/Crm/ImportHtml.php',
145                                                 
146                                                         method: 'POST',
147                                                         mask : "Loading",
148                                                         params : {
149                                                               importUrl : l.protocol +'//' + l.host +   rootURL + '/Pman/Crm/mail_templates/responsive1.html',
150                                                        },
151                                                         success : function (res) {
152                                                 
153                                                          _this.form.findField('bodytext').setValue(res.data);
154                                                         }
155                                                   
156                                                     });
157                                                 }
158                                             },
159                                             text : "Responsive Email (1)"
160                                         }
161                                     ]
162                                 }
163                             },
164                             {
165                                 xtype: 'ComboBox',
166                                 xns: Roo.form,
167                                 allowBlank : true,
168                                 alwaysQuery : true,
169                                 displayField : 'name',
170                                 editable : false,
171                                 emptyText : "Select Template",
172                                 fieldLabel : 'Template',
173                                 forceSelection : true,
174                                 hiddenName : 'template',
175                                 listWidth : 400,
176                                 loadingText : "Searching...",
177                                 minChars : 2,
178                                 name : 'template',
179                                 pageSize : 20,
180                                 qtip : "Select Template",
181                                 selectOnFocus : true,
182                                 tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
183                                 triggerAction : 'all',
184                                 typeAhead : true,
185                                 valueField : 'name',
186                                 width : 200,
187                                 store : {
188                                     xtype: 'Store',
189                                     xns: Roo.data,
190                                     listeners : {
191                                         beforeload : function (_self, o){
192                                             o.params = o.params || {};
193                                             // set more here
194                                            
195                                         }
196                                     },
197                                     remoteSort : true,
198                                     sortInfo : { direction : 'DESC', field: 'name' },
199                                     proxy : {
200                                         xtype: 'HttpProxy',
201                                         xns: Roo.data,
202                                         method : 'GET',
203                                         url : baseURL + '/Core/MailTemplateList.php'
204                                     },
205                                     reader : {
206                                         xtype: 'JsonReader',
207                                         xns: Roo.data,
208                                         id : 'name',
209                                         root : 'data',
210                                         totalProperty : 'total',
211                                         fields : [{"name":"name","type":"string"},{"name":"body","type":"string"}]
212                                     }
213                                 }
214                             },
215                             {
216                                 xtype: 'Fill',
217                                 xns: Roo.Toolbar
218                             },
219                             {
220                                 xtype: 'Button',
221                                 xns: Roo.Toolbar,
222                                 listeners : {
223                                     click : function (_self, e)
224                                     {
225                                         var el = _this.dialog.layout.getRegion('east');
226                                         if (el.visible) {
227                                             el.hide();
228                                         } else {
229                                             el.show();
230                                             el.showPanel(0);
231                                         }
232                                         
233                                     }
234                                 },
235                                 text : "Images / Attachments >>"
236                             }
237                         ]
238                     },
239                     layout : {
240                         xtype: 'BorderLayout',
241                         xns: Roo,
242                         items : [
243                             {
244                                 xtype: 'ContentPanel',
245                                 xns: Roo,
246                                 listeners : {
247                                     render : function (_self, width, height)
248                                     {
249                                         
250                                           Roo.log("RESIZE, " + width + ',' + height);
251                                         
252                                         var ew = Math.max(250, width-50);
253                                         var eh = Math.max(250,height-50) ;
254                                         
255                                        
256                                     
257                                     },
258                                     resize : function (_self, width, height)\r
259                                     {\r
260                                        var ew = Math.max(250, width-50);\r
261                                         var eh = Math.max(250,height-50) ;
262                                         
263                                         if (!_this.form) {\r
264                                             return;\r
265                                         }\r
266                                         var bdtext = _this.form.findField('bodytext');\r
267                                         var ptext = _this.form.findField('plaintext');\r
268                                         if(bdtext.resizeEl){\r
269                                             bdtext.width = ew-50;\r
270                                             bdtext.resizeEl.resizeTo.defer(110, bdtext.resizeEl,[ bdtext.width, bdtext.height  ] );\r
271                                             ptext.setSize(bdtext.width , bdtext.height);\r
272                                         }\r\r
273                                     \r
274                                     }
275                                 },
276                                 autoScroll : false,
277                                 background : false,
278                                 fitContainer : true,
279                                 fitToFrame : true,
280                                 region : 'center',
281                                 title : "Message",
282                                 items : [
283                                     {
284                                         xtype: 'Form',
285                                         xns: Roo.form,
286                                         listeners : {
287                                             actioncomplete : function(_self,action)
288                                             {
289                                                
290                                                 if (action.type == 'setdata') {
291                                                    // _this.loaded_data = _this.form.getValues();
292                                             
293                                                     if(_this.data.id*1 > 0){
294                                                         _this.dialog.el.mask("Loading");
295                                                         this.load({ method: 'GET', params: { '_id' : _this.data.id }});
296                                                         _this.html_preview.show();
297                                                         _this.preview_btn.show();
298                                                     } else {
299                                                         _this.html_preview.hide();
300                                                         _this.preview_btn.hide();
301                                                         _this.form.setValues({
302                                                             'from_name' : Pman.Login.authUser.name,
303                                                             'from_email' : Pman.Login.authUser.email
304                                                         });
305                                                     }
306                                                    return;
307                                                 }
308                                                 if (action.type == 'load') {
309                                                     _this.dialog.el.unmask();
310                                                     return;
311                                                 }
312                                                 if (action.type =='submit') {
313                                                 
314                                                     _this.dialog.el.unmask();
315                                                     _this.dialog.hide();
316                                                 
317                                                      if (_this.callback) {
318                                                         _this.callback.call(_this, action.result.data);
319                                                      }
320                                                      _this.form.reset();
321                                                      return;
322                                                 }
323                                             },
324                                             rendered : function (form)
325                                             {
326                                                 _this.form= form;
327                                             }
328                                         },
329                                         labelAlign : 'right',
330                                         labelWidth : 120,
331                                         method : 'POST',
332                                         style : 'margin:10px',
333                                         preValidate : function(done_callback) {
334                                             
335                                             Roo.MessageBox.progress("Uploading Images", "Uploading");
336                                             var html = _this.form.findField('bodytext').getValue();
337                                             
338                                             var s = Roo.get(_this.form.findField('bodytext').doc.documentElement);
339                                             
340                                             var nodes = [];
341                                             s.select('img[src]').each(function(i) {
342                                                 nodes.push(i.dom);
343                                             });
344                                             var total = nodes.length;
345                                             var mkimg = function() {
346                                             
347                                                 if (!nodes.length) {
348                                                       Roo.MessageBox.hide();
349                                                       _this.form.findField('bodytext').syncValue();
350                                                       done_callback(true);
351                                                    //    _this.form.doAction("submit");
352                                                       return;
353                                                 }
354                                                 var i = nodes.pop();        
355                                                 var n = i.getAttribute('src').match(/^http(.*)/);
356                                                 if(!n ){
357                                                     mkimg();
358                                                     return;
359                                                 }
360                                                 
361                                                 new Pman.Request({
362                                                     url : baseURL + '/Roo/Images.php',
363                                                     method : 'POST',
364                                                     params : {
365                                                         onid : _this.form.findField('id').getValue(),
366                                                         ontable : 'core_mailing_list_message' ,
367                                                         _remote_upload : i.src
368                                                     },
369                                                     success : function(res){
370                                                         if(res.success == true){      
371                                                             i.setAttribute('src', res.data);
372                                                             Roo.MessageBox.updateProgress( (total - nodes.length) / total , "Done " + (total - nodes.length) + '/' + total);
373                                                         }
374                                                         mkimg();
375                                                     }
376                                                 });
377                                                
378                                             }
379                                             mkimg();
380                                         },
381                                         url : baseURL + '/Roo/Core_mailing_list_message.php',
382                                         items : [
383                                             {
384                                                 xtype: 'Row',
385                                                 xns: Roo.form,
386                                                 items : [
387                                                     {
388                                                         xtype: 'TextField',
389                                                         xns: Roo.form,
390                                                         allowBlank : false,
391                                                         fieldLabel : 'Mailout Name',
392                                                         name : 'name',
393                                                         width : 400
394                                                     }
395                                                 ]
396                                             },
397                                             {
398                                                 xtype: 'Row',
399                                                 xns: Roo.form,
400                                                 items : [
401                                                     {
402                                                         xtype: 'TextField',
403                                                         xns: Roo.form,
404                                                         allowBlank : false,
405                                                         fieldLabel : 'From',
406                                                         name : 'from_name',
407                                                         width : 300
408                                                     },
409                                                     {
410                                                         xtype: 'TextField',
411                                                         xns: Roo.form,
412                                                         allowBlank : false,
413                                                         fieldLabel : 'Email address',
414                                                         name : 'from_email',
415                                                         width : 300
416                                                     }
417                                                 ]
418                                             },
419                                             {
420                                                 xtype: 'TextField',
421                                                 xns: Roo.form,
422                                                 allowBlank : false,
423                                                 fieldLabel : 'Subject',
424                                                 name : 'subject',
425                                                 width : 600
426                                             },
427                                             {
428                                                 xtype: 'Row',
429                                                 xns: Roo.form,
430                                                 hideLabels : true,
431                                                 items : [
432                                                     {
433                                                         xtype: 'FieldSet',
434                                                         xns: Roo.form,
435                                                         hideLabels : true,
436                                                         legend : "Html Editor",
437                                                         style : 'text-align:center;',
438                                                         items : [
439                                                             {
440                                                                 xtype: 'HtmlEditor',
441                                                                 xns: Roo.form,
442                                                                 height : 250,
443                                                                 name : 'bodytext',
444                                                                 resizable : 's',
445                                                                 cwhite : [ 
446                                                                     'margin',
447                                                                     'padding',
448                                                                     'text-align',
449                                                                     'background',
450                                                                     'height',
451                                                                     'width',
452                                                                     'background-color',
453                                                                     'font-size',
454                                                                     'line-height',
455                                                                     'color',
456                                                                     'outline',
457                                                                     'text-decoration',
458                                                                     'position',
459                                                                     'clear',
460                                                                     'overflow',
461                                                                     'margin-top',
462                                                                     'border-bottom',
463                                                                     'top',
464                                                                     'list-style',
465                                                                     'margin-left',
466                                                                     'border',
467                                                                     'float' ,
468                                                                     'margin-right',
469                                                                     'padding-top',
470                                                                     'min-height',
471                                                                     'left',
472                                                                     'padding-left',
473                                                                     'font-weight',
474                                                                     'font-family',
475                                                                     'display',
476                                                                     'margin-bottom',
477                                                                     'padding-bottom',
478                                                                     'vertical-align',
479                                                                     'cursor',
480                                                                     'z-index',
481                                                                     'right',
482                                                                  ],
483                                                                 toolbars : [
484                                                                     {
485                                                                         xtype: 'ToolbarContext',
486                                                                         xns: Roo.form.HtmlEditor
487                                                                     },
488                                                                     {
489                                                                         xtype: 'ToolbarStandard',
490                                                                         xns: Roo.form.HtmlEditor,
491                                                                         btns : [
492                                                                             {
493                                                                                 xtype: 'ComboBox',
494                                                                                 xns: Roo.form,
495                                                                                 listeners : {
496                                                                                     render : function (_self)
497                                                                                     {
498                                                                                         _this.extendimgselect = _self;
499                                                                                     },
500                                                                                     select : function (combo, record, index)
501                                                                                     {
502                                                                                         Roo.log(record);
503                                                                                         (function() { 
504                                                                                             combo.setValue('');
505                                                                                         }).defer(100);
506                                                                                         var editor = _this.form.findField('bodytext');
507                                                                                         editor.insertAtCursor(
508                                                                                                 String.format('<img src="{0}/Images/{1}/{2}#image-{1}">',
509                                                                                                 baseURL,  record.data.id, record.data.filename
510                                                                                                 )
511                                                                                          );
512                                                                                     
513                                                                                         
514                                                                                      },
515                                                                                     beforequery : function (combo, query, forceAll, cancel, e)
516                                                                                     {
517                                                                                         var id = _this.form.findField('id').getValue() * 1;    
518                                                                                         if (!id) {
519                                                                                             Roo.MessageBox.alert("Error", "Save email template first");
520                                                                                             return false;
521                                                                                         }
522                                                                                     }
523                                                                                 },
524                                                                                 alwaysQuery : true,
525                                                                                 displayField : 'name',
526                                                                                 editable : false,
527                                                                                 emptyText : "Add Image",
528                                                                                 fieldLabel : 'Images',
529                                                                                 forceSelection : true,
530                                                                                 listWidth : 400,
531                                                                                 loadingText : "Searching...",
532                                                                                 minChars : 2,
533                                                                                 pageSize : 20,
534                                                                                 qtip : "Select Images",
535                                                                                 selectOnFocus : true,
536                                                                                 tpl : '<div class="x-grid-cell-text x-btn button"><img src="{public_baseURL}/Core/Images/Thumb/150x150/{id}.jpg" height="150" width="150"><b>{filename}</b> </div>',
537                                                                                 triggerAction : 'all',
538                                                                                 typeAhead : true,
539                                                                                 valueField : 'id',
540                                                                                 width : 100,
541                                                                                 store : {
542                                                                                     xtype: 'Store',
543                                                                                     xns: Roo.data,
544                                                                                     listeners : {
545                                                                                         beforeload : function (_self, o){
546                                                                                             o.params = o.params || {};
547                                                                                         
548                                                                                             var id = _this.form.findField('id').getValue() * 1;    
549                                                                                             if (!id) {
550                                                                                                 Roo.MessageBox.alert("Error", "Save email template first");
551                                                                                                 return false;
552                                                                                             }
553                                                                                             o.params.onid = id
554                                                                                             o.params.ontable = 'core_mailing_list_message';
555                                                                                             
556                                                                                            // o.params.imgtype = 'PressRelease';
557                                                                                             //o.params['query[imagesize]'] = '150x150';
558                                                                                             // set more here
559                                                                                         }
560                                                                                     },
561                                                                                     remoteSort : true,
562                                                                                     sortInfo : { direction : 'ASC', field: 'id' },
563                                                                                     proxy : {
564                                                                                         xtype: 'HttpProxy',
565                                                                                         xns: Roo.data,
566                                                                                         method : 'GET',
567                                                                                         url : baseURL + '/Roo/Images.php'
568                                                                                     },
569                                                                                     reader : {
570                                                                                         xtype: 'JsonReader',
571                                                                                         xns: Roo.data,
572                                                                                         id : 'id',
573                                                                                         root : 'data',
574                                                                                         totalProperty : 'total',
575                                                                                         fields : [{"name":"id","type":"int"},{"name":"filename","type":"string"},{"name":"url_thumb","type":"string"}]
576                                                                                     }
577                                                                                 }
578                                                                             },
579                                                                             {
580                                                                                 xtype: 'ComboBox',
581                                                                                 xns: Roo.form,
582                                                                                 listeners : {
583                                                                                     render : function (_self)
584                                                                                     {
585                                                                                         _this.unsubscribeselect = _self;
586                                                                                     },
587                                                                                     select : function (combo, record, index)
588                                                                                     {
589                                                                                         Roo.log(record);
590                                                                                         (function() { 
591                                                                                             combo.setValue('');
592                                                                                         }).defer(100);
593                                                                                         var editor = _this.form.findField('bodytext');
594                                                                                         
595                                                                                         if(record.data.name == 'Unsubscribe'){
596                                                                                             editor.insertAtCursor(
597                                                                                                 String.format('<a href="{0}">{1}</a>',
598                                                                                                     record.data.type,  record.data.name
599                                                                                                 )
600                                                                                             );
601                                                                                             return;     
602                                                                                         }
603                                                                                         
604                                                                                         editor.insertAtCursor(
605                                                                                             String.format('{0}',
606                                                                                                 record.data.type
607                                                                                             )
608                                                                                         );
609                                                                                         
610                                                                                      }
611                                                                                 },
612                                                                                 alwaysQuery : true,
613                                                                                 displayField : 'name',
614                                                                                 editable : false,
615                                                                                 emptyText : "Insert Field",
616                                                                                 fieldLabel : 'Field',
617                                                                                 forceSelection : true,
618                                                                                 listWidth : 400,
619                                                                                 loadingText : "Searching...",
620                                                                                 minChars : 2,
621                                                                                 pageSize : 20,
622                                                                                 qtip : "Insert Field",
623                                                                                 selectOnFocus : true,
624                                                                                 tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
625                                                                                 triggerAction : 'all',
626                                                                                 typeAhead : true,
627                                                                                 valueField : 'type',
628                                                                                 width : 100,
629                                                                                 store : {
630                                                                                     xtype: 'SimpleStore',
631                                                                                     xns: Roo.data,
632                                                                                     data : [ 
633                                                                                         [ '{person.firstname}', "First Name"],
634                                                                                         [ '{person.lastname}' , "Last Name"],
635                                                                                         [ '{person.name}', "Full Name"],
636                                                                                         [ '#unsubscribe', "Unsubscribe"]
637                                                                                     ],
638                                                                                     fields : [  'type', 'name']
639                                                                                 }
640                                                                             }
641                                                                         ]
642                                                                     }
643                                                                 ]
644                                                             }
645                                                         ]
646                                                     }
647                                                 ]
648                                             },
649                                             {
650                                                 xtype: 'Row',
651                                                 xns: Roo.form,
652                                                 hideLabels : true,
653                                                 items : [
654                                                     {
655                                                         xtype: 'Button',
656                                                         xns: Roo,
657                                                         listeners : {
658                                                             click : function (_self, e)
659                                                             {
660                                                                 var h = _this.form.findField('bodytext').getValue();
661                                                                 var p = _this.form.findField('plaintext');
662                                                                 
663                                                                 new Pman.Request({\r
664                                                                     url : baseURL + '/Crm/ImportHtml.php',\r
665                                                                     method : 'POST',\r
666                                                                     params : {
667                                                                       bodytext : h,\r
668                                                                       _convertToPlain : true,
669                                                                       _check_unsubscribe : true\r
670                                                                     }, \r
671                                                                     success : function(res) {\r
672                                                                         if(res.success == true){
673                                                                            p.setValue(res.data);
674                                                                         }\r
675                                                                     }\r
676                                                                 });  
677                                                                 
678                                                             }
679                                                         },
680                                                         text : "Convert Html to Text"
681                                                     }
682                                                 ]
683                                             },
684                                             {
685                                                 xtype: 'Row',
686                                                 xns: Roo.form,
687                                                 hideLabels : true,
688                                                 items : [
689                                                     {
690                                                         xtype: 'FieldSet',
691                                                         xns: Roo.form,
692                                                         hideLabels : true,
693                                                         legend : "Plain Text",
694                                                         style : 'text-align:center;',
695                                                         items : [
696                                                             {
697                                                                 xtype: 'TextArea',
698                                                                 xns: Roo.form,
699                                                                 height : 50,
700                                                                 name : 'plaintext'
701                                                             }
702                                                         ]
703                                                     }
704                                                 ]
705                                             },
706                                             {
707                                                 xtype: 'Hidden',
708                                                 xns: Roo.form,
709                                                 name : 'id'
710                                             }
711                                         ]
712                                     }
713                                 ]
714                             }
715                         ],
716                         center : {
717                             xtype: 'LayoutRegion',
718                             xns: Roo,
719                             autoScroll : true
720                         }
721                     }
722                 },
723                 {
724                     xtype: 'GridPanel',
725                     xns: Roo,
726                     listeners : {
727                         activate : function() {
728                             _this.ipanel = this;
729                             if (_this.igrid) {
730                                _this.igrid.ds.load({});
731                             }
732                         }
733                     },
734                     autoScroll : false,
735                     background : false,
736                     fitContainer : true,
737                     fitToframe : true,
738                     region : 'east',
739                     tableName : 'Images',
740                     title : "Images / Attachments",
741                     grid : {
742                         xtype: 'Grid',
743                         xns: Roo.grid,
744                         listeners : {
745                             render : function() 
746                             {
747                                 _this.igrid = this; 
748                                 //_this.dialog = Pman.Dialog.FILL_IN
749                                 if (_this.ipanel.active) {
750                                //    _this.igrid.ds.load({});
751                                 }
752                             }
753                         },
754                         autoExpandColumn : 'filename',
755                         loadMask : true,
756                         dataSource : {
757                             xtype: 'Store',
758                             xns: Roo.data,
759                             listeners : {
760                                 beforeload : function (_self, options)
761                                 {
762                                     options.params = options.params || {};
763                                     if (typeof(_this.data) == 'undefined') {
764                                         return false;
765                                     }
766                                     if(_this.data.id * 1 >= 0)
767                                     {
768                                         options.params.onid = _this.data.id;
769                                         options.params.ontable = 'core_mailing_list_message';
770                                     }
771                                 }
772                             },
773                             remoteSort : true,
774                             sortInfo : { field : 'filename', direction: 'ASC' },
775                             proxy : {
776                                 xtype: 'HttpProxy',
777                                 xns: Roo.data,
778                                 method : 'GET',
779                                 url : baseURL + '/Roo/Images.php'
780                             },
781                             reader : {
782                                 xtype: 'JsonReader',
783                                 xns: Roo.data,
784                                 id : 'id',
785                                 root : 'data',
786                                 totalProperty : 'total',
787                                 fields : [
788                                     {
789                                         'name': 'id',
790                                         'type': 'int'
791                                     },
792                                     {
793                                         'name': 'filename',
794                                         'type': 'string'
795                                     },
796                                     {
797                                         'name': 'ontable',
798                                         'type': 'string'
799                                     },
800                                     {
801                                         'name': 'onid',
802                                         'type': 'int'
803                                     },
804                                     {
805                                         'name': 'mimetype',
806                                         'type': 'string'
807                                     },
808                                     {
809                                         'name': 'width',
810                                         'type': 'int'
811                                     },
812                                     {
813                                         'name': 'height',
814                                         'type': 'int'
815                                     },
816                                     {
817                                         'name': 'filesize',
818                                         'type': 'int'
819                                     },
820                                     {
821                                         'name': 'displayorder',
822                                         'type': 'int'
823                                     },
824                                     {
825                                         'name': 'language',
826                                         'type': 'string'
827                                     },
828                                     {
829                                         'name': 'parent_image_id',
830                                         'type': 'int'
831                                     },
832                                     {
833                                         'name': 'created',
834                                         'type': 'date',
835                                         'dateFormat': 'Y-m-d'
836                                     },
837                                     {
838                                         'name': 'imgtype',
839                                         'type': 'string'
840                                     },
841                                     {
842                                         'name': 'linkurl',
843                                         'type': 'string'
844                                     },
845                                     {
846                                         'name': 'descript',
847                                         'type': 'string'
848                                     },
849                                     {
850                                         'name': 'title',
851                                         'type': 'string'
852                                     },
853                                     {
854                                         'name': 'parent_image_id_id',
855                                         'type': 'int'
856                                     },
857                                     {
858                                         'name': 'parent_image_id_filename',
859                                         'type': 'string'
860                                     },
861                                     {
862                                         'name': 'parent_image_id_ontable',
863                                         'type': 'string'
864                                     },
865                                     {
866                                         'name': 'parent_image_id_onid',
867                                         'type': 'int'
868                                     },
869                                     {
870                                         'name': 'parent_image_id_mimetype',
871                                         'type': 'string'
872                                     },
873                                     {
874                                         'name': 'parent_image_id_width',
875                                         'type': 'int'
876                                     },
877                                     {
878                                         'name': 'parent_image_id_height',
879                                         'type': 'int'
880                                     },
881                                     {
882                                         'name': 'parent_image_id_filesize',
883                                         'type': 'int'
884                                     },
885                                     {
886                                         'name': 'parent_image_id_displayorder',
887                                         'type': 'int'
888                                     },
889                                     {
890                                         'name': 'parent_image_id_language',
891                                         'type': 'string'
892                                     },
893                                     {
894                                         'name': 'parent_image_id_parent_image_id',
895                                         'type': 'int'
896                                     },
897                                     {
898                                         'name': 'parent_image_id_created',
899                                         'type': 'date'
900                                     },
901                                     {
902                                         'name': 'parent_image_id_imgtype',
903                                         'type': 'string'
904                                     },
905                                     {
906                                         'name': 'parent_image_id_linkurl',
907                                         'type': 'string'
908                                     },
909                                     {
910                                         'name': 'parent_image_id_descript',
911                                         'type': 'string'
912                                     },
913                                     {
914                                         'name': 'parent_image_id_title',
915                                         'type': 'string'
916                                     }
917                                 ]
918                             }
919                         },
920                         toolbar : {
921                             xtype: 'Toolbar',
922                             xns: Roo,
923                             items : [
924                                 {
925                                     xtype: 'Button',
926                                     xns: Roo.Toolbar,
927                                     listeners : {
928                                         click : function()
929                                         {
930                                             var id = _this.form.findField('id').getValue();
931                                             
932                                             if(id*1 < 1){
933                                                 Roo.MessageBox.alert('Error', 'Please save the email template first');
934                                                 return;
935                                             }
936                                             
937                                             Pman.Dialog.Image.show( { id : 0, onid: _this.data.id, ontable: 'core_mailing_list_message' }, function() {
938                                                 _this.igrid.getDataSource().load({});
939                                             }); 
940                                         }
941                                     },
942                                     cls : 'x-btn-text-icon',
943                                     text : "Add",
944                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
945                                 },
946                                 {
947                                     xtype: 'Button',
948                                     xns: Roo.Toolbar,
949                                     listeners : {
950                                         click : function()
951                                         {
952                                             var s = _this.igrid.getSelectionModel().getSelected();
953                                             if (!s || isNaN(s.id *1)) {
954                                                 Roo.MessageBox.alert("Error", "Select a image"); 
955                                                 return;
956                                             }
957                                             Roo.MessageBox.confirm("Confirm", "Are sure you want to delete this image?", function (v){
958                                                 if (v != 'yes') {
959                                                     return;
960                                                 }
961                                                 
962                                                 new Pman.Request({
963                                                     url : baseURL + '/Roo/Images.php',
964                                                     method: 'POST',
965                                                     params : {
966                                                         _delete : s.id
967                                                     },
968                                                     success : function()
969                                                     {
970                                                         Roo.log('Got Success!!');
971                                                        _this.igrid.ds.load({});
972                                                     }
973                                                 });
974                                             });
975                                         }
976                                     },
977                                     cls : 'x-btn-text-icon',
978                                     text : "Delete",
979                                     icon : rootURL + '/Pman/templates/images/trash.gif'
980                                 }
981                             ]
982                         },
983                         colModel : [
984                             {
985                                 xtype: 'ColumnModel',
986                                 xns: Roo.grid,
987                                 dataIndex : 'filename',
988                                 header : 'Filename',
989                                 width : 300,
990                                 renderer : function(v,x,r)
991                                 {
992                                    return '<img src="' + baseURL + '/Images/' + r.data.id + '/' + r.data.filename + '" width="' + r.data.width + '" height="' + r.data.height + '" />';
993                                 }
994                             },
995                             {
996                                 xtype: 'ColumnModel',
997                                 xns: Roo.grid,
998                                 header : 'Displayorder',
999                                 width : 75,
1000                                 dataIndex : 'displayorder',
1001                                 renderer : function(v) { return String.format('{0}', v); }
1002                             },
1003                             {
1004                                 xtype: 'ColumnModel',
1005                                 xns: Roo.grid,
1006                                 dataIndex : 'title',
1007                                 header : 'Title',
1008                                 width : 75,
1009                                 renderer : function(v) { return String.format('{0}', v); }
1010                             }
1011                         ]
1012                     }
1013                 }
1014             ],
1015             center : {
1016                 xtype: 'LayoutRegion',
1017                 xns: Roo,
1018                 tabPosition : 'top'
1019             },
1020             east : {
1021                 xtype: 'LayoutRegion',
1022                 xns: Roo,
1023                 hidden : true,
1024                 split : true,
1025                 title : "Images / Attachments",
1026                 titlebar : true,
1027                 width : 500
1028             },
1029             buttons : [
1030                 {
1031                     xtype: 'Button',
1032                     xns: Roo,
1033                     listeners : {
1034                         click : function (_self, e)
1035                         {
1036                             //_this.dialog.hide();
1037                             
1038                             Pman.Dialog.CrmMailingListMessagePreview.show({ id : _this.form.findField('id').getValue() });
1039                         },
1040                         render : function (_self)
1041                         {
1042                             _this.preview_btn = _self;
1043                         }
1044                     },
1045                     text : "Preview"
1046                 },
1047                 {
1048                     xtype: 'Button',
1049                     xns: Roo,
1050                     listeners : {
1051                         click : function (_self, e)
1052                         {
1053                             //_this.dialog.hide();
1054                             
1055                             var id = _this.form.findField('id').getValue();
1056                             
1057                             if(id*1 < 1){
1058                                 Roo.MessageBox.alert('Error', 'Please select a queue to send');
1059                                 return;
1060                             }
1061                            
1062                             new Pman.Request({
1063                                 url : baseURL + '/Crm/MessagePreview',
1064                                 method : 'POST',
1065                                 mask: 'Sending',
1066                                 params : {
1067                                     _id : id,
1068                                     _action : 'html'
1069                                 }, 
1070                                 success : function(res) { 
1071                                     if(res.data == 'SUCCESS'){
1072                                         Roo.MessageBox.alert("Email Sent", 'The report was sent to your email (HTML format).');
1073                                     }
1074                                 }
1075                             });
1076                         },
1077                         render : function (_self)
1078                         {
1079                             _this.html_preview = _self;
1080                         }
1081                     },
1082                     text : "Send me a test copy"
1083                 },
1084                 {
1085                     xtype: 'Button',
1086                     xns: Roo,
1087                     listeners : {
1088                         click : function (_self, e)
1089                         {
1090                             _this.dialog.hide();
1091                         }
1092                     },
1093                     text : "Cancel"
1094                 },
1095                 {
1096                     xtype: 'Button',
1097                     xns: Roo,
1098                     listeners : {
1099                         click : function (_self, e)
1100                         {
1101                             // do some checks?
1102                             _this.form.preValidate(function(res) {
1103                                 if (!res) {
1104                                     return; //failed.
1105                                 }
1106                                  _this.form.doAction("submit");
1107                             });
1108                         
1109                         }
1110                     },
1111                     text : "Save"
1112                 }
1113             ]
1114         });
1115     }
1116 };