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