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