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