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