Pman.Tab.BuilderTree.bjs
[Pman.Builder] / Pman.Tab.BuilderTree.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5
6
7 // register the module first
8 Pman.on('beforeload', function()
9 {
10     Pman.register({
11         part :  ["Builder","Tree"],
12         modKey : '001-Pman.Tab.BuilderTree',
13         module : Pman.Tab.BuilderTree,
14         region : 'center',
15         parent : Pman.Tab.BuilderTab,
16         name : "Pman.Tab.BuilderTree",
17         disabled : false, 
18         permname: '' 
19     });
20 });
21
22 Pman.Tab.BuilderTree = new Roo.util.Observable({
23
24     panel : false,
25     disabled : false,
26     parentLayout:  false,
27
28     add : function(parentLayout, region)
29     {
30
31         var _this = this;
32         this.parentLayout = parentLayout;
33
34         this.panel = parentLayout.addxtype({
35             xtype: 'NestedLayoutPanel',
36             xns: Roo,
37             region : 'west',
38             layout : {
39                 xtype: 'BorderLayout',
40                 xns: Roo,
41                 items : [
42                     {
43                         xtype: 'TreePanel',
44                         xns: Roo,
45                         listeners : {
46                             activate : function (_self)
47                             {
48                                 
49                                 _this.tree = _self.tree;
50                                 _this.menu = _self.menu;
51                             
52                                 if (_this.hasMouseEvent) {
53                                     return;
54                                 }
55                                 
56                                 _this.hasMouseEvent = true;
57                                  this.el.on('mouseover', function() { _this.isMouseOver= true; });
58                                 this.el.on('mouseout', function() { _this.isMouseOver = false; });
59                             
60                             }
61                         },
62                         region : 'center',
63                         tree : {
64                             xtype: 'TreePanel',
65                             xns: Roo.tree,
66                             listeners : {
67                                 beforenodedrop : function (e)
68                                 {
69                                     
70                                     return Pman.Builder.Tree.handleDropNode(e);      
71                                 
72                                 },
73                                 click : function (node, e)
74                                 {
75                                       e.preventDefault();
76                                                        // console.log(e.button);
77                                         Pman.BuilderTree.setCurrentNode(node);
78                                         
79                                     
80                                         
81                                 
82                                 },
83                                 contextmenu : function (node, e)
84                                 {
85                                     e.stopEvent();
86                                         
87                                     this.getSelectionModel().select(node);
88                                      Pman.Builder.Tree.setCurrentNode(node);
89                                      
90                                           _this.menu = Roo.factory(_this.menu);
91                                 
92                                         _this.menu.show(node.ui.textNode, 'tr');
93                                      return;
94                                      
95                                      /*
96                                     var xt = node.elConfig.xtype;
97                                     var altx= false;
98                                     if (typeof(node.elConfig['*prop']) != 'undefined') {
99                                         altx = node.parentNode.elConfig.xtype +'.' + node.elConfig['*prop'];
100                                     }
101                                     var mn = Pman.Tab.BuilderPalete.getMenu(xt,altx);
102                                     
103                                     
104                                     if (mn) {
105                                         mn.show(e.getTarget());
106                                     }
107                                     
108                                  */
109                                 
110                                 },
111                                 nodedragover : function (e)
112                                 {
113                                     
114                                         return Pman.Builder.Tree.handleDragOver(e);      
115                                  
116                                      
117                                    
118                                 }
119                             },
120                             animate : false,
121                             containerScroll : true,
122                             ddGroup : 'component',
123                             enableDD : true,
124                             rootVisible : true,
125                             clearAll : function() {
126                                 var rt = this.root;
127                                  if (rt.childNodes.length) {
128                                     rt.removeChild(rt.childNodes[0]);
129                                 }
130                                
131                                 this.root.elConfig  = Roo.apply({ }, this.defaultElConfig());  
132                                 //var btop = Pman.Tab.BuilderTop;
133                                 //if (btop.modsel && btop.modsel.lastData) {
134                                 //    this.tree.root.elConfig.app = btop.modsel.lastData.app;
135                                 //}
136                                 
137                                 this.setCurrentNode(this.root,true);
138                             
139                             },
140                             cloneConfig : function(config) {
141                                 if (!config) { return null; }
142                                 var newConfig = {};
143                                 
144                                 for (var i in config) {
145                                     if (typeof config[i] == 'object') {
146                                          newConfig[i] = this.cloneConfig(config[i]);
147                                     } else if (typeof config[i] != 'function') { // should this happen?
148                                          newConfig[i] = config[i];
149                                     }
150                                 }
151                                 return newConfig;
152                             },
153                             configToText : function(c) {
154                                  
155                                 var txt = [];
156                                 c = c || {};
157                                       var sr = (typeof(c['+buildershow']) != 'undefined') &&  !c['+buildershow'] ? true : false;
158                                     if (sr) txt.push('<s>');
159                                     if (typeof(c['*prop']) != 'undefined')   { txt.push(c['*prop']+ ':'); }
160                                 if (c.xtype)      { txt.push(c.xtype); }
161                                 if (c.fieldLabel) { txt.push('[' + c.fieldLabel + ']'); }
162                                 if (c.boxLabel)   { txt.push('[' + c.boxLabel + ']'); }
163                                 
164                                 
165                                 if (c.layout)     { txt.push('<i>' + c.layout + '</i>'); }
166                                 if (c.title)      { txt.push('<b>' + c.title + '</b>'); }
167                                     if (c.header)    { txt.push('<b>' + c.header + '</b>'); }
168                                     if (c.legend)      { txt.push('<b>' + c.legend + '</b>'); }
169                                 if (c.text)       { txt.push('<b>' + c.text + '</b>'); }
170                                     if (c.name)       { txt.push('<b>' + c.name+ '</b>'); }
171                                 if (c.region)     { txt.push('<i>(' + c.region + ')</i>'); }
172                                     if (c.dataIndex) { txt.push('[' + c.dataIndex+ ']'); }
173                                     if (sr) txt.push('</s>');
174                                 return (txt.length == 0 ? "Element" : txt.join(" "));
175                              
176                               
177                             },
178                             currentNodeType : function() {
179                                 return this.nodeXtype(this.currentNode);
180                              
181                             },
182                             defaultElConfig : function() {
183                                 return {
184                                    xtype : '*top',
185                                     
186                                     module : 'TestApp',
187                                     part:   'Partname',
188                                     modkey : 0,
189                                     region : 'center',
190                                     parent : 'Pman',
191                                     name : 'Module Name',
192                                     items: [] 
193                                 };
194                             },
195                             deleteCurrent : function() {
196                                 if (this.currentNode == this.root) {
197                                     return false;
198                                 }
199                                 var cfg = this.currentNode.elConfig;
200                                 // things that can not be deleted...
201                                
202                                 
203                                 var pn = this.currentNode.parentNode;
204                                 
205                                 
206                                 var ix = pn.indexOf(this.currentNode);
207                               //  console.log(ix);
208                                 pn.removeChild(this.currentNode);
209                                 if (pn.childNodes.length) {
210                                     ix = Math.min(pn.childNodes.length-1, ix);
211                                 }
212                                 this.setCurrentNode(pn.childNodes.length ? pn.childNodes[ix] : pn  ,true);
213                                 return true;
214                             },
215                             dupeNode : function(node)
216                                 {
217                                     var cfg = this.cloneConfig(node.elConfig);
218                                     
219                                     var newNode = new Roo.tree.TreeNode(
220                                     {
221                                             id: Roo.id(),
222                                             text: this.configToText(cfg)
223                                     });
224                                     
225                                     newNode.elConfig = cfg;
226                                     node.eachChild(function(n) {
227                                         newNode.appendChild(this.dupeNode(n));
228                                     },this);
229                                     
230                                     return newNode;
231                                         
232                                 },
233                             loadBJS : function(module, part) {
234                                 var _t = this;
235                                 new Pman.Request({
236                                     url : baseURL + '/Roo/Builder_part.php',
237                                     method : 'GET',
238                                     params : {
239                                        _id : part
240                                     },
241                                     success : function(res)         
242                                     {
243                                         // data is in.. 
244                                         Roo.log(res);
245                                         
246                                         if (!res.data.json.length) {
247                                             var cfg = _t.defaultElConfig();
248                                             cfg.name = Pman.Tab.BuilderTop.filesel.lastData.name;
249                                             cfg.part = Pman.Tab.BuilderTop.filesel.lastData.name;
250                                             cfg.module = '';
251                                             _t.loadTree(cfg);
252                                             return;
253                                         
254                                         }
255                                         
256                                         _t.loadTree(JSON.parse(res.data.json));
257                                         
258                                      
259                                     }
260                             
261                                  })  
262                                     
263                                 
264                                 
265                             },
266                             loadTree : function(o) {
267                                 this.clearAll();
268                                 this.root.elConfig = o;
269                                 this.root.setText(this.configToText(this.root.elConfig));
270                                 this.appendNode(this.root, o.items[0]);
271                                 this.root.expand(true);
272                                 Pman.Tab.BuilderView.panel.redraw();
273                                 this.setCurrentNode(this.root,true);
274                             },
275                             nodeXtype : function(n) {
276                                  if (!n) {return ''; }
277                                 var xt = n.elConfig.xtype ||  '';
278                                 var xns= n.elConfig['|xns'] ||   '';
279                                 xns += xns.length ? '.' : '';
280                                 return xns + xt;
281                             },
282                             renderer : function(n) { return n.text; },
283                             setCurrentNode : function(node,select) {
284                                     this.currentNode = node || this.root;
285                                     
286                                     //Pman.Tab.BuilderView.highlightElement(this.currentNode);
287                             
288                                     var p = Pman.Tab.BuilderProps.grid;
289                                     if (p) { //may not be ready yet..
290                                         p.setCurrrentNode(this.currentNode);
291                                     }
292                                     
293                                   
294                                     this.currentNode.setText(this.configToText(this.currentNode.elConfig));
295                                     
296                                     if (select) { //&& node !== this.tree.root) {
297                                         if (this.currentNode !== this.root)  {
298                                                  this.currentNode.ensureVisible();
299                                           }   
300                                          this.currentNode.expand(false,false);
301                                         this.currentNode.select();
302                                 }
303                                 // update palete..
304                                 Pman.Tab.BuilderPalette.grid.getSelectionModel().clearSelections();
305                                 Pman.Tab.BuilderPalette.grid.view.refresh();
306                             
307                             },
308                             toJS : function(n)
309                             {
310                                 if (!n) {
311                                     return this.toJS(this.root);
312                                 }
313                                 var _this = this;
314                                 var ret = this.cloneConfig(n.elConfig);
315                                 if (n.childNodes.length) {
316                                     ret.items = [];
317                                     n.eachChild(function(cn) {
318                                         ret.items.push(_this.toJS(cn));
319                                     });
320                                         
321                                 }
322                                 return ret;
323                                   
324                                  
325                             },
326                             sm : {
327                                 xtype: 'DefaultSelectionModel',
328                                 xns: Roo.tree
329                             },
330                             root : {
331                                 xtype: 'TreeNode',
332                                 xns: Roo.tree,
333                                 text : "Part",
334                                 elConfig : function() {
335                                     return  {
336                                          xtype : '*top',
337                                             
338                                             app : 'TestApp',
339                                             // perm
340                                             // permtype
341                                             modkey : 0,
342                                             '|module' :  '',
343                                             region : 'center',
344                                             '|parent' : 'Pman',
345                                             name : "Module Name",
346                                             items: [] 
347                                 
348                                     
349                                     }
350                                 }
351                             }
352                         },
353                         menu : {
354                             xtype: 'Menu',
355                             xns: Roo.menu,
356                             items : [
357                                 {
358                                     xtype: 'Item',
359                                     xns: Roo.menu,
360                                     listeners : {
361                                         click : function (_self)
362                                         {
363                                             Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that node?",
364                                                 function(r) {
365                                                     if (r!='yes') {
366                                                         return;
367                                                     }
368                                                     _this.tree.deleteCurrent();
369                                                 }
370                                             );
371                                                 
372                                         }
373                                     },
374                                     text : "Delete Node"
375                                 },
376                                 {
377                                     xtype: 'Item',
378                                     xns: Roo.menu,
379                                     text : "Save as template"
380                                 }
381                             ]
382                         }
383                     }
384                 ],
385                 center : {
386                     xtype: 'LayoutRegion',
387                     xns: Roo
388                 },
389                 south : {
390                     xtype: 'LayoutRegion',
391                     xns: Roo,
392                     height : 300,
393                     split : true
394                 }
395             }
396         });
397         this.layout = this.panel.layout;
398
399     }
400 });