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, // default...
220                                                 
221                                                 method_id : _this.data.method_id, // default...
222                                                 method_id_display_name : _this.data.method_id_display_name, // default...        
223                                                 
224                                                 last_event_id : 0,
225                                                 freq_day_name : '',
226                                                 freq_hour_name : '',
227                                                 freq_name : ''
228                                                 
229                                             
230                                             });
231                                             grid.stopEditing();
232                                             grid.getDataSource().insert(0, r); 
233                                             grid.startEditing(0, 2); 
234                                             
235                                         
236                                         }
237                                     },
238                                     cls : 'x-btn-text-icon',
239                                     text : "Add",
240                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
241                                 },
242                                 {
243                                     xtype: 'Fill',
244                                     xns: Roo.Toolbar
245                                 },
246                                 {
247                                     xtype: 'Button',
248                                     xns: Roo.Toolbar,
249                                     listeners : {
250                                         click : function()
251                                         {
252                                              _this.grid.stopEditing();
253                                              var s = _this.grid.selModel.getSelectedCell();
254                                              if (!s) {
255                                                 Roo.MessageBox.alert("Error", "Select row");
256                                                 return;
257                                             }
258                                             
259                                             new Pman.Request({
260                                                 url : baseURL + '/Roo/core_notify_recur',
261                                                 method : 'POST',
262                                                 params : {
263                                                     _delete : _this.grid.ds.getAt(s[0]).data.id
264                                                 }, 
265                                                 success : function() {
266                                                     _this.grid.ds.load({});
267                                                 },
268                                                 failure : function() {
269                                                     Roo.MessageBox.alert("Error", "Deleting failed - try reloading");
270                                                 }
271                                            });
272                                             
273                                         }
274                                     },
275                                     cls : 'x-btn-text-icon',
276                                     text : "Delete",
277                                     icon : rootURL + '/Pman/templates/images/trash.gif'
278                                 }
279                             ]
280                         },
281                         colModel : [
282                             {
283                                 xtype: 'ColumnModel',
284                                 xns: Roo.grid,
285                                 dataIndex : 'method_id',
286                                 header : 'Type',
287                                 width : 75,
288                                 renderer : function(v,x,r) {
289                                      return String.format('{0}', r.data.method_id_display_name); 
290                                 },
291                                 editor : {
292                                     xtype: 'GridEditor',
293                                     xns: Roo.grid,
294                                     field : {
295                                         xtype: 'ComboBox',
296                                         xns: Roo.form,
297                                         allowBlank : 'false',
298                                         displayField : 'display_name',
299                                         editable : 'false',
300                                         emptyText : "Select core_enum",
301                                         fieldLabel : 'core_enum',
302                                         forceSelection : true,
303                                         hiddenName : '',
304                                         listWidth : 400,
305                                         loadingText : "Searching...",
306                                         minChars : 2,
307                                         name : '',
308                                         pageSize : 20,
309                                         qtip : "Select core_enum",
310                                         queryParam : '',
311                                         selectOnFocus : true,
312                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
313                                         triggerAction : 'all',
314                                         typeAhead : true,
315                                         valueField : 'id',
316                                         width : 300,
317                                         store : {
318                                             xtype: 'Store',
319                                             xns: Roo.data,
320                                             remoteSort : true,
321                                             sortInfo : { direction : 'ASC', field: 'id' },
322                                             listeners : {
323                                                 beforeload : function (_self, o){
324                                                     o.params = o.params || {};
325                                                     // set more here
326                                                 }
327                                             },
328                                             proxy : {
329                                                 xtype: 'HttpProxy',
330                                                 xns: Roo.data,
331                                                 method : 'GET',
332                                                 url : baseURL + '/Roo/core_enum.php'
333                                             },
334                                             reader : {
335                                                 xtype: 'JsonReader',
336                                                 xns: Roo.data,
337                                                 id : 'id',
338                                                 root : 'data',
339                                                 totalProperty : 'total',
340                                                 fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
341                                             }
342                                         }
343                                     }
344                                 }
345                             },
346                             {
347                                 xtype: 'ColumnModel',
348                                 xns: Roo.grid,
349                                 dataIndex : 'dtstart',
350                                 header : 'From',
351                                 width : 75,
352                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
353                                 editor : {
354                                     xtype: 'GridEditor',
355                                     xns: Roo.grid,
356                                     field : {
357                                         xtype: 'DateField',
358                                         xns: Roo.form
359                                     }
360                                 }
361                             },
362                             {
363                                 xtype: 'ColumnModel',
364                                 xns: Roo.grid,
365                                 dataIndex : 'dtend',
366                                 header : 'Until',
367                                 width : 75,
368                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
369                                 editor : {
370                                     xtype: 'GridEditor',
371                                     xns: Roo.grid,
372                                     field : {
373                                         xtype: 'DateField',
374                                         xns: Roo.form
375                                     }
376                                 }
377                             },
378                             {
379                                 xtype: 'ColumnModel',
380                                 xns: Roo.grid,
381                                 dataIndex : 'freq_day',
382                                 header : 'on day(s)',
383                                 width : 100,
384                                 renderer : function(v,x,r) { 
385                                     
386                                     if (v.length) {
387                                      
388                                         var cm = _this.grid.colModel;
389                                        
390                                         var ci = cm.getColumnByDataIndex(this.name);
391                                        
392                                          var tv = [];
393                                         var vals = Roo.decode(v);
394                                         Roo.each(vals, function(k) {
395                                             var r = this.findRecord(this.valueField, k);
396                                             if(r){
397                                                 tv.push(r.data[this.displayField]);
398                                             }else if(this.valueNotFoundText !== undefined){
399                                                 tv.push( this.valueNotFoundText );
400                                             }
401                                         },ci.editor.field);
402                                 
403                                         r.data[this.name + '_name'] = tv.join(', ');
404                                         return String.format('{0}',tv.join(', '));
405                                 
406                                         
407                                     
408                                     }
409                                     r.data[this.name + '_name'] = '';
410                                     return String.format('{0}', r.data.freq_day_name || v); 
411                                     
412                                 },
413                                 editor : {
414                                     xtype: 'GridEditor',
415                                     xns: Roo.grid,
416                                     field : {
417                                         xtype: 'ComboCheck',
418                                         xns: Roo.form,
419                                         allowBlank : false,
420                                         displayField : 'title',
421                                         editable : false,
422                                         fieldLabel : 'Country',
423                                         hiddenName : 'freq_day',
424                                         listWidth : 300,
425                                         mode : 'local',
426                                         name : 'freq_day_name',
427                                         pageSize : 40,
428                                         triggerAction : 'all',
429                                         valueField : 'code',
430                                         store : {
431                                             xtype: 'SimpleStore',
432                                             xns: Roo.data,
433                                             data : (function() { 
434                                                 var ret = [];
435                                                 Roo.each(Date.dayNames, function(d) {
436                                                     ret.push([ d.substring(0,3).toUpperCase(), d ]);
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 : 'freq_hour',
450                                 header : 'at Hour(s)',
451                                 width : 250,
452                                 renderer : function(v,x,r) { 
453                                     
454                                  
455                                     if (v.length) {
456                                      
457                                         var cm = _this.grid.colModel;
458                                        
459                                         var ci = cm.getColumnByDataIndex(this.name);
460                                        
461                                          var tv = [];
462                                         var vals = Roo.decode(v);
463                                         Roo.each(vals, function(k) {
464                                             var r = this.findRecord(this.valueField, k);
465                                             if(r){
466                                                 tv.push(r.data[this.displayField]);
467                                             }else if(this.valueNotFoundText !== undefined){
468                                                 tv.push( this.valueNotFoundText );
469                                             }
470                                         },ci.editor.field);
471                                 
472                                          r.data[this.name + '_name'] = tv.join(', ');
473                                         return String.format('{0}',tv.join(', '));
474                                 
475                                         
476                                     
477                                     }
478                                         r.data[this.name + '_name'] = '';
479                                     return String.format('{0}', r.data.freq_hour_name || v); 
480                                     
481                                 },
482                                 editor : {
483                                     xtype: 'GridEditor',
484                                     xns: Roo.grid,
485                                     field : {
486                                         xtype: 'ComboCheck',
487                                         xns: Roo.form,
488                                         allowBlank : false,
489                                         displayField : 'title',
490                                         editable : false,
491                                         fieldLabel : 'Country',
492                                         hiddenName : 'freq_hour',
493                                         listWidth : 300,
494                                         mode : 'local',
495                                         name : 'freq_hour_name',
496                                         pageSize : 40,
497                                         triggerAction : 'all',
498                                         valueField : 'code',
499                                         store : {
500                                             xtype: 'SimpleStore',
501                                             xns: Roo.data,
502                                             data : (function() { 
503                                                 var ret = [];
504                                                 for (var i = 5; i < 25; i++) {
505                                                     var h = i < 10 ? ('0' + i) : i;
506                                                     var mer = i < 12 || i > 23 ? 'am' : 'pm';
507                                                     var dh = i < 13 ? i : i-12;
508                                                     
509                                                     ret.push([ h+':00', dh+':00' + mer ]);
510                                                     ret.push([ h+':30', dh+':30' + mer ]);        
511                                                 }
512                                                 return ret;
513                                             })(),
514                                             fields : ['code', 'title'],
515                                             sortInfo : { field : 'title', direction: 'ASC' }
516                                         }
517                                     }
518                                 }
519                             },
520                             {
521                                 xtype: 'ColumnModel',
522                                 xns: Roo.grid,
523                                 dataIndex : 'tz',
524                                 header : 'Timezone',
525                                 width : 100,
526                                 renderer : function(v) { return String.format('{0}', v); },
527                                 editor : {
528                                     xtype: 'GridEditor',
529                                     xns: Roo.grid,
530                                     field : {
531                                         xtype: 'ComboBox',
532                                         xns: Roo.form,
533                                         allowBlank : 'false',
534                                         displayField : 'tz',
535                                         editable : true,
536                                         emptyText : "Select timezone",
537                                         fieldLabel : 'core_enum',
538                                         forceSelection : true,
539                                         listWidth : 400,
540                                         loadingText : "Searching...",
541                                         minChars : 2,
542                                         name : 'tz',
543                                         pageSize : 999,
544                                         qtip : "Select timezone",
545                                         queryParam : 'q',
546                                         selectOnFocus : true,
547                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
548                                         triggerAction : 'all',
549                                         typeAhead : true,
550                                         width : 300,
551                                         store : {
552                                             xtype: 'Store',
553                                             xns: Roo.data,
554                                             listeners : {
555                                                 beforeload : function (_self, o){
556                                                     o.params = o.params || {};
557                                                     // set more here
558                                                 }
559                                             },
560                                             remoteSort : true,
561                                             sortInfo : { direction : 'ASC', field: 'tz' },
562                                             proxy : {
563                                                 xtype: 'HttpProxy',
564                                                 xns: Roo.data,
565                                                 method : 'GET',
566                                                 url : baseURL + '/Core/I18n/Timezone.php'
567                                             },
568                                             reader : {
569                                                 xtype: 'JsonReader',
570                                                 xns: Roo.data,
571                                                 id : 'id',
572                                                 root : 'data',
573                                                 totalProperty : 'total',
574                                                 fields : [{"name":"tz","type":"string"}]
575                                             }
576                                         }
577                                     }
578                                 }
579                             },
580                             {
581                                 xtype: 'ColumnModel',
582                                 xns: Roo.grid,
583                                 dataIndex : 'last_event_id',
584                                 header : 'Last Sent',
585                                 width : 75,
586                                 renderer : function(v) { return String.format('{0}', v ? v : 'never'); }
587                             }
588                         ]
589                     }
590                 }
591             ],
592             center : {
593                 xtype: 'LayoutRegion',
594                 xns: Roo,
595                 autoScroll : true,
596                 loadOnce : true
597             },
598             buttons : [
599                 {
600                     xtype: 'Button',
601                     xns: Roo,
602                     listeners : {
603                         click : function (_self, e)
604                         {
605                             _this.dialog.hide();
606                         }
607                     },
608                     text : "Done"
609                 }
610             ]
611         });
612     }
613 };