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