DataObjects/Core_person_signup.php
[Pman.Core] / Pman.Dialog.CoreNotifyRecur.js
index b1263b4..fb12481 100644 (file)
@@ -30,7 +30,13 @@ Pman.Dialog.CoreNotifyRecur = {
         this.dialog = Roo.factory({
             xtype: 'LayoutDialog',
             xns: Roo,
-            height : 500,
+            listeners : {
+                show : function (_self)
+                {
+                    _this.grid.ds.load({});
+                }
+            },
+            height : 550,
             modal : true,
             resizable : false,
             title : "Modify Recurrent Notifications",
@@ -41,9 +47,9 @@ Pman.Dialog.CoreNotifyRecur = {
                     xns: Roo,
                     listeners : {
                         activate : function() {
-                            _this.panel = this;
+                         _this.panel = this;
                             if (_this.grid) {
-                                _this.grid.footer.onClick('first');
+                        //        _this.grid.footer.onClick('first');
                             }
                         }
                     },
@@ -62,7 +68,7 @@ Pman.Dialog.CoreNotifyRecur = {
                                 _this.grid = this; 
                                 //_this.dialog = Pman.Dialog.FILL_IN
                                 if (_this.panel.active) {
-                                   this.footer.onClick('first');
+                                //   this.footer.onClick('first');
                                 }
                             },
                             rowdblclick : function (_self, rowIndex, e)
@@ -86,17 +92,23 @@ Pman.Dialog.CoreNotifyRecur = {
                             listeners : {
                                 update : function (_self, record, operation)
                                 {
-                                    Roo.log(operation);
+                                    //Roo.log(operation);
                                     if (operation != 'commit') {
                                         return;
                                     }
+                                    var p = Roo.apply({}, record.data);
+                                    p.dtstart = record.data.dtstart.format('Y-m-d');
+                                    p.dtend = record.data.dtend.format('Y-m-d');    
+                                    
+                                    
                                     new Pman.Request({
                                         url : baseURL + '/Roo/Core_notify_recur',
                                         method :'POST',
-                                        params : record.data,
-                                        success : function()
+                                        params : p,
+                                        success : function(data)
                                         {
-                                            //??
+                                            //Roo.log(data);
+                                            record.set('id', data.data.id);
                                         },
                                         failure : function() {
                                             Roo.MessageBox.alert("Error", "There was a problem saving");
@@ -105,6 +117,19 @@ Pman.Dialog.CoreNotifyRecur = {
                                        
                                     
                                     
+                                },
+                                beforeload : function (_self, o)
+                                {
+                                    if (!_this.data) {
+                                        return false;
+                                    }
+                                    o.params =  Roo.apply(o.params || {}, {
+                                        person_id : _this.data.person_id,
+                                        onid : _this.data.onid,
+                                        ontable : _this.data.ontable,
+                                        method : _this.data.method
+                                    });
+                                        
                                 }
                             },
                             remoteSort : true,
@@ -172,14 +197,6 @@ Pman.Dialog.CoreNotifyRecur = {
                                 ]
                             }
                         },
-                        footer : {
-                            xtype: 'PagingToolbar',
-                            xns: Roo,
-                            pageSize : 25,
-                            displayInfo : true,
-                            displayMsg : "Displaying core_notify_recur{0} - {1} of {2}",
-                            emptyMsg : "No core_notify_recur found"
-                        },
                         toolbar : {
                             xtype: 'Toolbar',
                             xns: Roo,
@@ -194,12 +211,16 @@ Pman.Dialog.CoreNotifyRecur = {
                                             var r = grid.getDataSource().reader.newRow({
                                             // defaults..
                                                 person_id : _this.data.person_id,
-                                                dtstart : new Date(0),
+                                                dtstart : new Date(),
                                                 dtend : Date.parseDate('2050-01-01', 'Y-m-d'),
-                                                tz : 'Asia/Hong Kong',
+                                                tz : 'Asia/Hong_Kong',
                                                 onid : _this.data.onid,
                                                 ontable : _this.data.ontable,
-                                                method : _this.data.method,
+                                                method : _this.data.method, // default...
+                                                
+                                                method_id : _this.data.method_id, // default...
+                                                method_id_display_name : _this.data.method_id_display_name, // default...        
+                                                
                                                 last_event_id : 0,
                                                 freq_day_name : '',
                                                 freq_hour_name : '',
@@ -225,15 +246,35 @@ Pman.Dialog.CoreNotifyRecur = {
                                 {
                                     xtype: 'Button',
                                     xns: Roo.Toolbar,
-                                    text : "Delete",
-                                    cls : 'x-btn-text-icon',
-                                    icon : rootURL + '/Pman/templates/images/trash.gif',
                                     listeners : {
                                         click : function()
                                         {
-                                             Pman.genericDelete(_this, 'core_notify_recur'); 
+                                             _this.grid.stopEditing();
+                                             var s = _this.grid.selModel.getSelectedCell();
+                                             if (!s) {
+                                                Roo.MessageBox.alert("Error", "Select row");
+                                                return;
+                                            }
+                                            
+                                            new Pman.Request({
+                                                url : baseURL + '/Roo/core_notify_recur',
+                                                method : 'POST',
+                                                params : {
+                                                    _delete : _this.grid.ds.getAt(s[0]).data.id
+                                                }, 
+                                                success : function() {
+                                                    _this.grid.ds.load({});
+                                                },
+                                                failure : function() {
+                                                    Roo.MessageBox.alert("Error", "Deleting failed - try reloading");
+                                                }
+                                           });
+                                            
                                         }
-                                    }
+                                    },
+                                    cls : 'x-btn-text-icon',
+                                    text : "Delete",
+                                    icon : rootURL + '/Pman/templates/images/trash.gif'
                                 }
                             ]
                         },
@@ -241,24 +282,71 @@ Pman.Dialog.CoreNotifyRecur = {
                             {
                                 xtype: 'ColumnModel',
                                 xns: Roo.grid,
-                                dataIndex : 'dtstart',
-                                header : 'From',
-                                width : 75,
-                                renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
+                                dataIndex : 'method_id',
+                                header : 'Type',
+                                width : 120,
+                                renderer : function(v,x,r) {
+                                     return String.format('{0}', r.data.method_id_display_name); 
+                                },
                                 editor : {
                                     xtype: 'GridEditor',
                                     xns: Roo.grid,
                                     field : {
-                                        xtype: 'DateField',
-                                        xns: Roo.form
+                                        xtype: 'ComboBox',
+                                        xns: Roo.form,
+                                        allowBlank : 'false',
+                                        displayField : 'display_name',
+                                        editable : false,
+                                        emptyText : "Select Type",
+                                        fieldLabel : 'core_enum',
+                                        forceSelection : true,
+                                        hiddenName : 'method_id',
+                                        listWidth : 400,
+                                        loadingText : "Searching...",
+                                        name : 'method_id_display_name',
+                                        pageSize : 20,
+                                        qtip : "Select core_enum",
+                                        selectOnFocus : true,
+                                        tpl : '<div class="x-grid-cell-text x-btn button"><b>{display_name}</b> </div>',
+                                        triggerAction : 'all',
+                                        typeAhead : true,
+                                        valueField : 'id',
+                                        width : 300,
+                                        store : {
+                                            xtype: 'Store',
+                                            xns: Roo.data,
+                                            listeners : {
+                                                beforeload : function (_self, o){
+                                                    o.params = o.params || {};
+                                                    // set more here
+                                                    o.params.etype = 'core_notify_recur';
+                                                }
+                                            },
+                                            remoteSort : true,
+                                            sortInfo : { direction : 'ASC', field: 'id' },
+                                            proxy : {
+                                                xtype: 'HttpProxy',
+                                                xns: Roo.data,
+                                                method : 'GET',
+                                                url : baseURL + '/Roo/core_enum.php'
+                                            },
+                                            reader : {
+                                                xtype: 'JsonReader',
+                                                xns: Roo.data,
+                                                id : 'id',
+                                                root : 'data',
+                                                totalProperty : 'total',
+                                                fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
+                                            }
+                                        }
                                     }
                                 }
                             },
                             {
                                 xtype: 'ColumnModel',
                                 xns: Roo.grid,
-                                dataIndex : 'dtend',
-                                header : 'Until',
+                                dataIndex : 'dtstart',
+                                header : 'From',
                                 width : 75,
                                 renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
                                 editor : {
@@ -273,51 +361,16 @@ Pman.Dialog.CoreNotifyRecur = {
                             {
                                 xtype: 'ColumnModel',
                                 xns: Roo.grid,
-                                dataIndex : 'freq',
-                                header : 'Frequency',
-                                width : 70,
-                                renderer : function(v,x,r) { 
-                                
-                                    Roo.log(this);
-                                    var cm = _this.grid.colModel;
-                                    var ix = cm.findColumnIndex('freq');
-                                    var ce = cm.getCellEditor(ix)
-                                    var matches = ce.field.store.query('code',v);
-                                    if (!matches.length) {
-                                        return '';
-                                    }
-                                    return String.format('{0}', matches.first().data.title);
-                                 },
+                                dataIndex : 'dtend',
+                                header : 'Until',
+                                width : 75,
+                                renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); },
                                 editor : {
                                     xtype: 'GridEditor',
                                     xns: Roo.grid,
                                     field : {
-                                        xtype: 'ComboBox',
-                                        xns: Roo.form,
-                                        allowBlank : false,
-                                        displayField : 'title',
-                                        editable : false,
-                                        fieldLabel : 'Country',
-                                        hiddenName : 'freq',
-                                        listWidth : 200,
-                                        mode : 'local',
-                                        name : 'freq_name',
-                                        tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b> </div>',
-                                        triggerAction : 'all',
-                                        valueField : 'code',
-                                        width : 200,
-                                        store : {
-                                            xtype: 'SimpleStore',
-                                            xns: Roo.data,
-                                            data : [ 
-                                                [ 'HOURLY' , 'Hourly at' ] ,
-                                                   [ 'DAILY' , 'Daily at'] ,
-                                                    [ 'WEEKLY' , 'Weekly at'] ,
-                                                     [ 'Montly' , 'Montly at'] 
-                                            ],
-                                            fields : ['code', 'title'],
-                                            sortInfo : { field : 'title', direction: 'ASC' }
-                                        }
+                                        xtype: 'DateField',
+                                        xns: Roo.form
                                     }
                                 }
                             },
@@ -329,6 +382,30 @@ Pman.Dialog.CoreNotifyRecur = {
                                 width : 100,
                                 renderer : function(v,x,r) { 
                                     
+                                    if (v.length) {
+                                     
+                                        var cm = _this.grid.colModel;
+                                       
+                                        var ci = cm.getColumnByDataIndex(this.name);
+                                       
+                                         var tv = [];
+                                        var vals = Roo.decode(v);
+                                        Roo.each(vals, function(k) {
+                                            var r = this.findRecord(this.valueField, k);
+                                            if(r){
+                                                tv.push(r.data[this.displayField]);
+                                            }else if(this.valueNotFoundText !== undefined){
+                                                tv.push( this.valueNotFoundText );
+                                            }
+                                        },ci.editor.field);
+                                
+                                        r.data[this.name + '_name'] = tv.join(', ');
+                                        return String.format('{0}',tv.join(', '));
+                                
+                                        
+                                    
+                                    }
+                                    r.data[this.name + '_name'] = '';
                                     return String.format('{0}', r.data.freq_day_name || v); 
                                     
                                 },
@@ -373,6 +450,31 @@ Pman.Dialog.CoreNotifyRecur = {
                                 width : 250,
                                 renderer : function(v,x,r) { 
                                     
+                                 
+                                    if (v.length) {
+                                     
+                                        var cm = _this.grid.colModel;
+                                       
+                                        var ci = cm.getColumnByDataIndex(this.name);
+                                       
+                                         var tv = [];
+                                        var vals = Roo.decode(v);
+                                        Roo.each(vals, function(k) {
+                                            var r = this.findRecord(this.valueField, k);
+                                            if(r){
+                                                tv.push(r.data[this.displayField]);
+                                            }else if(this.valueNotFoundText !== undefined){
+                                                tv.push( this.valueNotFoundText );
+                                            }
+                                        },ci.editor.field);
+                                
+                                         r.data[this.name + '_name'] = tv.join(', ');
+                                        return String.format('{0}',tv.join(', '));
+                                
+                                        
+                                    
+                                    }
+                                        r.data[this.name + '_name'] = '';
                                     return String.format('{0}', r.data.freq_hour_name || v); 
                                     
                                 },
@@ -404,7 +506,7 @@ Pman.Dialog.CoreNotifyRecur = {
                                                     var dh = i < 13 ? i : i-12;
                                                     
                                                     ret.push([ h+':00', dh+':00' + mer ]);
-                                                    ret.push([ h+':00', dh+':30' + mer ]);        
+                                                    ret.push([ h+':30', dh+':30' + mer ]);        
                                                 }
                                                 return ret;
                                             })(),
@@ -424,83 +526,52 @@ Pman.Dialog.CoreNotifyRecur = {
                                 editor : {
                                     xtype: 'GridEditor',
                                     xns: Roo.grid,
-                                    items : [
-                                        {
-                                            xtype: 'ComboBox',
-                                            xns: Roo.form,
-                                            allowBlank : 'false',
-                                            displayField : 'tz',
-                                            editable : 'false',
-                                            emptyText : "Select core_enum",
-                                            fieldLabel : 'core_enum',
-                                            forceSelection : true,
-                                            hiddenName : 'tz',
-                                            listWidth : 400,
-                                            loadingText : "Searching...",
-                                            minChars : 2,
-                                            name : 'tz_name',
-                                            pageSize : 20,
-                                            qtip : "Select timezone",
-                                            selectOnFocus : true,
-                                            tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
-                                            triggerAction : 'all',
-                                            typeAhead : true,
-                                            valueField : 'id',
-                                            width : 300,
-                                            store : {
-                                                xtype: 'Store',
-                                                xns: Roo.data,
-                                                remoteSort : true,
-                                                sortInfo : { direction : 'ASC', field: 'id' },
-                                                listeners : {
-                                                    beforeload : function (_self, o){
-                                                        o.params = o.params || {};
-                                                        // set more here
-                                                    }
-                                                },
-                                                proxy : {
-                                                    xtype: 'HttpProxy',
-                                                    xns: Roo.data,
-                                                    method : 'GET',
-                                                    url : baseURL + '/Roo/core_enum.php'
-                                                },
-                                                reader : {
-                                                    xtype: 'JsonReader',
-                                                    xns: Roo.data,
-                                                    id : 'id',
-                                                    root : 'data',
-                                                    totalProperty : 'total',
-                                                    fields : [{"name":"id","type":"int"},{"name":"etype","type":"string"}]
-                                                }
-                                            }
-                                        }
-                                    ],
                                     field : {
                                         xtype: 'ComboBox',
                                         xns: Roo.form,
-                                        allowBlank : false,
-                                        displayField : 'title',
-                                        editable : false,
-                                        fieldLabel : 'Country',
-                                        hiddenName : 'freq',
-                                        listWidth : 200,
-                                        mode : 'local',
-                                        name : 'freq_name',
-                                        tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b> </div>',
+                                        allowBlank : 'false',
+                                        displayField : 'tz',
+                                        editable : true,
+                                        emptyText : "Select timezone",
+                                        fieldLabel : 'core_enum',
+                                        forceSelection : true,
+                                        listWidth : 400,
+                                        loadingText : "Searching...",
+                                        minChars : 2,
+                                        name : 'tz',
+                                        pageSize : 999,
+                                        qtip : "Select timezone",
+                                        queryParam : 'q',
+                                        selectOnFocus : true,
+                                        tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
                                         triggerAction : 'all',
-                                        valueField : 'code',
-                                        width : 200,
+                                        typeAhead : true,
+                                        width : 300,
                                         store : {
-                                            xtype: 'SimpleStore',
+                                            xtype: 'Store',
                                             xns: Roo.data,
-                                            data : [ 
-                                                [ 'HOURLY' , 'Hourly at' ] ,
-                                                   [ 'DAILY' , 'Daily at'] ,
-                                                    [ 'WEEKLY' , 'Weekly at'] ,
-                                                     [ 'Montly' , 'Montly at'] 
-                                            ],
-                                            fields : ['code', 'title'],
-                                            sortInfo : { field : 'title', direction: 'ASC' }
+                                            listeners : {
+                                                beforeload : function (_self, o){
+                                                    o.params = o.params || {};
+                                                    // set more here
+                                                }
+                                            },
+                                            remoteSort : true,
+                                            sortInfo : { direction : 'ASC', field: 'tz' },
+                                            proxy : {
+                                                xtype: 'HttpProxy',
+                                                xns: Roo.data,
+                                                method : 'GET',
+                                                url : baseURL + '/Core/I18n/Timezone.php'
+                                            },
+                                            reader : {
+                                                xtype: 'JsonReader',
+                                                xns: Roo.data,
+                                                id : 'id',
+                                                root : 'data',
+                                                totalProperty : 'total',
+                                                fields : [{"name":"tz","type":"string"}]
+                                            }
                                         }
                                     }
                                 }
@@ -508,10 +579,10 @@ Pman.Dialog.CoreNotifyRecur = {
                             {
                                 xtype: 'ColumnModel',
                                 xns: Roo.grid,
-                                header : 'Last event',
-                                width : 75,
                                 dataIndex : 'last_event_id',
-                                renderer : function(v) { return String.format('{0}', v); }
+                                header : 'Last Sent',
+                                width : 75,
+                                renderer : function(v) { return String.format('{0}', v ? v : 'never'); }
                             }
                         ]
                     }
@@ -527,6 +598,12 @@ Pman.Dialog.CoreNotifyRecur = {
                 {
                     xtype: 'Button',
                     xns: Roo,
+                    listeners : {
+                        click : function (_self, e)
+                        {
+                            _this.dialog.hide();
+                        }
+                    },
                     text : "Done"
                 }
             ]