Pman.Dialog.BuilderAdd.bjs
[Pman.Builder] / Pman.Tab.BuilderDatabase.js
index ba43021..992c0ff 100644 (file)
@@ -2,36 +2,19 @@
 
 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
 
-
-
-// register the module first
-Pman.on('beforeload', function()
-{
-    Pman.register({
-        part :  ["Builder","Database"],
-        modKey : '999-Pman.Tab.BuilderDatabase',
-        module : Pman.Tab.BuilderDatabase,
-        region : 'center',
-        parent : Pman.Tab.Builder,
-        name : "Pman.Tab.BuilderDatabase",
-        disabled : false, 
-        permname: '' 
-    });
-});
-
-Pman.Tab.BuilderDatabase = new Roo.util.Observable({
-
-    panel : false,
-    disabled : false,
-    parentLayout:  false,
-
-    add : function(parentLayout, region)
+Pman.Tab.BuilderDatabase = new Roo.XComponent({
+    part     :  ["Builder","Database"],
+    order    : '999-Pman.Tab.BuilderDatabase',
+    region   : 'center',
+    parent   : 'Pman.Tab.Builder',
+    name     : "Pman.Tab.BuilderDatabase",
+    disabled : false, 
+    permname : '', 
+    _tree : function()
     {
-
         var _this = this;
-        this.parentLayout = parentLayout;
-
-        this.panel = parentLayout.addxtype({
+        var MODULE = this;
+        return {
             xtype: 'NestedLayoutPanel',
             xns: Roo,
             listeners : {
@@ -101,6 +84,41 @@ Pman.Tab.BuilderDatabase = new Roo.util.Observable({
                                                     }
                                                 },
                                                 text : "Sync Tables"
+                                            },
+                                            {
+                                                xtype: 'Separator',
+                                                xns: Roo.menu
+                                            },
+                                            {
+                                                xtype: 'Item',
+                                                xns: Roo.menu,
+                                                listeners : {
+                                                    click : function (_self, e)
+                                                    {
+                                                    /*
+                                                        var node = _this.treepanel.tree.getSelectionModel().getSelectedNode();   
+                                                        
+                                                        if(!node){
+                                                            Roo.MessageBox.alert('Error', 'Please select a table');
+                                                            return;
+                                                        } 
+                                                        
+                                                        Roo.log(node.attributes.name);
+                                                        */
+                                                        new Pman.Download({
+                                                            url : baseURL + '/Roo/Builder_tables.php',
+                                                            timeout : 900000,
+                                                            params : {
+                                                                _dumpDatabase : 1
+                                                            },
+                                                            method : 'GET',
+                                                            success : function() {
+                                                            
+                                                            }
+                                                        });
+                                                    }
+                                                },
+                                                text : "Export Data"
                                             }
                                         ]
                                     }
@@ -116,6 +134,44 @@ Pman.Tab.BuilderDatabase = new Roo.util.Observable({
                                     if (!_this.panel.active) {
                                         return false;
                                     }
+                                },
+                                contextmenu : function (node, e)
+                                {
+                                    if (!node.expanded || node.leaf) {
+                                        return;
+                                    }
+                                
+                                   _this.treepanel.menu = Roo.factory(_this.treepanel.menu);
+                                   _this.treepanel.menu.show(node.ui.anchor,'tr');
+                                   _this.cxnode = node;
+                                },
+                                beforenodedrop : function (dropEvent)
+                                {
+                                    Roo.log(dropEvent);
+                                    var node = dropEvent.dropNode;
+                                    var targ = dropEvent.target;
+                                    var parent = dropEvent.target;
+                                    switch(dropEvent.point) {
+                                        case 'below': 
+                                         case 'above':  
+                                            parent = dropEvent.target.parentNode;
+                                            break;
+                                        default:
+                                            break;
+                                    }
+                                    // technically you should not be able to drag tables into other modules..
+                                    if (parent.attributes.id < 1) {
+                                        dropEvent.cancel = 1;
+                                    }
+                                    new Pman.Request({
+                                        url : baseURL + '/Roo/Builder_tables',
+                                        params : {
+                                            id : node.attributes.id,
+                                            parent_id : parent.attributes.id
+                                        }
+                                    });
+                                    
+                                    
                                 }
                             },
                             containerScroll : true,
@@ -150,15 +206,15 @@ Pman.Tab.BuilderDatabase = new Roo.util.Observable({
                                 baseParams : { _tree: 1, 'sort': 'name', dir: 'ASC', limit : 9999 },
                                 dataUrl : baseURL + '/Roo/Builder_tables.php'
                             },
+                            sm : {
+                                xtype: 'MultiSelectionModel',
+                                xns: Roo.tree
+                            },
                             root : {
                                 xtype: 'AsyncTreeNode',
                                 xns: Roo.tree,
                                 text : "TOP LEVEL"
                             },
-                            sm : {
-                                xtype: 'DefaultSelectionModel',
-                                xns: Roo.tree
-                            },
                             editor : {
                                 xtype: 'TreeEditor',
                                 xns: Roo.tree,
@@ -172,9 +228,100 @@ Pman.Tab.BuilderDatabase = new Roo.util.Observable({
                                         }
                                         return true;
                                         
+                                    },
+                                    complete : function (_self, value, startValue)
+                                    {
+                                        Roo.log(this.editNode);
+                                    
+                                        var attr = this.editNode.attributes;
+                                        
+                                        var pa = this.editNode.parentNode.attributes;
+                                        Roo.log(pa);
+                                        var pr =  {
+                                     
+                                            parent_id : pa.id,
+                                            descrip : value,
+                                            name : '',
+                                            dbschema : ''
+                                        };
+                                            
+                                        if (attr.id > 0) {
+                                            pr.id = attr.id;
+                                        }
+                                        
+                                        new Pman.Request({
+                                            url : baseURL + '/Roo/Builder_tables',
+                                            method : 'POST',
+                                            params : pr
+                                        });
+                                        
+                                        
+                                        
                                     }
                                 }
                             }
+                        },
+                        menu : {
+                            xtype: 'Menu',
+                            xns: Roo.menu,
+                            items : [
+                                {
+                                    xtype: 'Item',
+                                    xns: Roo.menu,
+                                    listeners : {
+                                        click : function (_self, e)
+                                        {
+                                            _this.nIndex =     _this.nIndex || 0;
+                                            
+                                            var m = _this.cxnode.firstChild ? 'insertBefore' : 'appendChild';
+                                            var tree =  _this.treepanel.tree;
+                                            
+                                            var n = tree.loader.createNode({
+                                                id : -1,
+                                                descrip :'New Group ' + (++_this.nIndex), 
+                                                name : ''
+                                            }); 
+                                            
+                                            var node = _this.cxnode[m]( n , _this.cxnode.firstChild);
+                                            setTimeout(function(){
+                                                    tree.editor.editNode = node;
+                                                    tree.editor.startEdit(node.ui.textNode);
+                                                }, 10);
+                                        }
+                                    },
+                                    text : "Add Group"
+                                },
+                                {
+                                    xtype: 'Separator',
+                                    xns: Roo.menu
+                                },
+                                {
+                                    xtype: 'Item',
+                                    xns: Roo.menu,
+                                    listeners : {
+                                        click : function (_self, e)
+                                        {
+                                            _this.nIndex =     _this.nIndex || 0;
+                                            
+                                            _this.cxnode;
+                                            // try and delete it..
+                                            new Pman.Request({
+                                                url : baseURL + '/Roo/Builder_tables',
+                                                params : {
+                                                    _delete : _this.cxnode.attributes.id
+                                                },
+                                                success : function() {
+                                                    _this.cxnode.parentNode.removeChild(_this.cxnode);
+                                                    _this.cxnode = false;
+                                                
+                                                }
+                                            });
+                                            
+                                        }
+                                    },
+                                    text : "Remove Group"
+                                }
+                            ]
                         }
                     },
                     {
@@ -440,8 +587,6 @@ Pman.Tab.BuilderDatabase = new Roo.util.Observable({
                     xns: Roo
                 }
             }
-        });
-        this.layout = this.panel.layout;
-
+        };
     }
 });