Pman.Tab.BuilderProps.js
[Pman.Builder] / Pman.Tab.BuilderProps.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","Props"],
12         modKey : '001-Pman.Tab.BuilderProps',
13         module : Pman.Tab.BuilderProps,
14         region : 'center',
15         parent : Pman.Tab.BuilderTree,
16         name : "Pman.Tab.BuilderProps",
17         disabled : false, 
18         permname: '' 
19     });
20 });
21
22 Pman.Tab.BuilderProps = 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: 'GridPanel',
36             xns: Roo,
37             region : 'south',
38             grid : {
39                 xtype: 'PropertyGrid',
40                 xns: Roo.grid,
41                 listeners : {
42                     render : function (grid)
43                     {
44                         _this.grid = grid;
45                     },
46                     afteredit : function (e)
47                     {
48                        // change this..
49                        //this.currentNode.elConfig
50                        
51                        
52                     },
53                     cellclick : function (_self, rowIndex, ci, e)
54                     {
55                          if (ci != 0) {
56                             return;
57                         }
58                         //console.log(e);
59                         // click on left col..
60                         // show menu..
61                         // make sure it's initialized..
62                         _this.panel.menu = Roo.factory(_this.panel.menu);
63                         
64                         _this.panel.menu.show(e.getTarget(), 'tr');
65                     },
66                     beforeedit : function (e)
67                     {
68                        Roo.log('beforeedit');
69                        Roo.log(e.record.data);
70                        var key = e.record.data.name;
71                        var val = e.record.data.value;
72                        // source code edit..
73                        if (key.match(/^\|/) || key.match(/^\!/)) {
74                             Pman.Dialog.BuilderSourceEdit.show( { value :  val }, function(d) {
75                                 // perhaps we should eval it..
76                             
77                                 _this.grid.currentNode.elConfig[key] = d.value;
78                                 _this.grid.setSourceFromNode(_this.grid.currentNode.elConfig);
79                                 _this.grid.fireEvent('propertychange', 
80                                     Pman.Tab.BuilderProps.grid, key, d.value, false
81                                 );
82                             });
83                             e.cancel = true;
84                             return;
85                        }
86                     },
87                     propertychange : function (grid, id, v, oldval)
88                     {
89                         if (v == 'false') {
90                             v = false;
91                         }
92                         if (v == 'true') {
93                             v = true;
94                         }
95                         if (!id.length) {
96                             return;
97                         }
98                         var ec = _this.grid.currentNode.elConfig.listeners ;
99                         if (id[0] == '!') {
100                             ec.listeners = ec.listeners || {};
101                             ec.listeners[id.substring(1)] = v;
102                         } else { 
103                             _this.grid.currentNode.elConfig[id] = v;
104                         }
105                         
106                         
107                         _this.grid.setSourceFromNode(_this.grid.currentNode.elConfig);
108                         
109                         var bp = Pman.Tab.BuilderView.panel;
110                         bp.redraw.defer(100,bp, [true]);
111                         _this.grid.currentNode.setText(
112                             Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
113                         );
114                     },
115                     contextmenu : function (e)
116                     {
117                         // should we check e..??
118                         _this.panel.menu2 = Roo.factory(_this.panel.menu2);
119                         
120                         _this.panel.menu2.show(e.getTarget());
121                         e.stopEvent()
122                     
123                     }
124                 },
125                 setCurrrentNode : function(node) {
126                    
127                     
128                     this.view.el.unmask();
129                     
130                     if (!node || !node.elConfig) {
131                         this.currentNode = false;
132                         this.setSourceFromNode({});
133                         this.view.el.mask('select a node');
134                     } else {
135                         this.currentNode = node;
136                         this.setSourceFromNode(this.currentNode.elConfig);
137                         
138                     }
139                     
140                 },
141                 setSourceFromNode : function(config) {
142                    
143                         
144                     var cfg = {};
145                     for (var k in config) {
146                         //if (k.charAt(0) == '*') {
147                         //    continue; // dont show props..
148                         //}
149                         
150                         if (k  == 'listeners') {
151                             for (var kk in config[k]) {
152                                 cfg['!' + kk ] = config[k][kk];
153                             }
154                             
155                             continue;
156                         }
157                         if (k  == 'items') {
158                             continue;
159                         }
160                         
161                         if (typeof config[k] == 'object') {
162                             
163                             try {
164                                 var ec = Roo.encode(config[k]);
165                                 cfg[k] = ec;
166                             } catch(e) {}
167                             continue;
168                         }
169                         cfg[k] = config[k];
170                     }
171                     
172                     if (!cfg.xtype) {
173                         return;
174                     }
175                 
176                     this.setSource(cfg);
177                 
178                     
179                       
180                 }
181             },
182             menu : {
183                 xtype: 'Menu',
184                 xns: Roo.menu,
185                 items : [
186                     {
187                         xtype: 'Item',
188                         xns: Roo.menu,
189                         listeners : {
190                             click : function (_self, e)
191                             {
192                              
193                                  var rc = _this.grid.getSelectionModel().getSelectedCell();
194                                  var n = _this.grid.getDataSource().getAt(rc[0]).data.name;
195                                  if (n == 'xtype') {
196                                     return;
197                                 }
198                                 if (n[0] == '!') {
199                                     delete _this.grid.currentNode.elConfig.listeners[n.substring(1)];
200                                 } else {
201                                     delete _this.grid.currentNode.elConfig[n];
202                                 }
203                                 // reloads      
204                                 _this.grid.setCurrrentNode(_this.grid.currentNode);
205                                 var bp = Pman.Tab.BuilderView.panel;
206                                 bp.redraw.defer(100,bp, [true]);
207                                 // update the tree's  text
208                                 _this.grid.currentNode.setText(
209                                     Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
210                                 );
211                             }
212                         },
213                         text : "Delete Property / Event"
214                     }
215                 ]
216             },
217             'menu2' : {
218                 xtype: 'Menu',
219                 xns: Roo.menu,
220                 items : [
221                     {
222                         xtype: 'Item',
223                         xns: Roo.menu,
224                         listeners : {
225                             click : function (_self, e)
226                             {
227                              
228                                 // show a dialog to select property??
229                                 // or should we add a line and get clever with pulldowns..
230                                 var ec = _this.grid.currentNode.elConfig;
231                                 Pman.Dialog.BuilderProp.show({
232                                         xtype : ec.xtype  || '',
233                                         xns: ec['|xns'] || '',
234                                         list: 'props'
235                                 }, function (n,val) {
236                                     ec[n] = val || '';
237                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
238                                     var bp = Pman.Tab.BuilderView.panel;
239                                     bp.redraw.defer(100,bp, [true]);
240                                     // update the tree's  text
241                                     _this.grid.currentNode.setText(
242                                         Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
243                                     );
244                                 });
245                             }
246                         },
247                         text : "Add Property"
248                     },
249                     {
250                         xtype: 'Item',
251                         xns: Roo.menu,
252                         listeners : {
253                             click : function (_self, e)
254                             {
255                              
256                                 // show a dialog to select property??
257                                 // or should we add a line and get clever with pulldowns..
258                                 var ec = _this.grid.currentNode.elConfig;
259                                 Pman.Dialog.BuilderProp.show({
260                                         xtype : ec.xtype  || '',
261                                         xns: ec['|xns'] || '',
262                                         list: 'events'
263                                 }, function (n,val) {
264                                     n = '!|' + n; // force the type..
265                                     ec[n] = val || "function () {\n\n}";
266                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
267                                     var bp = Pman.Tab.BuilderView.panel;
268                                     bp.redraw.defer(100,bp, [true]);
269                                     // update the tree's  text
270                                     _this.grid.currentNode.setText(
271                                         Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
272                                     );
273                                 });
274                             }
275                         },
276                         text : "Add Event Handler"
277                     },
278                     {
279                         xtype: 'Separator',
280                         xns: Roo.menu
281                     },
282                     {
283                         xtype: 'Item',
284                         xns: Roo.menu,
285                         listeners : {
286                             click : function (_self, e)
287                             {
288                              
289                                 // show a dialog to select property??
290                                 // or should we add a line and get clever with pulldowns..
291                             }
292                         },
293                         text : "Add User Defined Property"
294                     }
295                 ]
296             }
297         });
298         this.layout = this.panel.layout;
299
300     }
301 });