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