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