891f983b9c6315ff67912a2157cced41bb28f7f6
[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                                     delete _this.grid.currentNode.elConfig.listeners[n.substring(1)];
183                                 } else {
184                                     delete _this.grid.currentNode.elConfig[n];
185                                 }
186                                 // reloads      
187                                 _this.grid.setCurrrentNode(_this.grid.currentNode);
188                                 var bp = Pman.Tab.BuilderView.panel;
189                                 bp.redraw.defer(100,bp, [true]);
190                                 // update the tree's  text
191                                 _this.grid.currentNode.setText(
192                                     Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
193                                 );
194                             }
195                         },
196                         text : "Toggle property as Javascript"
197                     },
198                     {
199                         xtype: 'Separator',
200                         xns: Roo.menu
201                     },
202                     {
203                         xtype: 'Item',
204                         xns: Roo.menu,
205                         listeners : {
206                             click : function (_self, e)
207                             {
208                              
209                                  var rc = _this.grid.getSelectionModel().getSelectedCell();
210                                  var n = _this.grid.getDataSource().getAt(rc[0]).data.name;
211                                  if (n == 'xtype') {
212                                     return;
213                                 }
214                                 if (n[0] == '!') {
215                                     delete _this.grid.currentNode.elConfig.listeners[n.substring(1)];
216                                 } else {
217                                     delete _this.grid.currentNode.elConfig[n];
218                                 }
219                                 // reloads      
220                                 _this.grid.setCurrrentNode(_this.grid.currentNode);
221                                 var bp = Pman.Tab.BuilderView.panel;
222                                 bp.redraw.defer(100,bp, [true]);
223                                 // update the tree's  text
224                                 _this.grid.currentNode.setText(
225                                     Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
226                                 );
227                             }
228                         },
229                         text : "Delete Property / Event"
230                     }
231                 ]
232             },
233             'menu2' : {
234                 xtype: 'Menu',
235                 xns: Roo.menu,
236                 items : [
237                     {
238                         xtype: 'Item',
239                         xns: Roo.menu,
240                         listeners : {
241                             click : function (_self, e)
242                             {
243                              
244                                 // show a dialog to select property??
245                                 // or should we add a line and get clever with pulldowns..
246                                 var ec = _this.grid.currentNode.elConfig;
247                                 Pman.Dialog.BuilderProp.show({
248                                         xtype : ec.xtype  || '',
249                                         xns: ec['|xns'] || '',
250                                         list: 'props'
251                                 }, function (n,val) {
252                                     ec[n] = val || '';
253                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
254                                     var bp = Pman.Tab.BuilderView.panel;
255                                     bp.redraw.defer(100,bp, [true]);
256                                     // update the tree's  text
257                                     _this.grid.currentNode.setText(
258                                         Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
259                                     );
260                                 });
261                             }
262                         },
263                         text : "Add Property"
264                     },
265                     {
266                         xtype: 'Item',
267                         xns: Roo.menu,
268                         listeners : {
269                             click : function (_self, e)
270                             {
271                              
272                                 // show a dialog to select property??
273                                 // or should we add a line and get clever with pulldowns..
274                                 var ec = _this.grid.currentNode.elConfig;
275                                 Pman.Dialog.BuilderProp.show({
276                                         xtype : ec.xtype  || '',
277                                         xns: ec['|xns'] || '',
278                                         list: 'events'
279                                 }, function (n,val) {
280                                     n = '!|' + n;
281                                     ec[n] = val || "function () {\n\n}";
282                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
283                                     var bp = Pman.Tab.BuilderView.panel;
284                                     bp.redraw.defer(100,bp, [true]);
285                                     // update the tree's  text
286                                     _this.grid.currentNode.setText(
287                                         Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
288                                     );
289                                 });
290                             }
291                         },
292                         text : "Add Event Handler"
293                     },
294                     {
295                         xtype: 'Separator',
296                         xns: Roo.menu
297                     },
298                     {
299                         xtype: 'Item',
300                         xns: Roo.menu,
301                         listeners : {
302                             click : function (_self, e)
303                             {
304                              
305                                 // show a dialog to select property??
306                                 // or should we add a line and get clever with pulldowns..
307                             }
308                         },
309                         text : "Add User Defined Property"
310                     }
311                 ]
312             }
313         };
314     }
315 });