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 && 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);
57 if (nodeName.match(/^#/)) { // comments?
67 if (nodeName != 'BODY') {
68 //Roo.log(currentElement);
69 if (currentElement.hasAttribute('flexy:include')) {
72 cb( '<flexy:include src="'+currentElement.getAttribute('flexy:include')+'"></flexy:include>');
77 // Prints the node tagName, such as <A>, <IMG>, etc
80 for(i = 0; i < currentElement.attributes.length;i++) {
81 var aname = currentElement.attributes.item(i).name;
86 if (currentElement.attributes.item(i).value == 'builderel') {
89 attr.push(aname + '="' + currentElement.attributes.item(i).value + '"' );
93 cb("<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">");
105 var currentElementChild = currentElement.childNodes.item(i);
107 while (currentElementChild) {
108 // Formatting code (indent the tree so it looks nice on the screen)
110 if (currentElementChild.nodeName == '#text') {
111 cb(currentElementChild.nodeValue);
113 currentElementChild=currentElement.childNodes.item(i);
118 for (j = 0; j < depth; j++) {
119 // ¦ is just a vertical line
124 // Recursively traverse the tree structure of the child node
125 this.traverseDOMTree(cb, currentElementChild, depth+1);
127 currentElementChild=currentElement.childNodes.item(i);
130 // The remaining code is mostly for formatting the tree
132 for (j = 0; j < depth - 1; j++) {
137 cb("</"+tagName+">");
143 // this lot is to deal with draging // selecting? - not used at present
147 findNode : function(ftg , method) {
151 // console.log(ftg.id);
152 if (ftg.id && typeof(ftg.id) == 'string' && ftg.id.match(/builder-/)) {
153 var nid = ftg.id.replace('builder-', '').replace('x-form-el-', '');
158 if (ftg.dom.className.match(/[0-9]+/)) {
159 //console.log(ftg.dom.className);
160 var cmat = ftg.dom.className.match(/x-grid-hd-builder-(form-gen-[0-9:]+)/);
162 this[method]( cmat[1] );
173 overPos: function(x,y)
176 var el = document.elementFromPoint(x,y);
177 // //console.log(el.id);
178 // console.log(document.body.innerHTML);
180 getTarget : function () {
183 stopEvent : function() {
190 onclick: function(e) {
191 var tg = Roo.get(e.getTarget());
193 //console.log('no target');
197 if (this.findNode(tg,'logClick')) {
200 var dp = Roo.get(tg.up(''));
201 if (dp && this.findNode(dp,'logClick')) {
205 var ns = Roo.get(tg.getNextSibling());
206 if (ns && this.findNode(ns,'logClick')) {
210 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logClick') ) {
214 for(var i =0; i < 5; i++) {
215 tg = Roo.get(tg.up(''));
217 //console.log('no parent' + i);
220 if (tg && this.findNode(tg,'logClick')) {
224 //console.log('no target in parents');
227 logClick : function(id)
229 var bid = id.length ? 'builder-' + id : '';
230 console.log('{ "id" : "' + bid + '"}');
234 hover : function(e) {
237 var tg = Roo.get(e.getTarget());
239 //console.log('no target');
244 if (this.findNode(tg,'logMove')) {
248 var dp = Roo.get(tg.up(''));
249 if (dp && this.findNode(dp,'logMove')) {
254 var ns = Roo.get(tg.getNextSibling());
255 if (ns && this.findNode(ns,'logMove')) {
259 if (ns && ns.down('') && this.findNode(Roo.get(ns.down('')) ,'logMove' )) {
264 for(var i =0; i < 5; i++) {
265 tg = Roo.get(tg.up(''));
267 //console.log('no parent' + i);
271 if (tg && this.findNode(tg,'logMove')) {
276 //console.log('no target in parents');
279 logMove : function (id) {
280 //console.log("LOGMOVE: " + id);
282 if (this.lastID === id) {
286 var bid = id.length ? 'builder-' + id : '';
287 //console.log('{ "hover-node" : "' + bid + '"}');
290 clearBootstrap : function()
292 // if the page is not bootstrap
294 if ( typeof(BuilderUseBootstrap) != 'undefined' ) {
295 Roo.log("it's boostrap - BuilderUseBootstrap is defined ");
296 // it's bootstrap - probably remove roo's css..
299 Roo.log("remove css = BuilderUseBootstrap is not defined");
301 var ar = document.getElementsByTagName('link');
302 for (var i = 0; i < ar.length;i++) {
304 Roo.log(l.getAttribute('href'));
305 if (l.getAttribute('href').match(/bootstrap/)) {
312 Roo.each(rem, function(l) { l.parentNode.removeChild(l);});
315 applyFlexy: function(tree)
317 if (typeof(tree['flexy:foreach']) != 'undefined') {
318 //Roo.log("add flexy:foreach");
319 tree.el.attr('flexy:foreach', tree['flexy:foreach']);
321 if (typeof(tree['flexy:if']) != 'undefined') {
322 //Roo.log("add flexy:if");
323 tree.el.attr('flexy:if', tree['flexy:if']);
325 if (typeof(tree['xtype-bootstrap']) != 'undefined') {
326 //Roo.log("add flexy:if");
327 tree.el.attr('xtype', tree['xtype-bootstrap']);
330 if (typeof(tree['flexy:include']) != 'undefined') {
331 //Roo.log("add flexy:if");
332 tree.el.attr('flexy:include', tree['flexy:include']);
335 if (typeof(tree['flexy:ignore']) != 'undefined') {
336 //Roo.log("add flexy:if");
337 tree.el.attr('flexy:ignore', tree['flexy:ignore']);
340 //Roo.log("Add xtype")
341 tree.el.attr('xtype', tree['|xns'] + '.' + tree['xtype']);
342 if (!tree.items || !tree.items.length) { return; }
344 for (var i = 0; i < tree.items.length; i++){
345 this.applyFlexy(tree.items[i]);
347 if (typeof(tree.menu) != 'undefined') {
348 this.applyFlexy(tree.menu);
357 Roo.onReady(function() { Builder.clearBootstrap(); });
358 Roo.XComponent.on('buildcomplete', function() {
359 Roo.log("xcomponent built!");
360 var m = Roo.XComponent.modules;
361 Builder.applyFlexy(m[m.length-1].el);
363 Builder.saveHTML.defer(100, Builder);