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                             dupeNode : function(node)
126                                 {
127                                     var cfg = this.cloneConfig(node.elConfig);
128                                     
129                                     var newNode = new Roo.tree.TreeNode(
130                                     {
131                                             id: Roo.id(),
132                                             text: this.configToText(cfg)
133                                     });
134                                     
135                                     newNode.elConfig = cfg;
136                                     node.eachChild(function(n) {
137                                         newNode.appendChild(this.dupeNode(n));
138                                     },this);
139                                     
140                                     return newNode;
141                                         
142                                 },
143                             loadBJS : function(module, part) {
144                                 var _t = this;
145                                 new Pman.Request({
146                                     url : baseURL + '/Roo/Builder_part.php',
147                                     method : 'GET',
148                                     params : {
149                                        _id : part
150                                     },
151                                     success : function(res)         
152                                     {
153                                         // data is in.. 
154                                         Roo.log(res);
155                                         
156                                         if (!res.data.json.length) {
157                                             var cfg = _t.defaultElConfig();
158                                             cfg.name = Pman.Tab.BuilderTop.filesel.lastData.name;
159                                             cfg.part = Pman.Tab.BuilderTop.filesel.lastData.name;
160                                             cfg.module = '';
161                                             _t.loadTree(cfg);
162                                             return;
163                                         
164                                         }
165                                         
166                                         _t.loadTree(JSON.parse(res.data.json));
167                                         
168                                      
169                                     }
170                             
171                                  })  
172                                     
173                                 
174                                 
175                             },
176                             loadTree : function(o) {
177                                 this.clearAll();
178                                 this.root.elConfig = o;
179                                 this.root.setText(this.configToText(this.root.elConfig));
180                                 this.appendNode(this.root, o.items[0]);
181                                 this.root.expand(true);
182                                 Pman.Tab.BuilderView.panel.redraw();
183                                 this.setCurrentNode(this.root,true);
184                             },
185                             nodeXtype : function(n) {
186                                  if (!n) {return ''; }
187                                 var xt = n.elConfig.xtype ||  '';
188                                 var xns= n.elConfig['|xns'] ||   '';
189                                 xns += xns.length ? '.' : '';
190                                 return xns + xt;
191                             },
192                             renderer : function(n) { return n.text; },
193                             setCurrentNode : function(node,select) {
194                                     this.currentNode = node || this.root;
195                                     
196                                     //Pman.Tab.BuilderView.highlightElement(this.currentNode);
197                             
198                                     var p = Pman.Tab.BuilderProps.grid;
199                                     if (p) { //may not be ready yet..
200                                         p.setCurrrentNode(this.currentNode);
201                                     }
202                                     
203                                   
204                                     this.currentNode.setText(this.configToText(this.currentNode.elConfig));
205                                     
206                                     if (select) { //&& node !== this.tree.root) {
207                                         if (this.currentNode !== this.root)  {
208                                                  this.currentNode.ensureVisible();
209                                           }   
210                                          this.currentNode.expand(false,false);
211                                         this.currentNode.select();
212                                 }
213                                 // update palete..
214                                 Pman.Tab.BuilderPalette.grid.getSelectionModel().clearSelections();
215                                 Pman.Tab.BuilderPalette.grid.view.refresh();
216                             
217                             },
218                             toJS : function(n)
219                             {
220                                 if (!n) {
221                                     return this.toJS(this.root);
222                                 }
223                                 var _this = this;
224                                 var ret = this.cloneConfig(n.elConfig);
225                                 if (n.childNodes.length) {
226                                     ret.items = [];
227                                     n.eachChild(function(cn) {
228                                         ret.items.push(_this.toJS(cn));
229                                     });
230                                         
231                                 }
232                                 return ret;
233                                   
234                                  
235                             },
236                             sm : {
237                                 xtype: 'DefaultSelectionModel',
238                                 xns: Roo.tree
239                             },
240                             root : {
241                                 xtype: 'TreeNode',
242                                 xns: Roo.tree,
243                                 text : "Part",
244                                 elConfig : function() {
245                                     return  {
246                                          xtype : '*top',
247                                             
248                                             app : 'TestApp',
249                                             // perm
250                                             // permtype
251                                             modkey : 0,
252                                             '|module' :  '',
253                                             region : 'center',
254                                             '|parent' : 'Pman',
255                                             name : "Module Name",
256                                             items: [] 
257                                 
258                                     
259                                     }
260                                 }
261                             }
262                         },
263                         menu : {
264                             xtype: 'Menu',
265                             xns: Roo.menu,
266                             items : [
267                                 {
268                                     xtype: 'Item',
269                                     xns: Roo.menu,
270                                     listeners : {
271                                         click : function (_self)
272                                         {
273                                             Roo.MessageBox.confirm("Confirm", "Are you sure you want to delete that node?",
274                                                 function(r) {
275                                                     if (r!='yes') {
276                                                         return;
277                                                     }
278                                                     _this.tree.deleteCurrent();
279                                                 }
280                                             );
281                                                 
282                                         }
283                                     },
284                                     text : "Delete Node"
285                                 },
286                                 {
287                                     xtype: 'Item',
288                                     xns: Roo.menu,
289                                     text : "Save as template"
290                                 }
291                             ]
292                         }
293                     }
294                 ],
295                 center : {
296                     xtype: 'LayoutRegion',
297                     xns: Roo
298                 },
299                 south : {
300                     xtype: 'LayoutRegion',
301                     xns: Roo,
302                     height : 300,
303                     split : true
304                 }
305             }
306         });
307         this.layout = this.panel.layout;
308
309     }
310 });