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,
220                                                 last_event_id : 0,
221                                                 freq_day_name : '',
222                                                 freq_hour_name : '',
223                                                 freq_name : ''
224                                                 
225                                             
226                                             });
227                                             grid.stopEditing();
228                                             grid.getDataSource().insert(0, r); 
229                                             grid.startEditing(0, 2); 
230                                             
231                                         
232                                         }
233                                     },
234                                     cls : 'x-btn-text-icon',
235                                     text : "Add",
236                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
237                                 },
238                                 {
239                                     xtype: 'Fill',
240                                     xns: Roo.Toolbar
241                                 },
242                                 {
243                                     xtype: 'Button',
244                                     xns: Roo.Toolbar,
245                                     listeners : {
246                                         click : function()
247                                         {
248                                              _this.grid.stopEditing();
249                                              var s = _this.grid.selModel.getSelectedCell();
250                                              if (!s) {
251                                                 Roo.MessageBox.alert("Error", "Select row");
252                                                 return;
253                                             }
254                                             
255                                             new Pman.Request({
256                                                 url : baseURL + '/Roo/core_notify_recur',
257                                                 method : 'POST',
258                                                 params : {
259                                                     _delete : _this.grid.ds.getAt(s[0]).data.id
260                                                 }, 
261                                                 success : function() {
262                                                     _this.grid.ds.load({});
263                                                 },
264                                                 failure : function() {
265                                                     Roo.MessageBox.alert("Error", "Deleting failed - try reloading");
266                                                 }
267                                            });
268                                             
269                                         }
270                                     },
271                                     cls : 'x-btn-text-icon',
272                                     text : "Delete",
273                                     icon : rootURL + '/Pman/templates/images/trash.gif'
274                                 }
275                             ]
276                         },
277                         colModel : [
278                             {
279                                 xtype: 'ColumnModel',
280                                 xns: Roo.grid,
281                                 dataIndex : 'method_id',
282                                 header : 'From',
283                                 width : 75,
284                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
285                                 editor : {
286                                     xtype: 'GridEditor',
287                                     xns: Roo.grid,
288                                     items : [
289                                         {
290                                             xtype: 'ComboBox',
291                                             xns: Roo.form,
292                                             allowBlank : 'false',
293                                             editable : 'false',
294                                             emptyText : "Select core_enum",
295                                             forceSelection : true,
296                                             listWidth : 400,
297                                             loadingText : "Searching...",
298                                             minChars : 2,
299                                             pageSize : 20,
300                                             qtip : "Select core_enum",
301                                             selectOnFocus : true,
302                                             triggerAction : 'all',
303                                             typeAhead : true,
304                                             width : 300,
305                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
306                                             queryParam : '',
307                                             fieldLabel : 'core_enum',
308                                             valueField : 'id',
309                                             displayField : '',
310                                             hiddenName : '',
311                                             name : '',
312                                             store : {
313                                                 xtype: 'Store',
314                                                 xns: Roo.data,
315                                                 remoteSort : true,
316                                                 sortInfo : { direction : 'ASC', field: 'id' },
317                                                 listeners : {
318                                                     beforeload : function (_self, o){
319                                                         o.params = o.params || {};
320                                                         // set more here
321                                                     }
322                                                 },
323                                                 proxy : {
324                                                     xtype: 'HttpProxy',
325                                                     xns: Roo.data,
326                                                     method : 'GET',
327                                                     url : baseURL + '/Roo/core_enum.php'
328                                                 },
329                                                 reader : {
330                                                     xtype: 'JsonReader',
331                                                     xns: Roo.data,
332                                                     id : 'id',
333                                                     root : 'data',
334                                                     totalProperty : 'total',
335                                                     fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
336                                                 }
337                                             }
338                                         }
339                                     ]
340                                 }
341                             },
342                             {
343                                 xtype: 'ColumnModel',
344                                 xns: Roo.grid,
345                                 dataIndex : 'dtstart',
346                                 header : 'From',
347                                 width : 75,
348                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
349                                 editor : {
350                                     xtype: 'GridEditor',
351                                     xns: Roo.grid,
352                                     field : {
353                                         xtype: 'DateField',
354                                         xns: Roo.form
355                                     }
356                                 }
357                             },
358                             {
359                                 xtype: 'ColumnModel',
360                                 xns: Roo.grid,
361                                 dataIndex : 'dtend',
362                                 header : 'Until',
363                                 width : 75,
364                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
365                                 editor : {
366                                     xtype: 'GridEditor',
367                                     xns: Roo.grid,
368                                     field : {
369                                         xtype: 'DateField',
370                                         xns: Roo.form
371                                     }
372                                 }
373                             },
374                             {
375                                 xtype: 'ColumnModel',
376                                 xns: Roo.grid,
377                                 dataIndex : 'freq_day',
378                                 header : 'on day(s)',
379                                 width : 100,
380                                 renderer : function(v,x,r) { 
381                                     
382                                     if (v.length) {
383                                      
384                                         var cm = _this.grid.colModel;
385                                        
386                                         var ci = cm.getColumnByDataIndex(this.name);
387                                        
388                                          var tv = [];
389                                         var vals = Roo.decode(v);
390                                         Roo.each(vals, function(k) {
391                                             var r = this.findRecord(this.valueField, k);
392                                             if(r){
393                                                 tv.push(r.data[this.displayField]);
394                                             }else if(this.valueNotFoundText !== undefined){
395                                                 tv.push( this.valueNotFoundText );
396                                             }
397                                         },ci.editor.field);
398                                 
399                                         r.data[this.name + '_name'] = tv.join(', ');
400                                         return String.format('{0}',tv.join(', '));
401                                 
402                                         
403                                     
404                                     }
405                                     r.data[this.name + '_name'] = '';
406                                     return String.format('{0}', r.data.freq_day_name || v); 
407                                     
408                                 },
409                                 editor : {
410                                     xtype: 'GridEditor',
411                                     xns: Roo.grid,
412                                     field : {
413                                         xtype: 'ComboCheck',
414                                         xns: Roo.form,
415                                         allowBlank : false,
416                                         displayField : 'title',
417                                         editable : false,
418                                         fieldLabel : 'Country',
419                                         hiddenName : 'freq_day',
420                                         listWidth : 300,
421                                         mode : 'local',
422                                         name : 'freq_day_name',
423                                         pageSize : 40,
424                                         triggerAction : 'all',
425                                         valueField : 'code',
426                                         store : {
427                                             xtype: 'SimpleStore',
428                                             xns: Roo.data,
429                                             data : (function() { 
430                                                 var ret = [];
431                                                 Roo.each(Date.dayNames, function(d) {
432                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
433                                                 });
434                                                 return ret;
435                                             })(),
436                                             fields : ['code', 'title'],
437                                             sortInfo : { field : 'title', direction: 'ASC' }
438                                         }
439                                     }
440                                 }
441                             },
442                             {
443                                 xtype: 'ColumnModel',
444                                 xns: Roo.grid,
445                                 dataIndex : 'freq_hour',
446                                 header : 'at Hour(s)',
447                                 width : 250,
448                                 renderer : function(v,x,r) { 
449                                     
450                                  
451                                     if (v.length) {
452                                      
453                                         var cm = _this.grid.colModel;
454                                        
455                                         var ci = cm.getColumnByDataIndex(this.name);
456                                        
457                                          var tv = [];
458                                         var vals = Roo.decode(v);
459                                         Roo.each(vals, function(k) {
460                                             var r = this.findRecord(this.valueField, k);
461                                             if(r){
462                                                 tv.push(r.data[this.displayField]);
463                                             }else if(this.valueNotFoundText !== undefined){
464                                                 tv.push( this.valueNotFoundText );
465                                             }
466                                         },ci.editor.field);
467                                 
468                                          r.data[this.name + '_name'] = tv.join(', ');
469                                         return String.format('{0}',tv.join(', '));
470                                 
471                                         
472                                     
473                                     }
474                                         r.data[this.name + '_name'] = '';
475                                     return String.format('{0}', r.data.freq_hour_name || v); 
476                                     
477                                 },
478                                 editor : {
479                                     xtype: 'GridEditor',
480                                     xns: Roo.grid,
481                                     field : {
482                                         xtype: 'ComboCheck',
483                                         xns: Roo.form,
484                                         allowBlank : false,
485                                         displayField : 'title',
486                                         editable : false,
487                                         fieldLabel : 'Country',
488                                         hiddenName : 'freq_hour',
489                                         listWidth : 300,
490                                         mode : 'local',
491                                         name : 'freq_hour_name',
492                                         pageSize : 40,
493                                         triggerAction : 'all',
494                                         valueField : 'code',
495                                         store : {
496                                             xtype: 'SimpleStore',
497                                             xns: Roo.data,
498                                             data : (function() { 
499                                                 var ret = [];
500                                                 for (var i = 5; i < 25; i++) {
501                                                     var h = i < 10 ? ('0' + i) : i;
502                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
503                                                     var dh = i < 13 ? i : i-12;
504                                                     
505                                                     ret.push([ h+':00', dh+':00' + mer ]);
506                                                     ret.push([ h+':30', dh+':30' + mer ]);        
507                                                 }
508                                                 return ret;
509                                             })(),
510                                             fields : ['code', 'title'],
511                                             sortInfo : { field : 'title', direction: 'ASC' }
512                                         }
513                                     }
514                                 }
515                             },
516                             {
517                                 xtype: 'ColumnModel',
518                                 xns: Roo.grid,
519                                 dataIndex : 'tz',
520                                 header : 'Timezone',
521                                 width : 100,
522                                 renderer : function(v) { return String.format('{0}', v); },
523                                 editor : {
524                                     xtype: 'GridEditor',
525                                     xns: Roo.grid,
526                                     field : {
527                                         xtype: 'ComboBox',
528                                         xns: Roo.form,
529                                         allowBlank : 'false',
530                                         displayField : 'tz',
531                                         editable : true,
532                                         emptyText : "Select timezone",
533                                         fieldLabel : 'core_enum',
534                                         forceSelection : true,
535                                         listWidth : 400,
536                                         loadingText : "Searching...",
537                                         minChars : 2,
538                                         name : 'tz',
539                                         pageSize : 999,
540                                         qtip : "Select timezone",
541                                         queryParam : 'q',
542                                         selectOnFocus : true,
543                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
544                                         triggerAction : 'all',
545                                         typeAhead : true,
546                                         width : 300,
547                                         store : {
548                                             xtype: 'Store',
549                                             xns: Roo.data,
550                                             listeners : {
551                                                 beforeload : function (_self, o){
552                                                     o.params = o.params || {};
553                                                     // set more here
554                                                 }
555                                             },
556                                             remoteSort : true,
557                                             sortInfo : { direction : 'ASC', field: 'tz' },
558                                             proxy : {
559                                                 xtype: 'HttpProxy',
560                                                 xns: Roo.data,
561                                                 method : 'GET',
562                                                 url : baseURL + '/Core/I18n/Timezone.php'
563                                             },
564                                             reader : {
565                                                 xtype: 'JsonReader',
566                                                 xns: Roo.data,
567                                                 id : 'id',
568                                                 root : 'data',
569                                                 totalProperty : 'total',
570                                                 fields : [{"name":"tz","type":"string"}]
571                                             }
572                                         }
573                                     }
574                                 }
575                             },
576                             {
577                                 xtype: 'ColumnModel',
578                                 xns: Roo.grid,
579                                 dataIndex : 'last_event_id',
580                                 header : 'Last Sent',
581                                 width : 75,
582                                 renderer : function(v) { return String.format('{0}', v ? v : 'never'); }
583                             }
584                         ]
585                     }
586                 }
587             ],
588             center : {
589                 xtype: 'LayoutRegion',
590                 xns: Roo,
591                 autoScroll : true,
592                 loadOnce : true
593             },
594             buttons : [
595                 {
596                     xtype: 'Button',
597                     xns: Roo,
598                     listeners : {
599                         click : function (_self, e)
600                         {
601                             _this.dialog.hide();
602                         }
603                     },
604                     text : "Done"
605                 }
606             ]
607         });
608     }
609 };