1 //<Script type="text/javascript">
3 console = imports.console;
4 XObject = imports.XObject.XObject;
6 Lang = imports.Builder.Provider.File.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 * { success : , failure : , scope : }
42 getTree : function( o ) {
43 console.log("File.getTree tree called on base object?!?!");
45 toJsonArray : function()
49 ['id', 'name', 'parent', 'title', 'path'].forEach( function(k) {
59 return this.path.split('/').pop();
62 getTitleTip: function()
65 return '<b>' + this.title + '</b> ' + this.path;
71 this.cn.sort(function(a,b) {
72 return a.path > b.path;// ? 1 : -1;
79 toSourceStdClass: function()
81 var cfg = this.items[0]
82 var fcfg = XObject.extend({ }, this.items[0]);
83 delete fcfg['*class'];
84 delete fcfg['*extends'];
85 delete fcfg['*static'];
86 delete fcfg['|constructor'];
88 var hasExtends = (typeof(cfg['*extends']) != 'undefined') && cfg['*extends'].length;
89 var hasConstructor = (typeof(cfg['|constructor']) != 'undefined');
90 var isStatic = (typeof(cfg['*static']) == '*static');
95 newline = hasConstructor ?
98 cfg['//constructor'] + "\n" +
99 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
100 "Roo.extend(" + cfg['*class'] + ":, " + cfg['*extends'] + ", " :
102 cfg['//*class'] + "\n" +
103 cfg['*class'] + " = new " + cfg['*extends'] + "(" ;
110 newline = hasConstructor ?
112 cfg['//constructor'] + "\n" +
113 cfg['*class'] + " = " + cfg['|constructor'] + "\n\n"+
114 'Roo.apply( ' + cfg['*class'] + ".prototype , " :
116 cfg['//*class'] + "\n" +
117 cfg['*class'] + " = ";
120 endline = hasConstructor ? ');' : ';';
123 return this.outputHeader() +
125 this.objectToJsString(fcfg,1) +
134 copyTo: function(path, cb)
137 this.loadItems(function() {
149 * munges a prop object, removing all the special stuff..
150 * putting props back where they should go...
153 mungePropObj : function(o)
156 // console.log('mungePropObj: enter');
158 // standard props do not do anyting.
160 if (['items', '*prop'].indexOf(i) > -1) {
167 o.items = o.items || [];
169 o.items.forEach( function(e) {
170 if (typeof(e) == 'undefined') {
174 if (typeof(e) != 'object') {
175 // should not really hapen?!!?
176 ret.items.push(e); // could be
179 if (typeof(e['*prop']) != 'undefined') {
181 var val = _this.mungePropObj(e);
183 if (e['xtype'].match(/^Array/)) {
191 // handle fake arrays...
192 var val = _this.mungePropObj(e);
194 ret.items.push(val); // again should not really happen...
198 //console.log('mungePropObj: leave');
199 // do we munge '*' xtypes?
203 objectKeys : function(o) {
211 objectToJsString : function (o, ind)
217 var ix = new Array(ind+1).join(" ");
218 var ix1 = new Array(ind).join(" ");
221 if (k[0] == '+') { // + means hide from renderer.. we do not save this.
224 if (k[0] == '/') { // means hide from renderer.. we prefix the col with it..
229 if (typeof(v) == 'object') {
231 if ((v.constructor != Array) && !this.objectKeys(v).length) {
234 if ((v.constructor == Array) && !v.length && k == 'items') {
238 ret += ret.length ? ",\n" : '';
240 var kk = k[0] == '|' ? k.substring(1) : k;
241 if (typeof(o['//' + kk]) != 'undefined') {
242 ret += ix + o['//' + kk].split("\n").join( "\n" + ix) + "\n";
247 if (v.constructor == Array) {
248 ret += ix + this.toJsProp(k) + ' : ' + this.arrayToJsString(v, ind+1);
253 ret += ix + this.toJsProp(k) + ' : ' + this.objectToJsString(v, ind+1);
257 ret += ix + this.toJsProp(k) + ' : ' + (v ? 'true' : 'false');
261 ret += ix + this.toJsProp(k) + ' : ' + v;
267 ret += ix + this.toJsProp(k) + ' : ' + v.split("\n").join( "\n" + ix);
273 // we should use special stuff here to determine if it's a singly or dobuley
275 ret += ix + this.toJsProp(k) + ' : ' + this.stringToJsString(v, k, o);
281 return "{\n" + ret + "\n" + ix1 + '}';
284 arrayToJsString : function (ar, ind)
287 ar.forEach( function(o) {
288 if (typeof(o) == 'object' && (o.constructor != Array)) {
297 ix = new Array(ind+1).join(" ");
298 ix1 = new Array(ind).join(" ");
306 ar.forEach( function(v, n) {
307 // skip blank last element in an array
308 if ((n == (ar.length -1)) && typeof(v) == 'undefined') {
312 // empty objects in array?
313 if (typeof(v) == 'object' && v.constructor != Array) {
314 if (!_this.objectKeys(v).length) {
320 ret += ret.length ? cr : '';
325 if (v.constructor == Array) {
327 ret += ix + _this.arrayToJsString(v, ind+1);
331 ret += ix + _this.objectToJsString(v, ind+1);
335 ret += ix + (v ? 'true' : 'false');
345 ret += ix + v.split("\n").join( "\n" + ix);
351 // we should use special stuff here to determine if it's a singly or dobuley
353 ret += ix + JSON.stringify(v);
360 return "[" + lb + ret + lb + ix1 + "]";
363 stringToJsString : function(v, k , o) {
364 // since most properties can use single quotes (non-translatable)
365 // we try to fix this here..
366 var val = JSON.stringify(v);
367 if (['xns', 'xtype' ].indexOf(k) > -1) {
368 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";
376 toJsProp: function(v) {
377 var vv = v[0] == '|' ? v.substring(1) : v;
378 if (Lang.isKeyword(vv) || Lang.isBuiltin(vv)) {
379 return "'" + vv + "'";
381 if (vv.match(/[^A-Z_]+/i)) {
382 var val = JSON.stringify(vv);
383 return "'" + val.substring(1, val.length-1).replace(/'/, "\\'") + "'";