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