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