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