1 //<script type="text/javascript">
4 // IPC: - via alert("IPC:{method}:{data}
7 var MODULE = { isBuilder : true };
20 saveHTML : function( )
22 //print("TRAVERSE DOM?");
24 var dom = document.body;
27 //Roo.select('body > div',true).each(function(el) {
28 // if the tree is not ready yet?
31 this.traverseDOMTree(function(s) { ret+=s; }, dom, 1);
32 alert("IPC:SAVEHTML:" + ret);
37 traverseDOMTree : function(cb, currentElement, depth) {
38 if (!currentElement) {
42 console.log(currentElement);
43 if (currentElement.className.match(/roo-dynamic/)) {
47 //Roo.log(currentElement);
49 var nodeName = currentElement.nodeName;
50 var tagName = currentElement.tagName;
52 if (nodeName == '#text') {
53 cb(currentElement.nodeValue);
64 if (nodeName != 'BODY') {
69 // Prints the node tagName, such as <A>, <IMG>, etc
72 for(i = 0; i < currentElement.attributes.length;i++) {
73 var aname = currentElement.attributes.item(i).name;
78 if (currentElement.attributes.item(i).value == 'builderel') {
81 attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' );
85 cb("<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
95 var currentElementChild = currentElement.childNodes.item(i);
97 while (currentElementChild) {
98 // Formatting code (indent the tree so it looks nice on the screen)
100 if (currentElementChild.nodeName == '#text') {
101 cb(currentElementChild.nodeValue);
103 currentElementChild=currentElement.childNodes.item(i);
108 for (j = 0; j < depth; j++) {
109 // ¦ is just a vertical line
114 // Recursively traverse the tree structure of the child node
115 this.traverseDOMTree(cb, currentElementChild, depth+1);
117 currentElementChild=currentElement.childNodes.item(i);
120 // The remaining code is mostly for formatting the tree
122 for (j = 0; j < depth - 1; j++) {
127 cb("</"+tagName+">");
133 // this lot is to deal with draging // selecting? - not used at present
137 findNode : function(ftg , method) {
141 // console.log(ftg.id);
142 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
143 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
148 if (ftg.dom.className.match(/[0-9]+/)) {
149 //console.log(ftg.dom.className);
150 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
152 this[method]( cmat[1] );
163 overPos: function(x,y)
166 var el = document.elementFromPoint(x,y);
167 // //console.log(el.id);
168 // console.log(document.body.innerHTML);
170 getTarget : function () {
173 stopEvent : function() {
180 onclick: function(e) {
181 var tg = Roo.get(e.getTarget());
183 //console.log('no target');
187 if (this.findNode(tg,'logClick')) {
190 var dp = Roo.get(tg.up(''));
191 if (dp && this.findNode(dp,'logClick')) {
195 var ns = Roo.get(tg.getNextSibling());
196 if (ns && this.findNode(ns,'logClick')) {
200 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
204 for(var i =0; i < 5; i++) {
205 tg = Roo.get(tg.up(''));
207 //console.log('no parent' + i);
210 if (tg && this.findNode(tg,'logClick')) {
214 //console.log('no target in parents');
217 logClick : function(id)
219 var bid = id.length ? 'builder-' + id : '';
220 console.log('{ "id" : "' + bid + '"}');
224 hover : function(e) {
227 var tg = Roo.get(e.getTarget());
229 //console.log('no target');
234 if (this.findNode(tg,'logMove')) {
238 var dp = Roo.get(tg.up(''));
239 if (dp && this.findNode(dp,'logMove')) {
244 var ns = Roo.get(tg.getNextSibling());
245 if (ns && this.findNode(ns,'logMove')) {
249 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
254 for(var i =0; i < 5; i++) {
255 tg = Roo.get(tg.up(''));
257 //console.log('no parent' + i);
261 if (tg && this.findNode(tg,'logMove')) {
266 //console.log('no target in parents');
269 logMove : function (id) {
270 //console.log("LOGMOVE: " + id);
272 if (this.lastID === id) {
276 var bid = id.length ? 'builder-' + id : '';
277 console.log('{ "hover-node" : "' + bid + '"}');
280 clearBootstrap : function()
282 // if the page is not bootstrap
284 if ( typeof(BuilderUseBootstrap) != 'undefined' ) {
285 Roo.log("it's boostrap - BuilderUseBootstrap is defined ");
286 // it's bootstrap - probably remove roo's css..
289 Roo.log("remove css = BuilderUseBootstrap is not defined");
291 var ar = document.getElementsByTagName('link');
292 for (var i = 0; i < ar.length;i++) {
294 Roo.log(l.getAttribute('href'));
295 if (l.getAttribute('href').match(/bootstrap/)) {
302 Roo.each(rem, function(l) { l.parentNode.removeChild(l);});
305 applyFlexy: function(tree)
307 if (typeof(tree['flexy:foreach']) != 'undefined') {
308 //Roo.log("add flexy:foreach");
309 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
311 if (typeof(tree['flexy:if']) != 'undefined') {
312 //Roo.log("add flexy:if");
313 tree.el.attr('flexy:if', tree['flexy:if']);
315 if (typeof(tree['xtype-bootstrap']) != 'undefined') {
316 //Roo.log("add flexy:if");
317 tree.el.attr('xtype', tree['xtype-bootstrap']);
321 if (!tree.items || !tree.items.length) { return; }
323 for (var i = 0; i < tree.items.length; i++){
324 this.applyFlexy(tree.items[i]);
331 Roo.onReady(function() { Builder.clearBootstrap(); });
332 Roo.XComponent.on('buildcomplete', function() {
333 Roo.log("xcomponent built!");
335 Builder.applyFlexy(Roo.XComponent.modules[0].el);