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 return ar['|xns'] +'.' + ar['xtype'];
94 toSourceStdClass: function()
96 var cfg = this.items[0]
97 var fcfg = XObject.extend({ }, this.items[0]);
98 delete fcfg['*class'];
99 delete fcfg['*extends'];
100 delete fcfg['*static'];
101 delete fcfg['|constructor'];
103 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
104 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
105 var isStatic = (typeof(cfg['*static']) == '*static');
110 newline = hasConstructor ?
113 cfg['//constructor'] + "\n" +
114 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
115 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
117 cfg['//*class'] + "\n" +
118 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
125 newline = hasConstructor ?
127 cfg['//constructor'] + "\n" +
128 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
129 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
131 cfg['//*class'] + "\n" +
132 cfg['*class'] + " = ";
135 endline = hasConstructor ? ');' : ';';
138 return this.outputHeader() +
140 this.objectToJsString(fcfg,1) +
149 copyTo: function(path, cb)
152 this.loadItems(function() {
164 * munges a prop object, removing all the special stuff..
165 * putting props back where they should go...
168 mungePropObj : function(o)
171 // console.log('mungePropObj: enter');
173 // standard props do not do anyting.
175 if (['items', '*prop'].indexOf(i) > -1) {
182 o.items = o.items || [];
184 o.items.forEach( function(e) {
185 if (typeof(e) == 'undefined') {
189 if (typeof(e) != 'object') {
190 // should not really hapen?!!?
191 ret.items.push(e); // could be
194 if (typeof(e['*prop']) != 'undefined') {
196 var val = _this.mungePropObj(e);
198 if (e['xtype'].match(/^Array/)) {
206 // handle fake arrays...
207 var val = _this.mungePropObj(e);
209 ret.items.push(val); // again should not really happen...
213 //console.log('mungePropObj: leave');
214 // do we munge '*' xtypes?
218 objectKeys : function(o) {
226 objectToJsString : function (o, ind)
232 var ix = new Array(ind+1).join(" ");
233 var ix1 = new Array(ind).join(" ");
236 if (k[0] == '+') { // + means hide from renderer.. we do not save this.
239 if (k[0] == '/') { // means hide from renderer.. we prefix the col with it..
244 if (typeof(v) == 'object') {
246 if ((v.constructor != Array) && !this.objectKeys(v).length) {
249 if ((v.constructor == Array) && !v.length && k == 'items') {
253 ret += ret.length ? ",\n" : '';
255 var kk = k[0] == '|' ? k.substring(1) : k;
256 if (typeof(o['//' + kk]) != 'undefined') {
257 ret += ix + o['//' + kk].split("\n").join( "\n" + ix) + "\n";
262 if (v.constructor == Array) {
263 ret += ix + this.toJsProp(k) + ' : ' + this.arrayToJsString(v, ind+1);
268 ret += ix + this.toJsProp(k) + ' : ' + this.objectToJsString(v, ind+1);
272 ret += ix + this.toJsProp(k) + ' : ' + (v ? 'true' : 'false');
276 ret += ix + this.toJsProp(k) + ' : ' + v;
282 ret += ix + this.toJsProp(k) + ' : ' + v.split("\n").join( "\n" + ix);
288 // we should use special stuff here to determine if it's a singly or dobuley
290 ret += ix + this.toJsProp(k) + ' : ' + this.stringToJsString(v, k, o);
296 return "{\n" + ret + "\n" + ix1 + '}';
299 arrayToJsString : function (ar, ind)
302 ar.forEach( function(o) {
303 if (typeof(o) == 'object' && (o.constructor != Array)) {
312 ix = new Array(ind+1).join(" ");
313 ix1 = new Array(ind).join(" ");
321 ar.forEach( function(v, n) {
322 // skip blank last element in an array
323 if ((n == (ar.length -1)) && typeof(v) == 'undefined') {
327 // empty objects in array?
328 if (typeof(v) == 'object' && v.constructor != Array) {
329 if (!_this.objectKeys(v).length) {
335 ret += ret.length ? cr : '';
340 if (v.constructor == Array) {
342 ret += ix + _this.arrayToJsString(v, ind+1);
346 ret += ix + _this.objectToJsString(v, ind+1);
350 ret += ix + (v ? 'true' : 'false');
360 ret += ix + v.split("\n").join( "\n" + ix);
366 // we should use special stuff here to determine if it's a singly or dobuley
368 ret += ix + JSON.stringify(v);
375 return "[" + lb + ret + lb + ix1 + "]";
378 stringToJsString : function(v, k , o) {
379 // since most properties can use single quotes (non-translatable)
380 // we try to fix this here..
381 var val = JSON.stringify(v);
382 if (['xns', 'xtype' ].indexOf(k) > -1) {
383 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
391 toJsProp: function(v) {
392 var vv = v[0] == '|' ? v.substring(1) : v;
393 if (Lang.isKeyword(vv) || Lang.isBuiltin(vv)) {
394 return "'" + vv + "'";
396 if (vv.match(/[^A-Z_]+/i)) {
397 var val = JSON.stringify(vv);
398 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";