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