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                                     if (v.length) {
293                                      
294                                         var cm = _this.grid.colModel;
295                                        
296                                         var ci = cm.getColumnByDataIndex(this.name);
297                                        
298                                          var tv = [];
299                                         var vals = Roo.decode(v);
300                                         Roo.each(vals, function(k) {
301                                             var r = this.findRecord(this.valueField, k);
302                                             if(r){
303                                                 tv.push(r.data[this.displayField]);
304                                             }else if(this.valueNotFoundText !== undefined){
305                                                 tv.push( this.valueNotFoundText );
306                                             }
307                                         },ci.editor.field);
308                                 
309                                         r.data[this.name + '_name'] = tv.join(', ');
310                                         return String.format('{0}',tv.join(', '));
311                                 
312                                         
313                                     
314                                     }
315                                     return String.format('{0}', r.data.freq_day_name || v); 
316                                     
317                                 },
318                                 editor : {
319                                     xtype: 'GridEditor',
320                                     xns: Roo.grid,
321                                     field : {
322                                         xtype: 'ComboCheck',
323                                         xns: Roo.form,
324                                         allowBlank : false,
325                                         displayField : 'title',
326                                         editable : false,
327                                         fieldLabel : 'Country',
328                                         hiddenName : 'freq_day',
329                                         listWidth : 300,
330                                         mode : 'local',
331                                         name : 'freq_day_name',
332                                         pageSize : 40,
333                                         triggerAction : 'all',
334                                         valueField : 'code',
335                                         store : {
336                                             xtype: 'SimpleStore',
337                                             xns: Roo.data,
338                                             data : (function() { 
339                                                 var ret = [];
340                                                 Roo.each(Date.dayNames, function(d) {
341                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
342                                                 });
343                                                 return ret;
344                                             })(),
345                                             fields : ['code', 'title'],
346                                             sortInfo : { field : 'title', direction: 'ASC' }
347                                         }
348                                     }
349                                 }
350                             },
351                             {
352                                 xtype: 'ColumnModel',
353                                 xns: Roo.grid,
354                                 dataIndex : 'freq_hour',
355                                 header : 'at Hour(s)',
356                                 width : 250,
357                                 renderer : function(v,x,r) { 
358                                     
359                                  
360                                     if (v.length) {
361                                      
362                                         var cm = _this.grid.colModel;
363                                        
364                                         var ci = cm.getColumnByDataIndex(this.name);
365                                        
366                                          var tv = [];
367                                         var vals = Roo.decode(v);
368                                         Roo.each(vals, function(k) {
369                                             var r = this.findRecord(this.valueField, k);
370                                             if(r){
371                                                 tv.push(r.data[this.displayField]);
372                                             }else if(this.valueNotFoundText !== undefined){
373                                                 tv.push( this.valueNotFoundText );
374                                             }
375                                         },ci.editor.field);
376                                 
377                                              r.data[this.name + '_name'] = tv.join(', ');
378                                         return String.format('{0}',tv.join(', '));
379                                 
380                                         
381                                     
382                                     }
383                                     
384                                     return String.format('{0}', r.data.freq_hour_name || v); 
385                                     
386                                 },
387                                 editor : {
388                                     xtype: 'GridEditor',
389                                     xns: Roo.grid,
390                                     field : {
391                                         xtype: 'ComboCheck',
392                                         xns: Roo.form,
393                                         allowBlank : false,
394                                         displayField : 'title',
395                                         editable : false,
396                                         fieldLabel : 'Country',
397                                         hiddenName : 'freq_hour',
398                                         listWidth : 300,
399                                         mode : 'local',
400                                         name : 'freq_hour_name',
401                                         pageSize : 40,
402                                         triggerAction : 'all',
403                                         valueField : 'code',
404                                         store : {
405                                             xtype: 'SimpleStore',
406                                             xns: Roo.data,
407                                             data : (function() { 
408                                                 var ret = [];
409                                                 for (var i = 5; i < 25; i++) {
410                                                     var h = i < 10 ? ('0' + i) : i;
411                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
412                                                     var dh = i < 13 ? i : i-12;
413                                                     
414                                                     ret.push([ h+':00', dh+':00' + mer ]);
415                                                     ret.push([ h+':00', dh+':30' + mer ]);        
416                                                 }
417                                                 return ret;
418                                             })(),
419                                             fields : ['code', 'title'],
420                                             sortInfo : { field : 'title', direction: 'ASC' }
421                                         }
422                                     }
423                                 }
424                             },
425                             {
426                                 xtype: 'ColumnModel',
427                                 xns: Roo.grid,
428                                 dataIndex : 'tz',
429                                 header : 'Timezone',
430                                 width : 100,
431                                 renderer : function(v) { return String.format('{0}', v); },
432                                 editor : {
433                                     xtype: 'GridEditor',
434                                     xns: Roo.grid,
435                                     field : {
436                                         xtype: 'ComboBox',
437                                         xns: Roo.form,
438                                         allowBlank : 'false',
439                                         displayField : 'tz',
440                                         editable : true,
441                                         emptyText : "Select timezone",
442                                         fieldLabel : 'core_enum',
443                                         forceSelection : true,
444                                         hiddenName : 'tz',
445                                         listWidth : 400,
446                                         loadingText : "Searching...",
447                                         minChars : 2,
448                                         name : 'tz_name',
449                                         pageSize : 999,
450                                         qtip : "Select timezone",
451                                         queryParam : 'q',
452                                         selectOnFocus : true,
453                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
454                                         triggerAction : 'all',
455                                         typeAhead : true,
456                                         valueField : 'tz',
457                                         width : 300,
458                                         store : {
459                                             xtype: 'Store',
460                                             xns: Roo.data,
461                                             listeners : {
462                                                 beforeload : function (_self, o){
463                                                     o.params = o.params || {};
464                                                     // set more here
465                                                 }
466                                             },
467                                             remoteSort : true,
468                                             sortInfo : { direction : 'ASC', field: 'tz' },
469                                             proxy : {
470                                                 xtype: 'HttpProxy',
471                                                 xns: Roo.data,
472                                                 method : 'GET',
473                                                 url : baseURL + '/Core/I18n/Timezone.php'
474                                             },
475                                             reader : {
476                                                 xtype: 'JsonReader',
477                                                 xns: Roo.data,
478                                                 id : 'id',
479                                                 root : 'data',
480                                                 totalProperty : 'total',
481                                                 fields : [{"name":"tz","type":"string"}]
482                                             }
483                                         }
484                                     }
485                                 }
486                             },
487                             {
488                                 xtype: 'ColumnModel',
489                                 xns: Roo.grid,
490                                 header : 'Last event',
491                                 width : 75,
492                                 dataIndex : 'last_event_id',
493                                 renderer : function(v) { return String.format('{0}', v); }
494                             }
495                         ]
496                     }
497                 }
498             ],
499             center : {
500                 xtype: 'LayoutRegion',
501                 xns: Roo,
502                 autoScroll : true,
503                 loadOnce : true
504             },
505             buttons : [
506                 {
507                     xtype: 'Button',
508                     xns: Roo,
509                     listeners : {
510                         click : function (_self, e)
511                         {
512                             _this.dialog.hide();
513                         }
514                     },
515                     text : "Done"
516                 }
517             ]
518         });
519     }
520 };