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