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