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