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