DataObjects/Core_person_signup.php
[Pman.Core] / Pman.Tab.CoreOAuthClient.js
index 7ea8666..92d36bc 100644 (file)
@@ -4,9 +4,9 @@
 
 Pman.Tab.CoreOAuthClient = new Roo.XComponent({
     part     :  ["Core","OAuthClient"],
-    order    : '001-Pman.Tab.CoreOAuthClient',
+    order    : '900-Pman.Tab.CoreOAuthClient',
     region   : 'center',
-    parent   : false,
+    parent   : 'Pman.Tab.Admin',
     name     : "unnamed module",
     disabled : false, 
     permname : '', 
@@ -15,409 +15,264 @@ Pman.Tab.CoreOAuthClient = new Roo.XComponent({
         var _this = this;
         var MODULE = this;
         return {
-            xtype: 'GridPanel',
+            xtype: 'NestedLayoutPanel',
             xns: Roo,
-            listeners : {
-                activate : function() {
-                    _this.panel = this;
-                    
-                    
-                    var pid = _this.form.findField('pohead_id').getValue() * 1;
-                    if (pid < 1) {
-                        Roo.MessageBox.alert("Save First", "Please save the purchase order first, before adding items");
-                        _this.dialog.layout.getRegion('center').showPanel(0);
-                        return;
-                    }
-                    
-                    if (_this.grid) {
-                        _this.grid.footer.onClick('first');
-                    }
-                },
-                deactivate : function (_self)
-                {
-                     if(_this.grid){
-                        var ar = [];
-                
-                        _this.grid.ds.each(function(r) {
-                            ar.push({
-                                poitem_id : r.data.poitem_id,
-                                poitem_itemsite_id : r.data.poitem_itemsite_id,
-                                poitem_unitprice : r.data.poitem_unitprice,
-                                poitem_qty_ordered : r.data.poitem_qty_ordered
-                            });
-                                
-                        });
-                        
-                        _this.form.findField('items').setValue(JSON.stringify(ar));
-                    }
-                    _this.dontClose = true;
-                    _this.form.doAction("submit");
-                
-                }
-            },
-            background : true,
-            fitContainer : true,
-            fitToframe : true,
             region : 'center',
-            tableName : 'poitem',
-            title : "Order Items",
-            grid : {
-                xtype: 'EditorGrid',
-                xns: Roo.grid,
-                listeners : {
-                    render : function() 
+            title : "Oauth2 Clients",
+            layout : {
+                xtype: 'BorderLayout',
+                xns: Roo,
+                items : [
                     {
-                        _this.grid = this; 
-                        //_this.dialog = Pman.Dialog.FILL_IN
-                        if (_this.panel.active) {
-                           this.footer.onClick('first');
-                        }
-                    },
-                    beforeedit : 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");
-                            return false;
-                        }
-                        
-                        
-                    }
-                },
-                autoExpandColumn : 'item_descrip1',
-                clicksToEdit : 1,
-                loadMask : true,
-                dataSource : {
-                    xtype: 'Store',
-                    xns: Roo.data,
-                    listeners : {
-                        beforeload : function (_self, o){
-                            o.params = o.params || {};
-                            var hid = _this.form.findField('pohead_id').getValue();
-                            
-                            if(!hid.length){
-                                return false;
+                        xtype: 'GridPanel',
+                        xns: Roo,
+                        listeners : {
+                            activate : function() {
+                                _this.panel = this;
+                                
+                                if (_this.grid) {
+                                    _this.grid.footer.onClick('first');
+                                }
                             }
-                            
-                            o.params.poitem_pohead_id = hid;
-                            o.params._with_item = 1;
-                            o.params._roo_office = _this.data.office ? _this.data.office : baseURL.split('/').pop().substr(0,2);
-                        
                         },
-                        load : function (_self, records, options)
-                        {
-                            _this.grid.footer.updateSummary();
-                        }
-                    },
-                    remoteSort : true,
-                    sortInfo : { field : 'poitem_linenumber', direction: 'ASC' },
-                    proxy : {
-                        xtype: 'HttpProxy',
-                        xns: Roo.data,
-                        method : 'GET',
-                        timeout : 90000,
-                        url : baseURL + '/Xtuple/Roo/Poitem.php'
-                    },
-                    reader : {
-                        xtype: 'JsonReader',
-                        xns: Roo.data,
-                        id : 'poitem_id',
-                        root : 'data',
-                        totalProperty : 'total',
-                        fields : [
-                            {
-                                'name': 'poitem_id',
-                                'type': 'int'
-                            }
-                        ]
-                    }
-                },
-                toolbar : {
-                    xtype: 'Toolbar',
-                    xns: Roo,
-                    items : [
-                        {
-                            xtype: 'Button',
-                            xns: Roo.Toolbar,
+                        background : true,
+                        fitContainer : true,
+                        fitToframe : true,
+                        region : 'center',
+                        tableName : 'core_oauth_clients',
+                        title : "Oauth2 Clients",
+                        grid : {
+                            xtype: 'EditorGrid',
+                            xns: Roo.grid,
                             listeners : {
-                                click : function()
+                                render : function() 
                                 {
-                                    var status = _this.form.findField('pohead_status').getValue();
-                                    
-                                    if(status == 'C'){
-                                        Roo.MessageBox.alert("Error", "This PO has been closed");
-                                        return;
+                                    _this.grid = this; 
+                                    if (_this.panel.active) {
+                                       this.footer.onClick('first');
                                     }
-                                    
-                                    var ct  =    _this.grid.ds.getCount();
-                                    
-                                    var last = ct ? _this.grid.ds.getAt(ct-1).data.poitem_linenumber * 1 + 1 : 1;
-                                    
-                                    var dt = _this.form.findField('pohead_orderdate').getValue();
-                                    
-                                    var nr = _this.grid.ds.reader.newRow({
-                                        poitem_id : 0,
-                                        poitem_linenumber : last,
-                                        item_number : '',
-                                        item_descrip1 : '',
-                                        poitem_duedate : dt,
-                                        poitem_qty_ordered : 1,
-                                        poitem_unitprice : 0
-                                    });
-                                    
-                                    _this.grid.stopEditing();
-                                    _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
-                                    _this.grid.startEditing(_this.grid.ds.getCount()-1, 1);
-                                }
-                            },
-                            cls : 'x-btn-text-icon',
-                            text : "Add",
-                            icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
-                        },
-                        {
-                            xtype: 'Button',
-                            xns: Roo.Toolbar,
-                            listeners : {
-                                click : function ()
+                                },
+                                afteredit : function (e)
                                 {
-                                    var status = _this.form.findField('pohead_status').getValue();
-                                    
-                                    if(status == 'C'){
-                                        Roo.MessageBox.alert("Error", "This PO has been closed");
-                                        return;
+                                    if(e.originalValue == e.value || !e.value.length){
+                                        return false;
                                     }
                                     
-                                    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]);
-                                    
-                                    if(r.data.poitem_qty_received * 1 > 0){
-                                        Roo.MessageBox.alert("Error", "This item has been receipted");
-                                        return;
-                                    }
-                                    
-                                    
-                                    _this.grid.ds.remove(r);
-                                   
+                                    Roo.log('commit it');
+                                    e.record.commit();
                                 }
                             },
-                            cls : 'x-btn-text-icon',
-                            text : "Remove",
-                            icon : rootURL + '/Pman/templates/images/trash.gif'
-                        }
-                    ]
-                },
-                footer : {
-                    xtype: 'PagingToolbar',
-                    xns: Roo,
-                    displayInfo : true,
-                    emptyMsg : "No Item found",
-                    pageSize : 100,
-                    updateSummary : function() {
-                    \r
-                        var f = this;\r
-                        new Pman.Request({\r
-                            url : baseURL + '/Xtuple/Roo/Poitem',\r
-                            method : 'GET',\r
-                            params : {
-                                _roo_office : _this.data.office ? _this.data.office : baseURL.split('/').pop().substr(0,2),\r
-                                _totals : 1,\r
-                                poitem_pohead_id : _this.form.findField('pohead_id').getValue()\r
-                            },\r
-                            success : function(d) {
-                                Roo.log(d);\r
-                                f.displayEl.update(String.format(\r
-                                    "{0} items | Total : {1} {2}",\r
-                                    d.data[0].count_item,\r
-                                    _this.form.findField('pohead_curr_id').el.dom.value,\r
-                                    d.data[0].totals\r
-                                ));\r
-                                    \r
-                            }\r
-                        });\r
-                    
-                    }
-                },
-                colModel : [
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        align : 'right',
-                        dataIndex : 'poitem_linenumber',
-                        header : 'Line#',
-                        width : 50,
-                        renderer : function(v) { return String.format('{0}', v); }
-                    },
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        dataIndex : 'item_number',
-                        header : 'Item code',
-                        width : 100,
-                        renderer : function(v) { return String.format('{0}', v); },
-                        editor : {
-                            xtype: 'GridEditor',
-                            xns: Roo.grid,
-                            field : {
-                                xtype: 'ComboBox',
-                                xns: Roo.form,
+                            autoExpandColumn : 'redirect_uri',
+                            clicksToEdit : 1,
+                            loadMask : true,
+                            dataSource : {
+                                xtype: 'Store',
+                                xns: Roo.data,
                                 listeners : {
-                                    beforeselect : function (combo, record, index)
+                                    beforeload : function (_self, o){
+                                        o.params = o.params || {};
+                                    
+                                    },
+                                    update : function (_self, record, operation)
                                     {
-                                      var ar = _this.grid.activeEditor.record;
-                                      
-                                      (function() { 
-                                          ar.set('item_descrip1', record.data.itemsite_item_id_item_descrip1);
-                                          ar.set('poitem_itemsite_id', record.data.itemsite_id);
-                                      }).defer(100);
-                                      
+                                        if (operation != Roo.data.Record.COMMIT) {
+                                            return;
+                                        }
+                                    
+                                        if (!record.data.client_id.length || !record.data.client_secret.length) {
+                                            return;
+                                        }
+                                        
+                                        new Pman.Request({
+                                            url : baseURL + '/Roo/Core_oauth_clients',
+                                            method : 'POST',
+                                            params : {
+                                                id : record.data.id,
+                                                client_id : record.data.client_id,
+                                                client_secret : record.data.client_secret,
+                                                redirect_uri : record.data.redirect_uri
+                                            },
+                                            success : function(res) {
+                                                _this.grid.footer.onClick('refresh');
+                                            }
+                                        });
+                                        
                                     }
                                 },
-                                allowBlank : false,
-                                displayField : 'itemsite_item_id_item_number',
-                                editable : true,
-                                emptyText : "Select item",
-                                forceSelection : true,
-                                hiddenName : 'itemsite_item_id_item_number',
-                                listWidth : 400,
-                                loadingText : "Searching...",
-                                minChars : 2,
-                                name : 'item_number',
-                                pageSize : 20,
-                                qtip : "Select item",
-                                queryParam : 'query[number]',
-                                selectOnFocus : true,
-                                tpl : '<div class="x-grid-cell-text x-btn button"><b>{itemsite_item_id_item_number}</b> - {itemsite_item_id_item_descrip1} </div>',
-                                triggerAction : 'all',
-                                typeAhead : false,
-                                valueField : 'item_number',
-                                store : {
-                                    xtype: 'Store',
+                                remoteSort : true,
+                                sortInfo : { field : 'client_id', direction: 'ASC' },
+                                proxy : {
+                                    xtype: 'HttpProxy',
                                     xns: Roo.data,
-                                    listeners : {
-                                        beforeload : function (_self, o){
-                                            o.params = o.params || {}; 
-                                            o.params.itemsite_posupply = 1;
+                                    method : 'GET',
+                                    url : baseURL + '/Roo/Core_oauth_clients'
+                                },
+                                reader : {
+                                    xtype: 'JsonReader',
+                                    xns: Roo.data,
+                                    id : 'id',
+                                    root : 'data',
+                                    totalProperty : 'total',
+                                    fields : [
+                                        {
+                                            'name': 'id',
+                                            'type': 'int'
+                                        },
+                                        {
+                                            'name': 'client_id',
+                                            'type': 'string'
+                                        },
+                                        {
+                                            'name': 'client_secret',
+                                            'type': 'string'
+                                        },
+                                        {
+                                            'name': 'redirect_uri',
+                                            'type': 'string'
                                         }
+                                    ]
+                                }
+                            },
+                            toolbar : {
+                                xtype: 'Toolbar',
+                                xns: Roo,
+                                items : [
+                                    {
+                                        xtype: 'Button',
+                                        xns: Roo.Toolbar,
+                                        listeners : {
+                                            click : function()
+                                            {
+                                                
+                                                var nr = _this.grid.ds.reader.newRow({
+                                                    id : 0,
+                                                    client_id : '',
+                                                    client_secret : '',
+                                                    redirect_uri : ''
+                                                });
+                                                
+                                                _this.grid.stopEditing();
+                                                _this.grid.ds.insert(_this.grid.ds.getCount(), nr); 
+                                                _this.grid.startEditing(_this.grid.ds.getCount()-1, 0);
+                                            }
+                                        },
+                                        cls : 'x-btn-text-icon',
+                                        text : "Add",
+                                        icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
                                     },
-                                    remoteSort : true,
-                                    sortInfo : { direction : 'ASC', field: 'item_number' },
-                                    proxy : {
-                                        xtype: 'HttpProxy',
-                                        xns: Roo.data,
-                                        method : 'GET',
-                                        url : baseURL + '/Roo/itemsite.php'
+                                    {
+                                        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 client?", function (v){
+                                                    if (v != 'yes') {
+                                                        return;
+                                                    }
+                                                    
+                                                    new Pman.Request({
+                                                        url : baseURL + '/Roo/Core_oauth_clients',
+                                                        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'
+                                    }
+                                ]
+                            },
+                            footer : {
+                                xtype: 'PagingToolbar',
+                                xns: Roo,
+                                displayInfo : true,
+                                emptyMsg : "No Clients found",
+                                pageSize : 25
+                            },
+                            colModel : [
+                                {
+                                    xtype: 'ColumnModel',
+                                    xns: Roo.grid,
+                                    dataIndex : 'client_id',
+                                    header : 'Client ID',
+                                    width : 150,
+                                    renderer : function(v) { 
+                                        return String.format('{0}', v ? v : '');
+                                    },
+                                    editor : {
+                                        xtype: 'GridEditor',
+                                        xns: Roo.grid,
+                                        field : {
+                                            xtype: 'TextField',
+                                            xns: Roo.form,
+                                            allowBlank : false
+                                        }
+                                    }
+                                },
+                                {
+                                    xtype: 'ColumnModel',
+                                    xns: Roo.grid,
+                                    dataIndex : 'client_secret',
+                                    header : 'Client Secret',
+                                    width : 150,
+                                    renderer : function(v) { 
+                                        return String.format('{0}', v ? v : '');
                                     },
-                                    reader : {
-                                        xtype: 'JsonReader',
-                                        xns: Roo.data,
-                                        id : 'itemsite_id',
-                                        root : 'data',
-                                        totalProperty : 'total',
-                                        fields : [{"name":"item_id","type":"int"},"item_number"]
+                                    editor : {
+                                        xtype: 'GridEditor',
+                                        xns: Roo.grid,
+                                        field : {
+                                            xtype: 'TextField',
+                                            xns: Roo.form,
+                                            allowBlank : false
+                                        }
+                                    }
+                                },
+                                {
+                                    xtype: 'ColumnModel',
+                                    xns: Roo.grid,
+                                    dataIndex : 'redirect_uri',
+                                    header : 'Redirect URI',
+                                    width : 150,
+                                    renderer : function(v) { 
+                                        return String.format('{0}', v ? v : '');
+                                    },
+                                    editor : {
+                                        xtype: 'GridEditor',
+                                        xns: Roo.grid,
+                                        field : {
+                                            xtype: 'TextField',
+                                            xns: Roo.form
+                                        }
                                     }
                                 }
-                            }
-                        }
-                    },
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        dataIndex : 'item_descrip1',
-                        header : 'Item description',
-                        width : 150,
-                        renderer : function(v) { return String.format('{0}', v); }
-                    },
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        dataIndex : 'poitem_duedate',
-                        header : 'Due date',
-                        width : 100,
-                        renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
-                    },
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        align : 'right',
-                        dataIndex : 'poitem_qty_ordered',
-                        header : 'Ordered',
-                        width : 75,
-                        renderer : function(v) { return String.format('{0}', v); },
-                        editor : {
-                            xtype: 'GridEditor',
-                            xns: Roo.grid,
-                            field : {
-                                xtype: 'NumberField',
-                                xns: Roo.form,
-                                allowDecimals : false,
-                                decimalPrecision : 0,
-                                minValue : 1,
-                                style : 'text-align:right'
-                            }
-                        }
-                    },
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        align : 'right',
-                        dataIndex : 'poitem_qty_received',
-                        header : 'Received',
-                        width : 75,
-                        renderer : function(v,x,r) { 
-                            return String.format(
-                                r.data.poitem_qty_ordered != (v-r.data.poitem_qty_returned) ? '<span style="color:red">{0}</span>':  '{0}',
-                                 v - r.data.poitem_qty_returned);
-                        }
-                    },
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        align : 'right',
-                        dataIndex : 'poitem_qty_vouchered',
-                        header : 'Vouchered',
-                        width : 65,
-                        renderer : function(v,x,r) { 
-                            return String.format(
-                                r.data.poitem_qty_ordered != v ? '<span style="color:red">{0}</span>':  '{0}',
-                                 v);
-                        }
-                    },
-                    {
-                        xtype: 'ColumnModel',
-                        xns: Roo.grid,
-                        align : 'right',
-                        dataIndex : 'poitem_unitprice',
-                        header : 'Unit price',
-                        width : 100,
-                        renderer : function(v) { return String.format('{0}', (v || v == 0) ? parseFloat(v).toFixed(3) : ''); },
-                        editor : {
-                            xtype: 'GridEditor',
-                            xns: Roo.grid,
-                            field : {
-                                xtype: 'NumberField',
-                                xns: Roo.form,
-                                allowBlank : false,
-                                allowDecimals : false,
-                                decimalPrecision : 0,
-                                minValue : 1,
-                                style : 'text-align:right'
-                            }
+                            ]
                         }
                     }
-                ]
+                ],
+                center : {
+                    xtype: 'LayoutRegion',
+                    xns: Roo,
+                    autoScroll : false,
+                    split : true
+                }
             }
         };
     }