Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtupleMetric.js
index 43003c8..ac138f6 100644 (file)
@@ -42,23 +42,13 @@ Pman.Tab.XtupleMetric = new Roo.XComponent({
                            this.footer.onClick('first');
                         }
                     },
-                    beforeedit : function (e)
+                    afteredit : function (e)
                     {
-                        var r = e.record.data.poitem_qty_received * 1;
-                        
-                        if(r > 0){
-                            Roo.MessageBox.alert("Error", "This item has been receipted");
-                            return false;
-                        }
-                        
-                        var status = _this.form.findField('pohead_status').getValue();
-                        
-                        if(status == 'C'){
-                            Roo.MessageBox.alert("Error", "This PO has been closed");
+                        if(e.originalValue == e.value || !e.value.length){
                             return false;
                         }
                         
-                        
+                        e.record.commit();
                     }
                 },
                 autoExpandColumn : 'metric_value',
@@ -78,6 +68,26 @@ Pman.Tab.XtupleMetric = new Roo.XComponent({
                             }
                             
                             o.params['search[name]'] = s;
+                        },
+                        update : function (_self, record, operation)
+                        {
+                            if (operation != Roo.data.Record.COMMIT) {
+                                return;
+                            }
+                        
+                            if (!record.data.metric_name.length || !record.data.metric_value.length) {
+                                return;
+                            }
+                            
+                            new Pman.Request({
+                                url : baseURL + '/Roo/Metric',
+                                method : 'POST',
+                                params : record.data,
+                                success : function(res) {
+                                    _this.grid.footer.onClick('refresh');
+                                }
+                            });
+                            
                         }
                     },
                     remoteSort : true,
@@ -151,11 +161,77 @@ Pman.Tab.XtupleMetric = new Roo.XComponent({
                             listeners : {
                                 click : function (_self, e)
                                 {
-                                    _this.searchBox.setValue('');\r
+                                    _this.searchBox.setValue('');
+                                    _this.grid.footer.onClick('first');\r
                                 }
                             },
                             cls : 'x-btn-icon',
                             icon : rootURL + '/Pman/templates/images/edit-clear.gif'
+                        },
+                        {
+                            xtype: 'Fill',
+                            xns: Roo.Toolbar
+                        },
+                        {
+                            xtype: 'Button',
+                            xns: Roo.Toolbar,
+                            listeners : {
+                                click : function()
+                                {
+                                    
+                                    var nr = _this.grid.ds.reader.newRow({
+                                        metric_id : 0,
+                                        metric_name : '',
+                                        metric_value : '',
+                                        metric_module : ''
+                                    });
+                                    
+                                    _this.grid.stopEditing();
+                                    _this.grid.ds.insert(0, nr); 
+                                    _this.grid.startEditing(0, 0);
+                                }
+                            },
+                            cls : 'x-btn-text-icon',
+                            text : "Add",
+                            icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
+                        },
+                        {
+                            xtype: 'Button',
+                            xns: Roo.Toolbar,
+                            listeners : {
+                                click : function ()
+                                {   
+                                    var cs = _this.grid.getSelectionModel().getSelectedCell();
+                                    
+                                    if (!cs) {
+                                        Roo.MessageBox.alert("Error", "Select a cell");
+                                        return;
+                                    }
+                                    _this.grid.stopEditing();
+                                 
+                                    var r = _this.grid.ds.getAt(cs[0]);
+                                    
+                                    Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete this metric?", function (v){
+                                        if (v != 'yes') {
+                                            return;
+                                        }
+                                        
+                                        new Pman.Request({
+                                            url : baseURL + '/Roo/Metric',
+                                            method : 'POST',
+                                            params : {
+                                                _delete : r.data.id
+                                            },
+                                            success : function(res) {
+                                                _this.grid.footer.onClick('refresh');
+                                            }
+                                        });
+                                    });
+                                }
+                            },
+                            cls : 'x-btn-text-icon',
+                            text : "Remove",
+                            icon : rootURL + '/Pman/templates/images/trash.gif'
                         }
                     ]
                 },
@@ -167,21 +243,22 @@ Pman.Tab.XtupleMetric = new Roo.XComponent({
                     pageSize : 50
                 },
                 colModel : [
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        dataIndex : 'metric_id',
-                        header : 'ID',
-                        width : 75,
-                        renderer : function(v) { return String.format('{0}', v); }
-                    },
                     {
                         xtype: 'ColumnModel',
                         xns: Roo.grid,
                         dataIndex : 'metric_name',
                         header : 'Name',
-                        width : 150,
-                        renderer : function(v) { return String.format('{0}', v); }
+                        width : 250,
+                        renderer : function(v) { return String.format('{0}', v); },
+                        editor : {
+                            xtype: 'GridEditor',
+                            xns: Roo.grid,
+                            field : {
+                                xtype: 'TextField',
+                                xns: Roo.form,
+                                allowBlank : false
+                            }
+                        }
                     },
                     {
                         xtype: 'ColumnModel',
@@ -189,7 +266,16 @@ Pman.Tab.XtupleMetric = new Roo.XComponent({
                         dataIndex : 'metric_value',
                         header : 'Value',
                         width : 150,
-                        renderer : function(v) { return String.format('{0}', v); }
+                        renderer : function(v) { return String.format('{0}', v); },
+                        editor : {
+                            xtype: 'GridEditor',
+                            xns: Roo.grid,
+                            field : {
+                                xtype: 'TextField',
+                                xns: Roo.form,
+                                allowBlank : false
+                            }
+                        }
                     },
                     {
                         xtype: 'ColumnModel',
@@ -197,7 +283,16 @@ Pman.Tab.XtupleMetric = new Roo.XComponent({
                         dataIndex : 'metric_module',
                         header : 'Module',
                         width : 100,
-                        renderer : function(v) { return String.format('{0}', v); }
+                        renderer : function(v) { return String.format('{0}', v); },
+                        editor : {
+                            xtype: 'GridEditor',
+                            xns: Roo.grid,
+                            field : {
+                                xtype: 'TextField',
+                                xns: Roo.form,
+                                allowBlank : false
+                            }
+                        }
                     }
                 ]
             }