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