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 : 550,
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                                     var p = Roo.apply({}, record.data);
100                                     p.dtstart = record.data.dtstart.format('Y-m-d');
101                                     p.dtend = record.data.dtend.format('Y-m-d');    
102                                     
103                                     
104                                     new Pman.Request({
105                                         url : baseURL + '/Roo/Core_notify_recur',
106                                         method :'POST',
107                                         params : p,
108                                         success : function(data)
109                                         {
110                                             //Roo.log(data);
111                                             record.set('id', data.data.id);
112                                         },
113                                         failure : function() {
114                                             Roo.MessageBox.alert("Error", "There was a problem saving");
115                                         }
116                                     });
117                                        
118                                     
119                                     
120                                 },
121                                 beforeload : function (_self, o)
122                                 {
123                                     if (!_this.data) {
124                                         return false;
125                                     }
126                                     o.params =  Roo.apply(o.params || {}, {
127                                         person_id : _this.data.person_id,
128                                         onid : _this.data.onid,
129                                         ontable : _this.data.ontable,
130                                         method : _this.data.method
131                                     });
132                                         
133                                 }
134                             },
135                             remoteSort : true,
136                             sortInfo : { field : 'freq', direction: 'ASC' },
137                             proxy : {
138                                 xtype: 'HttpProxy',
139                                 xns: Roo.data,
140                                 method : 'GET',
141                                 url : baseURL + '/Roo/core_notify_recur.php'
142                             },
143                             reader : {
144                                 xtype: 'JsonReader',
145                                 xns: Roo.data,
146                                 id : 'id',
147                                 root : 'data',
148                                 totalProperty : 'total',
149                                 fields : [
150                                     {
151                                         'name': 'id',
152                                         'type': 'int'
153                                     },
154                                     {
155                                         'name': 'person_id',
156                                         'type': 'int'
157                                     },
158                                     {
159                                         'name': 'dtstart',
160                                         'type': 'date',
161                                         'dateFormat': 'Y-m-d'
162                                     },
163                                     {
164                                         'name': 'dtend',
165                                         'type': 'date',
166                                         'dateFormat': 'Y-m-d'
167                                     },
168                                     {
169                                         'name': 'tz',
170                                         'type': 'float'
171                                     },
172                                     {
173                                         'name': 'last_applied_dt',
174                                         'type': 'date',
175                                         'dateFormat': 'Y-m-d'
176                                     },
177                                     {
178                                         'name': 'freq',
179                                         'type': 'string'
180                                     },
181                                     {
182                                         'name': 'freq_day',
183                                         'type': 'string'
184                                     },
185                                     {
186                                         'name': 'freq_hour',
187                                         'type': 'string'
188                                     },
189                                     {
190                                         'name': 'last_event_id',
191                                         'type': 'int'
192                                     },
193                                     {
194                                         'name': 'method',
195                                         'type': 'string'
196                                     }
197                                 ]
198                             }
199                         },
200                         toolbar : {
201                             xtype: 'Toolbar',
202                             xns: Roo,
203                             items : [
204                                 {
205                                     xtype: 'Button',
206                                     xns: Roo.Toolbar,
207                                     listeners : {
208                                         click : function()
209                                         {
210                                             var grid = _this.grid;
211                                             var r = grid.getDataSource().reader.newRow({
212                                             // defaults..
213                                                 person_id : _this.data.person_id,
214                                                 dtstart : new Date(),
215                                                 dtend : Date.parseDate('2050-01-01', 'Y-m-d'),
216                                                 tz : 'Asia/Hong_Kong',
217                                                 onid : _this.data.onid,
218                                                 ontable : _this.data.ontable,
219                                                 method : _this.data.method,
220                                                 last_event_id : 0,
221                                                 freq_day_name : '',
222                                                 freq_hour_name : '',
223                                                 freq_name : ''
224                                                 
225                                             
226                                             });
227                                             grid.stopEditing();
228                                             grid.getDataSource().insert(0, r); 
229                                             grid.startEditing(0, 2); 
230                                             
231                                         
232                                         }
233                                     },
234                                     cls : 'x-btn-text-icon',
235                                     text : "Add",
236                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
237                                 },
238                                 {
239                                     xtype: 'Fill',
240                                     xns: Roo.Toolbar
241                                 },
242                                 {
243                                     xtype: 'Button',
244                                     xns: Roo.Toolbar,
245                                     listeners : {
246                                         click : function()
247                                         {
248                                              _this.grid.stopEditing();
249                                              var s = _this.grid.selModel.getSelectedCell();
250                                              if (!s) {
251                                                 Roo.MessageBox.alert("Error", "Select row");
252                                                 return;
253                                             }
254                                             
255                                             new Pman.Request({
256                                                 url : baseURL + '/Roo/core_notify_recur',
257                                                 method : 'POST',
258                                                 params : {
259                                                     _delete : _this.grid.ds.getAt(s[0]).data.id
260                                                 }, 
261                                                 success : function() {
262                                                     _this.grid.ds.load({});
263                                                 },
264                                                 failure : function() {
265                                                     Roo.MessageBox.alert("Error", "Deleting failed - try reloading");
266                                                 }
267                                            });
268                                             
269                                         }
270                                     },
271                                     cls : 'x-btn-text-icon',
272                                     text : "Delete",
273                                     icon : rootURL + '/Pman/templates/images/trash.gif'
274                                 }
275                             ]
276                         },
277                         colModel : [
278                             {
279                                 xtype: 'ColumnModel',
280                                 xns: Roo.grid,
281                                 dataIndex : 'method',
282                                 header : 'From',
283                                 width : 75,
284                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
285                                 editor : {
286                                     xtype: 'GridEditor',
287                                     xns: Roo.grid,
288                                     field : {
289                                         xtype: 'DateField',
290                                         xns: Roo.form
291                                     }
292                                 }
293                             },
294                             {
295                                 xtype: 'ColumnModel',
296                                 xns: Roo.grid,
297                                 dataIndex : 'dtstart',
298                                 header : 'From',
299                                 width : 75,
300                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
301                                 editor : {
302                                     xtype: 'GridEditor',
303                                     xns: Roo.grid,
304                                     field : {
305                                         xtype: 'DateField',
306                                         xns: Roo.form
307                                     }
308                                 }
309                             },
310                             {
311                                 xtype: 'ColumnModel',
312                                 xns: Roo.grid,
313                                 dataIndex : 'dtend',
314                                 header : 'Until',
315                                 width : 75,
316                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
317                                 editor : {
318                                     xtype: 'GridEditor',
319                                     xns: Roo.grid,
320                                     field : {
321                                         xtype: 'DateField',
322                                         xns: Roo.form
323                                     }
324                                 }
325                             },
326                             {
327                                 xtype: 'ColumnModel',
328                                 xns: Roo.grid,
329                                 dataIndex : 'freq_day',
330                                 header : 'on day(s)',
331                                 width : 100,
332                                 renderer : function(v,x,r) { 
333                                     
334                                     if (v.length) {
335                                      
336                                         var cm = _this.grid.colModel;
337                                        
338                                         var ci = cm.getColumnByDataIndex(this.name);
339                                        
340                                          var tv = [];
341                                         var vals = Roo.decode(v);
342                                         Roo.each(vals, function(k) {
343                                             var r = this.findRecord(this.valueField, k);
344                                             if(r){
345                                                 tv.push(r.data[this.displayField]);
346                                             }else if(this.valueNotFoundText !== undefined){
347                                                 tv.push( this.valueNotFoundText );
348                                             }
349                                         },ci.editor.field);
350                                 
351                                         r.data[this.name + '_name'] = tv.join(', ');
352                                         return String.format('{0}',tv.join(', '));
353                                 
354                                         
355                                     
356                                     }
357                                     r.data[this.name + '_name'] = '';
358                                     return String.format('{0}', r.data.freq_day_name || v); 
359                                     
360                                 },
361                                 editor : {
362                                     xtype: 'GridEditor',
363                                     xns: Roo.grid,
364                                     field : {
365                                         xtype: 'ComboCheck',
366                                         xns: Roo.form,
367                                         allowBlank : false,
368                                         displayField : 'title',
369                                         editable : false,
370                                         fieldLabel : 'Country',
371                                         hiddenName : 'freq_day',
372                                         listWidth : 300,
373                                         mode : 'local',
374                                         name : 'freq_day_name',
375                                         pageSize : 40,
376                                         triggerAction : 'all',
377                                         valueField : 'code',
378                                         store : {
379                                             xtype: 'SimpleStore',
380                                             xns: Roo.data,
381                                             data : (function() { 
382                                                 var ret = [];
383                                                 Roo.each(Date.dayNames, function(d) {
384                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
385                                                 });
386                                                 return ret;
387                                             })(),
388                                             fields : ['code', 'title'],
389                                             sortInfo : { field : 'title', direction: 'ASC' }
390                                         }
391                                     }
392                                 }
393                             },
394                             {
395                                 xtype: 'ColumnModel',
396                                 xns: Roo.grid,
397                                 dataIndex : 'freq_hour',
398                                 header : 'at Hour(s)',
399                                 width : 250,
400                                 renderer : function(v,x,r) { 
401                                     
402                                  
403                                     if (v.length) {
404                                      
405                                         var cm = _this.grid.colModel;
406                                        
407                                         var ci = cm.getColumnByDataIndex(this.name);
408                                        
409                                          var tv = [];
410                                         var vals = Roo.decode(v);
411                                         Roo.each(vals, function(k) {
412                                             var r = this.findRecord(this.valueField, k);
413                                             if(r){
414                                                 tv.push(r.data[this.displayField]);
415                                             }else if(this.valueNotFoundText !== undefined){
416                                                 tv.push( this.valueNotFoundText );
417                                             }
418                                         },ci.editor.field);
419                                 
420                                          r.data[this.name + '_name'] = tv.join(', ');
421                                         return String.format('{0}',tv.join(', '));
422                                 
423                                         
424                                     
425                                     }
426                                         r.data[this.name + '_name'] = '';
427                                     return String.format('{0}', r.data.freq_hour_name || v); 
428                                     
429                                 },
430                                 editor : {
431                                     xtype: 'GridEditor',
432                                     xns: Roo.grid,
433                                     field : {
434                                         xtype: 'ComboCheck',
435                                         xns: Roo.form,
436                                         allowBlank : false,
437                                         displayField : 'title',
438                                         editable : false,
439                                         fieldLabel : 'Country',
440                                         hiddenName : 'freq_hour',
441                                         listWidth : 300,
442                                         mode : 'local',
443                                         name : 'freq_hour_name',
444                                         pageSize : 40,
445                                         triggerAction : 'all',
446                                         valueField : 'code',
447                                         store : {
448                                             xtype: 'SimpleStore',
449                                             xns: Roo.data,
450                                             data : (function() { 
451                                                 var ret = [];
452                                                 for (var i = 5; i < 25; i++) {
453                                                     var h = i < 10 ? ('0' + i) : i;
454                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
455                                                     var dh = i < 13 ? i : i-12;
456                                                     
457                                                     ret.push([ h+':00', dh+':00' + mer ]);
458                                                     ret.push([ h+':30', dh+':30' + mer ]);        
459                                                 }
460                                                 return ret;
461                                             })(),
462                                             fields : ['code', 'title'],
463                                             sortInfo : { field : 'title', direction: 'ASC' }
464                                         }
465                                     }
466                                 }
467                             },
468                             {
469                                 xtype: 'ColumnModel',
470                                 xns: Roo.grid,
471                                 dataIndex : 'tz',
472                                 header : 'Timezone',
473                                 width : 100,
474                                 renderer : function(v) { return String.format('{0}', v); },
475                                 editor : {
476                                     xtype: 'GridEditor',
477                                     xns: Roo.grid,
478                                     field : {
479                                         xtype: 'ComboBox',
480                                         xns: Roo.form,
481                                         allowBlank : 'false',
482                                         displayField : 'tz',
483                                         editable : true,
484                                         emptyText : "Select timezone",
485                                         fieldLabel : 'core_enum',
486                                         forceSelection : true,
487                                         listWidth : 400,
488                                         loadingText : "Searching...",
489                                         minChars : 2,
490                                         name : 'tz',
491                                         pageSize : 999,
492                                         qtip : "Select timezone",
493                                         queryParam : 'q',
494                                         selectOnFocus : true,
495                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
496                                         triggerAction : 'all',
497                                         typeAhead : true,
498                                         width : 300,
499                                         store : {
500                                             xtype: 'Store',
501                                             xns: Roo.data,
502                                             listeners : {
503                                                 beforeload : function (_self, o){
504                                                     o.params = o.params || {};
505                                                     // set more here
506                                                 }
507                                             },
508                                             remoteSort : true,
509                                             sortInfo : { direction : 'ASC', field: 'tz' },
510                                             proxy : {
511                                                 xtype: 'HttpProxy',
512                                                 xns: Roo.data,
513                                                 method : 'GET',
514                                                 url : baseURL + '/Core/I18n/Timezone.php'
515                                             },
516                                             reader : {
517                                                 xtype: 'JsonReader',
518                                                 xns: Roo.data,
519                                                 id : 'id',
520                                                 root : 'data',
521                                                 totalProperty : 'total',
522                                                 fields : [{"name":"tz","type":"string"}]
523                                             }
524                                         }
525                                     }
526                                 }
527                             },
528                             {
529                                 xtype: 'ColumnModel',
530                                 xns: Roo.grid,
531                                 dataIndex : 'last_event_id',
532                                 header : 'Last Sent',
533                                 width : 75,
534                                 renderer : function(v) { return String.format('{0}', v ? v : 'never'); }
535                             }
536                         ]
537                     }
538                 }
539             ],
540             center : {
541                 xtype: 'LayoutRegion',
542                 xns: Roo,
543                 autoScroll : true,
544                 loadOnce : true
545             },
546             buttons : [
547                 {
548                     xtype: 'Button',
549                     xns: Roo,
550                     listeners : {
551                         click : function (_self, e)
552                         {
553                             _this.dialog.hide();
554                         }
555                     },
556                     text : "Done"
557                 }
558             ]
559         });
560     }
561 };