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