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