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;
84 guessName : function(ar) // turns the object into full name.
86 // eg. xns: Roo, xtype: XXX -> Roo.xxx
87 if (typeof( ar['|xns'] ) == 'undefined' || typeof( ar['xtype'] ) == 'undefined') {
91 return ar['|xns'] +'.' + ar['xtype'];
98 toSourceStdClass: function()
100 var cfg = this.items[0]
101 var fcfg = XObject.extend({ }, this.items[0]);
102 delete fcfg['*class'];
103 delete fcfg['*extends'];
104 delete fcfg['*static'];
105 delete fcfg['|constructor'];
107 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
108 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
109 var isStatic = (typeof(cfg['*static']) == '*static');
114 newline = hasConstructor ?
117 cfg['//constructor'] + "\n" +
118 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
119 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
121 cfg['//*class'] + "\n" +
122 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
129 newline = hasConstructor ?
131 cfg['//constructor'] + "\n" +
132 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
133 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
135 cfg['//*class'] + "\n" +
136 cfg['*class'] + " = ";
139 endline = hasConstructor ? ');' : ';';
142 return this.outputHeader() +
144 this.objectToJsString(fcfg,1) +
153 copyTo: function(path, cb)
156 this.loadItems(function() {
168 * munges a prop object, removing all the special stuff..
169 * putting props back where they should go...
172 mungePropObj : function(o)
175 // console.log('mungePropObj: enter');
177 // standard props do not do anyting.
179 if (['items', '*prop'].indexOf(i) > -1) {
186 o.items = o.items || [];
188 o.items.forEach( function(e) {
189 if (typeof(e) == 'undefined') {
193 if (typeof(e) != 'object') {
194 // should not really hapen?!!?
195 ret.items.push(e); // could be
198 if (typeof(e['*prop']) != 'undefined') {
200 var val = _this.mungePropObj(e);
202 if (e['xtype'].match(/^Array/)) {
210 // handle fake arrays...
211 var val = _this.mungePropObj(e);
213 ret.items.push(val); // again should not really happen...
217 //console.log('mungePropObj: leave');
218 // do we munge '*' xtypes?
222 objectKeys : function(o) {
230 objectToJsString : function (o, ind)
236 var ix = new Array(ind+1).join(" ");
237 var ix1 = new Array(ind).join(" ");
240 if (k[0] == '+') { // + means hide from renderer.. we do not save this.
243 if (k[0] == '/') { // means hide from renderer.. we prefix the col with it..
248 if (typeof(v) == 'object') {
250 if ((v.constructor != Array) && !this.objectKeys(v).length) {
253 if ((v.constructor == Array) && !v.length && k == 'items') {
257 ret += ret.length ? ",\n" : '';
259 var kk = k[0] == '|' ? k.substring(1) : k;
260 if (typeof(o['//' + kk]) != 'undefined') {
261 ret += ix + o['//' + kk].split("\n").join( "\n" + ix) + "\n";
266 if (v.constructor == Array) {
267 ret += ix + this.toJsProp(k) + ' : ' + this.arrayToJsString(v, ind+1);
272 ret += ix + this.toJsProp(k) + ' : ' + this.objectToJsString(v, ind+1);
276 ret += ix + this.toJsProp(k) + ' : ' + (v ? 'true' : 'false');
280 ret += ix + this.toJsProp(k) + ' : ' + v;
286 ret += ix + this.toJsProp(k) + ' : ' + v.split("\n").join( "\n" + ix);
292 // we should use special stuff here to determine if it's a singly or dobuley
294 ret += ix + this.toJsProp(k) + ' : ' + this.stringToJsString(v, k, o);
300 return "{\n" + ret + "\n" + ix1 + '}';
303 arrayToJsString : function (ar, ind)
306 ar.forEach( function(o) {
307 if (typeof(o) == 'object' && (o.constructor != Array)) {
316 ix = new Array(ind+1).join(" ");
317 ix1 = new Array(ind).join(" ");
325 ar.forEach( function(v, n) {
326 // skip blank last element in an array
327 if ((n == (ar.length -1)) && typeof(v) == 'undefined') {
331 // empty objects in array?
332 if (typeof(v) == 'object' && v.constructor != Array) {
333 if (!_this.objectKeys(v).length) {
339 ret += ret.length ? cr : '';
344 if (v.constructor == Array) {
346 ret += ix + _this.arrayToJsString(v, ind+1);
350 ret += ix + _this.objectToJsString(v, ind+1);
354 ret += ix + (v ? 'true' : 'false');
364 ret += ix + v.split("\n").join( "\n" + ix);
370 // we should use special stuff here to determine if it's a singly or dobuley
372 ret += ix + JSON.stringify(v);
379 return "[" + lb + ret + lb + ix1 + "]";
382 stringToJsString : function(v, k , o) {
383 // since most properties can use single quotes (non-translatable)
384 // we try to fix this here..
385 var val = JSON.stringify(v);
386 if (['xns', 'xtype' ].indexOf(k) > -1) {
387 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
395 toJsProp: function(v) {
396 var vv = v[0] == '|' ? v.substring(1) : v;
397 if (Lang.isKeyword(vv) || Lang.isBuiltin(vv)) {
398 return "'" + vv + "'";
400 if (vv.match(/[^A-Z_]+/i)) {
401 var val = JSON.stringify(vv);
402 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";