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.
36 File.write(this.path, JSON.stringify(this.items);
41 * { success : , failure : , scope : }
47 getTree : function( o ) {
48 console.log("File.getTree tree called on base object?!?!");
50 toJsonArray : function()
54 ['id', 'name', 'parent', 'title', 'path'].forEach( function(k) {
64 return this.path.split('/').pop();
67 getTitleTip: function()
70 return '<b>' + this.title + '</b> ' + this.path;
76 this.cn.sort(function(a,b) {
77 return a.path > b.path;// ? 1 : -1;
84 toSourceStdClass: function()
86 var cfg = this.items[0]
87 var fcfg = XObject.extend({ }, this.items[0]);
88 delete fcfg['*class'];
89 delete fcfg['*extends'];
90 delete fcfg['*static'];
91 delete fcfg['|constructor'];
93 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
94 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
95 var isStatic = (typeof(cfg['*static']) == '*static');
100 newline = hasConstructor ?
103 cfg['//constructor'] + "\n" +
104 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
105 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
107 cfg['//*class'] + "\n" +
108 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
115 newline = hasConstructor ?
117 cfg['//constructor'] + "\n" +
118 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
119 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
121 cfg['//*class'] + "\n" +
122 cfg['*class'] + " = ";
125 endline = hasConstructor ? ');' : ';';
128 return this.outputHeader() +
130 this.objectToJsString(fcfg,1) +
139 copyTo: function(path, cb)
142 this.loadItems(function() {
154 * munges a prop object, removing all the special stuff..
155 * putting props back where they should go...
158 mungePropObj : function(o)
161 // console.log('mungePropObj: enter');
163 // standard props do not do anyting.
165 if (['items', '*prop'].indexOf(i) > -1) {
172 o.items = o.items || [];
174 o.items.forEach( function(e) {
175 if (typeof(e) == 'undefined') {
179 if (typeof(e) != 'object') {
180 // should not really hapen?!!?
181 ret.items.push(e); // could be
184 if (typeof(e['*prop']) != 'undefined') {
186 var val = _this.mungePropObj(e);
188 if (e['xtype'].match(/^Array/)) {
196 // handle fake arrays...
197 var val = _this.mungePropObj(e);
199 ret.items.push(val); // again should not really happen...
203 //console.log('mungePropObj: leave');
204 // do we munge '*' xtypes?
208 objectKeys : function(o) {
216 objectToJsString : function (o, ind)
222 var ix = new Array(ind+1).join(" ");
223 var ix1 = new Array(ind).join(" ");
226 if (k[0] == '+') { // + means hide from renderer.. we do not save this.
229 if (k[0] == '/') { // means hide from renderer.. we prefix the col with it..
234 if (typeof(v) == 'object') {
236 if ((v.constructor != Array) && !this.objectKeys(v).length) {
239 if ((v.constructor == Array) && !v.length && k == 'items') {
243 ret += ret.length ? ",\n" : '';
245 var kk = k[0] == '|' ? k.substring(1) : k;
246 if (typeof(o['//' + kk]) != 'undefined') {
247 ret += ix + o['//' + kk].split("\n").join( "\n" + ix) + "\n";
252 if (v.constructor == Array) {
253 ret += ix + this.toJsProp(k) + ' : ' + this.arrayToJsString(v, ind+1);
258 ret += ix + this.toJsProp(k) + ' : ' + this.objectToJsString(v, ind+1);
262 ret += ix + this.toJsProp(k) + ' : ' + (v ? 'true' : 'false');
266 ret += ix + this.toJsProp(k) + ' : ' + v;
272 ret += ix + this.toJsProp(k) + ' : ' + v.split("\n").join( "\n" + ix);
278 // we should use special stuff here to determine if it's a singly or dobuley
280 ret += ix + this.toJsProp(k) + ' : ' + this.stringToJsString(v, k, o);
286 return "{\n" + ret + "\n" + ix1 + '}';
289 arrayToJsString : function (ar, ind)
292 ar.forEach( function(o) {
293 if (typeof(o) == 'object' && (o.constructor != Array)) {
302 ix = new Array(ind+1).join(" ");
303 ix1 = new Array(ind).join(" ");
311 ar.forEach( function(v, n) {
312 // skip blank last element in an array
313 if ((n == (ar.length -1)) && typeof(v) == 'undefined') {
317 // empty objects in array?
318 if (typeof(v) == 'object' && v.constructor != Array) {
319 if (!_this.objectKeys(v).length) {
325 ret += ret.length ? cr : '';
330 if (v.constructor == Array) {
332 ret += ix + _this.arrayToJsString(v, ind+1);
336 ret += ix + _this.objectToJsString(v, ind+1);
340 ret += ix + (v ? 'true' : 'false');
350 ret += ix + v.split("\n").join( "\n" + ix);
356 // we should use special stuff here to determine if it's a singly or dobuley
358 ret += ix + JSON.stringify(v);
365 return "[" + lb + ret + lb + ix1 + "]";
368 stringToJsString : function(v, k , o) {
369 // since most properties can use single quotes (non-translatable)
370 // we try to fix this here..
371 var val = JSON.stringify(v);
372 if (['xns', 'xtype' ].indexOf(k) > -1) {
373 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
381 toJsProp: function(v) {
382 var vv = v[0] == '|' ? v.substring(1) : v;
383 if (Lang.isKeyword(vv) || Lang.isBuiltin(vv)) {
384 return "'" + vv + "'";
386 if (vv.match(/[^A-Z_]+/i)) {
387 var val = JSON.stringify(vv);
388 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";