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