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