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                                     if (v.length) {
337                                         var cm = _this.grid.colModel;
338                                  
339                                         
340                                     
341                                     }
342                                     
343                                     return String.format('{0}', r.data.freq_hour_name || v); 
344                                     
345                                 },
346                                 editor : {
347                                     xtype: 'GridEditor',
348                                     xns: Roo.grid,
349                                     field : {
350                                         xtype: 'ComboCheck',
351                                         xns: Roo.form,
352                                         allowBlank : false,
353                                         displayField : 'title',
354                                         editable : false,
355                                         fieldLabel : 'Country',
356                                         hiddenName : 'freq_hour',
357                                         listWidth : 300,
358                                         mode : 'local',
359                                         name : 'freq_hour_name',
360                                         pageSize : 40,
361                                         triggerAction : 'all',
362                                         valueField : 'code',
363                                         store : {
364                                             xtype: 'SimpleStore',
365                                             xns: Roo.data,
366                                             data : (function() { 
367                                                 var ret = [];
368                                                 for (var i = 5; i < 25; i++) {
369                                                     var h = i < 10 ? ('0' + i) : i;
370                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
371                                                     var dh = i < 13 ? i : i-12;
372                                                     
373                                                     ret.push([ h+':00', dh+':00' + mer ]);
374                                                     ret.push([ h+':00', dh+':30' + mer ]);        
375                                                 }
376                                                 return ret;
377                                             })(),
378                                             fields : ['code', 'title'],
379                                             sortInfo : { field : 'title', direction: 'ASC' }
380                                         }
381                                     }
382                                 }
383                             },
384                             {
385                                 xtype: 'ColumnModel',
386                                 xns: Roo.grid,
387                                 dataIndex : 'tz',
388                                 header : 'Timezone',
389                                 width : 100,
390                                 renderer : function(v) { return String.format('{0}', v); },
391                                 editor : {
392                                     xtype: 'GridEditor',
393                                     xns: Roo.grid,
394                                     field : {
395                                         xtype: 'ComboBox',
396                                         xns: Roo.form,
397                                         allowBlank : 'false',
398                                         displayField : 'tz',
399                                         editable : true,
400                                         emptyText : "Select timezone",
401                                         fieldLabel : 'core_enum',
402                                         forceSelection : true,
403                                         hiddenName : 'tz',
404                                         listWidth : 400,
405                                         loadingText : "Searching...",
406                                         minChars : 2,
407                                         name : 'tz_name',
408                                         pageSize : 999,
409                                         qtip : "Select timezone",
410                                         queryParam : 'q',
411                                         selectOnFocus : true,
412                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
413                                         triggerAction : 'all',
414                                         typeAhead : true,
415                                         valueField : 'tz',
416                                         width : 300,
417                                         store : {
418                                             xtype: 'Store',
419                                             xns: Roo.data,
420                                             listeners : {
421                                                 beforeload : function (_self, o){
422                                                     o.params = o.params || {};
423                                                     // set more here
424                                                 }
425                                             },
426                                             remoteSort : true,
427                                             sortInfo : { direction : 'ASC', field: 'tz' },
428                                             proxy : {
429                                                 xtype: 'HttpProxy',
430                                                 xns: Roo.data,
431                                                 method : 'GET',
432                                                 url : baseURL + '/Core/I18n/Timezone.php'
433                                             },
434                                             reader : {
435                                                 xtype: 'JsonReader',
436                                                 xns: Roo.data,
437                                                 id : 'id',
438                                                 root : 'data',
439                                                 totalProperty : 'total',
440                                                 fields : [{"name":"tz","type":"string"}]
441                                             }
442                                         }
443                                     }
444                                 }
445                             },
446                             {
447                                 xtype: 'ColumnModel',
448                                 xns: Roo.grid,
449                                 header : 'Last event',
450                                 width : 75,
451                                 dataIndex : 'last_event_id',
452                                 renderer : function(v) { return String.format('{0}', v); }
453                             }
454                         ]
455                     }
456                 }
457             ],
458             center : {
459                 xtype: 'LayoutRegion',
460                 xns: Roo,
461                 autoScroll : true,
462                 loadOnce : true
463             },
464             buttons : [
465                 {
466                     xtype: 'Button',
467                     xns: Roo,
468                     listeners : {
469                         click : function (_self, e)
470                         {
471                             _this.dialog.hide();
472                         }
473                     },
474                     text : "Done"
475                 }
476             ]
477         });
478     }
479 };