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