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(' ') ) : '') + ">");
93 if (currentElement.hasAttribute('flexy:include')) {
94 cb( tagName ? "</"+tagName+">" : '');
99 var currentElementChild = currentElement.childNodes.item(i);
101 while (currentElementChild) {
102 // Formatting code (indent the tree so it looks nice on the screen)
104 if (currentElementChild.nodeName == '#text') {
105 cb(currentElementChild.nodeValue);
107 currentElementChild=currentElement.childNodes.item(i);
112 for (j = 0; j < depth; j++) {
113 // ¦ is just a vertical line
118 // Recursively traverse the tree structure of the child node
119 this.traverseDOMTree(cb, currentElementChild, depth+1);
121 currentElementChild=currentElement.childNodes.item(i);
124 // The remaining code is mostly for formatting the tree
126 for (j = 0; j < depth - 1; j++) {
131 cb("</"+tagName+">");
137 // this lot is to deal with draging // selecting? - not used at present
141 findNode : function(ftg , method) {
145 // console.log(ftg.id);
146 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
147 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
152 if (ftg.dom.className.match(/[0-9]+/)) {
153 //console.log(ftg.dom.className);
154 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
156 this[method]( cmat[1] );
167 overPos: function(x,y)
170 var el = document.elementFromPoint(x,y);
171 // //console.log(el.id);
172 // console.log(document.body.innerHTML);
174 getTarget : function () {
177 stopEvent : function() {
184 onclick: function(e) {
185 var tg = Roo.get(e.getTarget());
187 //console.log('no target');
191 if (this.findNode(tg,'logClick')) {
194 var dp = Roo.get(tg.up(''));
195 if (dp && this.findNode(dp,'logClick')) {
199 var ns = Roo.get(tg.getNextSibling());
200 if (ns && this.findNode(ns,'logClick')) {
204 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
208 for(var i =0; i < 5; i++) {
209 tg = Roo.get(tg.up(''));
211 //console.log('no parent' + i);
214 if (tg && this.findNode(tg,'logClick')) {
218 //console.log('no target in parents');
221 logClick : function(id)
223 var bid = id.length ? 'builder-' + id : '';
224 console.log('{ "id" : "' + bid + '"}');
228 hover : function(e) {
231 var tg = Roo.get(e.getTarget());
233 //console.log('no target');
238 if (this.findNode(tg,'logMove')) {
242 var dp = Roo.get(tg.up(''));
243 if (dp && this.findNode(dp,'logMove')) {
248 var ns = Roo.get(tg.getNextSibling());
249 if (ns && this.findNode(ns,'logMove')) {
253 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
258 for(var i =0; i < 5; i++) {
259 tg = Roo.get(tg.up(''));
261 //console.log('no parent' + i);
265 if (tg && this.findNode(tg,'logMove')) {
270 //console.log('no target in parents');
273 logMove : function (id) {
274 //console.log("LOGMOVE: " + id);
276 if (this.lastID === id) {
280 var bid = id.length ? 'builder-' + id : '';
281 console.log('{ "hover-node" : "' + bid + '"}');
284 clearBootstrap : function()
286 // if the page is not bootstrap
288 if ( typeof(BuilderUseBootstrap) != 'undefined' ) {
289 Roo.log("it's boostrap - BuilderUseBootstrap is defined ");
290 // it's bootstrap - probably remove roo's css..
293 Roo.log("remove css = BuilderUseBootstrap is not defined");
295 var ar = document.getElementsByTagName('link');
296 for (var i = 0; i < ar.length;i++) {
298 Roo.log(l.getAttribute('href'));
299 if (l.getAttribute('href').match(/bootstrap/)) {
306 Roo.each(rem, function(l) { l.parentNode.removeChild(l);});
309 applyFlexy: function(tree)
311 if (typeof(tree['flexy:foreach']) != 'undefined') {
312 //Roo.log("add flexy:foreach");
313 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
315 if (typeof(tree['flexy:if']) != 'undefined') {
316 //Roo.log("add flexy:if");
317 tree.el.attr('flexy:if', tree['flexy:if']);
319 if (typeof(tree['xtype-bootstrap']) != 'undefined') {
320 //Roo.log("add flexy:if");
321 tree.el.attr('xtype', tree['xtype-bootstrap']);
324 if (typeof(tree['flexy:include']) != 'undefined') {
325 //Roo.log("add flexy:if");
326 tree.el.attr('flexy:include', tree['flexy:include']);
329 tree.el.attr('xtype', tree['|xns'] + '.' + tree['xtype']);
330 if (!tree.items || !tree.items.length) { return; }
332 for (var i = 0; i < tree.items.length; i++){
333 this.applyFlexy(tree.items[i]);
340 Roo.onReady(function() { Builder.clearBootstrap(); });
341 Roo.XComponent.on('buildcomplete', function() {
342 Roo.log("xcomponent built!");
343 var m = Roo.XComponent.modules;
344 Builder.applyFlexy(m[m.length-1].el);
346 Builder.saveHTML.defer(100, Builder);