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