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