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                                 beforeload : function (_self, o)
110                                 {
111                                     if (!_this.data) {
112                                         return false;
113                                     }
114                                     o.params =  Roo.apply(o.params, {
115                                         person_id : _this.data.person_id,
116                                         onid : _this.data.onid,
117                                         ontable : _this.data.ontable,
118                                         method : _this.data.method
119                                     });
120                                         
121                                 }
122                             },
123                             remoteSort : true,
124                             sortInfo : { field : 'freq', direction: 'ASC' },
125                             proxy : {
126                                 xtype: 'HttpProxy',
127                                 xns: Roo.data,
128                                 method : 'GET',
129                                 url : baseURL + '/Roo/core_notify_recur.php'
130                             },
131                             reader : {
132                                 xtype: 'JsonReader',
133                                 xns: Roo.data,
134                                 id : 'id',
135                                 root : 'data',
136                                 totalProperty : 'total',
137                                 fields : [
138                                     {
139                                         'name': 'id',
140                                         'type': 'int'
141                                     },
142                                     {
143                                         'name': 'person_id',
144                                         'type': 'int'
145                                     },
146                                     {
147                                         'name': 'dtstart',
148                                         'type': 'date',
149                                         'dateFormat': 'Y-m-d'
150                                     },
151                                     {
152                                         'name': 'dtend',
153                                         'type': 'date',
154                                         'dateFormat': 'Y-m-d'
155                                     },
156                                     {
157                                         'name': 'tz',
158                                         'type': 'float'
159                                     },
160                                     {
161                                         'name': 'last_applied_dt',
162                                         'type': 'date',
163                                         'dateFormat': 'Y-m-d'
164                                     },
165                                     {
166                                         'name': 'freq',
167                                         'type': 'string'
168                                     },
169                                     {
170                                         'name': 'freq_day',
171                                         'type': 'string'
172                                     },
173                                     {
174                                         'name': 'freq_hour',
175                                         'type': 'string'
176                                     },
177                                     {
178                                         'name': 'last_event_id',
179                                         'type': 'int'
180                                     },
181                                     {
182                                         'name': 'method',
183                                         'type': 'string'
184                                     }
185                                 ]
186                             }
187                         },
188                         footer : {
189                             xtype: 'PagingToolbar',
190                             xns: Roo,
191                             pageSize : 25,
192                             displayInfo : true,
193                             displayMsg : "Displaying core_notify_recur{0} - {1} of {2}",
194                             emptyMsg : "No core_notify_recur found"
195                         },
196                         toolbar : {
197                             xtype: 'Toolbar',
198                             xns: Roo,
199                             items : [
200                                 {
201                                     xtype: 'Button',
202                                     xns: Roo.Toolbar,
203                                     listeners : {
204                                         click : function()
205                                         {
206                                             var grid = _this.grid;
207                                             var r = grid.getDataSource().reader.newRow({
208                                             // defaults..
209                                                 person_id : _this.data.person_id,
210                                                 dtstart : new Date(0),
211                                                 dtend : Date.parseDate('2050-01-01', 'Y-m-d'),
212                                                 tz : 'Asia/Hong Kong',
213                                                 onid : _this.data.onid,
214                                                 ontable : _this.data.ontable,
215                                                 method : _this.data.method,
216                                                 last_event_id : 0,
217                                                 freq_day_name : '',
218                                                 freq_hour_name : '',
219                                                 freq_name : ''
220                                                 
221                                             
222                                             });
223                                             grid.stopEditing();
224                                             grid.getDataSource().insert(0, r); 
225                                             grid.startEditing(0, 2); 
226                                             
227                                         
228                                         }
229                                     },
230                                     cls : 'x-btn-text-icon',
231                                     text : "Add",
232                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
233                                 },
234                                 {
235                                     xtype: 'Fill',
236                                     xns: Roo.Toolbar
237                                 },
238                                 {
239                                     xtype: 'Button',
240                                     xns: Roo.Toolbar,
241                                     text : "Delete",
242                                     cls : 'x-btn-text-icon',
243                                     icon : rootURL + '/Pman/templates/images/trash.gif',
244                                     listeners : {
245                                         click : function()
246                                         {
247                                              Pman.genericDelete(_this, 'core_notify_recur'); 
248                                         }
249                                     }
250                                 }
251                             ]
252                         },
253                         colModel : [
254                             {
255                                 xtype: 'ColumnModel',
256                                 xns: Roo.grid,
257                                 dataIndex : 'dtstart',
258                                 header : 'From',
259                                 width : 75,
260                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
261                                 editor : {
262                                     xtype: 'GridEditor',
263                                     xns: Roo.grid,
264                                     field : {
265                                         xtype: 'DateField',
266                                         xns: Roo.form
267                                     }
268                                 }
269                             },
270                             {
271                                 xtype: 'ColumnModel',
272                                 xns: Roo.grid,
273                                 dataIndex : 'dtend',
274                                 header : 'Until',
275                                 width : 75,
276                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
277                                 editor : {
278                                     xtype: 'GridEditor',
279                                     xns: Roo.grid,
280                                     field : {
281                                         xtype: 'DateField',
282                                         xns: Roo.form
283                                     }
284                                 }
285                             },
286                             {
287                                 xtype: 'ColumnModel',
288                                 xns: Roo.grid,
289                                 dataIndex : 'freq_day',
290                                 header : 'on day(s)',
291                                 width : 100,
292                                 renderer : function(v,x,r) { 
293                                     
294                                     return String.format('{0}', r.data.freq_day_name || v); 
295                                     
296                                 },
297                                 editor : {
298                                     xtype: 'GridEditor',
299                                     xns: Roo.grid,
300                                     field : {
301                                         xtype: 'ComboCheck',
302                                         xns: Roo.form,
303                                         allowBlank : false,
304                                         displayField : 'title',
305                                         editable : false,
306                                         fieldLabel : 'Country',
307                                         hiddenName : 'freq_day',
308                                         listWidth : 300,
309                                         mode : 'local',
310                                         name : 'freq_day_name',
311                                         pageSize : 40,
312                                         triggerAction : 'all',
313                                         valueField : 'code',
314                                         store : {
315                                             xtype: 'SimpleStore',
316                                             xns: Roo.data,
317                                             data : (function() { 
318                                                 var ret = [];
319                                                 Roo.each(Date.dayNames, function(d) {
320                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
321                                                 });
322                                                 return ret;
323                                             })(),
324                                             fields : ['code', 'title'],
325                                             sortInfo : { field : 'title', direction: 'ASC' }
326                                         }
327                                     }
328                                 }
329                             },
330                             {
331                                 xtype: 'ColumnModel',
332                                 xns: Roo.grid,
333                                 dataIndex : 'freq_hour',
334                                 header : 'at Hour(s)',
335                                 width : 250,
336                                 renderer : function(v,x,r) { 
337                                     
338                                     return String.format('{0}', r.data.freq_hour_name || v); 
339                                     
340                                 },
341                                 editor : {
342                                     xtype: 'GridEditor',
343                                     xns: Roo.grid,
344                                     field : {
345                                         xtype: 'ComboCheck',
346                                         xns: Roo.form,
347                                         allowBlank : false,
348                                         displayField : 'title',
349                                         editable : false,
350                                         fieldLabel : 'Country',
351                                         hiddenName : 'freq_hour',
352                                         listWidth : 300,
353                                         mode : 'local',
354                                         name : 'freq_hour_name',
355                                         pageSize : 40,
356                                         triggerAction : 'all',
357                                         valueField : 'code',
358                                         store : {
359                                             xtype: 'SimpleStore',
360                                             xns: Roo.data,
361                                             data : (function() { 
362                                                 var ret = [];
363                                                 for (var i = 5; i < 25; i++) {
364                                                     var h = i < 10 ? ('0' + i) : i;
365                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
366                                                     var dh = i < 13 ? i : i-12;
367                                                     
368                                                     ret.push([ h+':00', dh+':00' + mer ]);
369                                                     ret.push([ h+':00', dh+':30' + mer ]);        
370                                                 }
371                                                 return ret;
372                                             })(),
373                                             fields : ['code', 'title'],
374                                             sortInfo : { field : 'title', direction: 'ASC' }
375                                         }
376                                     }
377                                 }
378                             },
379                             {
380                                 xtype: 'ColumnModel',
381                                 xns: Roo.grid,
382                                 dataIndex : 'tz',
383                                 header : 'Timezone',
384                                 width : 100,
385                                 renderer : function(v) { return String.format('{0}', v); },
386                                 editor : {
387                                     xtype: 'GridEditor',
388                                     xns: Roo.grid,
389                                     field : {
390                                         xtype: 'ComboBox',
391                                         xns: Roo.form,
392                                         allowBlank : 'false',
393                                         displayField : 'tz',
394                                         editable : true,
395                                         emptyText : "Select timezone",
396                                         fieldLabel : 'core_enum',
397                                         forceSelection : true,
398                                         hiddenName : 'tz',
399                                         listWidth : 400,
400                                         loadingText : "Searching...",
401                                         minChars : 2,
402                                         name : 'tz_name',
403                                         pageSize : 999,
404                                         qtip : "Select timezone",
405                                         queryParam : 'q',
406                                         selectOnFocus : true,
407                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
408                                         triggerAction : 'all',
409                                         typeAhead : true,
410                                         valueField : 'tz',
411                                         width : 300,
412                                         store : {
413                                             xtype: 'Store',
414                                             xns: Roo.data,
415                                             listeners : {
416                                                 beforeload : function (_self, o){
417                                                     o.params = o.params || {};
418                                                     // set more here
419                                                 }
420                                             },
421                                             remoteSort : true,
422                                             sortInfo : { direction : 'ASC', field: 'tz' },
423                                             proxy : {
424                                                 xtype: 'HttpProxy',
425                                                 xns: Roo.data,
426                                                 method : 'GET',
427                                                 url : baseURL + '/Core/I18n/Timezone.php'
428                                             },
429                                             reader : {
430                                                 xtype: 'JsonReader',
431                                                 xns: Roo.data,
432                                                 id : 'id',
433                                                 root : 'data',
434                                                 totalProperty : 'total',
435                                                 fields : [{"name":"tz","type":"string"}]
436                                             }
437                                         }
438                                     }
439                                 }
440                             },
441                             {
442                                 xtype: 'ColumnModel',
443                                 xns: Roo.grid,
444                                 header : 'Last event',
445                                 width : 75,
446                                 dataIndex : 'last_event_id',
447                                 renderer : function(v) { return String.format('{0}', v); }
448                             }
449                         ]
450                     }
451                 }
452             ],
453             center : {
454                 xtype: 'LayoutRegion',
455                 xns: Roo,
456                 autoScroll : true,
457                 loadOnce : true
458             },
459             buttons : [
460                 {
461                     xtype: 'Button',
462                     xns: Roo,
463                     text : "Done"
464                 }
465             ]
466         });
467     }
468 };