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