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