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