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_day',
277                                 header : 'on day(s)',
278                                 width : 100,
279                                 renderer : function(v,x,r) { 
280                                     
281                                     return String.format('{0}', r.data.freq_day_name || v); 
282                                     
283                                 },
284                                 editor : {
285                                     xtype: 'GridEditor',
286                                     xns: Roo.grid,
287                                     field : {
288                                         xtype: 'ComboCheck',
289                                         xns: Roo.form,
290                                         allowBlank : false,
291                                         displayField : 'title',
292                                         editable : false,
293                                         fieldLabel : 'Country',
294                                         hiddenName : 'freq_day',
295                                         listWidth : 300,
296                                         mode : 'local',
297                                         name : 'freq_day_name',
298                                         pageSize : 40,
299                                         triggerAction : 'all',
300                                         valueField : 'code',
301                                         store : {
302                                             xtype: 'SimpleStore',
303                                             xns: Roo.data,
304                                             data : (function() { 
305                                                 var ret = [];
306                                                 Roo.each(Date.dayNames, function(d) {
307                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
308                                                 });
309                                                 return ret;
310                                             })(),
311                                             fields : ['code', 'title'],
312                                             sortInfo : { field : 'title', direction: 'ASC' }
313                                         }
314                                     }
315                                 }
316                             },
317                             {
318                                 xtype: 'ColumnModel',
319                                 xns: Roo.grid,
320                                 dataIndex : 'freq_hour',
321                                 header : 'at Hour(s)',
322                                 width : 250,
323                                 renderer : function(v,x,r) { 
324                                     
325                                     return String.format('{0}', r.data.freq_hour_name || v); 
326                                     
327                                 },
328                                 editor : {
329                                     xtype: 'GridEditor',
330                                     xns: Roo.grid,
331                                     field : {
332                                         xtype: 'ComboCheck',
333                                         xns: Roo.form,
334                                         allowBlank : false,
335                                         displayField : 'title',
336                                         editable : false,
337                                         fieldLabel : 'Country',
338                                         hiddenName : 'freq_hour',
339                                         listWidth : 300,
340                                         mode : 'local',
341                                         name : 'freq_hour_name',
342                                         pageSize : 40,
343                                         triggerAction : 'all',
344                                         valueField : 'code',
345                                         store : {
346                                             xtype: 'SimpleStore',
347                                             xns: Roo.data,
348                                             data : (function() { 
349                                                 var ret = [];
350                                                 for (var i = 5; i < 25; i++) {
351                                                     var h = i < 10 ? ('0' + i) : i;
352                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
353                                                     var dh = i < 13 ? i : i-12;
354                                                     
355                                                     ret.push([ h+':00', dh+':00' + mer ]);
356                                                     ret.push([ h+':00', dh+':30' + mer ]);        
357                                                 }
358                                                 return ret;
359                                             })(),
360                                             fields : ['code', 'title'],
361                                             sortInfo : { field : 'title', direction: 'ASC' }
362                                         }
363                                     }
364                                 }
365                             },
366                             {
367                                 xtype: 'ColumnModel',
368                                 xns: Roo.grid,
369                                 dataIndex : 'tz',
370                                 header : 'Timezone',
371                                 width : 100,
372                                 renderer : function(v) { return String.format('{0}', v); },
373                                 editor : {
374                                     xtype: 'GridEditor',
375                                     xns: Roo.grid,
376                                     field : {
377                                         xtype: 'ComboBox',
378                                         xns: Roo.form,
379                                         allowBlank : 'false',
380                                         displayField : 'tz',
381                                         editable : true,
382                                         emptyText : "Select timezone",
383                                         fieldLabel : 'core_enum',
384                                         forceSelection : true,
385                                         hiddenName : 'tz',
386                                         listWidth : 400,
387                                         loadingText : "Searching...",
388                                         minChars : 2,
389                                         name : 'tz_name',
390                                         pageSize : 999,
391                                         qtip : "Select timezone",
392                                         queryParam : 'q',
393                                         selectOnFocus : true,
394                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
395                                         triggerAction : 'all',
396                                         typeAhead : true,
397                                         valueField : 'tz',
398                                         width : 300,
399                                         store : {
400                                             xtype: 'Store',
401                                             xns: Roo.data,
402                                             listeners : {
403                                                 beforeload : function (_self, o){
404                                                     o.params = o.params || {};
405                                                     // set more here
406                                                 }
407                                             },
408                                             remoteSort : true,
409                                             sortInfo : { direction : 'ASC', field: 'tz' },
410                                             proxy : {
411                                                 xtype: 'HttpProxy',
412                                                 xns: Roo.data,
413                                                 method : 'GET',
414                                                 url : baseURL + '/Core/I18n/Timezone.php'
415                                             },
416                                             reader : {
417                                                 xtype: 'JsonReader',
418                                                 xns: Roo.data,
419                                                 id : 'id',
420                                                 root : 'data',
421                                                 totalProperty : 'total',
422                                                 fields : [{"name":"tz","type":"string"}]
423                                             }
424                                         }
425                                     }
426                                 }
427                             },
428                             {
429                                 xtype: 'ColumnModel',
430                                 xns: Roo.grid,
431                                 header : 'Last event',
432                                 width : 75,
433                                 dataIndex : 'last_event_id',
434                                 renderer : function(v) { return String.format('{0}', v); }
435                             }
436                         ]
437                     }
438                 }
439             ],
440             center : {
441                 xtype: 'LayoutRegion',
442                 xns: Roo,
443                 autoScroll : true,
444                 loadOnce : true
445             },
446             buttons : [
447                 {
448                     xtype: 'Button',
449                     xns: Roo,
450                     text : "Done"
451                 }
452             ]
453         });
454     }
455 };