sync
[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                         _this.grid.currentNode.elConfig[id] = v;
96                         _this.grid.setSourceFromNode(_this.grid.currentNode.elConfig);
97                         
98                         var bp = Pman.Tab.BuilderView.panel;
99                         bp.redraw.defer(100,bp, [true]);
100                         _this.grid.currentNode.setText(
101                             Pman.Tab.BuilderTree.tree.configToText(_this.grid.currentNode.elConfig)
102                         );
103                     },
104                     contextmenu : function (e)
105                     {
106                         // should we check e..??
107                         _this.panel.menu2 = Roo.factory(_this.panel.menu2);
108                         
109                         _this.panel.menu2.show(e.getTarget());
110                         e.stopEvent()
111                     
112                     }
113                 },
114                 setCurrrentNode : function(node) {
115                    
116                     
117                     this.view.el.unmask();
118                     
119                     if (!node || !node.elConfig) {
120                         this.currentNode = false;
121                         this.setSourceFromNode({});
122                         this.view.el.mask('select a node');
123                     } else {
124                         this.currentNode = node;
125                         this.setSourceFromNode(this.currentNode.elConfig);
126                         
127                     }
128                     
129                 },
130                 setSourceFromNode : function(config) {
131                    
132                         
133                     var cfg = {};
134                     for (var k in config) {
135                         //if (k.charAt(0) == '*') {
136                         //    continue; // dont show props..
137                         //}
138                         
139                         if (k  == 'listeners') {
140                             for (var kk in config[k]) {
141                                 cfg['!' + kk ] = config[k][kk];
142                             }
143                             
144                             continue;
145                         }
146                         if (k  == 'items') {
147                             continue;
148                         }
149                         
150                         if (typeof config[k] == 'object') {
151                             
152                             try {
153                                 var ec = Roo.encode(config[k]);
154                                 cfg[k] = ec;
155                             } catch(e) {}
156                             continue;
157                         }
158                         cfg[k] = config[k];
159                     }
160                     
161                     if (!cfg.xtype) {
162                         return;
163                     }
164                 
165                     this.setSource(cfg);
166                 
167                     
168                       
169                 }
170             },
171             menu : {
172                 xtype: 'Menu',
173                 xns: Roo.menu,
174                 items : [
175                     {
176                         xtype: 'Item',
177                         xns: Roo.menu,
178                         listeners : {
179                             click : function (_self, e)
180                             {
181                              
182                                  var rc = _this.grid.getSelectionModel().getSelectedCell();
183                                  var n = _this.grid.getDataSource().getAt(rc[0]).data.name;
184                                  if (n == 'xtype') {
185                                     return;
186                                 }
187                                 if (n[0] == '!') {
188                                     delete _this.grid.currentNode.elConfig.listeners[n.substring(1)];
189                                 } else {
190                                     delete _this.grid.currentNode.elConfig[n];
191                                 }
192                                 // reloads      
193                                 _this.grid.setCurrrentNode(_this.grid.currentNode);
194                                 var bp = Pman.Tab.BuilderView.panel;
195                                 bp.redraw.defer(100,bp, [true]);
196                                 // update the tree's  text
197                                 _this.grid.currentNode.setText(
198                                     Pman.Tab.BuilderTree.tree.configToText(_this.grid.currentNode.elConfig)
199                                 );
200                             }
201                         },
202                         text : "Delete Property / Event"
203                     }
204                 ]
205             },
206             'menu2' : {
207                 xtype: 'Menu',
208                 xns: Roo.menu,
209                 items : [
210                     {
211                         xtype: 'Item',
212                         xns: Roo.menu,
213                         listeners : {
214                             click : function (_self, e)
215                             {
216                              
217                                 // show a dialog to select property??
218                                 // or should we add a line and get clever with pulldowns..
219                                 var ec = _this.grid.currentNode.elConfig;
220                                 Pman.Dialog.BuilderProp.show({
221                                         xtype : ec.xtype  || '',
222                                         xns: ec['|xns'] || '',
223                                         list: 'props'
224                                 }, function (n,val) {
225                                     ec[n] = val || '';
226                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
227                                     var bp = Pman.Tab.BuilderView.panel;
228                                     bp.redraw.defer(100,bp, [true]);
229                                     // update the tree's  text
230                                     _this.grid.currentNode.setText(
231                                         Pman.Tab.BuilderTree.tree.configToText(_this.grid.currentNode.elConfig)
232                                     );
233                                 });
234                             }
235                         },
236                         text : "Add Property"
237                     },
238                     {
239                         xtype: 'Item',
240                         xns: Roo.menu,
241                         listeners : {
242                             click : function (_self, e)
243                             {
244                              
245                                 // show a dialog to select property??
246                                 // or should we add a line and get clever with pulldowns..
247                                 var ec = _this.grid.currentNode.elConfig;
248                                 Pman.Dialog.BuilderProp.show({
249                                         xtype : ec.xtype  || '',
250                                         xns: ec['|xns'] || '',
251                                         list: 'events'
252                                 }, function (n,val) {
253                                     ec[n] = val || "function () {\n\n}";
254                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
255                                     var bp = Pman.Tab.BuilderView.panel;
256                                     bp.redraw.defer(100,bp, [true]);
257                                     // update the tree's  text
258                                     _this.grid.currentNode.setText(
259                                         Pman.Tab.BuilderTree.tree.configToText(_this.grid.currentNode.elConfig)
260                                     );
261                                 });
262                             }
263                         },
264                         text : "Add Event Handler"
265                     },
266                     {
267                         xtype: 'Separator',
268                         xns: Roo.menu
269                     },
270                     {
271                         xtype: 'Item',
272                         xns: Roo.menu,
273                         listeners : {
274                             click : function (_self, e)
275                             {
276                              
277                                 // show a dialog to select property??
278                                 // or should we add a line and get clever with pulldowns..
279                             }
280                         },
281                         text : "Add User Defined Property"
282                     }
283                 ]
284             }
285         });
286         this.layout = this.panel.layout;
287
288     }
289 });