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