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