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