php7 fixes
[Pman.Builder] / Pman.Builder.Tree.js
index 16d1e4d..33170c2 100644 (file)
 Pman.Builder.Tree = {
     
     currentNode: false,
-
+    dragProp: '',
     
     appendNode : function(parent, inConfig, point) {
                                 
                                     
         var tree = Pman.Tab.BuilderTree.tree;
         
-        
+        if (typeof(inConfig) == 'undefined') {
+            return;
+        }
         var items = [];
-        if (inConfig.items) { // loading!
+        if (typeof(inConfig) !== 'undefined' && inConfig.items) { // loading!
             items = inConfig.items;
             delete inConfig.items;
         }
         
         var config = this.cloneConfig(inConfig);
         
+        var hidden =  config['builder.hidden'] || false;
+         
         if (!parent) {
             parent = tree.root;
         }
               
         var newNode = new Roo.tree.TreeNode({
-                text: this.configToText(config)
+            text: this.configToText(config)
         });
-                
-        
+              
         newNode.elConfig = config;
+        
         //if (markUndo === true) {
         //Pman.Tab.Builder.markUndo("Add " + newNode.text);
         //
@@ -47,6 +51,7 @@ Pman.Builder.Tree = {
         switch(point) {
             case 'above':
                 parent.parentNode.insertBefore(newNode, parent);
+                parent.parentNode.expand(true);
                 break;
             case 'below':
                 // if it's the last node.. then we append..
@@ -57,14 +62,18 @@ Pman.Builder.Tree = {
                 }
                 var bef = parent.parentNode.childNodes[ix];
                 parent.parentNode.insertBefore(newNode, bef);
+                parent.parentNode.expand(true);
                 break;
             
             case 'append':
             default:    
                 parent.appendChild(newNode);
+                parent.expand(true);
                 break;
         }
-            
+        
+        newNode.ui.ctNode.style.display = hidden ? 'none' : '';
+        
         if (items.length) {
             Roo.each(items, function(i) {
                 this.appendNode(newNode, i);
@@ -110,6 +119,9 @@ Pman.Builder.Tree = {
         var newConfig = {};
         
         for (var i in config) {
+            if (i.match(/^builder\./)) {
+                continue;
+            }
             if (typeof config[i] == 'object') {
                  newConfig[i] = this.cloneConfig(config[i]);
             } else if (typeof config[i] != 'function') { // should this happen?
@@ -123,7 +135,9 @@ Pman.Builder.Tree = {
         var txt = [];
         c = c || {};
               var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
-            if (sr) txt.push('<s>');
+            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 + ']'); }
@@ -138,7 +152,9 @@ Pman.Builder.Tree = {
             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>');
+            if (sr) {
+                txt.push('</s>');
+            }
         return (txt.length == 0 ? "Element" : txt.join(" "));
         
         
@@ -160,8 +176,68 @@ Pman.Builder.Tree = {
             items: [] 
         };
     },
+    
+    replaceCurrentNode : function(cfg)
+    {
+        var tree = Pman.Tab.BuilderTree.tree;
+
+        if (this.currentNode == tree.root) {
+            return false;
+        }
+        var pn = this.currentNode.parentNode;
+        
+        var ix = pn.indexOf(this.currentNode);
+        pn.removeChild(this.currentNode);
+          
+        if (!pn.childNodes.length) {
+            this.appendNode(pn, cfg, 'append');
+            return true;
+        }
+        if (!ix) {
+            // first..
+            this.appendNode(pn.childNodes[0], cfg, 'above');
+            return true;
+        
+        }
+        
+        this.appendNode(pn.childNodes[ix-1], cfg, 'below');
+        
+        
+        return true;
+    },
+    
+    collapseToggle : function()
+    {
+        var tree = Pman.Tab.BuilderTree.tree;
+        
+        if (this.currentNode == tree.root) {
+            return false;
+        }
+        var cfg = this.currentNode.elConfig;
+        // things that can not be deleted...
+        var hidden = cfg['builder.hidden'] || 0;
+        if (hidden) {
+            delete cfg['builder.hidden'];
+        } else {
+            cfg['builder.hidden'] = 1;
+        }
+         
+        
+        this.currentNode.ui.ctNode.style.display = !hidden ? 'none' : '';
+         
+         
+        //this.setCurrentNode(pn.childNodes.length ? pn.childNodes[ix] : pn  ,true);
+        return true;
+    },
+    
+    
+    
+    
     deleteCurrent : function()
     {
+        
+        var tree = Pman.Tab.BuilderTree.tree;
+        
         if (this.currentNode == tree.root) {
             return false;
         }
@@ -171,7 +247,7 @@ Pman.Builder.Tree = {
         
         var pn = this.currentNode.parentNode;
         
-        
+        // work out if we make the next or parent the 'current node'
         var ix = pn.indexOf(this.currentNode);
         //  console.log(ix);
         pn.removeChild(this.currentNode);
@@ -182,7 +258,7 @@ Pman.Builder.Tree = {
         return true;
     },
     dupeNode : function(node)
-        {
+    {
             var cfg = this.cloneConfig(node.elConfig);
             
             var newNode = new Roo.tree.TreeNode(
@@ -199,7 +275,8 @@ Pman.Builder.Tree = {
             return newNode;
                 
     },
-    loadBJS : function(module, part) {
+    loadBJS : function(module, part)
+    {
         var _t = this;
         new Pman.Request({
             url : baseURL + '/Roo/Builder_part.php',
@@ -235,8 +312,11 @@ Pman.Builder.Tree = {
     loadTree : function(o)
     {
         var tree = Pman.Tab.BuilderTree.tree;
-        tree.clearAll();
+        this.clearAll();
         tree.root.elConfig = o;
+        if (typeof(o.xtype) == 'undefined') {
+            o.xtype = '*top';
+        }
         tree.root.setText(this.configToText(tree.root.elConfig));
         this.appendNode(tree.root, o.items[0]);
         tree.root.expand(true);
@@ -246,7 +326,7 @@ Pman.Builder.Tree = {
     nodeXtype : function(n)
     {
         var tree = Pman.Tab.BuilderTree.tree;
-        if (!n) {return ''; }
+        if (!n || !n.elConfig) {return ''; }
         var xt = n.elConfig.xtype ||  '';
         var xns= n.elConfig['|xns'] ||   '';
         xns += xns.length ? '.' : '';
@@ -334,26 +414,26 @@ Pman.Builder.Tree = {
                 '|xns' : xar.join('.')
                 
             };
-            if (_this.dragProp.length > 1) {
-                cfg['*prop'] = _this.dragProp;
+            if (this.dragProp.length > 1) {
+                cfg['*prop'] = this.dragProp;
             }
             // at this point it should of a set of options...
              var cls = cfg['|xns'] + '.' + cfg['xtype'];
                 
     
-            if (typeof(Pman.Builder[cls]) != 'undefined') {
+            if (typeof(Pman.Builder.Wizard[cls]) != 'undefined') {
                 Pman.Dialog.BuilderAdd.show( cfg , function(fdata ) {
-    
-                
+     
                     _t.appendNode(e.target, fdata , e.point);
-    
+                     Pman.Tab.BuilderView.panel.redraw();
+             
                  });
-                 return;
+                 return false;
              }
              this.appendNode(e.target, cfg, e.point);
               Pman.Tab.BuilderView.panel.redraw();
              
-            return; // fixme drop of elements from palete..
+            return false; // fixme drop of elements from palete..
         }
     
         // always drop onto own parent
@@ -365,9 +445,12 @@ Pman.Builder.Tree = {
         }
         // can append has to use palete...
         // this code should be in nodedragover.
-        
-        Roo.log("move checks need moving");
-        return;
+        if (e.dropNode) {
+            var cfg = this.toJS(e.dropNode);
+            this.appendNode(e.target, cfg, e.point);
+        }
+        Roo.log('no e.dropNode?');
+        return false; // do not allow movement..
         
         if (_this.canAppend(np, e.dropNode.elConfig)) {
             if (e.rawEvent.ctrlKey) {
@@ -387,8 +470,117 @@ Pman.Builder.Tree = {
         return false;
                             
     
-    }
-    
+    },
+    handleDragOver : 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 :  e.target.parentNode);
+           Roo.log("NEW PARENT: " + e.point + " = " + new_parent);
+           
+           // see if the new_parent is actually in the list of ok_parents
+           e.cancel = true;
+           this.dragProp = '';
+           var _t = this;
+           Roo.each(ok_parents, function(n) {
+                Roo.log("compare "+n+" ? " + new_parent);
+                if (n == new_parent || n.split(':').shift() == new_parent) {
+                   Roo.log("got match!");
+                   e.cancel = false;
+                   _t.dragProp = (n == new_parent) ?  '' : n.split(':').pop();
+                   return true;
+                }
+               return null;
+            });
+   
+           // done all the checks...
+           return;
+           
+        }
+        
+        
+        // have a drop node - hence comming from the same object..
+        var drop_xtype = this.nodeXtype(e.dropNode);
+        // currently we can not determine validity..
+        e.cancel = false;
+        return ;
+        
+        
+        
+    },
+    save : function() 
+    {
+       // first see if first element has a name.. - we can not save otherwise..
+        var t = Pman.Tab.BuilderTree.tree;
+        if (!t.root.elConfig.name.length) {
+            Roo.MessageBox.alert("Error", "No name set for form");
+            return;
+        }
+     
+        var  sid = (typeof(sid) == 'undefined') ? 
+             (Pman.Tab.BuilderTop.filesel.lastData ? Pman.Tab.BuilderTop.filesel.lastData.id : 0) : sid;
+        
+
+        var js = this.toJS();
+        var render = new Pman.Builder.JsRender(js); 
+         
+        // console.log(js);
+        // console.log(json);
+        
+        // check the select box to see if that has been set... - save it with that id..
+        
+        //var _this = this;
+        
+        Pman.request({
+            url: baseURL + '/Roo/Builder_part.php',
+            method : 'POST',
+            params : {
+                json : Roo.encode(js, null, 4),
+                jsource : render.toSource(),
+                name :   js.name,
+                module_id : Pman.Tab.BuilderTop.modsel.getValue(),
+                id : sid
+            }, 
+            success : function(data) {
+                // set the fileSel!!
+                console.log(data);
+                //if (data) {
+                //    _this.filesel.setFromData(data);
+//                    if (cb) {
+//                        cb.call(_this,data);
+  //                  }
+//                    _this.postCode(data);
+//                }
+            }
+        });
+}
+
     
     
 }
\ No newline at end of file