Pman.Dialog.CoreNotifyRecur.bjs
[Pman.Core] / Pman.Dialog.CoreNotifyRecur.js
index 22034fa..9e5dcd1 100644 (file)
@@ -36,7 +36,7 @@ Pman.Dialog.CoreNotifyRecur = {
                     _this.grid.ds.load({});
                 }
             },
-            height : 500,
+            height : 550,
             modal : true,
             resizable : false,
             title : "Modify Recurrent Notifications",
@@ -92,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");
@@ -205,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 : '',
@@ -239,8 +249,27 @@ Pman.Dialog.CoreNotifyRecur = {
                                     listeners : {
                                         click : function()
                                         {
-                                             var s = _this.grid.getSelectionModel().getSelected();
-                                             Roo.log(s);
+                                             _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',
@@ -250,6 +279,70 @@ Pman.Dialog.CoreNotifyRecur = {
                             ]
                         },
                         colModel : [
+                            {
+                                xtype: 'ColumnModel',
+                                xns: Roo.grid,
+                                dataIndex : 'method_id',
+                                header : 'Type',
+                                width : 75,
+                                renderer : function(v,x,r) {
+                                     return String.format('{0}', r.data.method_id_display_name); 
+                                },
+                                editor : {
+                                    xtype: 'GridEditor',
+                                    xns: Roo.grid,
+                                    field : {
+                                        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...",
+                                        minChars : 2,
+                                        name : 'method_id_display_name',
+                                        pageSize : 20,
+                                        qtip : "Select core_enum",
+                                        queryParam : '',
+                                        selectOnFocus : true,
+                                        tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</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"}]
+                                            }
+                                        }
+                                    }
+                                }
+                            },
                             {
                                 xtype: 'ColumnModel',
                                 xns: Roo.grid,
@@ -414,7 +507,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;
                                             })(),
@@ -443,11 +536,10 @@ Pman.Dialog.CoreNotifyRecur = {
                                         emptyText : "Select timezone",
                                         fieldLabel : 'core_enum',
                                         forceSelection : true,
-                                        hiddenName : 'tz',
                                         listWidth : 400,
                                         loadingText : "Searching...",
                                         minChars : 2,
-                                        name : 'tz_name',
+                                        name : 'tz',
                                         pageSize : 999,
                                         qtip : "Select timezone",
                                         queryParam : 'q',
@@ -455,7 +547,6 @@ Pman.Dialog.CoreNotifyRecur = {
                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{tz}</b> </div>',
                                         triggerAction : 'all',
                                         typeAhead : true,
-                                        valueField : 'tz',
                                         width : 300,
                                         store : {
                                             xtype: 'Store',
@@ -489,10 +580,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'); }
                             }
                         ]
                     }