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                  toolbars : [
703                   {
704                    xns : Roo.form.HtmlEditor,
705                    '|xns' : 'Roo.form.HtmlEditor',
706                    xtype : 'ToolbarContext'
707                   },
708                   {
709                    xns : Roo.form.HtmlEditor,
710                    '|xns' : 'Roo.form.HtmlEditor',
711                    xtype : 'ToolbarStandard',
712                    btns : [
713                     {
714                      alwaysQuery : true,
715                      displayField : 'name',
716                      editable : false,
717                      emptyText : _this._strings['b9c49611cfda3259a2b837b39489e650'] /* Add Image */,
718                      fieldLabel : _this._strings['fff0d600f8a0b5e19e88bfb821dd1157'] /* Images */,
719                      forceSelection : true,
720                      listWidth : 400,
721                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
722                      minChars : 2,
723                      pageSize : 20,
724                      qtip : _this._strings['2f26e35d61be90501e099089dc533638'] /* Select Images */,
725                      selectOnFocus : true,
726                      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>',
727                      triggerAction : 'all',
728                      typeAhead : true,
729                      valueField : 'id',
730                      width : 100,
731                      xns : Roo.form,
732                      '|xns' : 'Roo.form',
733                      xtype : 'ComboBox',
734                      listeners : {
735                       beforequery : function (combo, query, forceAll, cancel, e)
736                        {
737                            var id = _this.form.findField('id').getValue() * 1;    
738                            if (!id) {
739                                Roo.MessageBox.alert("Error", "Save message first");
740                                return false;
741                            }
742                        },
743                       render : function (_self)
744                        {
745                            _this.extendimgselect = _self;
746                        },
747                       select : function (combo, record, index)
748                        {
749                            Roo.log(record);
750                            (function() { 
751                                combo.setValue('');
752                            }).defer(100);
753                            var editor = _this.form.findField('bodytext').editorcore;
754                            
755                            var curnode = editor.getSelectedNode();
756                            if (curnode && curnode.tagName == 'IMG') {
757                                curnode.src= String.format('{0}/Images/{1}/{2}#image-{1}',
758                                        baseURL,  record.data.id, record.data.filename
759                                    );
760                                    // note -forces an update... hopefully...
761                                editor.owner.fireEvent('editorevent', editor, false);
762                            } else {
763                            
764                                editor.insertAtCursor(
765                                    String.format('<img src="{0}/Images/{1}/{2}#image-{1}">',
766                                    baseURL,  record.data.id, record.data.filename
767                                    )
768                                );
769                        
770                            }
771                            
772                         }
773                      },
774                      store : {
775                       remoteSort : true,
776                       sortInfo : { direction : 'ASC', field: 'id' },
777                       xns : Roo.data,
778                       '|xns' : 'Roo.data',
779                       xtype : 'Store',
780                       listeners : {
781                        beforeload : function (_self, o){
782                             o.params = o.params || {};
783                         
784                             var id = _this.form.findField('id').getValue() * 1;    
785                             if (!id) {
786                                 Roo.MessageBox.alert("Error", "Save email template first");
787                                 return false;
788                             }
789                             o.params.onid = id;
790                             o.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
791                             
792                            // o.params.imgtype = 'PressRelease';
793                             //o.params['query[imagesize]'] = '150x150';
794                             // set more here
795                         }
796                       },
797                       proxy : {
798                        method : 'GET',
799                        url : baseURL + '/Roo/Images.php',
800                        xns : Roo.data,
801                        '|xns' : 'Roo.data',
802                        xtype : 'HttpProxy'
803                       },
804                       reader : {
805                        fields : [{"name":"id","type":"int"},{"name":"filename","type":"string"},{"name":"url_thumb","type":"string"}],
806                        id : 'id',
807                        root : 'data',
808                        totalProperty : 'total',
809                        xns : Roo.data,
810                        '|xns' : 'Roo.data',
811                        xtype : 'JsonReader'
812                       }
813                      }
814                     },
815                     {
816                      alwaysQuery : true,
817                      displayField : 'name',
818                      editable : false,
819                      emptyText : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
820                      fieldLabel : _this._strings['6f16a5f8ff5d75ab84c018adacdfcbb7'] /* Field */,
821                      forceSelection : true,
822                      listWidth : 400,
823                      loadingText : _this._strings['1243daf593fa297e07ab03bf06d925af'] /* Searching... */,
824                      minChars : 2,
825                      pageSize : 20,
826                      qtip : _this._strings['5feb9bf3c03b32635135006cbacb9542'] /* Insert Field */,
827                      selectOnFocus : true,
828                      tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{name}</b> </div>',
829                      triggerAction : 'all',
830                      typeAhead : true,
831                      valueField : 'type',
832                      width : 100,
833                      xns : Roo.form,
834                      '|xns' : 'Roo.form',
835                      xtype : 'ComboBox',
836                      listeners : {
837                       render : function (_self)
838                        {
839                            _this.unsubscribeselect = _self;
840                        },
841                       select : function (combo, record, index)
842                        {
843                            Roo.log(record);
844                            (function() { 
845                                combo.setValue('');
846                            }).defer(100);
847                            var editor = _this.form.findField('bodytext').editorcore;
848                            
849                            if(record.data.name == 'Unsubscribe'){
850                                editor.insertAtCursor(
851                                    String.format('<a href="{0}">{1}</a>',
852                                        record.data.type,  record.data.name
853                                    )
854                                );
855                                return;     
856                            }
857                            
858                            editor.insertAtCursor(
859                                String.format('{0}',
860                                    record.data.type
861                                )
862                            );
863                            
864                         }
865                      },
866                      store : {
867                       data : [ 
868                           [ '{person.firstname}', "First Name"],
869                           [ '{person.lastname}' , "Last Name"],
870                           [ '{person.name}', "Full Name"],
871                           [ '#unsubscribe', "Unsubscribe"]
872                       ],
873                       fields : [  'type', 'name'],
874                       xns : Roo.data,
875                       '|xns' : 'Roo.data',
876                       xtype : 'SimpleStore'
877                      }
878                     },
879                     {
880                      xns : Roo.Toolbar,
881                      '|xns' : 'Roo.Toolbar',
882                      xtype : 'Separator'
883                     },
884                     {
885                      text : _this._strings['bd88a20b53a47f7b5704a83a15ff5506'] /* Saved Version */,
886                      xns : Roo.Toolbar,
887                      '|xns' : 'Roo.Toolbar',
888                      xtype : 'Button',
889                      listeners : {
890                       click : function (_self, e)
891                        {
892                            this.scope.owner.fireEvent('savedpreview', this.scope.owner);
893                        }
894                      }
895                     }
896                    ]
897                   }
898                  ]
899                 }
900                ]
901               }
902              ]
903             },
904             {
905              hideLabels : true,
906              xns : Roo.form,
907              '|xns' : 'Roo.form',
908              xtype : 'Row',
909              items  : [
910               {
911                text : _this._strings['e9968623956c15023d54335ea3699855'] /* Convert Html to Text */,
912                xns : Roo,
913                '|xns' : 'Roo',
914                xtype : 'Button',
915                listeners : {
916                 click : function (_self, e)
917                  {
918                      var h = _this.form.findField('bodytext').getValue();
919                      var p = _this.form.findField('plaintext');
920                      
921                      new Pman.Request({\r
922                          url : baseURL + '/Core/ImportMailMessage.php',\r
923                          method : 'POST',\r
924                          params : {
925                            bodytext : h,\r
926                            _convertToPlain : true,
927                            _check_unsubscribe : true\r
928                          }, \r
929                          success : function(res) {\r
930                              if(res.success == true){
931                                 p.setValue(res.data);
932                              }\r
933                          }\r
934                      });  
935                      
936                  }
937                }
938               }
939              ]
940             },
941             {
942              hideLabels : true,
943              xns : Roo.form,
944              '|xns' : 'Roo.form',
945              xtype : 'Row',
946              items  : [
947               {
948                hideLabels : true,
949                legend : _this._strings['e44b145bd8b49b06e0ad2ced1ad56466'] /* Plain Text */,
950                style : 'text-align:center;',
951                xns : Roo.form,
952                '|xns' : 'Roo.form',
953                xtype : 'FieldSet',
954                items  : [
955                 {
956                  height : 50,
957                  name : 'plaintext',
958                  xns : Roo.form,
959                  '|xns' : 'Roo.form',
960                  xtype : 'TextArea'
961                 }
962                ]
963               }
964              ]
965             },
966             {
967              name : 'id',
968              xns : Roo.form,
969              '|xns' : 'Roo.form',
970              xtype : 'Hidden'
971             }
972            ]
973           }
974          ]
975         }
976        ]
977       }
978      },
979      {
980       autoScroll : false,
981       background : false,
982       fitContainer : true,
983       fitToframe : true,
984       region : 'east',
985       tableName : 'Images',
986       title : _this._strings['308f2757bfc9ce92fb00ff93fdffd279'] /* Images / Attachments */,
987       xns : Roo,
988       '|xns' : 'Roo',
989       xtype : 'GridPanel',
990       listeners : {
991        activate : function() {
992             _this.ipanel = this;
993             if (_this.igrid) {
994                _this.igrid.ds.load({});
995             }
996         }
997       },
998       grid : {
999        autoExpandColumn : 'filename',
1000        loadMask : true,
1001        xns : Roo.grid,
1002        '|xns' : 'Roo.grid',
1003        xtype : 'Grid',
1004        listeners : {
1005         render : function() 
1006          {
1007              _this.igrid = this; 
1008              //_this.dialog = Pman.Dialog.FILL_IN
1009              if (_this.ipanel.active) {
1010             //    _this.igrid.ds.load({});
1011              }
1012          }
1013        },
1014        toolbar : {
1015         xns : Roo,
1016         '|xns' : 'Roo',
1017         xtype : 'Toolbar',
1018         items  : [
1019          {
1020           cls : 'x-btn-text-icon',
1021           icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1022           text : _this._strings['ec211f7c20af43e742bf2570c3cb84f9'] /* Add */,
1023           xns : Roo.Toolbar,
1024           '|xns' : 'Roo.Toolbar',
1025           xtype : 'Button',
1026           listeners : {
1027            click : function()
1028             {
1029                 var id = _this.form.findField('id').getValue();
1030                 
1031                 if(id*1 < 1){
1032                     Roo.MessageBox.alert('Error', 'Please save the email template first');
1033                     return;
1034                 }
1035                 
1036                 var ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1037                 
1038                 Pman.Dialog.Image.show( { id : 0, onid: id, ontable: ontable }, function() {
1039                     _this.igrid.getDataSource().load({});
1040                 }); 
1041             }
1042           }
1043          },
1044          {
1045           cls : 'x-btn-text-icon',
1046           icon : rootURL + '/Pman/templates/images/trash.gif',
1047           text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'] /* Delete */,
1048           xns : Roo.Toolbar,
1049           '|xns' : 'Roo.Toolbar',
1050           xtype : 'Button',
1051           listeners : {
1052            click : function()
1053             {
1054                 var s = _this.igrid.getSelectionModel().getSelected();
1055                 if (!s || isNaN(s.id *1)) {
1056                     Roo.MessageBox.alert("Error", "Select a image"); 
1057                     return;
1058                 }
1059                 Roo.MessageBox.confirm("Confirm", "Are sure you want to delete this image?", function (v){
1060                     if (v != 'yes') {
1061                         return;
1062                     }
1063                     
1064                     new Pman.Request({
1065                         url : baseURL + '/Roo/Images.php',
1066                         method: 'POST',
1067                         params : {
1068                             _delete : s.id
1069                         },
1070                         success : function()
1071                         {
1072                             Roo.log('Got Success!!');
1073                            _this.igrid.ds.load({});
1074                         }
1075                     });
1076                 });
1077             }
1078           }
1079          }
1080         ]
1081        },
1082        dataSource : {
1083         remoteSort : true,
1084         sortInfo : { field : 'filename', direction: 'ASC' },
1085         xns : Roo.data,
1086         '|xns' : 'Roo.data',
1087         xtype : 'Store',
1088         listeners : {
1089          beforeload : function (_self, options)
1090           {
1091               options.params = options.params || {};
1092               if (typeof(_this.data) == 'undefined') {
1093                   return false;
1094               }
1095               if(_this.data.id * 1 >= 0)
1096               {
1097                   options.params.onid = _this.data.id;
1098           
1099                   options.params.ontable = (_this.data.module) ? _this.data.module : 'crm_mailing_list_message';
1100               }
1101           }
1102         },
1103         proxy : {
1104          method : 'GET',
1105          url : baseURL + '/Roo/Images.php',
1106          xns : Roo.data,
1107          '|xns' : 'Roo.data',
1108          xtype : 'HttpProxy'
1109         },
1110         reader : {
1111          fields : [
1112              {
1113                  'name': 'id',
1114                  'type': 'int'
1115              },
1116              {
1117                  'name': 'filename',
1118                  'type': 'string'
1119              },
1120              {
1121                  'name': 'ontable',
1122                  'type': 'string'
1123              },
1124              {
1125                  'name': 'onid',
1126                  'type': 'int'
1127              },
1128              {
1129                  'name': 'mimetype',
1130                  'type': 'string'
1131              },
1132              {
1133                  'name': 'width',
1134                  'type': 'int'
1135              },
1136              {
1137                  'name': 'height',
1138                  'type': 'int'
1139              },
1140              {
1141                  'name': 'filesize',
1142                  'type': 'int'
1143              },
1144              {
1145                  'name': 'displayorder',
1146                  'type': 'int'
1147              },
1148              {
1149                  'name': 'language',
1150                  'type': 'string'
1151              },
1152              {
1153                  'name': 'parent_image_id',
1154                  'type': 'int'
1155              },
1156              {
1157                  'name': 'created',
1158                  'type': 'date',
1159                  'dateFormat': 'Y-m-d'
1160              },
1161              {
1162                  'name': 'imgtype',
1163                  'type': 'string'
1164              },
1165              {
1166                  'name': 'linkurl',
1167                  'type': 'string'
1168              },
1169              {
1170                  'name': 'descript',
1171                  'type': 'string'
1172              },
1173              {
1174                  'name': 'title',
1175                  'type': 'string'
1176              },
1177              {
1178                  'name': 'parent_image_id_id',
1179                  'type': 'int'
1180              },
1181              {
1182                  'name': 'parent_image_id_filename',
1183                  'type': 'string'
1184              },
1185              {
1186                  'name': 'parent_image_id_ontable',
1187                  'type': 'string'
1188              },
1189              {
1190                  'name': 'parent_image_id_onid',
1191                  'type': 'int'
1192              },
1193              {
1194                  'name': 'parent_image_id_mimetype',
1195                  'type': 'string'
1196              },
1197              {
1198                  'name': 'parent_image_id_width',
1199                  'type': 'int'
1200              },
1201              {
1202                  'name': 'parent_image_id_height',
1203                  'type': 'int'
1204              },
1205              {
1206                  'name': 'parent_image_id_filesize',
1207                  'type': 'int'
1208              },
1209              {
1210                  'name': 'parent_image_id_displayorder',
1211                  'type': 'int'
1212              },
1213              {
1214                  'name': 'parent_image_id_language',
1215                  'type': 'string'
1216              },
1217              {
1218                  'name': 'parent_image_id_parent_image_id',
1219                  'type': 'int'
1220              },
1221              {
1222                  'name': 'parent_image_id_created',
1223                  'type': 'date'
1224              },
1225              {
1226                  'name': 'parent_image_id_imgtype',
1227                  'type': 'string'
1228              },
1229              {
1230                  'name': 'parent_image_id_linkurl',
1231                  'type': 'string'
1232              },
1233              {
1234                  'name': 'parent_image_id_descript',
1235                  'type': 'string'
1236              },
1237              {
1238                  'name': 'parent_image_id_title',
1239                  'type': 'string'
1240              }
1241          ],
1242          id : 'id',
1243          root : 'data',
1244          totalProperty : 'total',
1245          xns : Roo.data,
1246          '|xns' : 'Roo.data',
1247          xtype : 'JsonReader'
1248         }
1249        },
1250        colModel : [
1251         {
1252          dataIndex : 'filename',
1253          header : _this._strings['1351017ac6423911223bc19a8cb7c653'] /* Filename */,
1254          renderer : function(v,x,r)
1255          {
1256              var width = r.data.width;
1257              var height = r.data.height;
1258              
1259              if(width > 50){
1260                  height = Math.round(height * 50 / width);
1261                  width = 50;
1262              }
1263              
1264             return '<img src="' + baseURL + '/Images/' + r.data.id + '/' + r.data.filename + '" width="' + width + '" height="' + height + '" />';
1265          },
1266          width : 300,
1267          xns : Roo.grid,
1268          '|xns' : 'Roo.grid',
1269          xtype : 'ColumnModel'
1270         },
1271         {
1272          dataIndex : 'displayorder',
1273          header : _this._strings['2393ad754ba179442d85e415d1d5167c'] /* Displayorder */,
1274          renderer : function(v) { return String.format('{0}', v); },
1275          width : 75,
1276          xns : Roo.grid,
1277          '|xns' : 'Roo.grid',
1278          xtype : 'ColumnModel'
1279         },
1280         {
1281          dataIndex : 'title',
1282          header : _this._strings['b78a3223503896721cca1303f776159b'] /* Title */,
1283          renderer : function(v) { return String.format('{0}', v); },
1284          width : 75,
1285          xns : Roo.grid,
1286          '|xns' : 'Roo.grid',
1287          xtype : 'ColumnModel'
1288         }
1289        ]
1290       }
1291      }
1292     ]
1293    });
1294  }
1295 };