Pman.Tab.BuilderView.js
[Pman.Builder] / Pman.Tab.BuilderView.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.BuilderView',
12         module : Pman.Tab.BuilderView,
13         region : 'center',
14         parent : Pman.Tab.BuilderTab,
15         name : "Pman.Tab.BuilderView",
16         disabled : false, 
17         permname: '' 
18     });
19 });
20
21 Pman.Tab.BuilderView = 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: 'ContentPanel',
35             xns: Roo,
36             listeners : {
37                 activate : function (_self)
38                 {
39                     _this.panel = _self;
40                 }
41             },
42             region : 'center',
43             title : "View",
44             clearAll : function(isAuto) {
45             //        this.renderObj = { isBuilder : true };
46             
47                     
48                     if (this.panelroot) {
49                         this.scroll = this.panelroot.el.getScroll();
50                         this.layout.remove('center', this.panelroot);
51                         this.panelroot = false;
52                     }
53                     if (this.dialogroot) {
54                         this.dialogroot.remove();
55                         this.dialogroot = false;
56                     }
57             },
58             munge : function(cfg, keyname) {
59                 keyname = keyname || false;
60                 
61                 this.renderObj = this.renderObj || {};
62                 
63                 var xitems = false;
64                 if (cfg.items) {
65                     xitems = cfg.items;
66                     delete cfg.items;
67                 }
68                 
69                 if (typeof(cfg.background) != 'undefined') {
70                     cfg.background = false;
71                 }
72                 
73                 
74                 for(var p in cfg){
75                     // key is not string?!?!?!!?
76                     if (typeof(p) != 'string') {
77                         continue;
78                     }
79                     
80                     if (typeof(cfg[p]) == 'object') { // listeners!!!
81                         this.munge(cfg[p], p);
82                         continue;
83                     }
84                     // SPECIAL - PIPE
85                     if (p.charAt(0) == '|' || keyname=='listeners') {
86                         
87                         if (!cfg[p].length) {
88                             delete cfg[p];
89                             continue;
90                         }
91                         var str = cfg[p];
92                         if (str.match(/\s*function/)) {
93                             var btz = str.split('{');
94                             str = btz.shift()  +'{ try {' + btz.join('{') + 
95                                 ' catch (e) { Roo.log(e) } }';
96                         }
97                         try {
98                             var _tmp = false;
99                             var _this = this.renderObj; /// fake '_this' object..
100                             // stupid IE can not return objects evaluated..
101                             /**
102                              eval:var:_this  
103                              eval:var:_tmp 
104                             **/
105                             
106                             
107                             eval('_tmp =(' + str + ')');
108                             cfg[p.replace(/^\|/, '')] = _tmp;
109                             if (typeof(_tmp) == 'undefined') {
110                                 alert(cfg[p]);
111                             }
112                            
113                         } catch(e) {  console.log('Error evaluating: '  + str); };
114                         if (p.charAt(0) == '|' ) {
115                             delete cfg[p];
116                         }
117                             
118                         
119                         continue;
120                     }
121                     // skip '*'
122                     if ((p.charAt(0) == '*') || (p.charAt(0) == '+')) {
123                         delete cfg[p];
124                         continue;
125                     }
126                     // normal..
127                       
128                 }
129                 // now for all the children.. (items)
130                 if (xitems === false) {
131                     return;
132                 }
133                 cfg.items = [];
134                 for (var i = 0; i < xitems.length; i++) {
135                     // if +builderhide set !!!! drop it!!
136                     
137                     
138                     var xi = xitems[i];
139                     if (typeof(xi['*prop']) != 'undefined') {
140                         var pr = xi['*prop'];
141                         this.munge(xi);
142                         // if prop is an array - then it's items are really the value..
143                         if (pr.match(/\[\]$/)) {
144                             pr = pr.replace(/\[\]$/, '');
145                             if (typeof(cfg[pr]) == 'undefined') {
146                                 cfg[pr] = [];
147                             }
148                             cfg[pr].push(xi);
149                             continue;
150                         }
151                         if (xi.xtype && xi.xtype  == 'Array') {
152                             cfg[pr] = xi.items;
153                         } else {
154                             cfg[pr] = xi;
155                         }
156                         
157                         
158                         continue;
159                     }
160                     this.munge(xi);
161                     cfg.items.push(xi);
162                 }
163                 
164                 if (cfg.items.length == 0) {
165                     delete cfg.items;
166                 }
167                 // remove listeners if there are none..
168                 if (typeof(cfg['listeners']) != 'undefined') {
169                     var n =0;
170                     for (var i in cfg.listeners) { n++; }
171                     if (!n) {
172                         delete cfg['listeners'];
173                     }
174                     
175                 }
176                 
177                 if (typeof(cfg.id) != 'undefined') {
178                     cfg.id = 'pman-dyn-' + cfg.id;
179                 }
180                     
181                     
182             },
183             redraw : function(isAuto)
184                 {
185                     
186                     // top level is not relivant
187             
188             //          var btop =  Pman.Tab.BuilderTop2;
189               //      if (isAuto && btop.redrawBtn  && !btop.redrawBtn.auto) {
190                 //        return; /// auto redraw is turned off..
191                   //  }
192                     
193                     this.clearAll(isAuto);
194                     
195                     var cfg =  this.toJS();
196                     if (!cfg.items[0]) {
197                         return;
198                     }
199                     
200                     
201                     this.munge(cfg.items[0]);
202                     
203                     // we draw either a dialog or a tab..
204                     
205                     if (cfg.items[0].xtype == 'LayoutDialog') {
206                         
207                         cfg.items[0].modal = false;
208                         var xy  = this.el.getXY();
209                         cfg.items[0].x = xy[0];
210                         cfg.items[0].y = xy[1];
211                         cfg.items[0].constraintoviewport = false;
212                     
213                         this.dialogroot = Roo.get( document.body).createChild();
214                          
215                         this.dialog = new Roo[cfg.items[0].xtype](this.dialogroot, cfg.items[0]);
216                       //  this.dialog.el.on('click', this.panelClick, this);
217                         this.dialog.show();
218                         var dlg = this.dialog;
219                         (function () {
220                             dlg.moveTo(xy[0], xy[1]);
221                         }).defer(100);
222                         return;
223                         
224                     }
225                     // should we render this into a dialog???
226                          // force center region..
227                     cfg.items[0].region = 'center';
228                     cfg.items[0].background = false;
229                     
230                     this.panelroot = _this.parentLayout.addxtype(cfg.items[0]);
231                     
232                      
233                     //this.highlightElement(Pman.Tab.BuilderTree.currentNode);
234                     
235                     if (this.panelroot.el) {
236                             this.panelroot.el.scrollTo('top', this.scroll.top);
237                             this.panelroot.el.scrollTo('left', this.scroll.left);
238                         
239                     }
240                 },
241             toJS : function(n) {
242                 var bt = Pman.Tab.BuilderTree.tree;
243                 if (!n) {
244                     return this.toJS(bt.root);
245                 }
246             
247                 var _this = this;
248                 var ret = bt.cloneConfig(n.elConfig);
249                 
250                 // flag to prevent rendering..
251                 if ((typeof(ret['+buildershow']) != 'undefined') && !ret['+buildershow']) {
252                     return false;
253                 }
254             
255                 ret.id = typeof(ret.id) == 'undefined' ? 'builder-' + n.id : ret.id;
256             
257                 if (n.childNodes.length) {
258                     ret.items = [];
259                     n.eachChild(function(cn) {
260                         var add = _this.toJS(cn);
261                         if (add === false) {
262                             return;
263                         }
264                         
265                         
266                         ret.items.push(add);
267                     });
268                         
269                 }
270                 return ret;
271             }
272         });
273         this.layout = this.panel.layout;
274
275     }
276 });