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