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