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