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