1 //<Script type="text/javascript">
3 console = imports.console;
4 XObject = imports.XObject.XObject;
6 Lang = imports.Builder.Provider.File.Lang.Lang;
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.
37 var data = ['name', 'parent', 'title', 'items'].forEach( function(k) {
40 print("WRITE: " + this.path + "\n" + JSON.stringify(write));
41 //File.write(this.path, JSON.stringify(write));
46 * { success : , failure : , scope : }
52 getTree : function( o ) {
53 console.log("File.getTree tree called on base object?!?!");
55 toJsonArray : function()
59 ['id', 'name', 'parent', 'title', 'path'].forEach( function(k) {
69 return this.path.split('/').pop();
72 getTitleTip: function()
75 return '<b>' + this.title + '</b> ' + this.path;
81 this.cn.sort(function(a,b) {
82 return a.path > b.path;// ? 1 : -1;
89 toSourceStdClass: function()
91 var cfg = this.items[0]
92 var fcfg = XObject.extend({ }, this.items[0]);
93 delete fcfg['*class'];
94 delete fcfg['*extends'];
95 delete fcfg['*static'];
96 delete fcfg['|constructor'];
98 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
99 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
100 var isStatic = (typeof(cfg['*static']) == '*static');
105 newline = hasConstructor ?
108 cfg['//constructor'] + "\n" +
109 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
110 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
112 cfg['//*class'] + "\n" +
113 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
120 newline = hasConstructor ?
122 cfg['//constructor'] + "\n" +
123 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
124 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
126 cfg['//*class'] + "\n" +
127 cfg['*class'] + " = ";
130 endline = hasConstructor ? ');' : ';';
133 return this.outputHeader() +
135 this.objectToJsString(fcfg,1) +
144 copyTo: function(path, cb)
147 this.loadItems(function() {
159 * munges a prop object, removing all the special stuff..
160 * putting props back where they should go...
163 mungePropObj : function(o)
166 // console.log('mungePropObj: enter');
168 // standard props do not do anyting.
170 if (['items', '*prop'].indexOf(i) > -1) {
177 o.items = o.items || [];
179 o.items.forEach( function(e) {
180 if (typeof(e) == 'undefined') {
184 if (typeof(e) != 'object') {
185 // should not really hapen?!!?
186 ret.items.push(e); // could be
189 if (typeof(e['*prop']) != 'undefined') {
191 var val = _this.mungePropObj(e);
193 if (e['xtype'].match(/^Array/)) {
201 // handle fake arrays...
202 var val = _this.mungePropObj(e);
204 ret.items.push(val); // again should not really happen...
208 //console.log('mungePropObj: leave');
209 // do we munge '*' xtypes?
213 objectKeys : function(o) {
221 objectToJsString : function (o, ind)
227 var ix = new Array(ind+1).join(" ");
228 var ix1 = new Array(ind).join(" ");
231 if (k[0] == '+') { // + means hide from renderer.. we do not save this.
234 if (k[0] == '/') { // means hide from renderer.. we prefix the col with it..
239 if (typeof(v) == 'object') {
241 if ((v.constructor != Array) && !this.objectKeys(v).length) {
244 if ((v.constructor == Array) && !v.length && k == 'items') {
248 ret += ret.length ? ",\n" : '';
250 var kk = k[0] == '|' ? k.substring(1) : k;
251 if (typeof(o['//' + kk]) != 'undefined') {
252 ret += ix + o['//' + kk].split("\n").join( "\n" + ix) + "\n";
257 if (v.constructor == Array) {
258 ret += ix + this.toJsProp(k) + ' : ' + this.arrayToJsString(v, ind+1);
263 ret += ix + this.toJsProp(k) + ' : ' + this.objectToJsString(v, ind+1);
267 ret += ix + this.toJsProp(k) + ' : ' + (v ? 'true' : 'false');
271 ret += ix + this.toJsProp(k) + ' : ' + v;
277 ret += ix + this.toJsProp(k) + ' : ' + v.split("\n").join( "\n" + ix);
283 // we should use special stuff here to determine if it's a singly or dobuley
285 ret += ix + this.toJsProp(k) + ' : ' + this.stringToJsString(v, k, o);
291 return "{\n" + ret + "\n" + ix1 + '}';
294 arrayToJsString : function (ar, ind)
297 ar.forEach( function(o) {
298 if (typeof(o) == 'object' && (o.constructor != Array)) {
307 ix = new Array(ind+1).join(" ");
308 ix1 = new Array(ind).join(" ");
316 ar.forEach( function(v, n) {
317 // skip blank last element in an array
318 if ((n == (ar.length -1)) && typeof(v) == 'undefined') {
322 // empty objects in array?
323 if (typeof(v) == 'object' && v.constructor != Array) {
324 if (!_this.objectKeys(v).length) {
330 ret += ret.length ? cr : '';
335 if (v.constructor == Array) {
337 ret += ix + _this.arrayToJsString(v, ind+1);
341 ret += ix + _this.objectToJsString(v, ind+1);
345 ret += ix + (v ? 'true' : 'false');
355 ret += ix + v.split("\n").join( "\n" + ix);
361 // we should use special stuff here to determine if it's a singly or dobuley
363 ret += ix + JSON.stringify(v);
370 return "[" + lb + ret + lb + ix1 + "]";
373 stringToJsString : function(v, k , o) {
374 // since most properties can use single quotes (non-translatable)
375 // we try to fix this here..
376 var val = JSON.stringify(v);
377 if (['xns', 'xtype' ].indexOf(k) > -1) {
378 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
386 toJsProp: function(v) {
387 var vv = v[0] == '|' ? v.substring(1) : v;
388 if (Lang.isKeyword(vv) || Lang.isBuiltin(vv)) {
389 return "'" + vv + "'";
391 if (vv.match(/[^A-Z_]+/i)) {
392 var val = JSON.stringify(vv);
393 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";