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                
475                
476                
477                var html = _this.form.findField('bodytext').getValue();
478                
479                var s = Roo.get(_this.form.findField('bodytext').editorcore.doc.documentElement);
480                
481                var ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
482                
483                var nodes = [];
484                s.select('img[src]').each(function(i) {
485                    nodes.push(i.dom);
486                });
487                var total = nodes.length;
488                var mkimg = function() {
489                
490                    if (!nodes.length) {
491                          Roo.MessageBox.hide();
492                          _this.form.findField('bodytext').syncValue();
493                          done_callback(true);
494                       //    _this.form.doAction("submit");
495                          return;
496                    }
497                    var i = nodes.pop(); 
498                    
499                    var n = i.getAttribute('src').match(/(baseURL|server_baseurl)/);
500                    
501                    if(n){
502                        mkimg();
503                        return;
504                    }
505                    
506                    n = i.getAttribute('src').match(/^http(.*)/);
507                   
508                    if(!n ){
509                        mkimg();
510                        return;
511                    }
512                    
513                    new Pman.Request({
514                        url : baseURL + '/Roo/Images.php',
515                        method : 'POST',
516                        params : {
517                            onid : _this.form.findField('id').getValue(),
518                            ontable : ontable ,
519                            _remote_upload : i.src
520                        },
521                        success : function(res){
522                            if(res.success == true){      
523                                i.setAttribute('src', res.data);
524                                Roo.MessageBox.updateProgress( (total - nodes.length) / total , "Done " + (total - nodes.length) + '/' + total);
525                            }
526                            mkimg();
527                        }
528                    });
529                   
530                }
531                mkimg();
532            },
533            style : 'margin:10px',
534            url : baseURL + '/Roo/crm_mailing_list_message.php',
535            xns : Roo.form,
536            '|xns' : 'Roo.form',
537            xtype : 'Form',
538            listeners : {
539             actioncomplete : function(_self,action)
540              {
541                 
542                  if (action.type == 'setdata') {
543                  
544                      _this.data.module = _this.data.module || 'crm_mailing_list_message';
545                      
546                      _this.form.url = baseURL + '/Roo/' + _this.data.module;
547                      
548                      _this.html_preview.hide();
549                      _this.preview_btn.hide();
550                          
551                      if(_this.data.id*1 > 0){
552                          _this.dialog.el.mask("Loading");
553                          this.load({ method: 'GET', params: { '_id' : _this.data.id }});
554                          _this.html_preview.show();
555                          _this.preview_btn.show();
556                          
557                      } else {
558                          _this.form.setValues({
559                              'from_name' : Pman.Login.authUser.name,
560                              'from_email' : Pman.Login.authUser.email
561                          });
562                      }
563                     return;
564                  }
565                  if (action.type == 'load') {
566                      _this.dialog.el.unmask();
567                      return;
568                  }
569                  if (action.type =='submit') {
570                  
571                      _this.dialog.el.unmask();
572                      _this.dialog.hide();
573                  
574                       if (_this.callback) {
575                          _this.callback.call(_this, action.result.data);
576                       }
577                       _this.form.reset();
578                       return;
579                  }
580              },
581             rendered : function (form)
582              {
583                  _this.form= form;
584              }
585            },
586            items  : [
587             {
588              xns : Roo.form,
589              '|xns' : 'Roo.form',
590              xtype : 'Row',
591              items  : [
592               {
593                allowBlank : false,
594                fieldLabel : _this._strings['b20a8b77b05d53b4e695738731400c85'] /* Mailout Name */,
595                name : 'name',
596                width : 400,
597                xns : Roo.form,
598                '|xns' : 'Roo.form',
599                xtype : 'TextField'
600               }
601              ]
602             },
603             {
604              xns : Roo.form,
605              '|xns' : 'Roo.form',
606              xtype : 'Row',
607              items  : [
608               {
609                allowBlank : false,
610                fieldLabel : _this._strings['5da618e8e4b89c66fe86e32cdafde142'] /* From */,
611                name : 'from_name',
612                width : 300,
613                xns : Roo.form,
614                '|xns' : 'Roo.form',
615                xtype : 'TextField'
616               },
617               {
618                allowBlank : false,
619                fieldLabel : _this._strings['b357b524e740bc85b9790a0712d84a30'] /* Email address */,
620                name : 'from_email',
621                width : 300,
622                xns : Roo.form,
623                '|xns' : 'Roo.form',
624                xtype : 'TextField'
625               }
626              ]
627             },
628             {
629              allowBlank : false,
630              fieldLabel : _this._strings['c7892ebbb139886662c6f2fc8c450710'] /* Subject */,
631              name : 'subject',
632              width : 600,
633              xns : Roo.form,
634              '|xns' : 'Roo.form',
635              xtype : 'TextField'
636             },
637             {
638              hideLabels : true,
639              xns : Roo.form,
640              '|xns' : 'Roo.form',
641              xtype : 'Row',
642              items  : [
643               {
644                hideLabels : true,
645                legend : _this._strings['962b90039a542a29cedd51d87a9f28a1'] /* Html Editor */,
646                style : 'text-align:center;',
647                xns : Roo.form,
648                '|xns' : 'Roo.form',
649                xtype : 'FieldSet',
650                items  : [
651                 {
652                  clearUp : false,
653                  cwhite : [ 
654                      'margin',
655                      'padding',
656                      'text-align',
657                      'background',
658                      'height',
659                      'width',
660                      'background-color',
661                      'font-size',
662                      'line-height',
663                      'color',
664                      'outline',
665                      'text-decoration',
666                      'position',
667                      'clear',
668                      'overflow',
669                      'margin-top',
670                      'border-bottom',
671                      'top',
672                      'list-style',
673                      'margin-left',
674                      'border',
675                      'float' ,
676                      'margin-right',
677                      'padding-top',
678                      'min-height',
679                      'left',
680                      'padding-left',
681                      'font-weight',
682                      'font-family',
683                      'display',
684                      'margin-bottom',
685                      'padding-bottom',
686                      'vertical-align',
687                      'cursor',
688                      'z-index',
689                      'right'
690                   ],
691                  height : 250,
692                  name : 'bodytext',
693                  resizable : 's',
694                  xns : Roo.form,
695                  '|xns' : 'Roo.form',
696                  xtype : 'HtmlEditor',
697                  toolbars : [
698                   {
699                    xns : Roo.form.HtmlEditor,
700                    '|xns' : 'Roo.form.HtmlEditor',
701                    xtype : 'ToolbarContext'
702                   },
703                   {
704                    xns : Roo.form.HtmlEditor,
705                    '|xns' : 'Roo.form.HtmlEditor',
706                    xtype : 'ToolbarStandard',
707                    btns : [
708                     {
709                      alwaysQuery : true,
710                      displayField : 'name',
711                      editable : false,
712                      emptyText : _this._strings['b9c49611cfda3259a2b837b39489e650'] /* Add Image */,
713                      fieldLabel : _this._strings['fff0d600f8a0b5e19e88bfb821dd1157'] /* Images */,
714                      forceSelection : true,
715                      listWidth : 400,
716                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
717                      minChars : 2,
718                      pageSize : 20,
719                      qtip : _this._strings['2f26e35d61be90501e099089dc533638'] /* Select Images */,
720                      selectOnFocus : true,
721                      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>',
722                      triggerAction : 'all',
723                      typeAhead : true,
724                      valueField : 'id',
725                      width : 100,
726                      xns : Roo.form,
727                      '|xns' : 'Roo.form',
728                      xtype : 'ComboBox',
729                      listeners : {
730                       beforequery : function (combo, query, forceAll, cancel, e)
731                        {
732                            var id = _this.form.findField('id').getValue() * 1;    
733                            if (!id) {
734                                Roo.MessageBox.alert("Error", "Save message first");
735                                return false;
736                            }
737                        },
738                       render : function (_self)
739                        {
740                            _this.extendimgselect = _self;
741                        },
742                       select : function (combo, record, index)
743                        {
744                            Roo.log(record);
745                            (function() { 
746                                combo.setValue('');
747                            }).defer(100);
748                            var editor = _this.form.findField('bodytext').editorcore;
749                            
750                            var curnode = editor.getSelectedNode();
751                            if (curnode && curnode.tagName == 'IMG') {
752                                curnode.src= String.format('{0}/Images/{1}/{2}#image-{1}',
753                                        baseURL,  record.data.id, record.data.filename
754                                    );
755                                    // note -forces an update... hopefully...
756                                editor.owner.fireEvent('editorevent', editor, false);
757                            } else {
758                            
759                                editor.insertAtCursor(
760                                    String.format('<img src="{0}/Images/{1}/{2}#image-{1}">',
761                                    baseURL,  record.data.id, record.data.filename
762                                    )
763                                );
764                        
765                            }
766                            
767                         }
768                      },
769                      store : {
770                       remoteSort : true,
771                       sortInfo : { direction : 'ASC', field: 'id' },
772                       xns : Roo.data,
773                       '|xns' : 'Roo.data',
774                       xtype : 'Store',
775                       listeners : {
776                        beforeload : function (_self, o){
777                             o.params = o.params || {};
778                         
779                             var id = _this.form.findField('id').getValue() * 1;    
780                             if (!id) {
781                                 Roo.MessageBox.alert("Error", "Save email template first");
782                                 return false;
783                             }
784                             o.params.onid = id;
785                             o.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
786                             
787                            // o.params.imgtype = 'PressRelease';
788                             //o.params['query[imagesize]'] = '150x150';
789                             // set more here
790                         }
791                       },
792                       proxy : {
793                        method : 'GET',
794                        url : baseURL + '/Roo/Images.php',
795                        xns : Roo.data,
796                        '|xns' : 'Roo.data',
797                        xtype : 'HttpProxy'
798                       },
799                       reader : {
800                        fields : [{"name":"id","type":"int"},{"name":"filename","type":"string"},{"name":"url_thumb","type":"string"}],
801                        id : 'id',
802                        root : 'data',
803                        totalProperty : 'total',
804                        xns : Roo.data,
805                        '|xns' : 'Roo.data',
806                        xtype : 'JsonReader'
807                       }
808                      }
809                     },
810                     {
811                      alwaysQuery : true,
812                      displayField : 'name',
813                      editable : false,
814                      emptyText : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
815                      fieldLabel : _this._strings['6f16a5f8ff5d75ab84c018adacdfcbb7'] /* Field */,
816                      forceSelection : true,
817                      listWidth : 400,
818                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
819                      minChars : 2,
820                      pageSize : 20,
821                      qtip : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
822                      selectOnFocus : true,
823                      tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{name}</b> </div>',
824                      triggerAction : 'all',
825                      typeAhead : true,
826                      valueField : 'type',
827                      width : 100,
828                      xns : Roo.form,
829                      '|xns' : 'Roo.form',
830                      xtype : 'ComboBox',
831                      listeners : {
832                       render : function (_self)
833                        {
834                            _this.unsubscribeselect = _self;
835                        },
836                       select : function (combo, record, index)
837                        {
838                            Roo.log(record);
839                            (function() { 
840                                combo.setValue('');
841                            }).defer(100);
842                            var editor = _this.form.findField('bodytext').editorcore;
843                            
844                            if(record.data.name == 'Unsubscribe'){
845                                editor.insertAtCursor(
846                                    String.format('<a href="{0}">{1}</a>',
847                                        record.data.type,  record.data.name
848                                    )
849                                );
850                                return;     
851                            }
852                            
853                            editor.insertAtCursor(
854                                String.format('{0}',
855                                    record.data.type
856                                )
857                            );
858                            
859                         }
860                      },
861                      store : {
862                       data : [ 
863                           [ '{person.firstname}', "First Name"],
864                           [ '{person.lastname}' , "Last Name"],
865                           [ '{person.name}', "Full Name"],
866                           [ '#unsubscribe', "Unsubscribe"]
867                       ],
868                       fields : [  'type', 'name'],
869                       xns : Roo.data,
870                       '|xns' : 'Roo.data',
871                       xtype : 'SimpleStore'
872                      }
873                     }
874                    ]
875                   }
876                  ]
877                 }
878                ]
879               }
880              ]
881             },
882             {
883              hideLabels : true,
884              xns : Roo.form,
885              '|xns' : 'Roo.form',
886              xtype : 'Row',
887              items  : [
888               {
889                text : _this._strings['e9968623956c15023d54335ea3699855'] /* Convert Html to Text */,
890                xns : Roo,
891                '|xns' : 'Roo',
892                xtype : 'Button',
893                listeners : {
894                 click : function (_self, e)
895                  {
896                      var h = _this.form.findField('bodytext').getValue();
897                      var p = _this.form.findField('plaintext');
898                      
899                      new Pman.Request({\r
900                          url : baseURL + '/Core/ImportMailMessage.php',\r
901                          method : 'POST',\r
902                          params : {
903                            bodytext : h,\r
904                            _convertToPlain : true,
905                            _check_unsubscribe : true\r
906                          }, \r
907                          success : function(res) {\r
908                              if(res.success == true){
909                                 p.setValue(res.data);
910                              }\r
911                          }\r
912                      });  
913                      
914                  }
915                }
916               }
917              ]
918             },
919             {
920              hideLabels : true,
921              xns : Roo.form,
922              '|xns' : 'Roo.form',
923              xtype : 'Row',
924              items  : [
925               {
926                hideLabels : true,
927                legend : _this._strings['e44b145bd8b49b06e0ad2ced1ad56466'] /* Plain Text */,
928                style : 'text-align:center;',
929                xns : Roo.form,
930                '|xns' : 'Roo.form',
931                xtype : 'FieldSet',
932                items  : [
933                 {
934                  height : 50,
935                  name : 'plaintext',
936                  xns : Roo.form,
937                  '|xns' : 'Roo.form',
938                  xtype : 'TextArea'
939                 }
940                ]
941               }
942              ]
943             },
944             {
945              name : 'id',
946              xns : Roo.form,
947              '|xns' : 'Roo.form',
948              xtype : 'Hidden'
949             }
950            ]
951           }
952          ]
953         }
954        ]
955       }
956      },
957      {
958       autoScroll : false,
959       background : false,
960       fitContainer : true,
961       fitToframe : true,
962       region : 'east',
963       tableName : 'Images',
964       title : _this._strings['308f2757bfc9ce92fb00ff93fdffd279'] /* Images / Attachments */,
965       xns : Roo,
966       '|xns' : 'Roo',
967       xtype : 'GridPanel',
968       listeners : {
969        activate : function() {
970             _this.ipanel = this;
971             if (_this.igrid) {
972                _this.igrid.ds.load({});
973             }
974         }
975       },
976       grid : {
977        autoExpandColumn : 'filename',
978        loadMask : true,
979        xns : Roo.grid,
980        '|xns' : 'Roo.grid',
981        xtype : 'Grid',
982        listeners : {
983         render : function() 
984          {
985              _this.igrid = this; 
986              //_this.dialog = Pman.Dialog.FILL_IN
987              if (_this.ipanel.active) {
988             //    _this.igrid.ds.load({});
989              }
990          }
991        },
992        toolbar : {
993         xns : Roo,
994         '|xns' : 'Roo',
995         xtype : 'Toolbar',
996         items  : [
997          {
998           cls : 'x-btn-text-icon',
999           icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1000           text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
1001           xns : Roo.Toolbar,
1002           '|xns' : 'Roo.Toolbar',
1003           xtype : 'Button',
1004           listeners : {
1005            click : function()
1006             {
1007                 var id = _this.form.findField('id').getValue();
1008                 
1009                 if(id*1 < 1){
1010                     Roo.MessageBox.alert('Error', 'Please save the email template first');
1011                     return;
1012                 }
1013                 
1014                 var ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1015                 
1016                 Pman.Dialog.Image.show( { id : 0, onid: id, ontable: ontable }, function() {
1017                     _this.igrid.getDataSource().load({});
1018                 }); 
1019             }
1020           }
1021          },
1022          {
1023           cls : 'x-btn-text-icon',
1024           icon : rootURL + '/Pman/templates/images/trash.gif',
1025           text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
1026           xns : Roo.Toolbar,
1027           '|xns' : 'Roo.Toolbar',
1028           xtype : 'Button',
1029           listeners : {
1030            click : function()
1031             {
1032                 var s = _this.igrid.getSelectionModel().getSelected();
1033                 if (!s || isNaN(s.id *1)) {
1034                     Roo.MessageBox.alert("Error", "Select a image"); 
1035                     return;
1036                 }
1037                 Roo.MessageBox.confirm("Confirm", "Are sure you want to delete this image?", function (v){
1038                     if (v != 'yes') {
1039                         return;
1040                     }
1041                     
1042                     new Pman.Request({
1043                         url : baseURL + '/Roo/Images.php',
1044                         method: 'POST',
1045                         params : {
1046                             _delete : s.id
1047                         },
1048                         success : function()
1049                         {
1050                             Roo.log('Got Success!!');
1051                            _this.igrid.ds.load({});
1052                         }
1053                     });
1054                 });
1055             }
1056           }
1057          }
1058         ]
1059        },
1060        dataSource : {
1061         remoteSort : true,
1062         sortInfo : { field : 'filename', direction: 'ASC' },
1063         xns : Roo.data,
1064         '|xns' : 'Roo.data',
1065         xtype : 'Store',
1066         listeners : {
1067          beforeload : function (_self, options)
1068           {
1069               options.params = options.params || {};
1070               if (typeof(_this.data) == 'undefined') {
1071                   return false;
1072               }
1073               if(_this.data.id * 1 >= 0)
1074               {
1075                   options.params.onid = _this.data.id;
1076           
1077                   options.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1078               }
1079           }
1080         },
1081         proxy : {
1082          method : 'GET',
1083          url : baseURL + '/Roo/Images.php',
1084          xns : Roo.data,
1085          '|xns' : 'Roo.data',
1086          xtype : 'HttpProxy'
1087         },
1088         reader : {
1089          fields : [
1090              {
1091                  'name': 'id',
1092                  'type': 'int'
1093              },
1094              {
1095                  'name': 'filename',
1096                  'type': 'string'
1097              },
1098              {
1099                  'name': 'ontable',
1100                  'type': 'string'
1101              },
1102              {
1103                  'name': 'onid',
1104                  'type': 'int'
1105              },
1106              {
1107                  'name': 'mimetype',
1108                  'type': 'string'
1109              },
1110              {
1111                  'name': 'width',
1112                  'type': 'int'
1113              },
1114              {
1115                  'name': 'height',
1116                  'type': 'int'
1117              },
1118              {
1119                  'name': 'filesize',
1120                  'type': 'int'
1121              },
1122              {
1123                  'name': 'displayorder',
1124                  'type': 'int'
1125              },
1126              {
1127                  'name': 'language',
1128                  'type': 'string'
1129              },
1130              {
1131                  'name': 'parent_image_id',
1132                  'type': 'int'
1133              },
1134              {
1135                  'name': 'created',
1136                  'type': 'date',
1137                  'dateFormat': 'Y-m-d'
1138              },
1139              {
1140                  'name': 'imgtype',
1141                  'type': 'string'
1142              },
1143              {
1144                  'name': 'linkurl',
1145                  'type': 'string'
1146              },
1147              {
1148                  'name': 'descript',
1149                  'type': 'string'
1150              },
1151              {
1152                  'name': 'title',
1153                  'type': 'string'
1154              },
1155              {
1156                  'name': 'parent_image_id_id',
1157                  'type': 'int'
1158              },
1159              {
1160                  'name': 'parent_image_id_filename',
1161                  'type': 'string'
1162              },
1163              {
1164                  'name': 'parent_image_id_ontable',
1165                  'type': 'string'
1166              },
1167              {
1168                  'name': 'parent_image_id_onid',
1169                  'type': 'int'
1170              },
1171              {
1172                  'name': 'parent_image_id_mimetype',
1173                  'type': 'string'
1174              },
1175              {
1176                  'name': 'parent_image_id_width',
1177                  'type': 'int'
1178              },
1179              {
1180                  'name': 'parent_image_id_height',
1181                  'type': 'int'
1182              },
1183              {
1184                  'name': 'parent_image_id_filesize',
1185                  'type': 'int'
1186              },
1187              {
1188                  'name': 'parent_image_id_displayorder',
1189                  'type': 'int'
1190              },
1191              {
1192                  'name': 'parent_image_id_language',
1193                  'type': 'string'
1194              },
1195              {
1196                  'name': 'parent_image_id_parent_image_id',
1197                  'type': 'int'
1198              },
1199              {
1200                  'name': 'parent_image_id_created',
1201                  'type': 'date'
1202              },
1203              {
1204                  'name': 'parent_image_id_imgtype',
1205                  'type': 'string'
1206              },
1207              {
1208                  'name': 'parent_image_id_linkurl',
1209                  'type': 'string'
1210              },
1211              {
1212                  'name': 'parent_image_id_descript',
1213                  'type': 'string'
1214              },
1215              {
1216                  'name': 'parent_image_id_title',
1217                  'type': 'string'
1218              }
1219          ],
1220          id : 'id',
1221          root : 'data',
1222          totalProperty : 'total',
1223          xns : Roo.data,
1224          '|xns' : 'Roo.data',
1225          xtype : 'JsonReader'
1226         }
1227        },
1228        colModel : [
1229         {
1230          dataIndex : 'filename',
1231          header : _this._strings['1351017ac6423911223bc19a8cb7c653'] /* Filename */,
1232          renderer : function(v,x,r)
1233          {
1234              var width = r.data.width;
1235              var height = r.data.height;
1236              
1237              if(width > 50){
1238                  height = Math.round(height * 50 / width);
1239                  width = 50;
1240              }
1241              
1242             return '<img src="' + baseURL + '/Images/' + r.data.id + '/' + r.data.filename + '" width="' + width + '" height="' + height + '" />';
1243          },
1244          width : 300,
1245          xns : Roo.grid,
1246          '|xns' : 'Roo.grid',
1247          xtype : 'ColumnModel'
1248         },
1249         {
1250          dataIndex : 'displayorder',
1251          header : _this._strings['2393ad754ba179442d85e415d1d5167c'] /* Displayorder */,
1252          renderer : function(v) { return String.format('{0}', v); },
1253          width : 75,
1254          xns : Roo.grid,
1255          '|xns' : 'Roo.grid',
1256          xtype : 'ColumnModel'
1257         },
1258         {
1259          dataIndex : 'title',
1260          header : _this._strings['b78a3223503896721cca1303f776159b'] /* Title */,
1261          renderer : function(v) { return String.format('{0}', v); },
1262          width : 75,
1263          xns : Roo.grid,
1264          '|xns' : 'Roo.grid',
1265          xtype : 'ColumnModel'
1266         }
1267        ]
1268       }
1269      }
1270     ]
1271    });
1272  }
1273 };