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