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                                     cls : 'x-btn-text-icon',
217                                     text : "Add",
218                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
219                                 },
220                                 {
221                                     xtype: 'Fill',
222                                     xns: Roo.Toolbar
223                                 },
224                                 {
225                                     xtype: 'Button',
226                                     xns: Roo.Toolbar,
227                                     text : "Delete",
228                                     cls : 'x-btn-text-icon',
229                                     icon : rootURL + '/Pman/templates/images/trash.gif',
230                                     listeners : {
231                                         click : function()
232                                         {
233                                              Pman.genericDelete(_this, 'core_notify_recur'); 
234                                         }
235                                     }
236                                 }
237                             ]
238                         },
239                         colModel : [
240                             {
241                                 xtype: 'ColumnModel',
242                                 xns: Roo.grid,
243                                 dataIndex : 'dtstart',
244                                 header : 'From',
245                                 width : 75,
246                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
247                                 editor : {
248                                     xtype: 'GridEditor',
249                                     xns: Roo.grid,
250                                     field : {
251                                         xtype: 'DateField',
252                                         xns: Roo.form
253                                     }
254                                 }
255                             },
256                             {
257                                 xtype: 'ColumnModel',
258                                 xns: Roo.grid,
259                                 dataIndex : 'dtend',
260                                 header : 'Until',
261                                 width : 75,
262                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
263                                 editor : {
264                                     xtype: 'GridEditor',
265                                     xns: Roo.grid,
266                                     field : {
267                                         xtype: 'DateField',
268                                         xns: Roo.form
269                                     }
270                                 }
271                             },
272                             {
273                                 xtype: 'ColumnModel',
274                                 xns: Roo.grid,
275                                 dataIndex : 'freq',
276                                 header : 'Frequency',
277                                 width : 70,
278                                 renderer : function(v,x,r) { 
279                                 
280                                     Roo.log(this);
281                                     var cm = _this.grid.colModel;
282                                     var ix = cm.findColumnIndex('freq');
283                                     var ce = cm.getCellEditor(ix)
284                                     var matches = ce.field.store.query('code',v);
285                                     if (!matches.length) {
286                                         return '';
287                                     }
288                                     return String.format('{0}', matches.first().data.title);
289                                  },
290                                 editor : {
291                                     xtype: 'GridEditor',
292                                     xns: Roo.grid,
293                                     field : {
294                                         xtype: 'ComboBox',
295                                         xns: Roo.form,
296                                         allowBlank : false,
297                                         displayField : 'title',
298                                         editable : false,
299                                         fieldLabel : 'Country',
300                                         hiddenName : 'freq',
301                                         listWidth : 200,
302                                         mode : 'local',
303                                         name : 'freq_name',
304                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b> </div>',
305                                         triggerAction : 'all',
306                                         valueField : 'code',
307                                         width : 200,
308                                         store : {
309                                             xtype: 'SimpleStore',
310                                             xns: Roo.data,
311                                             data : [ 
312                                                 [ 'HOURLY' , 'Hourly at' ] ,
313                                                    [ 'DAILY' , 'Daily at'] ,
314                                                     [ 'WEEKLY' , 'Weekly at'] ,
315                                                      [ 'Montly' , 'Montly at'] 
316                                             ],
317                                             fields : ['code', 'title'],
318                                             sortInfo : { field : 'title', direction: 'ASC' }
319                                         }
320                                     }
321                                 }
322                             },
323                             {
324                                 xtype: 'ColumnModel',
325                                 xns: Roo.grid,
326                                 dataIndex : 'freq_day',
327                                 header : 'on day(s)',
328                                 width : 100,
329                                 renderer : function(v,x,r) { 
330                                     
331                                     return String.format('{0}', r.data.freq_day_name || v); 
332                                     
333                                 },
334                                 editor : {
335                                     xtype: 'GridEditor',
336                                     xns: Roo.grid,
337                                     field : {
338                                         xtype: 'ComboCheck',
339                                         xns: Roo.form,
340                                         allowBlank : false,
341                                         displayField : 'title',
342                                         editable : false,
343                                         fieldLabel : 'Country',
344                                         hiddenName : 'freq_day',
345                                         listWidth : 300,
346                                         mode : 'local',
347                                         name : 'freq_day_name',
348                                         pageSize : 40,
349                                         triggerAction : 'all',
350                                         valueField : 'code',
351                                         store : {
352                                             xtype: 'SimpleStore',
353                                             xns: Roo.data,
354                                             data : (function() { 
355                                                 var ret = [];
356                                                 Roo.each(Date.dayNames, function(d) {
357                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
358                                                 });
359                                                 return ret;
360                                             })(),
361                                             fields : ['code', 'title'],
362                                             sortInfo : { field : 'title', direction: 'ASC' }
363                                         }
364                                     }
365                                 }
366                             },
367                             {
368                                 xtype: 'ColumnModel',
369                                 xns: Roo.grid,
370                                 dataIndex : 'freq_hour',
371                                 header : 'at Hour(s)',
372                                 width : 250,
373                                 renderer : function(v,x,r) { 
374                                     
375                                     return String.format('{0}', r.data.freq_hour_name || v); 
376                                     
377                                 },
378                                 editor : {
379                                     xtype: 'GridEditor',
380                                     xns: Roo.grid,
381                                     field : {
382                                         xtype: 'ComboCheck',
383                                         xns: Roo.form,
384                                         allowBlank : false,
385                                         displayField : 'title',
386                                         editable : false,
387                                         fieldLabel : 'Country',
388                                         hiddenName : 'freq_hour',
389                                         listWidth : 300,
390                                         mode : 'local',
391                                         name : 'freq_hour_name',
392                                         pageSize : 40,
393                                         triggerAction : 'all',
394                                         valueField : 'code',
395                                         store : {
396                                             xtype: 'SimpleStore',
397                                             xns: Roo.data,
398                                             data : (function() { 
399                                                 var ret = [];
400                                                 for (var i = 5; i < 25; i++) {
401                                                     var h = i < 10 ? ('0' + i) : i;
402                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
403                                                     var dh = i < 13 ? i : i-12;
404                                                     
405                                                     ret.push([ h+':00', dh+':00' + mer ]);
406                                                     ret.push([ h+':00', dh+':30' + mer ]);        
407                                                 }
408                                                 return ret;
409                                             })(),
410                                             fields : ['code', 'title'],
411                                             sortInfo : { field : 'title', direction: 'ASC' }
412                                         }
413                                     }
414                                 }
415                             },
416                             {
417                                 xtype: 'ColumnModel',
418                                 xns: Roo.grid,
419                                 dataIndex : 'tz',
420                                 header : 'Timezone',
421                                 width : 100,
422                                 renderer : function(v) { return String.format('{0}', v); }
423                             },
424                             {
425                                 xtype: 'ColumnModel',
426                                 xns: Roo.grid,
427                                 header : 'Last event',
428                                 width : 75,
429                                 dataIndex : 'last_event_id',
430                                 renderer : function(v) { return String.format('{0}', v); }
431                             }
432                         ]
433                     }
434                 }
435             ],
436             center : {
437                 xtype: 'LayoutRegion',
438                 xns: Roo,
439                 autoScroll : true,
440                 loadOnce : true
441             },
442             buttons : [
443                 {
444                     xtype: 'Button',
445                     xns: Roo,
446                     text : "Done"
447                 }
448             ]
449         });
450     }
451 };