php7 fixes
[Pman.Builder] / Pman.Tab.BuilderEvents.js
1 //<script type="text/javascript">
2   
3 // tab on left...  
4 /*
5 Pman.on('beforeload', function()
6 {
7     
8     
9     Pman.register({
10         modKey : '002-pman-tab-builderevents',
11         module : Pman.Tab.BuilderEvents,
12         region : 'south',
13         parent : Pman.Tab.BuilderTree,
14         name : "Builder Events"
15     });
16      
17 });
18
19 Pman.Tab.BuilderEvents = {
20     grid : false,
21     panel : false,
22     loaded : false,
23     currentNode : false, // pointer to edited node.
24     add : function(parentLayout, region) {
25         
26         var _this = this;
27         
28         
29         if (this.panel) {
30             parentLayout.getRegion(region).showPanel(this.panel);
31             return;
32         }
33        
34        
35         parentLayout.beginUpdate();
36        
37         var frm = parentLayout.getRegion(region).getEl().createChild({tag:'div'});
38         //this.grid = new Roo.grid.EditorGrid(frm,  {
39         this.grid = new Roo.grid.PropertyGrid(frm,  {
40                 id: 'grid-builderevents',
41                 toolbar: true,
42                 //nameText: 'Properties Grid',
43                 enableHdMenu: false,
44                 viewConfig : {
45                     forceFit:true//,
46                   //  scrollOffset:2 // the grid will never have scrollbars
47                 },
48                 clicksToEdit : 1,
49                 
50                 loadMask: true,
51
52                 listeners : {
53                   
54                     propertychange : function(s, id, v, ov) {
55                         //console.log(id + ':'+ v);
56                         _this.currentNode.elConfig.listeners = _this.currentNode.elConfig.listeners || {};
57                         _this.currentNode.elConfig.listeners[id] = v;
58                         // no need to update view..
59                         //var bp = Pman.Tab.BuilderPanel;
60                         //bp.redraw.defer(100,bp);
61                         //_this.currentNode.setText(
62                         //    Pman.Tab.BuilderTree.configToText(_this.currentNode.elConfig)
63                         //);
64                     },
65                     cellclick :function (g, ri, ci, e)
66                     {
67                        // console.log('rowclick');
68                         //console.log(e);
69                         if (ci == 0) {
70                             _this.menu.show(e.getTarget(), 'tr');
71                             return;
72                         }
73                         // other wise edith it!!!
74                         var data = _this.grid.getDataSource().getAt(ri).data;
75                         Pman.Dialog.BuilderSourceEdit.show({
76                             title : data.name,
77                             value : data.value
78                         }, function(d) {
79                             _this.currentNode.elConfig.listeners[data.name] = d.value;
80                             _this.setCurrrentNode(_this.currentNode);
81                             // no point in redrawing the panel!!!
82                             //var bp = Pman.Tab.BuilderPanel;
83                             //bp.redraw.defer(100,bp);
84                         });
85                         
86                         
87                         
88                         
89                         //console.log(e);
90                         // click on left col..
91                         // show menu..
92                        // _this.menu.show(e.getTarget(), 'tr');
93                     }
94                 }
95                  
96         });
97         
98         this.menu =  new Roo.menu.Menu({
99
100             items: [
101                 {
102                     text: 'Delete Listener',
103
104                     handler : function() {
105                         var rc = _this.grid.getSelectionModel().getSelectedCell();
106                         var n = _this.grid.getDataSource().getAt(rc[0]).data.name;
107                         
108                         delete _this.currentNode.elConfig.listeners[n];
109                         _this.setCurrrentNode(_this.currentNode);
110                         //var bp = Pman.Tab.BuilderPanel;
111                         //bp.redraw.defer(100,bp);
112                         //_this.currentNode.setText(
113                         //    Pman.Tab.BuilderTree.configToText(_this.currentNode.elConfig)
114                         //);
115                     }
116                 } 
117                 
118             ]
119         });
120             
121         this.panel  = parentLayout.add(region,  new Roo.GridPanel(this.grid ,
122             { fitToframe: true,fitContainer: true, title: "Events", background: true })
123         );
124         this.grid.render();
125         
126         this.grid.getColumnModel().renderPropDelegate = function(v,p) {
127             return String.format('<b qtip="{0}">{1}</b>', _this.getDesc(v),v );
128         };
129         
130         var gridHead = this.grid.getView().getHeaderPanel(true);
131         //this.toolbar = new Roo.Toolbar(gridHead);
132         this.toolbar = new Roo.Toolbar(gridHead.createChild({tag: 'span'}));
133        
134        
135        
136         this.addsel = new Roo.form.ComboBox({
137             
138          
139             selectOnFocus:true,
140            
141             allowBlank : true,
142             width: 150,
143             editable: false,
144             
145             store: {
146                 xtype : 'Store',
147                 
148                   // load using HTTP
149                 proxy: {
150                     xtype: 'HttpProxy',
151                     url: baseURL + '/Builder/PropList.php',
152                     method: 'GET'
153                     
154                 }, 
155                 listeners : {
156                     beforeload: function(s, o) {
157                         o.params = o.params || {}; 
158                         if (!_this.currentNode || !_this.currentNode.elConfig) {
159                             return false;
160                         }
161                         o.params.xtype =  _this.currentNode.elConfig.xtype;
162                          o.params.xns=  _this.currentNode.elConfig['|xns'] || '';
163                         o.params.view = 'listeners'
164                     }
165                 },
166                 reader: {
167                     root : 'data',
168                     totalProperty : 'total',
169                     id : 'id',
170                     xtype : 'JsonReader',
171                     fields : [
172                         'name', 'desc', 'type', 'sig'
173                     ]
174
175                 }
176             },
177             
178             displayField:'name',
179             valueField : 'name',
180             
181             typeAhead: true,
182             forceSelection: true,
183            
184             triggerAction: 'all',
185              
186             tpl: new Roo.Template(
187                 '<div class="x-grid-cell-text x-btn button" qtip="\{desc\}">',
188                     '<b >\{name\}</b> [\{type\}] ',
189                 '</div>'
190             ),
191              
192             queryParam: 'query[name]',
193             loadingText: "Searching...",
194             listWidth: 300,
195            
196             minChars: 2,
197             //pageSize:20,
198             listeners : {
199                 select :  function(cb, rec, ix) {
200                     cb.lastData = rec.data;
201                     _this.addProp(rec.data.name, rec.data.sig);
202                     this.reset();
203                     // add a field...
204                 },
205                 collapse : function()
206                 {
207                     this.lastQuery = '~~~~~~~~'; // force a query!
208                 }
209             },
210             lastData : false 
211         
212              
213              
214         });
215
216
217
218        
219        
220         this.toolbar.add('Add:', this.addsel); 
221         
222         
223         // add stuff to toolbar?
224         //this.innerLayout.endUpdate();
225         parentLayout.endUpdate();
226         
227         
228     },
229     
230     setCurrrentNode : function(node) {
231         var p = this.grid;
232         p.view.el.unmask();
233         
234         if (!node || !node.elConfig) {
235             this.currentNode = false;
236             p.setSource({});
237             p.view.el.mask('select a node');
238         } else {
239             node.elConfig.listeners= node.elConfig.listeners || { };
240             if (node.elConfig.listener) { // kludge to fix old bug.
241                 delete node.elConfig.listener;
242             }
243             var config = node.elConfig.listeners;
244                
245             
246             // for anything that is a onject - ecode it to set it..
247             // probably should dupe the config first..
248             ncfg = {};
249             for (var k in config) {
250                 
251                 ncfg[k] = config[k];
252             }
253             //p.setSource(ncfg);
254             this.currentNode = node;
255             this.setSource(ncfg);
256             
257             //if (node.fEl == this.builderPanel) {
258         //              p.disable();
259         //      }
260         }
261     },
262      
263     
264     getDesc :function(prop) {
265          
266        
267         if (typeof(this.currentNode.elConfig) == 'undefined') {
268              return '?';
269         }
270         var cfg = this.currentNode.elConfig;
271         
272         var data = this.getPropDef(cfg.xtype, cfg['|xns']);
273         var pp= prop.replace('|', '');
274         
275         if ((typeof(data[pp]) == 'undefined') || (typeof(data[pp].desc) == 'undefined')) {
276             return '';
277         }
278         return data[pp].desc;
279        
280        
281     },
282     
283     
284     getPropDef : function(xtype,xns)
285     {
286         // phase this out..!
287         this.propdefs = Pman.Tab.BuilderProps.propdefs;
288         
289         var xpre = xns ? (xns + '.') :  '';
290         if (typeof(this.propdefs[xpre + xtype]) != 'undefined') {
291             return this.propdefToMap(xpre +  xtype);
292         }
293         
294         for (var i in [ 'Roo',  'Roo.menu' , 'Roo.form',  'Roo.data',   'Roo.grid',   'Roo.Toolbar' ]) {
295             if (typeof(this.propdefs[i +'.' + xtype]) != 'undefined') {
296                 return this.propdefToMap(i +'.' + xtype);
297             }
298         }
299         return {};
300         
301     },
302     // map the props!!
303     propdefToMap : function(cls)
304     {
305         var ret = {};
306         if ((typeof(this.propdefs[cls].events) == 'undefined') || !this.propdefs[cls].events.length) {
307             return ret; 
308         };
309         Roo.each(this.propdefs[cls].events, function(c) {
310             ret[c.name] = c;
311         });
312         return ret;
313     },
314     
315     
316     setSource : function(ltns)
317     {
318         
319         var et = {}; // editor type
320         var _this =this;   
321         for(var k in ltns) {
322             et[k] = false; // not really...
323         }
324         
325         _this.grid.customEditors = et;
326         _this.grid.setSource(ltns);
327         
328         
329     },
330     addProp:  function (name, sig) { // messy but will do..
331         this.currentNode.elConfig.listeners = this.currentNode.elConfig.listeners || { };
332        
333         var c = this.currentNode.elConfig.listeners;
334         if (typeof(c['|' +name]) != 'undefined') {
335             return;
336         }
337         // get sig..
338         c['|' + name] = sig;
339         this.setSource(c);
340         var _this = this;
341         Pman.Dialog.BuilderSourceEdit.show({
342             title : name,
343             value : sig
344         }, function(d) {
345             _this.currentNode.elConfig.listeners['|'+ name] = d.value;
346             _this.setCurrrentNode(_this.currentNode);
347             //var bp = Pman.Tab.BuilderPanel;
348             //bp.redraw.defer(100,bp);
349         });
350         
351         //this.currentNode.setText(
352         //    Pman.Tab.BuilderTree.configToText(this.currentNode.elConfig)
353         //);
354     }
355     
356 };
357
358 // tab in admin 
359
360 */