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