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