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