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