php7 fixes
[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                                     try{
225                                         delete _this.grid.currentNode.elConfig.listeners[n.substring(1)]; 
226                                     }catch(err){
227                                         delete _this.grid.currentNode.elConfig[n];
228                                         Roo.log(err);
229                                     }
230                                     
231                                 } else {
232                                     delete _this.grid.currentNode.elConfig[n];
233                                 }
234                                 // reloads      
235                                 _this.grid.setCurrrentNode(_this.grid.currentNode);
236                                 var bp = Pman.Tab.BuilderView.panel;
237                                 bp.redraw.defer(100,bp, [true]);
238                                 // update the tree's  text
239                                 _this.grid.currentNode.setText(
240                                     Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
241                                 );
242                             }
243                         },
244                         text : "Delete Property / Event"
245                     }
246                 ]
247             },
248             'menu2' : {
249                 xtype: 'Menu',
250                 xns: Roo.menu,
251                 items : [
252                     {
253                         xtype: 'Item',
254                         xns: Roo.menu,
255                         listeners : {
256                             click : function (_self, e)
257                             {
258                              
259                                 // show a dialog to select property??
260                                 // or should we add a line and get clever with pulldowns..
261                                 var ec = _this.grid.currentNode.elConfig;
262                             
263                                 Pman.Dialog.BuilderProp.show({
264                                         xtype : ec.xtype  || '',
265                                         xns: ec['|xns'] || '',
266                                         list: 'props'
267                                 }, function (n,val) {
268                                     ec[n] = val || '';
269                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
270                                     var bp = Pman.Tab.BuilderView.panel;
271                                     bp.redraw.defer(100,bp, [true]);
272                                     // update the tree's  text
273                                     _this.grid.currentNode.setText(
274                                         Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
275                                     );
276                                 });
277                             }
278                         },
279                         text : "Add Property"
280                     },
281                     {
282                         xtype: 'Item',
283                         xns: Roo.menu,
284                         listeners : {
285                             click : function (_self, e)
286                             {
287                              
288                                 // show a dialog to select property??
289                                 // or should we add a line and get clever with pulldowns..
290                                 var ec = _this.grid.currentNode.elConfig;
291                                 Pman.Dialog.BuilderProp.show({
292                                         xtype : ec.xtype  || '',
293                                         xns: ec['|xns'] || '',
294                                         list: 'events'
295                                 }, function (n,val) {
296                                     n = '!|' + n;
297                                     ec[n] = val || "function () {\n\n}";
298                                     _this.grid.setCurrrentNode(_this.grid.currentNode);
299                                     var bp = Pman.Tab.BuilderView.panel;
300                                     bp.redraw.defer(100,bp, [true]);
301                                     // update the tree's  text
302                                     _this.grid.currentNode.setText(
303                                         Pman.Builder.Tree.configToText(_this.grid.currentNode.elConfig)
304                                     );
305                                 });
306                             }
307                         },
308                         text : "Add Event Handler"
309                     },
310                     {
311                         xtype: 'Separator',
312                         xns: Roo.menu
313                     },
314                     {
315                         xtype: 'Item',
316                         xns: Roo.menu,
317                         listeners : {
318                             click : function (_self, e)
319                             {
320                              
321                                 // show a dialog to select property??
322                                 // or should we add a line and get clever with pulldowns..
323                             }
324                         },
325                         text : "Add User Defined Property"
326                     }
327                 ]
328             }
329         };
330     }
331 });