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 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.CoreEmail = {
8
9  _strings : {
10   'e44b145bd8b49b06e0ad2ced1ad56466' :"Plain Text",
11   '2f26e35d61be90501e099089dc533638' :"Select Images",
12   'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
13   'b357b524e740bc85b9790a0712d84a30' :"Email address",
14   '962b90039a542a29cedd51d87a9f28a1' :"Html Editor",
15   '72d6d7a1885885bb55a565fd1070581a' :"Import",
16   '31fde7b05ac8952dacf4af8a704074ec' :"Preview",
17   'ea30b40c3caf28acb29198d20d243e54' :"Images / Attachments >>",
18   '884df8e413319ff51a3f5f528606238a' :"Use template",
19   'e6b391a8d2c4d45902a23a8b6585703d' :"URL",
20   '2393ad754ba179442d85e415d1d5167c' :"Displayorder",
21   '6f16a5f8ff5d75ab84c018adacdfcbb7' :"Field",
22   'ec211f7c20af43e742bf2570c3cb84f9' :"Add",
23   'e9968623956c15023d54335ea3699855' :"Convert Html to Text",
24   '5b8ef4e762c00a15a41cfc26dc3ef99c' :"Send me a test copy",
25   '1243daf593fa297e07ab03bf06d925af' :"Searching...",
26   'c7892ebbb139886662c6f2fc8c450710' :"Subject",
27   'dc0de523c25be298ba751c63c694109e' :"Responsive Email (1)",
28   '396ecabf0cd1f9503e591418851ef406' :"Edit / Create Message",
29   'b9c49611cfda3259a2b837b39489e650' :"Add Image",
30   'ea4788705e6873b424c65e91c2846b19' :"Cancel",
31   'b20a8b77b05d53b4e695738731400c85' :"Mailout Name",
32   '1bd18d39370b7f26c1c5e18067b74c6f' :"Html File",
33   '5da618e8e4b89c66fe86e32cdafde142' :"From",
34   '31bb2f6e9b8fb11cbb7fb63c6025223f' :"Select Template",
35   'b78a3223503896721cca1303f776159b' :"Title",
36   '278c491bdd8a53618c149c4ac790da34' :"Template",
37   'c9cc8cce247e49bae79f15173ce97354' :"Save",
38   '1351017ac6423911223bc19a8cb7c653' :"Filename",
39   '308f2757bfc9ce92fb00ff93fdffd279' :"Images / Attachments",
40   '5feb9bf3c03b32635135006cbacb9542' :"Insert Field",
41   '4c2a8fe7eaf24721cc7a9f0175115bd4' :"Message",
42   'fff0d600f8a0b5e19e88bfb821dd1157' :"Images"
43  },
44
45  dialog : false,
46  callback:  false,
47
48  show : function(data, cb)
49  {
50   if (!this.dialog) {
51    this.create();
52   }
53
54   this.callback = cb;
55   this.data = data;
56   this.dialog.show(this.data._el);
57   if (this.form) {
58    this.form.reset();
59    this.form.setValues(data);
60    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
61   }
62
63  },
64
65  create : function()
66  {
67    var _this = this;
68    this.dialog = Roo.factory({
69     closable : true,
70     collapsible : false,
71     height : 500,
72     modal : true,
73     resizable : true,
74     title : _this._strings['396ecabf0cd1f9503e591418851ef406'] /* Edit / Create Message */,
75     width : 800,
76     xns : Roo,
77     '|xns' : 'Roo',
78     xtype : 'LayoutDialog',
79     listeners : {
80      show : function (_self)
81       {
82           
83           _self.layout.getRegion('center').showPanel(0);
84           var w = Roo.lib.Dom.getViewWidth();\r
85           var h = Roo.lib.Dom.getViewHeight();    \r    this.resizeTo(w-50, h-50);\r
86           this.center();\r    
87           var ew = Math.max(250, w-320);\r
88           var eh = Math.max(250, h-350) ;\r
89           var e = _this.dialog.layout.getRegion('east');
90           if (e.visible) {
91               e.hide();
92           }
93           
94           var el = _self.getEl();
95           var elw = el.dom.clientWidth;
96           
97           var bdtext = _this.form.findField('bodytext');
98           var ptext = _this.form.findField('plaintext');
99           if(bdtext.resizeEl){
100               bdtext.width = elw-100;
101               bdtext.resizeEl.resizeTo.defer(110, bdtext.resizeEl,[ bdtext.width, bdtext.height  ] );
102               ptext.setSize(bdtext.width , bdtext.height);
103           }
104           
105       }
106     },
107     center : {
108      tabPosition : 'top',
109      xns : Roo,
110      '|xns' : 'Roo',
111      xtype : 'LayoutRegion'
112     },
113     east : {
114      hidden : true,
115      split : true,
116      title : _this._strings['308f2757bfc9ce92fb00ff93fdffd279'] /* Images / Attachments */,
117      titlebar : true,
118      width : 500,
119      xns : Roo,
120      '|xns' : 'Roo',
121      xtype : 'LayoutRegion'
122     },
123     buttons : [
124      {
125       text : _this._strings['31fde7b05ac8952dacf4af8a704074ec'] /* Preview */,
126       xns : Roo,
127       '|xns' : 'Roo',
128       xtype : 'Button',
129       listeners : {
130        click : function (_self, e)
131         {
132             //_this.dialog.hide();
133             Roo.log(_this.data.module);
134             Pman.Dialog.CoreEmailPreview.show({ id : _this.form.findField('id').getValue(), module : _this.data.module });
135         },
136        render : function (_self)
137         {
138             _this.preview_btn = _self;
139         }
140       }
141      },
142      {
143       text : _this._strings['5b8ef4e762c00a15a41cfc26dc3ef99c'] /* Send me a test copy */,
144       xns : Roo,
145       '|xns' : 'Roo',
146       xtype : 'Button',
147       listeners : {
148        click : function (_self, e)
149         {
150             //_this.dialog.hide();
151             
152             var id = _this.form.findField('id').getValue();
153             
154             if(id*1 < 1){
155                 Roo.MessageBox.alert('Error', 'Please save the message frist!');
156                 return;
157             }
158            
159             new Pman.Request({
160                 url : baseURL + '/Core/MessagePreview',
161                 method : 'POST',
162                 mask: 'Sending',
163                 params : {
164                     _id : id,
165                     _table : _this.data.module
166                 }, 
167                 success : function(res) { 
168                     if(res.data == 'SUCCESS'){
169                         Roo.MessageBox.alert("Email Sent", 'The report was sent to your email (HTML format).');
170                     }
171                 }
172             });
173         },
174        render : function (_self)
175         {
176             _this.html_preview = _self;
177         }
178       }
179      },
180      {
181       text : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
182       xns : Roo,
183       '|xns' : 'Roo',
184       xtype : 'Button',
185       listeners : {
186        click : function (_self, e)
187         {
188             _this.dialog.hide();
189         }
190       }
191      },
192      {
193       text : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
194       xns : Roo,
195       '|xns' : 'Roo',
196       xtype : 'Button',
197       listeners : {
198        click : function (_self, e)
199         {
200         
201             // do some checks?
202             _this.form.preValidate(function(res) {
203                 if (!res) {
204                     return; //failed.
205                 }
206                  _this.form.doAction("submit");
207             });
208         
209         }
210       }
211      }
212     ],
213     items  : [
214      {
215       autoScroll : false,
216       fitContainer : true,
217       fitToFrame : true,
218       region : 'center',
219       xns : Roo,
220       '|xns' : 'Roo',
221       xtype : 'NestedLayoutPanel',
222       toolbar : {
223        xns : Roo,
224        '|xns' : 'Roo',
225        xtype : 'Toolbar',
226        items  : [
227         {
228          text : _this._strings['72d6d7a1885885bb55a565fd1070581a'] /* Import */,
229          xns : Roo.Toolbar,
230          '|xns' : 'Roo.Toolbar',
231          xtype : 'Button',
232          menu : {
233           xns : Roo.menu,
234           '|xns' : 'Roo.menu',
235           xtype : 'Menu',
236           items  : [
237            {
238             text : _this._strings['e6b391a8d2c4d45902a23a8b6585703d'] /* URL */,
239             xns : Roo.menu,
240             '|xns' : 'Roo.menu',
241             xtype : 'Item',
242             listeners : {
243              click : function (_self, e)
244               {
245                   Pman.Dialog.CoreImportUrl.show({
246                       target : '/Core/ImportMailMessage.php'
247                   }, function(data) {
248                       if  (data) {
249                         //  Roo.log(data);
250                           _this.form.findField('bodytext').setValue(data);
251                       }
252                   });
253               }
254             }
255            },
256            {
257             text : _this._strings['1bd18d39370b7f26c1c5e18067b74c6f'] /* Html File */,
258             xns : Roo.menu,
259             '|xns' : 'Roo.menu',
260             xtype : 'Item',
261             listeners : {
262              click : function (_self, e)
263               {
264                   Pman.Dialog.Image.show({
265                       _url : baseURL + '/Core/ImportMailMessage.php'
266                   }, function(data) {
267                       if  (data) {
268                           _this.form.findField('bodytext').setValue(data);
269                       }
270                   });
271               }
272             }
273            }
274           ]
275          }
276         },
277         {
278          text : _this._strings['884df8e413319ff51a3f5f528606238a'] /* Use template */,
279          xns : Roo.Toolbar,
280          '|xns' : 'Roo.Toolbar',
281          xtype : 'Button',
282          menu : {
283           xns : Roo.menu,
284           '|xns' : 'Roo.menu',
285           xtype : 'Menu',
286           items  : [
287            {
288             text : _this._strings['dc0de523c25be298ba751c63c694109e'] /* Responsive Email (1) */,
289             xns : Roo.menu,
290             '|xns' : 'Roo.menu',
291             xtype : 'Item',
292             listeners : {
293              click : function (_self, e)
294               {
295               
296                   var l = document.location;
297                   new Pman.Request({
298               
299                       url : baseURL + '/Core/ImportMailMessage.php',
300               
301                       method: 'POST',
302                       mask : "Loading",
303                       params : {
304                             importUrl : l.protocol +'//' + l.host +   rootURL + '/Pman/Crm/mail_templates/responsive1.html'
305                      },
306                       success : function (res) {
307               
308                        _this.form.findField('bodytext').setValue(res.data);
309                       }
310                 
311                   });
312               }
313             }
314            }
315           ]
316          }
317         },
318         {
319          allowBlank : true,
320          alwaysQuery : true,
321          displayField : 'file',
322          editable : false,
323          emptyText : _this._strings['31bb2f6e9b8fb11cbb7fb63c6025223f'] /* Select Template */,
324          fieldLabel : _this._strings['278c491bdd8a53618c149c4ac790da34'] /* Template */,
325          forceSelection : true,
326          hiddenName : 'template',
327          listWidth : 400,
328          loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
329          minChars : 2,
330          name : 'template',
331          pageSize : 20,
332          qtip : _this._strings['31bb2f6e9b8fb11cbb7fb63c6025223f'] /* Select Template */,
333          selectOnFocus : true,
334          tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{file}</b> </div>',
335          triggerAction : 'all',
336          typeAhead : true,
337          valueField : 'file',
338          width : 200,
339          xns : Roo.form,
340          '|xns' : 'Roo.form',
341          xtype : 'ComboBox',
342          listeners : {
343           select : function (combo, record, index)
344            {
345               
346            /*
347                (function() { 
348                    combo.setValue('');
349                }).defer(100);
350            */    
351                if(!record){
352                    return;
353                }
354                _this.form.findField('bodytext').setValue(record.data.content);
355            
356            }
357          },
358          store : {
359           remoteSort : true,
360           sortInfo : { direction : 'DESC', field: 'file' },
361           xns : Roo.data,
362           '|xns' : 'Roo.data',
363           xtype : 'Store',
364           listeners : {
365            beforeload : function (_self, o){
366                 o.params = o.params || {};
367                 // set more here
368                
369             }
370           },
371           proxy : {
372            method : 'GET',
373            url : baseURL + '/Core/MailTemplateList.php',
374            xns : Roo.data,
375            '|xns' : 'Roo.data',
376            xtype : 'HttpProxy'
377           },
378           reader : {
379            fields : [{"name":"file","type":"string"},{"name":"content","type":"string"}],
380            id : 'name',
381            root : 'data',
382            totalProperty : 'total',
383            xns : Roo.data,
384            '|xns' : 'Roo.data',
385            xtype : 'JsonReader'
386           }
387          }
388         },
389         {
390          xns : Roo.Toolbar,
391          '|xns' : 'Roo.Toolbar',
392          xtype : 'Fill'
393         },
394         {
395          text : _this._strings['ea30b40c3caf28acb29198d20d243e54'] /* Images / Attachments >> */,
396          xns : Roo.Toolbar,
397          '|xns' : 'Roo.Toolbar',
398          xtype : 'Button',
399          listeners : {
400           click : function (_self, e)
401            {
402                var el = _this.dialog.layout.getRegion('east');
403                if (el.visible) {
404                    el.hide();
405                } else {
406                    el.show();
407                    el.showPanel(0);
408                }
409                
410            }
411          }
412         }
413        ]
414       },
415       layout : {
416        xns : Roo,
417        '|xns' : 'Roo',
418        xtype : 'BorderLayout',
419        center : {
420         autoScroll : true,
421         xns : Roo,
422         '|xns' : 'Roo',
423         xtype : 'LayoutRegion'
424        },
425        items  : [
426         {
427          autoScroll : false,
428          background : false,
429          fitContainer : true,
430          fitToFrame : true,
431          region : 'center',
432          title : _this._strings['4c2a8fe7eaf24721cc7a9f0175115bd4'] /* Message */,
433          xns : Roo,
434          '|xns' : 'Roo',
435          xtype : 'ContentPanel',
436          listeners : {
437           render : function (_self, width, height)
438            {
439                
440                  Roo.log("RESIZE, " + width + ',' + height);
441                
442                var ew = Math.max(250, width-50);
443                var eh = Math.max(250,height-50) ;
444                
445               
446            
447            },
448           resize : function (_self, width, height)\r
449            {\r
450               var ew = Math.max(250, width-50);\r
451                var eh = Math.max(250,height-50) ;
452                
453                if (!_this.form) {\r
454                    return;\r
455                }\r
456                var bdtext = _this.form.findField('bodytext');\r
457                var ptext = _this.form.findField('plaintext');\r
458                if(bdtext.resizeEl){\r
459                    bdtext.width = ew-50;\r
460                    bdtext.resizeEl.resizeTo.defer(110, bdtext.resizeEl,[ bdtext.width, bdtext.height  ] );\r
461                    ptext.setSize(bdtext.width , bdtext.height);\r
462                }\r\r
463            \r
464            }
465          },
466          items  : [
467           {
468            labelAlign : 'right',
469            labelWidth : 120,
470            method : 'POST',
471            preValidate : function(done_callback) {
472                
473                Roo.MessageBox.progress("Uploading Images", "Uploading");
474                var html = _this.form.findField('bodytext').getValue();
475                
476                var s = Roo.get(_this.form.findField('bodytext').editorcore.doc.documentElement);
477                
478                var ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
479                
480                var nodes = [];
481                s.select('img[src]').each(function(i) {
482                    nodes.push(i.dom);
483                });
484                var total = nodes.length;
485                var mkimg = function() {
486                
487                    if (!nodes.length) {
488                          Roo.MessageBox.hide();
489                          _this.form.findField('bodytext').syncValue();
490                          done_callback(true);
491                       //    _this.form.doAction("submit");
492                          return;
493                    }
494                    var i = nodes.pop(); 
495                    
496                    var n = i.getAttribute('src').match(/(baseURL|server_baseurl)/);
497                    
498                    if(n){
499                        mkimg();
500                        return;
501                    }
502                    
503                    n = i.getAttribute('src').match(/^http(.*)/);
504                   
505                    if(!n ){
506                        mkimg();
507                        return;
508                    }
509                    
510                    new Pman.Request({
511                        url : baseURL + '/Roo/Images.php',
512                        method : 'POST',
513                        params : {
514                            onid : _this.form.findField('id').getValue(),
515                            ontable : ontable ,
516                            _remote_upload : i.src
517                        },
518                        success : function(res){
519                            if(res.success == true){      
520                                i.setAttribute('src', res.data);
521                                Roo.MessageBox.updateProgress( (total - nodes.length) / total , "Done " + (total - nodes.length) + '/' + total);
522                            }
523                            mkimg();
524                        }
525                    });
526                   
527                }
528                mkimg();
529            },
530            style : 'margin:10px',
531            url : baseURL + '/Roo/crm_mailing_list_message.php',
532            xns : Roo.form,
533            '|xns' : 'Roo.form',
534            xtype : 'Form',
535            listeners : {
536             actioncomplete : function(_self,action)
537              {
538                 
539                  if (action.type == 'setdata') {
540                  
541                      _this.data.module = _this.data.module || 'crm_mailing_list_message';
542                      
543                      _this.form.url = baseURL + '/Roo/' + _this.data.module;
544                      
545                      _this.html_preview.hide();
546                      _this.preview_btn.hide();
547                          
548                      if(_this.data.id*1 > 0){
549                          _this.dialog.el.mask("Loading");
550                          this.load({ method: 'GET', params: { '_id' : _this.data.id }});
551                          _this.html_preview.show();
552                          _this.preview_btn.show();
553                          
554                      } else {
555                          _this.form.setValues({
556                              'from_name' : Pman.Login.authUser.name,
557                              'from_email' : Pman.Login.authUser.email
558                          });
559                      }
560                     return;
561                  }
562                  if (action.type == 'load') {
563                      _this.dialog.el.unmask();
564                      return;
565                  }
566                  if (action.type =='submit') {
567                  
568                      _this.dialog.el.unmask();
569                      _this.dialog.hide();
570                  
571                       if (_this.callback) {
572                          _this.callback.call(_this, action.result.data);
573                       }
574                       _this.form.reset();
575                       return;
576                  }
577              },
578             rendered : function (form)
579              {
580                  _this.form= form;
581              }
582            },
583            items  : [
584             {
585              xns : Roo.form,
586              '|xns' : 'Roo.form',
587              xtype : 'Row',
588              items  : [
589               {
590                allowBlank : false,
591                fieldLabel : _this._strings['b20a8b77b05d53b4e695738731400c85'] /* Mailout Name */,
592                name : 'name',
593                width : 400,
594                xns : Roo.form,
595                '|xns' : 'Roo.form',
596                xtype : 'TextField'
597               }
598              ]
599             },
600             {
601              xns : Roo.form,
602              '|xns' : 'Roo.form',
603              xtype : 'Row',
604              items  : [
605               {
606                allowBlank : false,
607                fieldLabel : _this._strings['5da618e8e4b89c66fe86e32cdafde142'] /* From */,
608                name : 'from_name',
609                width : 300,
610                xns : Roo.form,
611                '|xns' : 'Roo.form',
612                xtype : 'TextField'
613               },
614               {
615                allowBlank : false,
616                fieldLabel : _this._strings['b357b524e740bc85b9790a0712d84a30'] /* Email address */,
617                name : 'from_email',
618                width : 300,
619                xns : Roo.form,
620                '|xns' : 'Roo.form',
621                xtype : 'TextField'
622               }
623              ]
624             },
625             {
626              allowBlank : false,
627              fieldLabel : _this._strings['c7892ebbb139886662c6f2fc8c450710'] /* Subject */,
628              name : 'subject',
629              width : 600,
630              xns : Roo.form,
631              '|xns' : 'Roo.form',
632              xtype : 'TextField'
633             },
634             {
635              hideLabels : true,
636              xns : Roo.form,
637              '|xns' : 'Roo.form',
638              xtype : 'Row',
639              items  : [
640               {
641                hideLabels : true,
642                legend : _this._strings['962b90039a542a29cedd51d87a9f28a1'] /* Html Editor */,
643                style : 'text-align:center;',
644                xns : Roo.form,
645                '|xns' : 'Roo.form',
646                xtype : 'FieldSet',
647                items  : [
648                 {
649                  clearUp : false,
650                  cwhite : [ 
651                      'margin',
652                      'padding',
653                      'text-align',
654                      'background',
655                      'height',
656                      'width',
657                      'background-color',
658                      'font-size',
659                      'line-height',
660                      'color',
661                      'outline',
662                      'text-decoration',
663                      'position',
664                      'clear',
665                      'overflow',
666                      'margin-top',
667                      'border-bottom',
668                      'top',
669                      'list-style',
670                      'margin-left',
671                      'border',
672                      'float' ,
673                      'margin-right',
674                      'padding-top',
675                      'min-height',
676                      'left',
677                      'padding-left',
678                      'font-weight',
679                      'font-family',
680                      'display',
681                      'margin-bottom',
682                      'padding-bottom',
683                      'vertical-align',
684                      'cursor',
685                      'z-index',
686                      'right'
687                   ],
688                  height : 250,
689                  name : 'bodytext',
690                  resizable : 's',
691                  xns : Roo.form,
692                  '|xns' : 'Roo.form',
693                  xtype : 'HtmlEditor',
694                  toolbars : [
695                   {
696                    xns : Roo.form.HtmlEditor,
697                    '|xns' : 'Roo.form.HtmlEditor',
698                    xtype : 'ToolbarContext'
699                   },
700                   {
701                    xns : Roo.form.HtmlEditor,
702                    '|xns' : 'Roo.form.HtmlEditor',
703                    xtype : 'ToolbarStandard',
704                    btns : [
705                     {
706                      alwaysQuery : true,
707                      displayField : 'name',
708                      editable : false,
709                      emptyText : _this._strings['b9c49611cfda3259a2b837b39489e650'] /* Add Image */,
710                      fieldLabel : _this._strings['fff0d600f8a0b5e19e88bfb821dd1157'] /* Images */,
711                      forceSelection : true,
712                      listWidth : 400,
713                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
714                      minChars : 2,
715                      pageSize : 20,
716                      qtip : _this._strings['2f26e35d61be90501e099089dc533638'] /* Select Images */,
717                      selectOnFocus : true,
718                      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>',
719                      triggerAction : 'all',
720                      typeAhead : true,
721                      valueField : 'id',
722                      width : 100,
723                      xns : Roo.form,
724                      '|xns' : 'Roo.form',
725                      xtype : 'ComboBox',
726                      listeners : {
727                       beforequery : function (combo, query, forceAll, cancel, e)
728                        {
729                            var id = _this.form.findField('id').getValue() * 1;    
730                            if (!id) {
731                                Roo.MessageBox.alert("Error", "Save message first");
732                                return false;
733                            }
734                        },
735                       render : function (_self)
736                        {
737                            _this.extendimgselect = _self;
738                        },
739                       select : function (combo, record, index)
740                        {
741                            Roo.log(record);
742                            (function() { 
743                                combo.setValue('');
744                            }).defer(100);
745                            var editor = _this.form.findField('bodytext').editorcore;
746                            
747                            var curnode = editor.getSelectedNode();
748                            if (curnode && curnode.tagName == 'IMG') {
749                                curnode.src= String.format('{0}/Images/{1}/{2}#image-{1}',
750                                        baseURL,  record.data.id, record.data.filename
751                                    );
752                                    // note -forces an update... hopefully...
753                                editor.owner.fireEvent('editorevent', editor, false);
754                            } else {
755                            
756                                editor.insertAtCursor(
757                                    String.format('<img src="{0}/Images/{1}/{2}#image-{1}">',
758                                    baseURL,  record.data.id, record.data.filename
759                                    )
760                                );
761                        
762                            }
763                            
764                         }
765                      },
766                      store : {
767                       remoteSort : true,
768                       sortInfo : { direction : 'ASC', field: 'id' },
769                       xns : Roo.data,
770                       '|xns' : 'Roo.data',
771                       xtype : 'Store',
772                       listeners : {
773                        beforeload : function (_self, o){
774                             o.params = o.params || {};
775                         
776                             var id = _this.form.findField('id').getValue() * 1;    
777                             if (!id) {
778                                 Roo.MessageBox.alert("Error", "Save email template first");
779                                 return false;
780                             }
781                             o.params.onid = id
782                             o.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
783                             
784                            // o.params.imgtype = 'PressRelease';
785                             //o.params['query[imagesize]'] = '150x150';
786                             // set more here
787                         }
788                       },
789                       proxy : {
790                        method : 'GET',
791                        url : baseURL + '/Roo/Images.php',
792                        xns : Roo.data,
793                        '|xns' : 'Roo.data',
794                        xtype : 'HttpProxy'
795                       },
796                       reader : {
797                        fields : [{"name":"id","type":"int"},{"name":"filename","type":"string"},{"name":"url_thumb","type":"string"}],
798                        id : 'id',
799                        root : 'data',
800                        totalProperty : 'total',
801                        xns : Roo.data,
802                        '|xns' : 'Roo.data',
803                        xtype : 'JsonReader'
804                       }
805                      }
806                     },
807                     {
808                      alwaysQuery : true,
809                      displayField : 'name',
810                      editable : false,
811                      emptyText : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
812                      fieldLabel : _this._strings['6f16a5f8ff5d75ab84c018adacdfcbb7'] /* Field */,
813                      forceSelection : true,
814                      listWidth : 400,
815                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
816                      minChars : 2,
817                      pageSize : 20,
818                      qtip : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
819                      selectOnFocus : true,
820                      tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{name}</b> </div>',
821                      triggerAction : 'all',
822                      typeAhead : true,
823                      valueField : 'type',
824                      width : 100,
825                      xns : Roo.form,
826                      '|xns' : 'Roo.form',
827                      xtype : 'ComboBox',
828                      listeners : {
829                       render : function (_self)
830                        {
831                            _this.unsubscribeselect = _self;
832                        },
833                       select : function (combo, record, index)
834                        {
835                            Roo.log(record);
836                            (function() { 
837                                combo.setValue('');
838                            }).defer(100);
839                            var editor = _this.form.findField('bodytext').editorcore;
840                            
841                            if(record.data.name == 'Unsubscribe'){
842                                editor.insertAtCursor(
843                                    String.format('<a href="{0}">{1}</a>',
844                                        record.data.type,  record.data.name
845                                    )
846                                );
847                                return;     
848                            }
849                            
850                            editor.insertAtCursor(
851                                String.format('{0}',
852                                    record.data.type
853                                )
854                            );
855                            
856                         }
857                      },
858                      store : {
859                       data : [ 
860                           [ '{person.firstname}', "First Name"],
861                           [ '{person.lastname}' , "Last Name"],
862                           [ '{person.name}', "Full Name"],
863                           [ '#unsubscribe', "Unsubscribe"]
864                       ],
865                       fields : [  'type', 'name'],
866                       xns : Roo.data,
867                       '|xns' : 'Roo.data',
868                       xtype : 'SimpleStore'
869                      }
870                     }
871                    ]
872                   }
873                  ]
874                 }
875                ]
876               }
877              ]
878             },
879             {
880              hideLabels : true,
881              xns : Roo.form,
882              '|xns' : 'Roo.form',
883              xtype : 'Row',
884              items  : [
885               {
886                text : _this._strings['e9968623956c15023d54335ea3699855'] /* Convert Html to Text */,
887                xns : Roo,
888                '|xns' : 'Roo',
889                xtype : 'Button',
890                listeners : {
891                 click : function (_self, e)
892                  {
893                      var h = _this.form.findField('bodytext').getValue();
894                      var p = _this.form.findField('plaintext');
895                      
896                      new Pman.Request({\r
897                          url : baseURL + '/Core/ImportMailMessage.php',\r
898                          method : 'POST',\r
899                          params : {
900                            bodytext : h,\r
901                            _convertToPlain : true,
902                            _check_unsubscribe : true\r
903                          }, \r
904                          success : function(res) {\r
905                              if(res.success == true){
906                                 p.setValue(res.data);
907                              }\r
908                          }\r
909                      });  
910                      
911                  }
912                }
913               }
914              ]
915             },
916             {
917              hideLabels : true,
918              xns : Roo.form,
919              '|xns' : 'Roo.form',
920              xtype : 'Row',
921              items  : [
922               {
923                hideLabels : true,
924                legend : _this._strings['e44b145bd8b49b06e0ad2ced1ad56466'] /* Plain Text */,
925                style : 'text-align:center;',
926                xns : Roo.form,
927                '|xns' : 'Roo.form',
928                xtype : 'FieldSet',
929                items  : [
930                 {
931                  height : 50,
932                  name : 'plaintext',
933                  xns : Roo.form,
934                  '|xns' : 'Roo.form',
935                  xtype : 'TextArea'
936                 }
937                ]
938               }
939              ]
940             },
941             {
942              name : 'id',
943              xns : Roo.form,
944              '|xns' : 'Roo.form',
945              xtype : 'Hidden'
946             }
947            ]
948           }
949          ]
950         }
951        ]
952       }
953      },
954      {
955       autoScroll : false,
956       background : false,
957       fitContainer : true,
958       fitToframe : true,
959       region : 'east',
960       tableName : 'Images',
961       title : _this._strings['308f2757bfc9ce92fb00ff93fdffd279'] /* Images / Attachments */,
962       xns : Roo,
963       '|xns' : 'Roo',
964       xtype : 'GridPanel',
965       listeners : {
966        activate : function() {
967             _this.ipanel = this;
968             if (_this.igrid) {
969                _this.igrid.ds.load({});
970             }
971         }
972       },
973       grid : {
974        autoExpandColumn : 'filename',
975        loadMask : true,
976        xns : Roo.grid,
977        '|xns' : 'Roo.grid',
978        xtype : 'Grid',
979        listeners : {
980         render : function() 
981          {
982              _this.igrid = this; 
983              //_this.dialog = Pman.Dialog.FILL_IN
984              if (_this.ipanel.active) {
985             //    _this.igrid.ds.load({});
986              }
987          }
988        },
989        toolbar : {
990         xns : Roo,
991         '|xns' : 'Roo',
992         xtype : 'Toolbar',
993         items  : [
994          {
995           cls : 'x-btn-text-icon',
996           icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
997           text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
998           xns : Roo.Toolbar,
999           '|xns' : 'Roo.Toolbar',
1000           xtype : 'Button',
1001           listeners : {
1002            click : function()
1003             {
1004                 var id = _this.form.findField('id').getValue();
1005                 
1006                 if(id*1 < 1){
1007                     Roo.MessageBox.alert('Error', 'Please save the email template first');
1008                     return;
1009                 }
1010                 
1011                 var ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1012                 
1013                 Pman.Dialog.Image.show( { id : 0, onid: id, ontable: ontable }, function() {
1014                     _this.igrid.getDataSource().load({});
1015                 }); 
1016             }
1017           }
1018          },
1019          {
1020           cls : 'x-btn-text-icon',
1021           icon : rootURL + '/Pman/templates/images/trash.gif',
1022           text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
1023           xns : Roo.Toolbar,
1024           '|xns' : 'Roo.Toolbar',
1025           xtype : 'Button',
1026           listeners : {
1027            click : function()
1028             {
1029                 var s = _this.igrid.getSelectionModel().getSelected();
1030                 if (!s || isNaN(s.id *1)) {
1031                     Roo.MessageBox.alert("Error", "Select a image"); 
1032                     return;
1033                 }
1034                 Roo.MessageBox.confirm("Confirm", "Are sure you want to delete this image?", function (v){
1035                     if (v != 'yes') {
1036                         return;
1037                     }
1038                     
1039                     new Pman.Request({
1040                         url : baseURL + '/Roo/Images.php',
1041                         method: 'POST',
1042                         params : {
1043                             _delete : s.id
1044                         },
1045                         success : function()
1046                         {
1047                             Roo.log('Got Success!!');
1048                            _this.igrid.ds.load({});
1049                         }
1050                     });
1051                 });
1052             }
1053           }
1054          }
1055         ]
1056        },
1057        dataSource : {
1058         remoteSort : true,
1059         sortInfo : { field : 'filename', direction: 'ASC' },
1060         xns : Roo.data,
1061         '|xns' : 'Roo.data',
1062         xtype : 'Store',
1063         listeners : {
1064          beforeload : function (_self, options)
1065           {
1066               options.params = options.params || {};
1067               if (typeof(_this.data) == 'undefined') {
1068                   return false;
1069               }
1070               if(_this.data.id * 1 >= 0)
1071               {
1072                   options.params.onid = _this.data.id;
1073           
1074                   options.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1075               }
1076           }
1077         },
1078         proxy : {
1079          method : 'GET',
1080          url : baseURL + '/Roo/Images.php',
1081          xns : Roo.data,
1082          '|xns' : 'Roo.data',
1083          xtype : 'HttpProxy'
1084         },
1085         reader : {
1086          fields : [
1087              {
1088                  'name': 'id',
1089                  'type': 'int'
1090              },
1091              {
1092                  'name': 'filename',
1093                  'type': 'string'
1094              },
1095              {
1096                  'name': 'ontable',
1097                  'type': 'string'
1098              },
1099              {
1100                  'name': 'onid',
1101                  'type': 'int'
1102              },
1103              {
1104                  'name': 'mimetype',
1105                  'type': 'string'
1106              },
1107              {
1108                  'name': 'width',
1109                  'type': 'int'
1110              },
1111              {
1112                  'name': 'height',
1113                  'type': 'int'
1114              },
1115              {
1116                  'name': 'filesize',
1117                  'type': 'int'
1118              },
1119              {
1120                  'name': 'displayorder',
1121                  'type': 'int'
1122              },
1123              {
1124                  'name': 'language',
1125                  'type': 'string'
1126              },
1127              {
1128                  'name': 'parent_image_id',
1129                  'type': 'int'
1130              },
1131              {
1132                  'name': 'created',
1133                  'type': 'date',
1134                  'dateFormat': 'Y-m-d'
1135              },
1136              {
1137                  'name': 'imgtype',
1138                  'type': 'string'
1139              },
1140              {
1141                  'name': 'linkurl',
1142                  'type': 'string'
1143              },
1144              {
1145                  'name': 'descript',
1146                  'type': 'string'
1147              },
1148              {
1149                  'name': 'title',
1150                  'type': 'string'
1151              },
1152              {
1153                  'name': 'parent_image_id_id',
1154                  'type': 'int'
1155              },
1156              {
1157                  'name': 'parent_image_id_filename',
1158                  'type': 'string'
1159              },
1160              {
1161                  'name': 'parent_image_id_ontable',
1162                  'type': 'string'
1163              },
1164              {
1165                  'name': 'parent_image_id_onid',
1166                  'type': 'int'
1167              },
1168              {
1169                  'name': 'parent_image_id_mimetype',
1170                  'type': 'string'
1171              },
1172              {
1173                  'name': 'parent_image_id_width',
1174                  'type': 'int'
1175              },
1176              {
1177                  'name': 'parent_image_id_height',
1178                  'type': 'int'
1179              },
1180              {
1181                  'name': 'parent_image_id_filesize',
1182                  'type': 'int'
1183              },
1184              {
1185                  'name': 'parent_image_id_displayorder',
1186                  'type': 'int'
1187              },
1188              {
1189                  'name': 'parent_image_id_language',
1190                  'type': 'string'
1191              },
1192              {
1193                  'name': 'parent_image_id_parent_image_id',
1194                  'type': 'int'
1195              },
1196              {
1197                  'name': 'parent_image_id_created',
1198                  'type': 'date'
1199              },
1200              {
1201                  'name': 'parent_image_id_imgtype',
1202                  'type': 'string'
1203              },
1204              {
1205                  'name': 'parent_image_id_linkurl',
1206                  'type': 'string'
1207              },
1208              {
1209                  'name': 'parent_image_id_descript',
1210                  'type': 'string'
1211              },
1212              {
1213                  'name': 'parent_image_id_title',
1214                  'type': 'string'
1215              }
1216          ],
1217          id : 'id',
1218          root : 'data',
1219          totalProperty : 'total',
1220          xns : Roo.data,
1221          '|xns' : 'Roo.data',
1222          xtype : 'JsonReader'
1223         }
1224        },
1225        colModel : [
1226         {
1227          dataIndex : 'filename',
1228          header : _this._strings['1351017ac6423911223bc19a8cb7c653'] /* Filename */,
1229          renderer : function(v,x,r)
1230          {
1231              var width = r.data.width;
1232              var height = r.data.height;
1233              
1234              if(width > 50){
1235                  height = Math.round(height * 50 / width);
1236                  width = 50;
1237              }
1238              
1239             return '<img src="' + baseURL + '/Images/' + r.data.id + '/' + r.data.filename + '" width="' + width + '" height="' + height + '" />';
1240          },
1241          width : 300,
1242          xns : Roo.grid,
1243          '|xns' : 'Roo.grid',
1244          xtype : 'ColumnModel'
1245         },
1246         {
1247          dataIndex : 'displayorder',
1248          header : _this._strings['2393ad754ba179442d85e415d1d5167c'] /* Displayorder */,
1249          renderer : function(v) { return String.format('{0}', v); },
1250          width : 75,
1251          xns : Roo.grid,
1252          '|xns' : 'Roo.grid',
1253          xtype : 'ColumnModel'
1254         },
1255         {
1256          dataIndex : 'title',
1257          header : _this._strings['b78a3223503896721cca1303f776159b'] /* Title */,
1258          renderer : function(v) { return String.format('{0}', v); },
1259          width : 75,
1260          xns : Roo.grid,
1261          '|xns' : 'Roo.grid',
1262          xtype : 'ColumnModel'
1263         }
1264        ]
1265       }
1266      }
1267     ]
1268    });
1269  }
1270 };