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