php7 fixes
[Pman.Builder] / Pman.Tab.BuilderTree.js
index b4e92d3..2a0375d 100644 (file)
@@ -2,35 +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({
-        modKey : '001-Pman.Tab.BuilderTree',
-        module : Pman.Tab.BuilderTree,
-        region : 'center',
-        parent : Pman.Tab.BuilderTab,
-        name : "Pman.Tab.BuilderTree",
-        disabled : false, 
-        permname: '' 
-    });
-});
-
-Pman.Tab.BuilderTree = new Roo.util.Observable({
-
-    panel : false,
-    disabled : false,
-    parentLayout:  false,
-
-    add : function(parentLayout, region)
+Pman.Tab.BuilderTree = new Roo.XComponent({
+    part     :  ["Builder","Tree"],
+    order    : '001-Pman.Tab.BuilderTree',
+    region   : 'center',
+    parent   : 'Pman.Tab.BuilderTab',
+    name     : "Pman.Tab.BuilderTree",
+    disabled : false, 
+    permname : '', 
+    _tree : function()
     {
-
         var _this = this;
-        this.parentLayout = parentLayout;
-
-        this.panel = parentLayout.addxtype({
+        var MODULE = this;
+        return {
             xtype: 'NestedLayoutPanel',
             xns: Roo,
             region : 'west',
@@ -46,13 +30,15 @@ Pman.Tab.BuilderTree = new Roo.util.Observable({
                             {
                                 
                                 _this.tree = _self.tree;
+                                _this.menu = _self.menu;
+                            
                                 if (_this.hasMouseEvent) {
                                     return;
                                 }
                                 
                                 _this.hasMouseEvent = true;
-                                 this.el.on('mouseover', function() { _this.isMouseOver= true; });
-                                this.el.on('mouseout', function() { _this.isMouseOver = false; });
+                              //   this.el.on('mouseover', function() { _this.isMouseOver= true; });
+                                 // this.el.on('mouseout', function() { _this.isMouseOver = false; });
                             
                             }
                         },
@@ -63,143 +49,53 @@ Pman.Tab.BuilderTree = new Roo.util.Observable({
                             listeners : {
                                 beforenodedrop : function (e)
                                 {
-                                    /*
-                                    tree - The TreePanel
-                                    target - The node being targeted for the drop
-                                    data - The drag data from the drag source
-                                    point - The point of the drop - append, above or below
-                                    source - The drag source
-                                    rawEvent - Raw mouse event
-                                    dropNode - Drop node(s) provided by the source OR you can supply node(s) to be inserted by setting them on this object.
-                                    cancel - Set this to true to cancel the drop.
-                                    */
-                                    Roo.log(e);
-                                    if (!e.tree || !e.dropNode) {
-                                        console.log('no tree or dropNode');
-                                        return; // fixme drop of elements from palete..
-                                    }
-                                    var np = false; // new parent
-                                    
-                                    switch (e.point) {
-                                        case 'above':
-                                        case 'below':
-                                            np = e.target.parentNode;
-                                            break;
-                                        case 'append':
-                                            np = e.target;
-                                            break;
-                                    }
                                     
-                                    // always drop onto own parent
-                                    if (np == e.dropNode.parentNode) {
-                                        if (e.rawEvent.ctrlKey) {
-                                            e.dropNode = _this.dupeNode(e.dropNode);
-                                        }
-                                        return true;
-                                    }
-                                   if (_this.canAppend(np, e.dropNode.elConfig)) {
-                                        if (e.rawEvent.ctrlKey) {
-                                            e.dropNode = _this.dupeNode(e.dropNode);
-                                              
-                                            if (np.elConfig.xtype == 'GridEditor') {
-                                                e.dropNode.elConfig['*prop'] = 'field';
-                                            }
-                                            
-                                        }
-                                        return true;
-                                    }  
-                                    console.log('can not drop ' + e.dropNode.elConfig.xtype + ' ontop of ' + np.elConfig.xtype);
-                                    
-                                    
-                                    
-                                    return false;
-                                                        
-                                
-                                },
-                                nodedrop : function (e)
-                                {
-                                    
-                                    Roo.log("Node Drop");
-                                    return;
-                                    e.dropNode.setText(
-                                        _this.configToText(e.dropNode.elConfig)
-                                        );
-                                        var bp = Pman.Tab.BuilderPanel;
-                                        bp.redraw.defer(1000, bp, [true]);
+                                    return Pman.Builder.Tree.handleDropNode(e);      
                                 
                                 },
                                 click : function (node, e)
                                 {
                                       e.preventDefault();
                                                        // console.log(e.button);
-                                        this.setCurrentNode(node);
+                                        Pman.Builder.Tree.setCurrentNode(node);
+                                        
+                                    
+                                        
                                 
                                 },
                                 contextmenu : function (node, e)
                                 {
                                     e.stopEvent();
                                         
-                                        this.getSelectionModel().select(node);
-                                         _this.setCurrentNode(node);
-                                        var xt = node.elConfig.xtype;
-                                        var altx= false;
-                                        if (typeof(node.elConfig['*prop']) != 'undefined') {
-                                            altx = node.parentNode.elConfig.xtype +'.' + node.elConfig['*prop'];
-                                        }
-                                        var mn = Pman.Tab.BuilderPalete.getMenu(xt,altx);
-                                        
-                                        
-                                        if (mn) {
-                                            mn.show(e.getTarget());
-                                        }
-                                        
+                                    this.getSelectionModel().select(node);
+                                     Pman.Builder.Tree.setCurrentNode(node);
+                                     
+                                          _this.menu = Roo.factory(_this.menu);
                                 
+                                        _this.menu.show(node.ui.textNode, 'tr');
+                                     return;
+                                     
+                                     /*
+                                    var xt = node.elConfig.xtype;
+                                    var altx= false;
+                                    if (typeof(node.elConfig['*prop']) != 'undefined') {
+                                        altx = node.parentNode.elConfig.xtype +'.' + node.elConfig['*prop'];
+                                    }
+                                    var mn = Pman.Tab.BuilderPalete.getMenu(xt,altx);
+                                    
+                                    
+                                    if (mn) {
+                                        mn.show(e.getTarget());
+                                    }
+                                    
+                                 */
                                 
                                 },
                                 nodedragover : function (e)
                                 {
-                                    Roo.log('nodedragover');
-                                     Roo.log(e);
-                                     // e.cancel..
-                                     // if we have within the same tree:
-                                       // dropNode (the node being dragged !!important!!) 
-                                       // point: below, append
-                                       // target - node 
-                                    // for palete
-                                        // dropNode = false;
-                                        // grid = the grid...
-                                        // source.dragData.selections[..] 
-                                   
-                                    
-                                    // we can only check parents... (we in theory can check dupe properties.. but let's ignore that for the time being.)
-                                    
-                                    // ok off we go.
                                     
-                                    if (!e.dropNode) {
-                                        // drag from palete..
-                                        if (!e.source.dragData.selections.length) {
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                        var drop_rec = e.source.dragData.selections[0];
-                                        var drop_xtype = drop_rec.data.name;
-                                        var ok_parents = drop_rec.json.parents;
-                                        Roo.log("TEST PARENTS: " + ok_parents.join(', '));
-                                        var new_parent = this.nodeXtype((e.point == 'append') ? e.target.parentNode :  e.target);
-                                        Roo.log("NEW PARENT: " + new_parent);
-                                        
-                                        // see if the new_parent is actually in the list of ok_parents
-                                        e.cancel = true;
-                                        Roo.each(ok_parents,function(n) {
-                                            if (n == new_parent || n.split(':').shift() == new_parent) {
-                                                e.cancel = false;
-                                                return true;
-                                            }
-                                        });
-                                        // done all the checks...
-                                        return;
-                                        
-                                    }
+                                        return Pman.Builder.Tree.handleDragOver(e);      
+                                 
                                      
                                    
                                 }
@@ -209,199 +105,7 @@ Pman.Tab.BuilderTree = new Roo.util.Observable({
                             ddGroup : 'component',
                             enableDD : true,
                             rootVisible : true,
-                            nodeXtype : function(n) {
-                                 if (!n) {return ''; }
-                                var xt = n.elConfig.xtype ||  '';
-                                var xns= n.elConfig['|xns'] ||   '';
-                                xns += xns.length ? '.' : '';
-                                return xns + xt;
-                            },
-                            appendNode : function(parent, inConfig, markUndo) {
-                                
-                                    
-                             
-                                var items = [];
-                                if (inConfig.items) { // loading!
-                                    items = inConfig.items;
-                                    delete inConfig.items;
-                                }
-                                var config = this.cloneConfig(inConfig);
-                                
-                                if (!parent) {
-                               parent = this.root;
-                                }
-                                    
-                                    
-                                //var canAppend = this.canAppend(parent,config);
-                                //if (canAppend !== true) {
-                                //    console.log("Unable to add element " + canAppend);
-                                //     Roo.Msg.alert("Unable to add element", canAppend);
-                                //             return false;
-                               //              }
-                                     
-                                var newNode = new Roo.tree.TreeNode({
-                                        text: this.configToText(config)
-                                });
-                                        
-                                
-                                newNode.elConfig = config;
-                                //if (markUndo === true) {
-                                //Pman.Tab.Builder.markUndo("Add " + newNode.text);
-                                //
-                                    // appends to our tree...
-                                parent.appendChild(newNode);
-                                
-                                    
-                                if (items.length) {
-                                    Roo.each(items, function(i) {
-                                        this.appendNode(newNode, i);
-                                    },this);
-                                    
-                                }
-                                    
-                                    
-                                    /*
-                                    -- panels with panes...
-                                       if (items && items.length) {
-                                               for (var i = 0; i < items.length; i++) {
-                                                               this.appendConfig(items[i], newNode, false);
-                                               }
-                                       }
-                                       if (opts.doUpdate !== false) {
-                                               this.updateForm(false, newNode);
-                                       }
-                                    */
-                                return newNode;
-                            
-                                
-                            },
-                            clearAll : function() {
-                                var rt = this.root;
-                                 if (rt.childNodes.length) {
-                                    rt.removeChild(rt.childNodes[0]);
-                                }
-                               
-                                this.root.elConfig  = Roo.apply({ }, this.defaultElConfig());  
-                                //var btop = Pman.Tab.BuilderTop;
-                                //if (btop.modsel && btop.modsel.lastData) {
-                                //    this.tree.root.elConfig.app = btop.modsel.lastData.app;
-                                //}
-                                
-                                this.setCurrentNode(this.root,true);
-                            
-                            },
-                            cloneConfig : function(config) {
-                                if (!config) { return null; }
-                                var newConfig = {};
-                                
-                                for (var i in config) {
-                                    if (typeof config[i] == 'object') {
-                                         newConfig[i] = this.cloneConfig(config[i]);
-                                    } else if (typeof config[i] != 'function') { // should this happen?
-                                         newConfig[i] = config[i];
-                                    }
-                                }
-                                return newConfig;
-                            },
-                            configToText : function(c) {
-                                 
-                               var txt = [];
-                               c = c || {};
-                                      var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
-                                    if (sr) txt.push('<s>');
-                                    if (typeof(c['*prop']) != 'undefined')   { txt.push(c['*prop']+ ':'); }
-                               if (c.xtype)      { txt.push(c.xtype); }
-                               if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
-                               if (c.boxLabel)   { txt.push('[' + c.boxLabel + ']'); }
-                                
-                                
-                               if (c.layout)     { txt.push('<i>' + c.layout + '</i>'); }
-                               if (c.title)      { txt.push('<b>' + c.title + '</b>'); }
-                                    if (c.header)    { txt.push('<b>' + c.header + '</b>'); }
-                                    if (c.legend)      { txt.push('<b>' + c.legend + '</b>'); }
-                               if (c.text)       { txt.push('<b>' + c.text + '</b>'); }
-                                    if (c.name)       { txt.push('<b>' + c.name+ '</b>'); }
-                               if (c.region)     { txt.push('<i>(' + c.region + ')</i>'); }
-                                    if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
-                                    if (sr) txt.push('</s>');
-                               return (txt.length == 0 ? "Element" : txt.join(" "));
-                             
-                              
-                            },
-                            currentNodeType : function() {
-                                return this.nodeXtype(this.currentNode);
-                             
-                            },
-                            defaultElConfig : function() {
-                                return {
-                                   xtype : '*Module',
-                                    
-                                    module : 'TestApp',
-                                    part:   'Partname',
-                                    modkey : 0,
-                                    region : 'center',
-                                    parent : 'Pman',
-                                    name : 'Module Name',
-                                    items: [] 
-                                };
-                            },
-                            loadBJS : function(module, part) {
-                                var _t = this;
-                                new Pman.Request({
-                                    url : baseURL + '/Roo/Builder_part.php',
-                                    method : 'GET',
-                                    params : {
-                                       _id : part
-                                    },
-                                    success : function(res)         
-                                    {
-                                        // data is in.. 
-                                        Roo.log(res);
-                                        _t.loadTree(JSON.parse(res.data.json));
-                                        
-                                     
-                                    },
-                            
-                                 })  
-                                    
-                                
-                                
-                            },
-                            loadTree : function(o) {
-                                this.clearAll();
-                                this.root.elConfig = o;
-                                this.root.setText(this.configToText(this.root.elConfig));
-                                this.appendNode(this.root, o.items[0]);
-                                this.root.expand(true);
-                                Pman.Tab.BuilderView.panel.redraw();
-                                this.setCurrentNode(this.root,true);
-                            },
                             renderer : function(n) { return n.text; },
-                            setCurrentNode : function(node,select) {
-                                    this.currentNode = node || this.root;
-                                    
-                                    //Pman.Tab.BuilderView.highlightElement(this.currentNode);
-                            
-                                    var p = Pman.Tab.BuilderProps.grid;
-                                    if (p) { //may not be ready yet..
-                                        p.setCurrrentNode(this.currentNode);
-                                    }
-                                    
-                                  
-                                    this.currentNode.setText(this.configToText(this.currentNode.elConfig));
-                                    
-                                    if (select) { //&& node !== this.tree.root) {
-                                        if (this.currentNode !== this.root)  {
-                                                 this.currentNode.ensureVisible();
-                                          }   
-                                         this.currentNode.expand(false,false);
-                                        this.currentNode.select();
-                               }
-                               // update palete..
-                               Pman.Tab.BuilderPalette.grid.getSelectionModel().clearSelections();
-                               Pman.Tab.BuilderPalette.grid.view.refresh();
-                            
-                            },
                             sm : {
                                 xtype: 'DefaultSelectionModel',
                                 xns: Roo.tree
@@ -412,7 +116,7 @@ Pman.Tab.BuilderTree = new Roo.util.Observable({
                                 text : "Part",
                                 elConfig : function() {
                                     return  {
-                                         xtype : '*Module',
+                                         xtype : '*top',
                                             
                                             app : 'TestApp',
                                             // perm
@@ -428,6 +132,116 @@ Pman.Tab.BuilderTree = new Roo.util.Observable({
                                     }
                                 }
                             }
+                        },
+                        menu : {
+                            xtype: 'Menu',
+                            xns: Roo.menu,
+                            items : [
+                                {
+                                    xtype: 'Item',
+                                    xns: Roo.menu,
+                                    listeners : {
+                                        click : function (_self)
+                                        {
+                                            
+                                            var str = Pman.Builder.Tree.currentNodeType();
+                                            if (typeof(Pman.Builder.Wizard[str]) == 'undefined') {
+                                                Roo.MessageBox.alert("Sorry", "No wizard exists for " + str);
+                                                return;
+                                            }
+                                            var cn = Pman.Builder.Tree.currentNode;
+                                            if (typeof(cn.elConfig['.builderCfg']) == 'undefined') {
+                                                Roo.MessageBox.alert("Sorry", "No configuration exists for " + str);
+                                                return;
+                                            }
+                                            
+                                            
+                                            var cfg = Roo.decode(cn.elConfig['.builderCfg']);
+                                            
+                                            Roo.log(cfg);
+                                            Pman.Dialog.BuilderAddTable.show( 
+                                                cfg,  
+                                                function(data) {
+                                        
+                                                     
+                                                    var res = Pman.Builder.Wizard[str](data); // with old..
+                                                     Pman.Builder.Tree.replaceCurrentNode( res );
+                                                     Pman.Tab.BuilderView.panel.redraw();
+                                         
+                                               }
+                                            );
+                                        
+                                           
+                                            // otherwise, call back with template??
+                                            
+                                           
+                                           
+                                                
+                                        }
+                                    },
+                                    text : "Edit Using Wizard"
+                                },
+                                {
+                                    xtype: 'Separator',
+                                    xns: Roo.menu
+                                },
+                                {
+                                    xtype: 'Item',
+                                    xns: Roo.menu,
+                                    listeners : {
+                                        click : function (_self)
+                                        {
+                                            
+                                              
+                                            Pman.Builder.Tree.collapseToggle();
+                                                
+                                        }
+                                    },
+                                    text : "Toggle Collapse"
+                                },
+                                {
+                                    xtype: 'Item',
+                                    xns: Roo.menu,
+                                    listeners : {
+                                        click : function (_self)
+                                        {
+                                            
+                                              
+                                            Pman.Builder.Tree.createSharedPart();
+                                                
+                                        }
+                                    },
+                                    text : "Create shared part from this node"
+                                },
+                                {
+                                    xtype: 'Separator',
+                                    xns: Roo.menu
+                                },
+                                {
+                                    xtype: 'Item',
+                                    xns: Roo.menu,
+                                    listeners : {
+                                        click : function (_self)
+                                        {
+                                            Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that node?",
+                                                function(r) {
+                                                    if (r!='yes') {
+                                                        return;
+                                                    }
+                                                   Pman.Builder.Tree.deleteCurrent();
+                                                }
+                                            );
+                                                
+                                        }
+                                    },
+                                    text : "Delete Node"
+                                },
+                                {
+                                    xtype: 'Item',
+                                    xns: Roo.menu,
+                                    text : "Save as template"
+                                }
+                            ]
                         }
                     }
                 ],
@@ -442,8 +256,6 @@ Pman.Tab.BuilderTree = new Roo.util.Observable({
                     split : true
                 }
             }
-        });
-        this.layout = this.panel.layout;
-
+        };
     }
 });