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   'ea30b40c3caf28acb29198d20d243e54' :"Images / Attachments >>",
17   '31fde7b05ac8952dacf4af8a704074ec' :"Preview",
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   '68b00d723d37122f64da8d9939f836f0' :"BCC Group",
32   'c4ca4238a0b923820dcc509a6f75849b' :"1",
33   'bd88a20b53a47f7b5704a83a15ff5506' :"Saved Version",
34   'b20a8b77b05d53b4e695738731400c85' :"Mailout Name",
35   '1bd18d39370b7f26c1c5e18067b74c6f' :"Html File",
36   '2c466a2c159463f1d9ef5a7b57b52827' :"Select BCC Group",
37   '5da618e8e4b89c66fe86e32cdafde142' :"From",
38   '31bb2f6e9b8fb11cbb7fb63c6025223f' :"Select Template",
39   'b78a3223503896721cca1303f776159b' :"Title",
40   '278c491bdd8a53618c149c4ac790da34' :"Template",
41   '1351017ac6423911223bc19a8cb7c653' :"Filename",
42   '308f2757bfc9ce92fb00ff93fdffd279' :"Images / Attachments",
43   'c9cc8cce247e49bae79f15173ce97354' :"Save",
44   '5feb9bf3c03b32635135006cbacb9542' :"Insert Field",
45   '4c2a8fe7eaf24721cc7a9f0175115bd4' :"Message",
46   'fff0d600f8a0b5e19e88bfb821dd1157' :"Images"
47  },
48
49  dialog : false,
50  callback:  false,
51
52  show : function(data, cb)
53  {
54   if (!this.dialog) {
55    this.create();
56   }
57
58   this.callback = cb;
59   this.data = data;
60   this.dialog.show(this.data._el);
61   if (this.form) {
62    this.form.reset();
63    this.form.setValues(data);
64    this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
65   }
66
67  },
68
69  create : function()
70  {
71    var _this = this;
72    this.dialog = Roo.factory({
73     closable : true,
74     collapsible : false,
75     height : 500,
76     modal : true,
77     resizable : true,
78     title : _this._strings['396ecabf0cd1f9503e591418851ef406'] /* Edit / Create Message */,
79     width : 800,
80     xns : Roo,
81     '|xns' : 'Roo',
82     xtype : 'LayoutDialog',
83     listeners : {
84      show : function (_self)
85       {
86           
87           _self.layout.getRegion('center').showPanel(0);
88           var w = Roo.lib.Dom.getViewWidth();\r
89           var h = Roo.lib.Dom.getViewHeight();    \r    this.resizeTo(w-50, h-50);\r
90           this.center();\r    
91           var ew = Math.max(250, w-320);\r
92           var eh = Math.max(250, h-350) ;\r
93           var e = _this.dialog.layout.getRegion('east');
94           if (e.visible) {
95               e.hide();
96           }
97           
98           var el = _self.getEl();
99           var elw = el.dom.clientWidth;
100           
101           var bdtext = _this.form.findField('bodytext');
102           var ptext = _this.form.findField('plaintext');
103           if(bdtext.resizeEl){
104               bdtext.width = elw-100;
105               bdtext.resizeEl.resizeTo.defer(110, bdtext.resizeEl,[ bdtext.width, bdtext.height  ] );
106               ptext.setSize(bdtext.width , bdtext.height);
107           }
108           
109       }
110     },
111     center : {
112      tabPosition : 'top',
113      xns : Roo,
114      '|xns' : 'Roo',
115      xtype : 'LayoutRegion'
116     },
117     east : {
118      hidden : true,
119      split : true,
120      title : _this._strings['308f2757bfc9ce92fb00ff93fdffd279'] /* Images / Attachments */,
121      titlebar : true,
122      width : 500,
123      xns : Roo,
124      '|xns' : 'Roo',
125      xtype : 'LayoutRegion'
126     },
127     buttons : [
128      {
129       text : _this._strings['31fde7b05ac8952dacf4af8a704074ec'] /* Preview */,
130       xns : Roo,
131       '|xns' : 'Roo',
132       xtype : 'Button',
133       listeners : {
134        click : function (_self, e)
135         {
136             //_this.dialog.hide();
137             Roo.log(_this.data.module);
138             Pman.Dialog.CoreEmailPreview.show({ id : _this.form.findField('id').getValue(), module : _this.data.module });
139         },
140        render : function (_self)
141         {
142             _this.preview_btn = _self;
143         }
144       }
145      },
146      {
147       text : _this._strings['5b8ef4e762c00a15a41cfc26dc3ef99c'] /* Send me a test copy */,
148       xns : Roo,
149       '|xns' : 'Roo',
150       xtype : 'Button',
151       listeners : {
152        click : function (_self, e)
153         {
154             //_this.dialog.hide();
155             
156             var id = _this.form.findField('id').getValue();
157             
158             if(id*1 < 1){
159                 Roo.MessageBox.alert('Error', 'Please save the message frist!');
160                 return;
161             }
162            
163             new Pman.Request({
164                 url : baseURL + '/Core/MessagePreview',
165                 method : 'POST',
166                 mask: 'Sending',
167                 params : {
168                     _id : id,
169                     _table : _this.data.module
170                 }, 
171                 success : function(res) { 
172                     if(res.data == 'SUCCESS'){
173                         Roo.MessageBox.alert("Email Sent", 'The report was sent to your email (HTML format).');
174                     }
175                 }
176             });
177         },
178        render : function (_self)
179         {
180             _this.html_preview = _self;
181         }
182       }
183      },
184      {
185       text : _this._strings['ea4788705e6873b424c65e91c2846b19'] /* Cancel */,
186       xns : Roo,
187       '|xns' : 'Roo',
188       xtype : 'Button',
189       listeners : {
190        click : function (_self, e)
191         {
192             _this.dialog.hide();
193         }
194       }
195      },
196      {
197       text : _this._strings['c9cc8cce247e49bae79f15173ce97354'] /* Save */,
198       xns : Roo,
199       '|xns' : 'Roo',
200       xtype : 'Button',
201       listeners : {
202        click : function (_self, e)
203         {
204         
205             // do some checks?
206             _this.form.preValidate(function(res) {
207                 if (!res) {
208                     return; //failed.
209                 }
210                  _this.form.doAction("submit");
211             });
212         
213         }
214       }
215      }
216     ],
217     items  : [
218      {
219       autoScroll : false,
220       fitContainer : true,
221       fitToFrame : true,
222       region : 'center',
223       xns : Roo,
224       '|xns' : 'Roo',
225       xtype : 'NestedLayoutPanel',
226       toolbar : {
227        xns : Roo,
228        '|xns' : 'Roo',
229        xtype : 'Toolbar',
230        items  : [
231         {
232          text : _this._strings['72d6d7a1885885bb55a565fd1070581a'] /* Import */,
233          xns : Roo.Toolbar,
234          '|xns' : 'Roo.Toolbar',
235          xtype : 'Button',
236          menu : {
237           xns : Roo.menu,
238           '|xns' : 'Roo.menu',
239           xtype : 'Menu',
240           items  : [
241            {
242             text : _this._strings['e6b391a8d2c4d45902a23a8b6585703d'] /* URL */,
243             xns : Roo.menu,
244             '|xns' : 'Roo.menu',
245             xtype : 'Item',
246             listeners : {
247              click : function (_self, e)
248               {
249                   Pman.Dialog.CoreImportUrl.show({
250                       target : '/Core/ImportMailMessage.php'
251                   }, function(data) {
252                       if  (data) {
253                         //  Roo.log(data);
254                           _this.form.findField('bodytext').setValue(data);
255                       }
256                   });
257               }
258             }
259            },
260            {
261             text : _this._strings['1bd18d39370b7f26c1c5e18067b74c6f'] /* Html File */,
262             xns : Roo.menu,
263             '|xns' : 'Roo.menu',
264             xtype : 'Item',
265             listeners : {
266              click : function (_self, e)
267               {
268                   Pman.Dialog.Image.show({
269                       _url : baseURL + '/Core/ImportMailMessage.php'
270                   }, function(data) {
271                       if  (data) {
272                           _this.form.findField('bodytext').setValue(data);
273                       }
274                   });
275               }
276             }
277            }
278           ]
279          }
280         },
281         {
282          text : _this._strings['884df8e413319ff51a3f5f528606238a'] /* Use template */,
283          xns : Roo.Toolbar,
284          '|xns' : 'Roo.Toolbar',
285          xtype : 'Button',
286          menu : {
287           xns : Roo.menu,
288           '|xns' : 'Roo.menu',
289           xtype : 'Menu',
290           items  : [
291            {
292             text : _this._strings['dc0de523c25be298ba751c63c694109e'] /* Responsive Email (1) */,
293             xns : Roo.menu,
294             '|xns' : 'Roo.menu',
295             xtype : 'Item',
296             listeners : {
297              click : function (_self, e)
298               {
299               
300                   var l = document.location;
301                   new Pman.Request({
302               
303                       url : baseURL + '/Core/ImportMailMessage.php',
304               
305                       method: 'POST',
306                       mask : "Loading",
307                       params : {
308                             importUrl : l.protocol +'//' + l.host +   rootURL + '/Pman/Crm/mail_templates/responsive1.html'
309                      },
310                       success : function (res) {
311               
312                        _this.form.findField('bodytext').setValue(res.data);
313                       }
314                 
315                   });
316               }
317             }
318            }
319           ]
320          }
321         },
322         {
323          allowBlank : true,
324          alwaysQuery : true,
325          displayField : 'file',
326          editable : false,
327          emptyText : _this._strings['31bb2f6e9b8fb11cbb7fb63c6025223f'] /* Select Template */,
328          fieldLabel : _this._strings['278c491bdd8a53618c149c4ac790da34'] /* Template */,
329          forceSelection : true,
330          hiddenName : 'template',
331          listWidth : 400,
332          loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
333          minChars : 2,
334          name : 'template',
335          pageSize : 20,
336          qtip : _this._strings['31bb2f6e9b8fb11cbb7fb63c6025223f'] /* Select Template */,
337          selectOnFocus : true,
338          tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{file}</b> </div>',
339          triggerAction : 'all',
340          typeAhead : true,
341          valueField : 'file',
342          width : 200,
343          xns : Roo.form,
344          '|xns' : 'Roo.form',
345          xtype : 'ComboBox',
346          listeners : {
347           select : function (combo, record, index)
348            {
349               
350            /*
351                (function() { 
352                    combo.setValue('');
353                }).defer(100);
354            */    
355                if(!record){
356                    return;
357                }
358                _this.form.findField('bodytext').setValue(record.data.content);
359            
360            }
361          },
362          store : {
363           remoteSort : true,
364           sortInfo : { direction : 'DESC', field: 'file' },
365           xns : Roo.data,
366           '|xns' : 'Roo.data',
367           xtype : 'Store',
368           listeners : {
369            beforeload : function (_self, o){
370                 o.params = o.params || {};
371                 // set more here
372                
373             }
374           },
375           proxy : {
376            method : 'GET',
377            url : baseURL + '/Core/MailTemplateList.php',
378            xns : Roo.data,
379            '|xns' : 'Roo.data',
380            xtype : 'HttpProxy'
381           },
382           reader : {
383            fields : [{"name":"file","type":"string"},{"name":"content","type":"string"}],
384            id : 'name',
385            root : 'data',
386            totalProperty : 'total',
387            xns : Roo.data,
388            '|xns' : 'Roo.data',
389            xtype : 'JsonReader'
390           }
391          }
392         },
393         {
394          xns : Roo.Toolbar,
395          '|xns' : 'Roo.Toolbar',
396          xtype : 'Fill'
397         },
398         {
399          text : _this._strings['ea30b40c3caf28acb29198d20d243e54'] /* Images / Attachments >> */,
400          xns : Roo.Toolbar,
401          '|xns' : 'Roo.Toolbar',
402          xtype : 'Button',
403          listeners : {
404           click : function (_self, e)
405            {
406                var el = _this.dialog.layout.getRegion('east');
407                if (el.visible) {
408                    el.hide();
409                } else {
410                    el.show();
411                    el.showPanel(0);
412                }
413                
414            }
415          }
416         }
417        ]
418       },
419       layout : {
420        xns : Roo,
421        '|xns' : 'Roo',
422        xtype : 'BorderLayout',
423        center : {
424         autoScroll : true,
425         xns : Roo,
426         '|xns' : 'Roo',
427         xtype : 'LayoutRegion'
428        },
429        items  : [
430         {
431          autoScroll : false,
432          background : false,
433          fitContainer : true,
434          fitToFrame : true,
435          region : 'center',
436          title : _this._strings['4c2a8fe7eaf24721cc7a9f0175115bd4'] /* Message */,
437          xns : Roo,
438          '|xns' : 'Roo',
439          xtype : 'ContentPanel',
440          listeners : {
441           render : function (_self, width, height)
442            {
443                
444                  Roo.log("RESIZE, " + width + ',' + height);
445                
446                var ew = Math.max(250, width-50);
447                var eh = Math.max(250,height-50) ;
448                
449               
450            
451            },
452           resize : function (_self, width, height)\r
453            {\r
454               var ew = Math.max(250, width-50);\r
455                var eh = Math.max(250,height-50) ;
456                
457                if (!_this.form) {\r
458                    return;\r
459                }\r
460                var bdtext = _this.form.findField('bodytext');\r
461                var ptext = _this.form.findField('plaintext');\r
462                if(bdtext.resizeEl){\r
463                    bdtext.width = ew-50;\r
464                    bdtext.resizeEl.resizeTo.defer(110, bdtext.resizeEl,[ bdtext.width, bdtext.height  ] );\r
465                    ptext.setSize(bdtext.width , bdtext.height);\r
466                }\r\r
467            \r
468            }
469          },
470          items  : [
471           {
472            labelAlign : 'right',
473            labelWidth : 120,
474            method : 'POST',
475            preValidate : function(done_callback) {
476                
477                Roo.MessageBox.progress("Uploading Images", "Uploading");
478                
479                if(!_this.form.findField('bodytext').editorcore.sourceEditMode){
480                    _this.form.findField('bodytext').syncValue();
481                }else{
482                    _this.form.findField('bodytext').pushValue();
483                }
484                
485                var html = _this.form.findField('bodytext').getValue();
486                
487                var s = Roo.get(_this.form.findField('bodytext').editorcore.doc.documentElement);
488                
489                var ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
490                
491                var nodes = [];
492                s.select('img[src]').each(function(i) {
493                    nodes.push(i.dom);
494                });
495                var total = nodes.length;
496                var mkimg = function() {
497                
498                    if (!nodes.length) {
499                          Roo.MessageBox.hide();
500                          _this.form.findField('bodytext').syncValue();
501                          done_callback(true);
502                       //    _this.form.doAction("submit");
503                          return;
504                    }
505                    var i = nodes.pop(); 
506                    
507                    var n = i.getAttribute('src').match(/(baseURL|server_baseurl)/);
508                    
509                    if(n){
510                        mkimg();
511                        return;
512                    }
513                    
514                    n = i.getAttribute('src').match(/^http(.*)/);
515                   
516                    if(!n ){
517                        mkimg();
518                        return;
519                    }
520                    
521                    new Pman.Request({
522                        url : baseURL + '/Roo/Images.php',
523                        method : 'POST',
524                        params : {
525                            onid : _this.form.findField('id').getValue(),
526                            ontable : ontable ,
527                            _remote_upload : i.src
528                        },
529                        success : function(res){
530                            if(res.success == true){      
531                                i.setAttribute('src', res.data);
532                                Roo.MessageBox.updateProgress( (total - nodes.length) / total , "Done " + (total - nodes.length) + '/' + total);
533                            }
534                            mkimg();
535                        }
536                    });
537                   
538                }
539                mkimg();
540            },
541            style : 'margin:10px',
542            url : baseURL + '/Roo/crm_mailing_list_message.php',
543            xns : Roo.form,
544            '|xns' : 'Roo.form',
545            xtype : 'Form',
546            listeners : {
547             actioncomplete : function(_self,action)
548              {
549                 
550                  if (action.type == 'setdata') {
551                  
552                      setInterval(_this.form.findField('bodytext').autosave, 5000);
553                      
554                      _this.data.module = _this.data.module || 'crm_mailing_list_message';
555                      
556                      _this.form.url = baseURL + '/Roo/' + _this.data.module;
557                      
558                      _this.html_preview.hide();
559                      _this.preview_btn.hide();
560                          
561                      if(_this.data.id*1 > 0){
562                          _this.dialog.el.mask("Loading");
563                          this.load({ method: 'GET', params: { '_id' : _this.data.id }});
564                          _this.html_preview.show();
565                          _this.preview_btn.show();
566                          
567                      } else {
568                          _this.form.setValues({
569                              'from_name' : Pman.Login.authUser.name,
570                              'from_email' : Pman.Login.authUser.email
571                          });
572                      }
573                     return;
574                  }
575                  if (action.type == 'load') {
576                      _this.dialog.el.unmask();
577                      
578                      _this.form.findField('bodytext').originalValue = _this.form.findField('bodytext').getValue();
579                      
580                      return;
581                  }
582                  if (action.type =='submit') {
583                  
584                      _this.dialog.el.unmask();
585                      _this.dialog.hide();
586                  
587                       if (_this.callback) {
588                          _this.callback.call(_this, action.result.data);
589                       }
590                       _this.form.reset();
591                       return;
592                  }
593              },
594             rendered : function (form)
595              {
596                  _this.form= form;
597              }
598            },
599            items  : [
600             {
601              xns : Roo.form,
602              '|xns' : 'Roo.form',
603              xtype : 'Row',
604              items  : [
605               {
606                allowBlank : false,
607                fieldLabel : _this._strings['b20a8b77b05d53b4e695738731400c85'] /* Mailout Name */,
608                name : 'name',
609                width : 400,
610                xns : Roo.form,
611                '|xns' : 'Roo.form',
612                xtype : 'TextField'
613               },
614               {
615                hideLabels : true,
616                xns : Roo.form,
617                '|xns' : 'Roo.form',
618                xtype : 'Column',
619                items  : [
620                 {
621                  boxLabel : 'Enabled - will be sent out',
622                  checked : true,
623                  name : 'active',
624                  value : 1,
625                  valueOff : 0,
626                  xns : Roo.form,
627                  '|xns' : 'Roo.form',
628                  xtype : 'Checkbox',
629                  listeners : {
630                   check : function (_self, checked)
631                    {
632                        var boxLabel = 'Enabled - will be sent out';
633                        
634                        if(!checked){
635                            boxLabel = 'Disabled - will NOT be sent out';
636                        }
637                        
638                        this.setBoxLabel(boxLabel);
639                    }
640                  }
641                 }
642                ]
643               }
644              ]
645             },
646             {
647              xns : Roo.form,
648              '|xns' : 'Roo.form',
649              xtype : 'Row',
650              items  : [
651               {
652                allowBlank : false,
653                fieldLabel : _this._strings['5da618e8e4b89c66fe86e32cdafde142'] /* From */,
654                name : 'from_name',
655                width : 300,
656                xns : Roo.form,
657                '|xns' : 'Roo.form',
658                xtype : 'TextField'
659               },
660               {
661                allowBlank : false,
662                fieldLabel : _this._strings['b357b524e740bc85b9790a0712d84a30'] /* Email address */,
663                name : 'from_email',
664                width : 300,
665                xns : Roo.form,
666                '|xns' : 'Roo.form',
667                xtype : 'TextField'
668               },
669               {
670                allowBlank : true,
671                alwaysQuery : true,
672                displayField : 'name',
673                editable : false,
674                emptyText : _this._strings['2c466a2c159463f1d9ef5a7b57b52827'] /* Select BCC Group */,
675                fieldLabel : _this._strings['68b00d723d37122f64da8d9939f836f0'] /* BCC Group */,
676                forceSelection : true,
677                hiddenName : 'bcc_group',
678                loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
679                minChars : 2,
680                name : 'bcc_group_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 : 300,
689                xns : Roo.form,
690                '|xns' : 'Roo.form',
691                xtype : 'ComboBox',
692                store : {
693                 remoteSort : true,
694                 sortInfo : { direction : 'ASC', field: 'name' },
695                 xns : Roo.data,
696                 '|xns' : 'Roo.data',
697                 xtype : 'Store',
698                 listeners : {
699                  beforeload : function (_self, o){
700                       o.params = o.params || {};
701                       
702                       o.params._direct_return = 1;
703                   }
704                 },
705                 proxy : {
706                  method : 'GET',
707                  url : baseURL + '/Roo/Groups',
708                  xns : Roo.data,
709                  '|xns' : 'Roo.data',
710                  xtype : 'HttpProxy'
711                 },
712                 reader : {
713                  fields : [{"name":"name","type":"string"},{"name":"id","type":"int"}],
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 };