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