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