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