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