Pman.Dialog.CoreNotifyRecur.bjs
[Pman.Core] / Pman.Dialog.CoreNotifyRecur.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.CoreNotifyRecur = {
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                     _this.grid.ds.load({});
37                 }
38             },
39             height : 550,
40             modal : true,
41             resizable : false,
42             title : "Modify Recurrent Notifications",
43             width : 800,
44             items : [
45                 {
46                     xtype: 'GridPanel',
47                     xns: Roo,
48                     listeners : {
49                         activate : function() {
50                          _this.panel = this;
51                             if (_this.grid) {
52                         //        _this.grid.footer.onClick('first');
53                             }
54                         }
55                     },
56                     background : false,
57                     fitContainer : true,
58                     fitToFrame : true,
59                     region : 'center',
60                     tableName : 'core_notify_recur',
61                     title : "core_notify_recur",
62                     grid : {
63                         xtype: 'EditorGrid',
64                         xns: Roo.grid,
65                         listeners : {
66                             render : function() 
67                             {
68                                 _this.grid = this; 
69                                 //_this.dialog = Pman.Dialog.FILL_IN
70                                 if (_this.panel.active) {
71                                 //   this.footer.onClick('first');
72                                 }
73                             },
74                             rowdblclick : function (_self, rowIndex, e)
75                             {
76                                 if (!_this.dialog) return;
77                                 _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
78                                     _this.grid.footer.onClick('first');
79                                 }); 
80                             },
81                             afteredit : function (e)
82                             {
83                                e.record.commit();
84                             }
85                         },
86                         autoExpandColumn : 'freq_day',
87                         clicksToEdit : 1,
88                         loadMask : true,
89                         dataSource : {
90                             xtype: 'Store',
91                             xns: Roo.data,
92                             listeners : {
93                                 update : function (_self, record, operation)
94                                 {
95                                     //Roo.log(operation);
96                                     if (operation != 'commit') {
97                                         return;
98                                     }
99                                     var p = Roo.apply({}, record.data);
100                                     p.dtstart = record.data.dtstart.format('Y-m-d');
101                                     p.dtend = record.data.dtend.format('Y-m-d');    
102                                     
103                                     
104                                     new Pman.Request({
105                                         url : baseURL + '/Roo/Core_notify_recur',
106                                         method :'POST',
107                                         params : p,
108                                         success : function(data)
109                                         {
110                                             //Roo.log(data);
111                                             record.set('id', data.data.id);
112                                         },
113                                         failure : function() {
114                                             Roo.MessageBox.alert("Error", "There was a problem saving");
115                                         }
116                                     });
117                                        
118                                     
119                                     
120                                 },
121                                 beforeload : function (_self, o)
122                                 {
123                                     if (!_this.data) {
124                                         return false;
125                                     }
126                                     o.params =  Roo.apply(o.params || {}, {
127                                         person_id : _this.data.person_id,
128                                         onid : _this.data.onid,
129                                         ontable : _this.data.ontable,
130                                         method : _this.data.method
131                                     });
132                                         
133                                 }
134                             },
135                             remoteSort : true,
136                             sortInfo : { field : 'freq', direction: 'ASC' },
137                             proxy : {
138                                 xtype: 'HttpProxy',
139                                 xns: Roo.data,
140                                 method : 'GET',
141                                 url : baseURL + '/Roo/core_notify_recur.php'
142                             },
143                             reader : {
144                                 xtype: 'JsonReader',
145                                 xns: Roo.data,
146                                 id : 'id',
147                                 root : 'data',
148                                 totalProperty : 'total',
149                                 fields : [
150                                     {
151                                         'name': 'id',
152                                         'type': 'int'
153                                     },
154                                     {
155                                         'name': 'person_id',
156                                         'type': 'int'
157                                     },
158                                     {
159                                         'name': 'dtstart',
160                                         'type': 'date',
161                                         'dateFormat': 'Y-m-d'
162                                     },
163                                     {
164                                         'name': 'dtend',
165                                         'type': 'date',
166                                         'dateFormat': 'Y-m-d'
167                                     },
168                                     {
169                                         'name': 'tz',
170                                         'type': 'float'
171                                     },
172                                     {
173                                         'name': 'last_applied_dt',
174                                         'type': 'date',
175                                         'dateFormat': 'Y-m-d'
176                                     },
177                                     {
178                                         'name': 'freq',
179                                         'type': 'string'
180                                     },
181                                     {
182                                         'name': 'freq_day',
183                                         'type': 'string'
184                                     },
185                                     {
186                                         'name': 'freq_hour',
187                                         'type': 'string'
188                                     },
189                                     {
190                                         'name': 'last_event_id',
191                                         'type': 'int'
192                                     },
193                                     {
194                                         'name': 'method',
195                                         'type': 'string'
196                                     }
197                                 ]
198                             }
199                         },
200                         toolbar : {
201                             xtype: 'Toolbar',
202                             xns: Roo,
203                             items : [
204                                 {
205                                     xtype: 'Button',
206                                     xns: Roo.Toolbar,
207                                     listeners : {
208                                         click : function()
209                                         {
210                                             var grid = _this.grid;
211                                             var r = grid.getDataSource().reader.newRow({
212                                             // defaults..
213                                                 person_id : _this.data.person_id,
214                                                 dtstart : new Date(),
215                                                 dtend : Date.parseDate('2050-01-01', 'Y-m-d'),
216                                                 tz : 'Asia/Hong_Kong',
217                                                 onid : _this.data.onid,
218                                                 ontable : _this.data.ontable,
219                                                 method : _this.data.method, // default...
220                                                 
221                                                 method_id : _this.data.method_id, // default...
222                                                 method_id_display_name : _this.data.method_id_display_name, // default...        
223                                                 
224                                                 last_event_id : 0,
225                                                 freq_day_name : '',
226                                                 freq_hour_name : '',
227                                                 freq_name : ''
228                                                 
229                                             
230                                             });
231                                             grid.stopEditing();
232                                             grid.getDataSource().insert(0, r); 
233                                             grid.startEditing(0, 2); 
234                                             
235                                         
236                                         }
237                                     },
238                                     cls : 'x-btn-text-icon',
239                                     text : "Add",
240                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
241                                 },
242                                 {
243                                     xtype: 'Fill',
244                                     xns: Roo.Toolbar
245                                 },
246                                 {
247                                     xtype: 'Button',
248                                     xns: Roo.Toolbar,
249                                     listeners : {
250                                         click : function()
251                                         {
252                                              _this.grid.stopEditing();
253                                              var s = _this.grid.selModel.getSelectedCell();
254                                              if (!s) {
255                                                 Roo.MessageBox.alert("Error", "Select row");
256                                                 return;
257                                             }
258                                             
259                                             new Pman.Request({
260                                                 url : baseURL + '/Roo/core_notify_recur',
261                                                 method : 'POST',
262                                                 params : {
263                                                     _delete : _this.grid.ds.getAt(s[0]).data.id
264                                                 }, 
265                                                 success : function() {
266                                                     _this.grid.ds.load({});
267                                                 },
268                                                 failure : function() {
269                                                     Roo.MessageBox.alert("Error", "Deleting failed - try reloading");
270                                                 }
271                                            });
272                                             
273                                         }
274                                     },
275                                     cls : 'x-btn-text-icon',
276                                     text : "Delete",
277                                     icon : rootURL + '/Pman/templates/images/trash.gif'
278                                 }
279                             ]
280                         },
281                         colModel : [
282                             {
283                                 xtype: 'ColumnModel',
284                                 xns: Roo.grid,
285                                 dataIndex : 'method_id',
286                                 header : 'Type',
287                                 width : 75,
288                                 renderer : function(v,x,r) {
289                                      return String.format('{0}', r.data.method_id_display_name); 
290                                 },
291                                 editor : {
292                                     xtype: 'GridEditor',
293                                     xns: Roo.grid,
294                                     field : {
295                                         xtype: 'ComboBox',
296                                         xns: Roo.form,
297                                         allowBlank : 'false',
298                                         displayField : 'display_name',
299                                         emptyText : "Select Type",
300                                         fieldLabel : 'core_enum',
301                                         forceSelection : true,
302                                         hiddenName : 'method_id',
303                                         listWidth : 400,
304                                         loadingText : "Searching...",
305                                         minChars : 2,
306                                         name : 'method_id_display_name',
307                                         pageSize : 20,
308                                         qtip : "Select core_enum",
309                                         selectOnFocus : true,
310                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
311                                         triggerAction : 'all',
312                                         typeAhead : true,
313                                         valueField : 'id',
314                                         width : 300,
315                                         store : {
316                                             xtype: 'Store',
317                                             xns: Roo.data,
318                                             remoteSort : true,
319                                             sortInfo : { direction : 'ASC', field: 'id' },
320                                             listeners : {
321                                                 beforeload : function (_self, o){
322                                                     o.params = o.params || {};
323                                                     // set more here
324                                                 }
325                                             },
326                                             proxy : {
327                                                 xtype: 'HttpProxy',
328                                                 xns: Roo.data,
329                                                 method : 'GET',
330                                                 url : baseURL + '/Roo/core_enum.php'
331                                             },
332                                             reader : {
333                                                 xtype: 'JsonReader',
334                                                 xns: Roo.data,
335                                                 id : 'id',
336                                                 root : 'data',
337                                                 totalProperty : 'total',
338                                                 fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
339                                             }
340                                         }
341                                     }
342                                 }
343                             },
344                             {
345                                 xtype: 'ColumnModel',
346                                 xns: Roo.grid,
347                                 dataIndex : 'dtstart',
348                                 header : 'From',
349                                 width : 75,
350                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
351                                 editor : {
352                                     xtype: 'GridEditor',
353                                     xns: Roo.grid,
354                                     field : {
355                                         xtype: 'DateField',
356                                         xns: Roo.form
357                                     }
358                                 }
359                             },
360                             {
361                                 xtype: 'ColumnModel',
362                                 xns: Roo.grid,
363                                 dataIndex : 'dtend',
364                                 header : 'Until',
365                                 width : 75,
366                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
367                                 editor : {
368                                     xtype: 'GridEditor',
369                                     xns: Roo.grid,
370                                     field : {
371                                         xtype: 'DateField',
372                                         xns: Roo.form
373                                     }
374                                 }
375                             },
376                             {
377                                 xtype: 'ColumnModel',
378                                 xns: Roo.grid,
379                                 dataIndex : 'freq_day',
380                                 header : 'on day(s)',
381                                 width : 100,
382                                 renderer : function(v,x,r) { 
383                                     
384                                     if (v.length) {
385                                      
386                                         var cm = _this.grid.colModel;
387                                        
388                                         var ci = cm.getColumnByDataIndex(this.name);
389                                        
390                                          var tv = [];
391                                         var vals = Roo.decode(v);
392                                         Roo.each(vals, function(k) {
393                                             var r = this.findRecord(this.valueField, k);
394                                             if(r){
395                                                 tv.push(r.data[this.displayField]);
396                                             }else if(this.valueNotFoundText !== undefined){
397                                                 tv.push( this.valueNotFoundText );
398                                             }
399                                         },ci.editor.field);
400                                 
401                                         r.data[this.name + '_name'] = tv.join(', ');
402                                         return String.format('{0}',tv.join(', '));
403                                 
404                                         
405                                     
406                                     }
407                                     r.data[this.name + '_name'] = '';
408                                     return String.format('{0}', r.data.freq_day_name || v); 
409                                     
410                                 },
411                                 editor : {
412                                     xtype: 'GridEditor',
413                                     xns: Roo.grid,
414                                     field : {
415                                         xtype: 'ComboCheck',
416                                         xns: Roo.form,
417                                         allowBlank : false,
418                                         displayField : 'title',
419                                         editable : false,
420                                         fieldLabel : 'Country',
421                                         hiddenName : 'freq_day',
422                                         listWidth : 300,
423                                         mode : 'local',
424                                         name : 'freq_day_name',
425                                         pageSize : 40,
426                                         triggerAction : 'all',
427                                         valueField : 'code',
428                                         store : {
429                                             xtype: 'SimpleStore',
430                                             xns: Roo.data,
431                                             data : (function() { 
432                                                 var ret = [];
433                                                 Roo.each(Date.dayNames, function(d) {
434                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
435                                                 });
436                                                 return ret;
437                                             })(),
438                                             fields : ['code', 'title'],
439                                             sortInfo : { field : 'title', direction: 'ASC' }
440                                         }
441                                     }
442                                 }
443                             },
444                             {
445                                 xtype: 'ColumnModel',
446                                 xns: Roo.grid,
447                                 dataIndex : 'freq_hour',
448                                 header : 'at Hour(s)',
449                                 width : 250,
450                                 renderer : function(v,x,r) { 
451                                     
452                                  
453                                     if (v.length) {
454                                      
455                                         var cm = _this.grid.colModel;
456                                        
457                                         var ci = cm.getColumnByDataIndex(this.name);
458                                        
459                                          var tv = [];
460                                         var vals = Roo.decode(v);
461                                         Roo.each(vals, function(k) {
462                                             var r = this.findRecord(this.valueField, k);
463                                             if(r){
464                                                 tv.push(r.data[this.displayField]);
465                                             }else if(this.valueNotFoundText !== undefined){
466                                                 tv.push( this.valueNotFoundText );
467                                             }
468                                         },ci.editor.field);
469                                 
470                                          r.data[this.name + '_name'] = tv.join(', ');
471                                         return String.format('{0}',tv.join(', '));
472                                 
473                                         
474                                     
475                                     }
476                                         r.data[this.name + '_name'] = '';
477                                     return String.format('{0}', r.data.freq_hour_name || v); 
478                                     
479                                 },
480                                 editor : {
481                                     xtype: 'GridEditor',
482                                     xns: Roo.grid,
483                                     field : {
484                                         xtype: 'ComboCheck',
485                                         xns: Roo.form,
486                                         allowBlank : false,
487                                         displayField : 'title',
488                                         editable : false,
489                                         fieldLabel : 'Country',
490                                         hiddenName : 'freq_hour',
491                                         listWidth : 300,
492                                         mode : 'local',
493                                         name : 'freq_hour_name',
494                                         pageSize : 40,
495                                         triggerAction : 'all',
496                                         valueField : 'code',
497                                         store : {
498                                             xtype: 'SimpleStore',
499                                             xns: Roo.data,
500                                             data : (function() { 
501                                                 var ret = [];
502                                                 for (var i = 5; i < 25; i++) {
503                                                     var h = i < 10 ? ('0' + i) : i;
504                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
505                                                     var dh = i < 13 ? i : i-12;
506                                                     
507                                                     ret.push([ h+':00', dh+':00' + mer ]);
508                                                     ret.push([ h+':30', dh+':30' + mer ]);        
509                                                 }
510                                                 return ret;
511                                             })(),
512                                             fields : ['code', 'title'],
513                                             sortInfo : { field : 'title', direction: 'ASC' }
514                                         }
515                                     }
516                                 }
517                             },
518                             {
519                                 xtype: 'ColumnModel',
520                                 xns: Roo.grid,
521                                 dataIndex : 'tz',
522                                 header : 'Timezone',
523                                 width : 100,
524                                 renderer : function(v) { return String.format('{0}', v); },
525                                 editor : {
526                                     xtype: 'GridEditor',
527                                     xns: Roo.grid,
528                                     field : {
529                                         xtype: 'ComboBox',
530                                         xns: Roo.form,
531                                         allowBlank : 'false',
532                                         displayField : 'tz',
533                                         editable : true,
534                                         emptyText : "Select timezone",
535                                         fieldLabel : 'core_enum',
536                                         forceSelection : true,
537                                         listWidth : 400,
538                                         loadingText : "Searching...",
539                                         minChars : 2,
540                                         name : 'tz',
541                                         pageSize : 999,
542                                         qtip : "Select timezone",
543                                         queryParam : 'q',
544                                         selectOnFocus : true,
545                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
546                                         triggerAction : 'all',
547                                         typeAhead : true,
548                                         width : 300,
549                                         store : {
550                                             xtype: 'Store',
551                                             xns: Roo.data,
552                                             listeners : {
553                                                 beforeload : function (_self, o){
554                                                     o.params = o.params || {};
555                                                     // set more here
556                                                 }
557                                             },
558                                             remoteSort : true,
559                                             sortInfo : { direction : 'ASC', field: 'tz' },
560                                             proxy : {
561                                                 xtype: 'HttpProxy',
562                                                 xns: Roo.data,
563                                                 method : 'GET',
564                                                 url : baseURL + '/Core/I18n/Timezone.php'
565                                             },
566                                             reader : {
567                                                 xtype: 'JsonReader',
568                                                 xns: Roo.data,
569                                                 id : 'id',
570                                                 root : 'data',
571                                                 totalProperty : 'total',
572                                                 fields : [{"name":"tz","type":"string"}]
573                                             }
574                                         }
575                                     }
576                                 }
577                             },
578                             {
579                                 xtype: 'ColumnModel',
580                                 xns: Roo.grid,
581                                 dataIndex : 'last_event_id',
582                                 header : 'Last Sent',
583                                 width : 75,
584                                 renderer : function(v) { return String.format('{0}', v ? v : 'never'); }
585                             }
586                         ]
587                     }
588                 }
589             ],
590             center : {
591                 xtype: 'LayoutRegion',
592                 xns: Roo,
593                 autoScroll : true,
594                 loadOnce : true
595             },
596             buttons : [
597                 {
598                     xtype: 'Button',
599                     xns: Roo,
600                     listeners : {
601                         click : function (_self, e)
602                         {
603                             _this.dialog.hide();
604                         }
605                     },
606                     text : "Done"
607                 }
608             ]
609         });
610     }
611 };