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