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 : 500,
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                                     new Pman.Request({
100                                         url : baseURL + '/Roo/Core_notify_recur',
101                                         method :'POST',
102                                         params : record.data,
103                                         success : function(data)
104                                         {
105                                             //Roo.log(data);
106                                             record.set('id', data.data.id);
107                                         },
108                                         failure : function() {
109                                             Roo.MessageBox.alert("Error", "There was a problem saving");
110                                         }
111                                     });
112                                        
113                                     
114                                     
115                                 },
116                                 beforeload : function (_self, o)
117                                 {
118                                     if (!_this.data) {
119                                         return false;
120                                     }
121                                     o.params =  Roo.apply(o.params || {}, {
122                                         person_id : _this.data.person_id,
123                                         onid : _this.data.onid,
124                                         ontable : _this.data.ontable,
125                                         method : _this.data.method
126                                     });
127                                         
128                                 }
129                             },
130                             remoteSort : true,
131                             sortInfo : { field : 'freq', direction: 'ASC' },
132                             proxy : {
133                                 xtype: 'HttpProxy',
134                                 xns: Roo.data,
135                                 method : 'GET',
136                                 url : baseURL + '/Roo/core_notify_recur.php'
137                             },
138                             reader : {
139                                 xtype: 'JsonReader',
140                                 xns: Roo.data,
141                                 id : 'id',
142                                 root : 'data',
143                                 totalProperty : 'total',
144                                 fields : [
145                                     {
146                                         'name': 'id',
147                                         'type': 'int'
148                                     },
149                                     {
150                                         'name': 'person_id',
151                                         'type': 'int'
152                                     },
153                                     {
154                                         'name': 'dtstart',
155                                         'type': 'date',
156                                         'dateFormat': 'Y-m-d'
157                                     },
158                                     {
159                                         'name': 'dtend',
160                                         'type': 'date',
161                                         'dateFormat': 'Y-m-d'
162                                     },
163                                     {
164                                         'name': 'tz',
165                                         'type': 'float'
166                                     },
167                                     {
168                                         'name': 'last_applied_dt',
169                                         'type': 'date',
170                                         'dateFormat': 'Y-m-d'
171                                     },
172                                     {
173                                         'name': 'freq',
174                                         'type': 'string'
175                                     },
176                                     {
177                                         'name': 'freq_day',
178                                         'type': 'string'
179                                     },
180                                     {
181                                         'name': 'freq_hour',
182                                         'type': 'string'
183                                     },
184                                     {
185                                         'name': 'last_event_id',
186                                         'type': 'int'
187                                     },
188                                     {
189                                         'name': 'method',
190                                         'type': 'string'
191                                     }
192                                 ]
193                             }
194                         },
195                         toolbar : {
196                             xtype: 'Toolbar',
197                             xns: Roo,
198                             items : [
199                                 {
200                                     xtype: 'Button',
201                                     xns: Roo.Toolbar,
202                                     listeners : {
203                                         click : function()
204                                         {
205                                             var grid = _this.grid;
206                                             var r = grid.getDataSource().reader.newRow({
207                                             // defaults..
208                                                 person_id : _this.data.person_id,
209                                                 dtstart : new Date(0),
210                                                 dtend : Date.parseDate('2030-01-01', 'Y-m-d'),
211                                                 tz : 'Asia/Hong Kong',
212                                                 onid : _this.data.onid,
213                                                 ontable : _this.data.ontable,
214                                                 method : _this.data.method,
215                                                 last_event_id : 0,
216                                                 freq_day_name : '',
217                                                 freq_hour_name : '',
218                                                 freq_name : ''
219                                                 
220                                             
221                                             });
222                                             grid.stopEditing();
223                                             grid.getDataSource().insert(0, r); 
224                                             grid.startEditing(0, 2); 
225                                             
226                                         
227                                         }
228                                     },
229                                     cls : 'x-btn-text-icon',
230                                     text : "Add",
231                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
232                                 },
233                                 {
234                                     xtype: 'Fill',
235                                     xns: Roo.Toolbar
236                                 },
237                                 {
238                                     xtype: 'Button',
239                                     xns: Roo.Toolbar,
240                                     listeners : {
241                                         click : function()
242                                         {
243                                              _this.grid.stopEditing();
244                                              var s = _this.grid.selModel.getSelectedCell()
245                                              if (!s) {
246                                                 Roo.MessageBox.alert("Error", "Select row");
247                                                 return;
248                                             }
249                                             
250                                             new Pman.Request({
251                                                 url : baseURL + '/Roo/core_notify_recur',
252                                                 method : 'POST',
253                                                 params : {
254                                                     _delete : _this.grid.ds.getAt(s[0]).data.id,
255                                                 }, 
256                                                 success : function() {
257                                                     _this.grid.ds.load({});
258                                                 },
259                                                 failure : function() {
260                                                     Roo.MessageBox.alert("Error", "Deleting failed - try reloading");
261                                                 }
262                                            });
263                                             
264                                         }
265                                     },
266                                     cls : 'x-btn-text-icon',
267                                     text : "Delete",
268                                     icon : rootURL + '/Pman/templates/images/trash.gif'
269                                 }
270                             ]
271                         },
272                         colModel : [
273                             {
274                                 xtype: 'ColumnModel',
275                                 xns: Roo.grid,
276                                 dataIndex : 'dtstart',
277                                 header : 'From',
278                                 width : 75,
279                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
280                                 editor : {
281                                     xtype: 'GridEditor',
282                                     xns: Roo.grid,
283                                     field : {
284                                         xtype: 'DateField',
285                                         xns: Roo.form
286                                     }
287                                 }
288                             },
289                             {
290                                 xtype: 'ColumnModel',
291                                 xns: Roo.grid,
292                                 dataIndex : 'dtend',
293                                 header : 'Until',
294                                 width : 75,
295                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
296                                 editor : {
297                                     xtype: 'GridEditor',
298                                     xns: Roo.grid,
299                                     field : {
300                                         xtype: 'DateField',
301                                         xns: Roo.form
302                                     }
303                                 }
304                             },
305                             {
306                                 xtype: 'ColumnModel',
307                                 xns: Roo.grid,
308                                 dataIndex : 'freq_day',
309                                 header : 'on day(s)',
310                                 width : 100,
311                                 renderer : function(v,x,r) { 
312                                     
313                                     if (v.length) {
314                                      
315                                         var cm = _this.grid.colModel;
316                                        
317                                         var ci = cm.getColumnByDataIndex(this.name);
318                                        
319                                          var tv = [];
320                                         var vals = Roo.decode(v);
321                                         Roo.each(vals, function(k) {
322                                             var r = this.findRecord(this.valueField, k);
323                                             if(r){
324                                                 tv.push(r.data[this.displayField]);
325                                             }else if(this.valueNotFoundText !== undefined){
326                                                 tv.push( this.valueNotFoundText );
327                                             }
328                                         },ci.editor.field);
329                                 
330                                         r.data[this.name + '_name'] = tv.join(', ');
331                                         return String.format('{0}',tv.join(', '));
332                                 
333                                         
334                                     
335                                     }
336                                     r.data[this.name + '_name'] = '';
337                                     return String.format('{0}', r.data.freq_day_name || v); 
338                                     
339                                 },
340                                 editor : {
341                                     xtype: 'GridEditor',
342                                     xns: Roo.grid,
343                                     field : {
344                                         xtype: 'ComboCheck',
345                                         xns: Roo.form,
346                                         allowBlank : false,
347                                         displayField : 'title',
348                                         editable : false,
349                                         fieldLabel : 'Country',
350                                         hiddenName : 'freq_day',
351                                         listWidth : 300,
352                                         mode : 'local',
353                                         name : 'freq_day_name',
354                                         pageSize : 40,
355                                         triggerAction : 'all',
356                                         valueField : 'code',
357                                         store : {
358                                             xtype: 'SimpleStore',
359                                             xns: Roo.data,
360                                             data : (function() { 
361                                                 var ret = [];
362                                                 Roo.each(Date.dayNames, function(d) {
363                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
364                                                 });
365                                                 return ret;
366                                             })(),
367                                             fields : ['code', 'title'],
368                                             sortInfo : { field : 'title', direction: 'ASC' }
369                                         }
370                                     }
371                                 }
372                             },
373                             {
374                                 xtype: 'ColumnModel',
375                                 xns: Roo.grid,
376                                 dataIndex : 'freq_hour',
377                                 header : 'at Hour(s)',
378                                 width : 250,
379                                 renderer : function(v,x,r) { 
380                                     
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_hour_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_hour',
420                                         listWidth : 300,
421                                         mode : 'local',
422                                         name : 'freq_hour_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                                                 for (var i = 5; i < 25; i++) {
432                                                     var h = i < 10 ? ('0' + i) : i;
433                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
434                                                     var dh = i < 13 ? i : i-12;
435                                                     
436                                                     ret.push([ h+':00', dh+':00' + mer ]);
437                                                     ret.push([ h+':00', dh+':30' + mer ]);        
438                                                 }
439                                                 return ret;
440                                             })(),
441                                             fields : ['code', 'title'],
442                                             sortInfo : { field : 'title', direction: 'ASC' }
443                                         }
444                                     }
445                                 }
446                             },
447                             {
448                                 xtype: 'ColumnModel',
449                                 xns: Roo.grid,
450                                 dataIndex : 'tz',
451                                 header : 'Timezone',
452                                 width : 100,
453                                 renderer : function(v) { return String.format('{0}', v); },
454                                 editor : {
455                                     xtype: 'GridEditor',
456                                     xns: Roo.grid,
457                                     field : {
458                                         xtype: 'ComboBox',
459                                         xns: Roo.form,
460                                         allowBlank : 'false',
461                                         displayField : 'tz',
462                                         editable : true,
463                                         emptyText : "Select timezone",
464                                         fieldLabel : 'core_enum',
465                                         forceSelection : true,
466                                         hiddenName : 'tz',
467                                         listWidth : 400,
468                                         loadingText : "Searching...",
469                                         minChars : 2,
470                                         name : 'tz_name',
471                                         pageSize : 999,
472                                         qtip : "Select timezone",
473                                         queryParam : 'q',
474                                         selectOnFocus : true,
475                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
476                                         triggerAction : 'all',
477                                         typeAhead : true,
478                                         valueField : 'tz',
479                                         width : 300,
480                                         store : {
481                                             xtype: 'Store',
482                                             xns: Roo.data,
483                                             listeners : {
484                                                 beforeload : function (_self, o){
485                                                     o.params = o.params || {};
486                                                     // set more here
487                                                 }
488                                             },
489                                             remoteSort : true,
490                                             sortInfo : { direction : 'ASC', field: 'tz' },
491                                             proxy : {
492                                                 xtype: 'HttpProxy',
493                                                 xns: Roo.data,
494                                                 method : 'GET',
495                                                 url : baseURL + '/Core/I18n/Timezone.php'
496                                             },
497                                             reader : {
498                                                 xtype: 'JsonReader',
499                                                 xns: Roo.data,
500                                                 id : 'id',
501                                                 root : 'data',
502                                                 totalProperty : 'total',
503                                                 fields : [{"name":"tz","type":"string"}]
504                                             }
505                                         }
506                                     }
507                                 }
508                             },
509                             {
510                                 xtype: 'ColumnModel',
511                                 xns: Roo.grid,
512                                 header : 'Last event',
513                                 width : 75,
514                                 dataIndex : 'last_event_id',
515                                 renderer : function(v) { return String.format('{0}', v); }
516                             }
517                         ]
518                     }
519                 }
520             ],
521             center : {
522                 xtype: 'LayoutRegion',
523                 xns: Roo,
524                 autoScroll : true,
525                 loadOnce : true
526             },
527             buttons : [
528                 {
529                     xtype: 'Button',
530                     xns: Roo,
531                     listeners : {
532                         click : function (_self, e)
533                         {
534                             _this.dialog.hide();
535                         }
536                     },
537                     text : "Done"
538                 }
539             ]
540         });
541     }
542 };