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