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                hideLabels : true,
613                xns : Roo.form,
614                '|xns' : 'Roo.form',
615                xtype : 'Column',
616                items  : [
617                 {
618                  boxLabel : 'Enabled',
619                  xns : Roo.form,
620                  '|xns' : 'Roo.form',
621                  xtype : 'Checkbox'
622                 }
623                ]
624               }
625              ]
626             },
627             {
628              xns : Roo.form,
629              '|xns' : 'Roo.form',
630              xtype : 'Row',
631              items  : [
632               {
633                allowBlank : false,
634                fieldLabel : _this._strings['5da618e8e4b89c66fe86e32cdafde142'] /* From */,
635                name : 'from_name',
636                width : 300,
637                xns : Roo.form,
638                '|xns' : 'Roo.form',
639                xtype : 'TextField'
640               },
641               {
642                allowBlank : false,
643                fieldLabel : _this._strings['b357b524e740bc85b9790a0712d84a30'] /* Email address */,
644                name : 'from_email',
645                width : 300,
646                xns : Roo.form,
647                '|xns' : 'Roo.form',
648                xtype : 'TextField'
649               }
650              ]
651             },
652             {
653              allowBlank : false,
654              fieldLabel : _this._strings['c7892ebbb139886662c6f2fc8c450710'] /* Subject */,
655              name : 'subject',
656              width : 600,
657              xns : Roo.form,
658              '|xns' : 'Roo.form',
659              xtype : 'TextField'
660             },
661             {
662              hideLabels : true,
663              xns : Roo.form,
664              '|xns' : 'Roo.form',
665              xtype : 'Row',
666              items  : [
667               {
668                hideLabels : true,
669                legend : _this._strings['962b90039a542a29cedd51d87a9f28a1'] /* Html Editor */,
670                style : 'text-align:center;',
671                xns : Roo.form,
672                '|xns' : 'Roo.form',
673                xtype : 'FieldSet',
674                items  : [
675                 {
676                  autosave : function() {
677                      
678                      var body = _this.form.findField('bodytext');
679                      
680                      if(!body.wrap.isVisible(true) || body.getValue() == '' || !body.isDirty()){
681                          Roo.log('body not dirty');
682                          return;
683                      }
684                      
685                      Roo.log('body dirty, auto save!');
686                      
687                      body.fireEvent('autosave', body);
688                     
689                  },
690                  clearUp : false,
691                  cwhite : [ 
692                      'margin',
693                      'padding',
694                      'text-align',
695                      'background',
696                      'height',
697                      'width',
698                      'background-color',
699                      'font-size',
700                      'line-height',
701                      'color',
702                      'outline',
703                      'text-decoration',
704                      'position',
705                      'clear',
706                      'overflow',
707                      'margin-top',
708                      'border-bottom',
709                      'top',
710                      'list-style',
711                      'margin-left',
712                      'border',
713                      'float' ,
714                      'margin-right',
715                      'padding-top',
716                      'min-height',
717                      'left',
718                      'padding-left',
719                      'font-weight',
720                      'font-family',
721                      'display',
722                      'margin-bottom',
723                      'padding-bottom',
724                      'vertical-align',
725                      'cursor',
726                      'z-index',
727                      'right'
728                   ],
729                  height : 250,
730                  name : 'bodytext',
731                  resizable : 's',
732                  xns : Roo.form,
733                  '|xns' : 'Roo.form',
734                  xtype : 'HtmlEditor',
735                  listeners : {
736                   autosave : function (_self)
737                    {
738                        Roo.log('autosave');
739                        
740                        var id = _this.form.findField('id').getValue() * 1;
741                        
742                        /*
743                        if(!_self.editorcore.sourceEditMode){
744                            _self.syncValue();
745                        }else{
746                            _self.pushValue();
747                        }
748                        */
749                        
750                        new Pman.Request({
751                            url : baseURL + '/Roo/Events.php',
752                            method :'POST',
753                            params : {
754                                id : 0,
755                                action : 'AUTOSAVE',
756                                on_id : (id > 0) ? id : 0,
757                                on_table : 'crm_mailing_list_message',
758                                remarks : 'BODY',
759                                source: _self.getValue()
760                            },
761                            success : function() {
762                                _self.originalValue = _self.getValue();
763                                
764                            },
765                            failure : function() 
766                            {
767                                Roo.log('body autosave failed?!');
768                            }
769                        });
770                        
771                    },
772                   savedpreview : function (_self)
773                    {
774                        var id = _this.form.findField('id').getValue() * 1;
775                        
776                        var successFn = function(res){
777                            return res.data.POST.source;
778                        };
779                        
780                        var params = {
781                            action : 'AUTOSAVE',
782                            remarks : 'BODY',
783                            on_id : (id < 1) ? 0 : id,
784                            on_table : 'crm_mailing_list_message',
785                            successFn : successFn
786                        };
787                        
788                        
789                        Pman.Dialog.CoreAutoSavePreview.show(params, function(res){
790                            _self.setValue(res);
791                            _self.originalValue = res;
792                        });
793                    }
794                  },
795                  toolbars : [
796                   {
797                    xns : Roo.form.HtmlEditor,
798                    '|xns' : 'Roo.form.HtmlEditor',
799                    xtype : 'ToolbarContext'
800                   },
801                   {
802                    xns : Roo.form.HtmlEditor,
803                    '|xns' : 'Roo.form.HtmlEditor',
804                    xtype : 'ToolbarStandard',
805                    btns : [
806                     {
807                      alwaysQuery : true,
808                      displayField : 'name',
809                      editable : false,
810                      emptyText : _this._strings['b9c49611cfda3259a2b837b39489e650'] /* Add Image */,
811                      fieldLabel : _this._strings['fff0d600f8a0b5e19e88bfb821dd1157'] /* Images */,
812                      forceSelection : true,
813                      listWidth : 400,
814                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
815                      minChars : 2,
816                      pageSize : 20,
817                      qtip : _this._strings['2f26e35d61be90501e099089dc533638'] /* Select Images */,
818                      selectOnFocus : true,
819                      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>',
820                      triggerAction : 'all',
821                      typeAhead : true,
822                      valueField : 'id',
823                      width : 100,
824                      xns : Roo.form,
825                      '|xns' : 'Roo.form',
826                      xtype : 'ComboBox',
827                      listeners : {
828                       beforequery : function (combo, query, forceAll, cancel, e)
829                        {
830                            var id = _this.form.findField('id').getValue() * 1;    
831                            if (!id) {
832                                Roo.MessageBox.alert("Error", "Save message first");
833                                return false;
834                            }
835                        },
836                       render : function (_self)
837                        {
838                            _this.extendimgselect = _self;
839                        },
840                       select : function (combo, record, index)
841                        {
842                            Roo.log(record);
843                            (function() { 
844                                combo.setValue('');
845                            }).defer(100);
846                            var editor = _this.form.findField('bodytext').editorcore;
847                            
848                            var curnode = editor.getSelectedNode();
849                            if (curnode && curnode.tagName == 'IMG') {
850                                curnode.src= String.format('{0}/Images/{1}/{2}#image-{1}',
851                                        baseURL,  record.data.id, record.data.filename
852                                    );
853                                    // note -forces an update... hopefully...
854                                editor.owner.fireEvent('editorevent', editor, false);
855                            } else {
856                            
857                                editor.insertAtCursor(
858                                    String.format('<img src="{0}/Images/{1}/{2}#image-{1}">',
859                                    baseURL,  record.data.id, record.data.filename
860                                    )
861                                );
862                        
863                            }
864                            
865                         }
866                      },
867                      store : {
868                       remoteSort : true,
869                       sortInfo : { direction : 'ASC', field: 'id' },
870                       xns : Roo.data,
871                       '|xns' : 'Roo.data',
872                       xtype : 'Store',
873                       listeners : {
874                        beforeload : function (_self, o){
875                             o.params = o.params || {};
876                         
877                             var id = _this.form.findField('id').getValue() * 1;    
878                             if (!id) {
879                                 Roo.MessageBox.alert("Error", "Save email template first");
880                                 return false;
881                             }
882                             o.params.onid = id;
883                             o.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
884                             
885                            // o.params.imgtype = 'PressRelease';
886                             //o.params['query[imagesize]'] = '150x150';
887                             // set more here
888                         }
889                       },
890                       proxy : {
891                        method : 'GET',
892                        url : baseURL + '/Roo/Images.php',
893                        xns : Roo.data,
894                        '|xns' : 'Roo.data',
895                        xtype : 'HttpProxy'
896                       },
897                       reader : {
898                        fields : [{"name":"id","type":"int"},{"name":"filename","type":"string"},{"name":"url_thumb","type":"string"}],
899                        id : 'id',
900                        root : 'data',
901                        totalProperty : 'total',
902                        xns : Roo.data,
903                        '|xns' : 'Roo.data',
904                        xtype : 'JsonReader'
905                       }
906                      }
907                     },
908                     {
909                      alwaysQuery : true,
910                      displayField : 'name',
911                      editable : false,
912                      emptyText : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
913                      fieldLabel : _this._strings['6f16a5f8ff5d75ab84c018adacdfcbb7'] /* Field */,
914                      forceSelection : true,
915                      listWidth : 400,
916                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
917                      minChars : 2,
918                      pageSize : 20,
919                      qtip : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
920                      selectOnFocus : true,
921                      tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{name}</b> </div>',
922                      triggerAction : 'all',
923                      typeAhead : true,
924                      valueField : 'type',
925                      width : 100,
926                      xns : Roo.form,
927                      '|xns' : 'Roo.form',
928                      xtype : 'ComboBox',
929                      listeners : {
930                       render : function (_self)
931                        {
932                            _this.unsubscribeselect = _self;
933                        },
934                       select : function (combo, record, index)
935                        {
936                            Roo.log(record);
937                            (function() { 
938                                combo.setValue('');
939                            }).defer(100);
940                            var editor = _this.form.findField('bodytext').editorcore;
941                            
942                            if(record.data.name == 'Unsubscribe'){
943                                editor.insertAtCursor(
944                                    String.format('<a href="{0}">{1}</a>',
945                                        record.data.type,  record.data.name
946                                    )
947                                );
948                                return;     
949                            }
950                            
951                            editor.insertAtCursor(
952                                String.format('{0}',
953                                    record.data.type
954                                )
955                            );
956                            
957                         }
958                      },
959                      store : {
960                       data : [ 
961                           [ '{person.firstname}', "First Name"],
962                           [ '{person.lastname}' , "Last Name"],
963                           [ '{person.name}', "Full Name"],
964                           [ '#unsubscribe', "Unsubscribe"]
965                       ],
966                       fields : [  'type', 'name'],
967                       xns : Roo.data,
968                       '|xns' : 'Roo.data',
969                       xtype : 'SimpleStore'
970                      }
971                     },
972                     {
973                      xns : Roo.Toolbar,
974                      '|xns' : 'Roo.Toolbar',
975                      xtype : 'Separator'
976                     },
977                     {
978                      cls : 'x-init-enable',
979                      text : _this._strings['bd88a20b53a47f7b5704a83a15ff5506'] /* Saved Version */,
980                      xns : Roo.Toolbar,
981                      '|xns' : 'Roo.Toolbar',
982                      xtype : 'Button',
983                      listeners : {
984                       click : function (_self, e)
985                        {
986                            this.scope.owner.fireEvent('savedpreview', this.scope.owner);
987                            
988                        }
989                      }
990                     }
991                    ]
992                   }
993                  ]
994                 }
995                ]
996               }
997              ]
998             },
999             {
1000              hideLabels : true,
1001              xns : Roo.form,
1002              '|xns' : 'Roo.form',
1003              xtype : 'Row',
1004              items  : [
1005               {
1006                text : _this._strings['e9968623956c15023d54335ea3699855'] /* Convert Html to Text */,
1007                xns : Roo,
1008                '|xns' : 'Roo',
1009                xtype : 'Button',
1010                listeners : {
1011                 click : function (_self, e)
1012                  {
1013                      var h = _this.form.findField('bodytext').getValue();
1014                      var p = _this.form.findField('plaintext');
1015                      
1016                      new Pman.Request({\r
1017                          url : baseURL + '/Core/ImportMailMessage.php',\r
1018                          method : 'POST',\r
1019                          params : {
1020                            bodytext : h,\r
1021                            _convertToPlain : true,
1022                            _check_unsubscribe : true\r
1023                          }, \r
1024                          success : function(res) {\r
1025                              if(res.success == true){
1026                                 p.setValue(res.data);
1027                              }\r
1028                          }\r
1029                      });  
1030                      
1031                  }
1032                }
1033               }
1034              ]
1035             },
1036             {
1037              hideLabels : true,
1038              xns : Roo.form,
1039              '|xns' : 'Roo.form',
1040              xtype : 'Row',
1041              items  : [
1042               {
1043                hideLabels : true,
1044                legend : _this._strings['e44b145bd8b49b06e0ad2ced1ad56466'] /* Plain Text */,
1045                style : 'text-align:center;',
1046                xns : Roo.form,
1047                '|xns' : 'Roo.form',
1048                xtype : 'FieldSet',
1049                items  : [
1050                 {
1051                  height : 50,
1052                  name : 'plaintext',
1053                  xns : Roo.form,
1054                  '|xns' : 'Roo.form',
1055                  xtype : 'TextArea'
1056                 }
1057                ]
1058               }
1059              ]
1060             },
1061             {
1062              name : 'id',
1063              xns : Roo.form,
1064              '|xns' : 'Roo.form',
1065              xtype : 'Hidden'
1066             }
1067            ]
1068           }
1069          ]
1070         }
1071        ]
1072       }
1073      },
1074      {
1075       autoScroll : false,
1076       background : false,
1077       fitContainer : true,
1078       fitToframe : true,
1079       region : 'east',
1080       tableName : 'Images',
1081       title : _this._strings['308f2757bfc9ce92fb00ff93fdffd279'] /* Images / Attachments */,
1082       xns : Roo,
1083       '|xns' : 'Roo',
1084       xtype : 'GridPanel',
1085       listeners : {
1086        activate : function() {
1087             _this.ipanel = this;
1088             if (_this.igrid) {
1089                _this.igrid.ds.load({});
1090             }
1091         }
1092       },
1093       grid : {
1094        autoExpandColumn : 'filename',
1095        loadMask : true,
1096        xns : Roo.grid,
1097        '|xns' : 'Roo.grid',
1098        xtype : 'Grid',
1099        listeners : {
1100         render : function() 
1101          {
1102              _this.igrid = this; 
1103              //_this.dialog = Pman.Dialog.FILL_IN
1104              if (_this.ipanel.active) {
1105             //    _this.igrid.ds.load({});
1106              }
1107          }
1108        },
1109        toolbar : {
1110         xns : Roo,
1111         '|xns' : 'Roo',
1112         xtype : 'Toolbar',
1113         items  : [
1114          {
1115           cls : 'x-btn-text-icon',
1116           icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1117           text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
1118           xns : Roo.Toolbar,
1119           '|xns' : 'Roo.Toolbar',
1120           xtype : 'Button',
1121           listeners : {
1122            click : function()
1123             {
1124                 var id = _this.form.findField('id').getValue();
1125                 
1126                 if(id*1 < 1){
1127                     Roo.MessageBox.alert('Error', 'Please save the email template first');
1128                     return;
1129                 }
1130                 
1131                 var ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1132                 
1133                 Pman.Dialog.Image.show( { id : 0, onid: id, ontable: ontable }, function() {
1134                     _this.igrid.getDataSource().load({});
1135                 }); 
1136             }
1137           }
1138          },
1139          {
1140           cls : 'x-btn-text-icon',
1141           icon : rootURL + '/Pman/templates/images/trash.gif',
1142           text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
1143           xns : Roo.Toolbar,
1144           '|xns' : 'Roo.Toolbar',
1145           xtype : 'Button',
1146           listeners : {
1147            click : function()
1148             {
1149                 var s = _this.igrid.getSelectionModel().getSelected();
1150                 if (!s || isNaN(s.id *1)) {
1151                     Roo.MessageBox.alert("Error", "Select a image"); 
1152                     return;
1153                 }
1154                 Roo.MessageBox.confirm("Confirm", "Are sure you want to delete this image?", function (v){
1155                     if (v != 'yes') {
1156                         return;
1157                     }
1158                     
1159                     new Pman.Request({
1160                         url : baseURL + '/Roo/Images.php',
1161                         method: 'POST',
1162                         params : {
1163                             _delete : s.id
1164                         },
1165                         success : function()
1166                         {
1167                             Roo.log('Got Success!!');
1168                            _this.igrid.ds.load({});
1169                         }
1170                     });
1171                 });
1172             }
1173           }
1174          }
1175         ]
1176        },
1177        dataSource : {
1178         remoteSort : true,
1179         sortInfo : { field : 'filename', direction: 'ASC' },
1180         xns : Roo.data,
1181         '|xns' : 'Roo.data',
1182         xtype : 'Store',
1183         listeners : {
1184          beforeload : function (_self, options)
1185           {
1186               options.params = options.params || {};
1187               if (typeof(_this.data) == 'undefined') {
1188                   return false;
1189               }
1190               if(_this.data.id * 1 >= 0)
1191               {
1192                   options.params.onid = _this.data.id;
1193           
1194                   options.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1195               }
1196           }
1197         },
1198         proxy : {
1199          method : 'GET',
1200          url : baseURL + '/Roo/Images.php',
1201          xns : Roo.data,
1202          '|xns' : 'Roo.data',
1203          xtype : 'HttpProxy'
1204         },
1205         reader : {
1206          fields : [
1207              {
1208                  'name': 'id',
1209                  'type': 'int'
1210              },
1211              {
1212                  'name': 'filename',
1213                  'type': 'string'
1214              },
1215              {
1216                  'name': 'ontable',
1217                  'type': 'string'
1218              },
1219              {
1220                  'name': 'onid',
1221                  'type': 'int'
1222              },
1223              {
1224                  'name': 'mimetype',
1225                  'type': 'string'
1226              },
1227              {
1228                  'name': 'width',
1229                  'type': 'int'
1230              },
1231              {
1232                  'name': 'height',
1233                  'type': 'int'
1234              },
1235              {
1236                  'name': 'filesize',
1237                  'type': 'int'
1238              },
1239              {
1240                  'name': 'displayorder',
1241                  'type': 'int'
1242              },
1243              {
1244                  'name': 'language',
1245                  'type': 'string'
1246              },
1247              {
1248                  'name': 'parent_image_id',
1249                  'type': 'int'
1250              },
1251              {
1252                  'name': 'created',
1253                  'type': 'date',
1254                  'dateFormat': 'Y-m-d'
1255              },
1256              {
1257                  'name': 'imgtype',
1258                  'type': 'string'
1259              },
1260              {
1261                  'name': 'linkurl',
1262                  'type': 'string'
1263              },
1264              {
1265                  'name': 'descript',
1266                  'type': 'string'
1267              },
1268              {
1269                  'name': 'title',
1270                  'type': 'string'
1271              },
1272              {
1273                  'name': 'parent_image_id_id',
1274                  'type': 'int'
1275              },
1276              {
1277                  'name': 'parent_image_id_filename',
1278                  'type': 'string'
1279              },
1280              {
1281                  'name': 'parent_image_id_ontable',
1282                  'type': 'string'
1283              },
1284              {
1285                  'name': 'parent_image_id_onid',
1286                  'type': 'int'
1287              },
1288              {
1289                  'name': 'parent_image_id_mimetype',
1290                  'type': 'string'
1291              },
1292              {
1293                  'name': 'parent_image_id_width',
1294                  'type': 'int'
1295              },
1296              {
1297                  'name': 'parent_image_id_height',
1298                  'type': 'int'
1299              },
1300              {
1301                  'name': 'parent_image_id_filesize',
1302                  'type': 'int'
1303              },
1304              {
1305                  'name': 'parent_image_id_displayorder',
1306                  'type': 'int'
1307              },
1308              {
1309                  'name': 'parent_image_id_language',
1310                  'type': 'string'
1311              },
1312              {
1313                  'name': 'parent_image_id_parent_image_id',
1314                  'type': 'int'
1315              },
1316              {
1317                  'name': 'parent_image_id_created',
1318                  'type': 'date'
1319              },
1320              {
1321                  'name': 'parent_image_id_imgtype',
1322                  'type': 'string'
1323              },
1324              {
1325                  'name': 'parent_image_id_linkurl',
1326                  'type': 'string'
1327              },
1328              {
1329                  'name': 'parent_image_id_descript',
1330                  'type': 'string'
1331              },
1332              {
1333                  'name': 'parent_image_id_title',
1334                  'type': 'string'
1335              }
1336          ],
1337          id : 'id',
1338          root : 'data',
1339          totalProperty : 'total',
1340          xns : Roo.data,
1341          '|xns' : 'Roo.data',
1342          xtype : 'JsonReader'
1343         }
1344        },
1345        colModel : [
1346         {
1347          dataIndex : 'filename',
1348          header : _this._strings['1351017ac6423911223bc19a8cb7c653'] /* Filename */,
1349          renderer : function(v,x,r)
1350          {
1351              var width = r.data.width;
1352              var height = r.data.height;
1353              
1354              if(width > 50){
1355                  height = Math.round(height * 50 / width);
1356                  width = 50;
1357              }
1358              
1359             return '<img src="' + baseURL + '/Images/' + r.data.id + '/' + r.data.filename + '" width="' + width + '" height="' + height + '" />';
1360          },
1361          width : 300,
1362          xns : Roo.grid,
1363          '|xns' : 'Roo.grid',
1364          xtype : 'ColumnModel'
1365         },
1366         {
1367          dataIndex : 'displayorder',
1368          header : _this._strings['2393ad754ba179442d85e415d1d5167c'] /* Displayorder */,
1369          renderer : function(v) { return String.format('{0}', v); },
1370          width : 75,
1371          xns : Roo.grid,
1372          '|xns' : 'Roo.grid',
1373          xtype : 'ColumnModel'
1374         },
1375         {
1376          dataIndex : 'title',
1377          header : _this._strings['b78a3223503896721cca1303f776159b'] /* Title */,
1378          renderer : function(v) { return String.format('{0}', v); },
1379          width : 75,
1380          xns : Roo.grid,
1381          '|xns' : 'Roo.grid',
1382          xtype : 'ColumnModel'
1383         }
1384        ]
1385       }
1386      }
1387     ]
1388    });
1389  }
1390 };