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