1 //<Script type="text/javascript">
3 console = imports.console;
4 XObject = imports.XObject.XObject;
6 Lang = imports.Builder.Provider.File.Lang.Lang;
8 File = imports.File.File;
11 Base = XObject.define(
15 XObject.extend(this, cfg);
21 name : false, // is the JS name of the file.
22 path : '', // is the full path to the file.
23 parent : false, // JS parent.
25 title : false, // a title.. ?? nickname.. ??? -
26 project: false, // name...
27 Project : false, // link to container project!
29 items : false, // the tree of nodes.
31 cn : false, // array used by project tree.
38 var write = this.toJsonArray()
39 print("WRITE: " + this.path + "\n" + JSON.stringify(write));
40 File.write(this.path, JSON.stringify(write));
45 * { success : , failure : , scope : }
51 getTree : function( o ) {
52 console.log("File.getTree tree called on base object?!?!");
54 toJsonArray : function()
58 ['id', 'name', 'parent', 'title', 'path', 'items'].forEach( function(k) {
68 return this.path.split('/').pop();
71 getTitleTip: function()
74 return '<b>' + this.title + '</b> ' + this.path;
80 this.cn.sort(function(a,b) {
81 return a.path > b.path;// ? 1 : -1;
88 toSourceStdClass: function()
90 var cfg = this.items[0]
91 var fcfg = XObject.extend({ }, this.items[0]);
92 delete fcfg['*class'];
93 delete fcfg['*extends'];
94 delete fcfg['*static'];
95 delete fcfg['|constructor'];
97 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
98 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
99 var isStatic = (typeof(cfg['*static']) == '*static');
104 newline = hasConstructor ?
107 cfg['//constructor'] + "\n" +
108 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
109 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
111 cfg['//*class'] + "\n" +
112 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
119 newline = hasConstructor ?
121 cfg['//constructor'] + "\n" +
122 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
123 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
125 cfg['//*class'] + "\n" +
126 cfg['*class'] + " = ";
129 endline = hasConstructor ? ');' : ';';
132 return this.outputHeader() +
134 this.objectToJsString(fcfg,1) +
143 copyTo: function(path, cb)
146 this.loadItems(function() {
158 * munges a prop object, removing all the special stuff..
159 * putting props back where they should go...
162 mungePropObj : function(o)
165 // console.log('mungePropObj: enter');
167 // standard props do not do anyting.
169 if (['items', '*prop'].indexOf(i) > -1) {
176 o.items = o.items || [];
178 o.items.forEach( function(e) {
179 if (typeof(e) == 'undefined') {
183 if (typeof(e) != 'object') {
184 // should not really hapen?!!?
185 ret.items.push(e); // could be
188 if (typeof(e['*prop']) != 'undefined') {
190 var val = _this.mungePropObj(e);
192 if (e['xtype'].match(/^Array/)) {
200 // handle fake arrays...
201 var val = _this.mungePropObj(e);
203 ret.items.push(val); // again should not really happen...
207 //console.log('mungePropObj: leave');
208 // do we munge '*' xtypes?
212 objectKeys : function(o) {
220 objectToJsString : function (o, ind)
226 var ix = new Array(ind+1).join(" ");
227 var ix1 = new Array(ind).join(" ");
230 if (k[0] == '+') { // + means hide from renderer.. we do not save this.
233 if (k[0] == '/') { // means hide from renderer.. we prefix the col with it..
238 if (typeof(v) == 'object') {
240 if ((v.constructor != Array) && !this.objectKeys(v).length) {
243 if ((v.constructor == Array) && !v.length && k == 'items') {
247 ret += ret.length ? ",\n" : '';
249 var kk = k[0] == '|' ? k.substring(1) : k;
250 if (typeof(o['//' + kk]) != 'undefined') {
251 ret += ix + o['//' + kk].split("\n").join( "\n" + ix) + "\n";
256 if (v.constructor == Array) {
257 ret += ix + this.toJsProp(k) + ' : ' + this.arrayToJsString(v, ind+1);
262 ret += ix + this.toJsProp(k) + ' : ' + this.objectToJsString(v, ind+1);
266 ret += ix + this.toJsProp(k) + ' : ' + (v ? 'true' : 'false');
270 ret += ix + this.toJsProp(k) + ' : ' + v;
276 ret += ix + this.toJsProp(k) + ' : ' + v.split("\n").join( "\n" + ix);
282 // we should use special stuff here to determine if it's a singly or dobuley
284 ret += ix + this.toJsProp(k) + ' : ' + this.stringToJsString(v, k, o);
290 return "{\n" + ret + "\n" + ix1 + '}';
293 arrayToJsString : function (ar, ind)
296 ar.forEach( function(o) {
297 if (typeof(o) == 'object' && (o.constructor != Array)) {
306 ix = new Array(ind+1).join(" ");
307 ix1 = new Array(ind).join(" ");
315 ar.forEach( function(v, n) {
316 // skip blank last element in an array
317 if ((n == (ar.length -1)) && typeof(v) == 'undefined') {
321 // empty objects in array?
322 if (typeof(v) == 'object' && v.constructor != Array) {
323 if (!_this.objectKeys(v).length) {
329 ret += ret.length ? cr : '';
334 if (v.constructor == Array) {
336 ret += ix + _this.arrayToJsString(v, ind+1);
340 ret += ix + _this.objectToJsString(v, ind+1);
344 ret += ix + (v ? 'true' : 'false');
354 ret += ix + v.split("\n").join( "\n" + ix);
360 // we should use special stuff here to determine if it's a singly or dobuley
362 ret += ix + JSON.stringify(v);
369 return "[" + lb + ret + lb + ix1 + "]";
372 stringToJsString : function(v, k , o) {
373 // since most properties can use single quotes (non-translatable)
374 // we try to fix this here..
375 var val = JSON.stringify(v);
376 if (['xns', 'xtype' ].indexOf(k) > -1) {
377 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
385 toJsProp: function(v) {
386 var vv = v[0] == '|' ? v.substring(1) : v;
387 if (Lang.isKeyword(vv) || Lang.isBuiltin(vv)) {
388 return "'" + vv + "'";
390 if (vv.match(/[^A-Z_]+/i)) {
391 var val = JSON.stringify(vv);
392 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";