Base = XObject.define(
function(cfg) {
-
+
XObject.extend(this, cfg);
+
},
Object,
{
+ /**
+ * @cfg {Array} doubleStringProps list of properties that can be double quoted.
+ */
+ doubleStringProps : false,
id : false,
name : false, // is the JS name of the file.
var _this = this;
var write = this.toJsonArray()
print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
- File.write(this.path, JSON.stringify(write));
+ File.write(this.path, JSON.stringify(write, null, 4));
},
/**
{
var ret = { };
var _this = this;
- ['id', 'name', 'parent', 'title', 'path', 'items', 'project'].forEach( function(k) {
- ret[k] = _this[k];
+ ['id', 'name', 'parent', 'title', 'path', 'items' , 'permname' ].forEach( function(k) {
+ ret[k] = typeof(_this[k]) == 'undefined' ? '' _this[k];
});
return ret;
},
}
- if (!isArray) {
- if (obj.items && obj.items.length) {
- //console.dump(obj.items);
+ if (!isArray && obj.items && obj.items.length) {
+ // look for props..
+ var newitems = [];
+ obj.items.forEach(function(pl) {
+ if (typeof(pl['*prop']) == 'undefined') {
+ newitems.push(pl);
+ return;
+ }
+ // we have a prop...
+ var prop = pl['*prop'] + '';
+ delete pl['*prop'];
+ if (!prop.match(/\[\]$/)) {
+ // it's a standard prop..
+ obj[prop] = pl;
+ keys.push(prop);
+ return;
+ }
+ prop = prop.substring(0, prop.length -2); //strip []
+ // it's an array type..
+ obj[prop] = obj[prop] || [];
+ obj[prop].push(pl);
+ print("ADDNG PROP:" + prop + ' ' + keys.indexOf(prop) );
+ if (keys.indexOf(prop) < 0) {
+ keys.push(prop);
+ }
+
+
+
+ });
+ obj.items = newitems;
+ if (!obj.items.length) {
+ delete obj.items;
}
- }
+
+ }
var left = '';
keys.forEach(function(i) {
+
+ if (typeof(obj[i]) == 'undefined') { // empty or removed.
+ return;
+ }
var el = obj[i];
if (!isArray && skip.indexOf(i) > -1) { // things we do not write..
return;
left = "'" + leftv + "'";
} else if (leftv.match(/[^A-Z_]+/i)) { // not plain a-z... - quoted.
var val = JSON.stringify(leftv);
- left = "'" + leftv.substring(1, leftv.length-1).replace(/'/, "\\'") + "'";
+ left = "'" + val.substring(1, val.length-1).replace(/'/g, "\\'") + "'";
} else {
left = '' + leftv;
}
if (lines.length > 1) {
str = lines.join("\n" + pad);
}
- els.push(left + ":" + str);
+ els.push(left + str);
return;
}
if (typeof(el) == 'object') {
- els.push(left + _this.mungeToString(el, i == 'listeners', pad + ' '));
+
+ // we can skip empty items lists and empty listeners..
+ //if (!isArray && i == 'items' && !el.length) {
+ // return;
+ //}
+ //
+ var right = _this.mungeToString(el, i == 'listeners', pad + ' ');
+ if (typeof(right) != 'undefined') {
+ els.push(left + right);
+ }
+
return;
}
// standard. .
+ if (typeof(obj[i]) != 'string') {
+ els.push(left + JSON.stringify(obj[i]));
+ return;
+ }
+ // strings..
+ if (!_this.doubleStringProps) {
+ els.push(left + JSON.stringify(obj[i]));
+ return;
+ }
+ if (_this.doubleStringProps.indexOf(i) > -1) {
+ els.push(left + JSON.stringify(obj[i]));
+ return;
+ }
+ // single quote..
+ els.push(left + "'" + obj[i].replace(/'/g, "\\'") + "'");
- els.push(left + JSON.stringify(obj[i]));
+
});
+ if (!isArray && !els.length) {
+ return;
+ }
//output the thing.
var spad = pad.substring(0, pad.length-4);
return (isArray ? '[' : '{') + "\n" +
}
+
+
+
);