|
@@ -80,7 +80,7 @@ class Cell extends Component {
|
|
|
|
|
|
public function refresh() {
|
|
|
currentValue = Reflect.field(line.obj, column.name);
|
|
|
- var html = valueHtml(column, value, line.table.sheet, line.obj);
|
|
|
+ var html = valueHtml(column, value, line.table.getRealSheet(), line.obj, []);
|
|
|
if( html == " " ) element.text(" ") else if( html.indexOf('<') < 0 && html.indexOf('&') < 0 ) element.text(html) else element.html(html);
|
|
|
updateClasses();
|
|
|
}
|
|
@@ -113,7 +113,51 @@ class Cell extends Component {
|
|
|
return view.show == null || view.show.indexOf(column) >= 0;
|
|
|
}
|
|
|
|
|
|
- public function valueHtml( c : cdb.Data.Column, v : Dynamic, sheet : cdb.Sheet, obj : Dynamic ) : String {
|
|
|
+ var _cachedScope : Array<{ s : cdb.Sheet, obj : Dynamic }>;
|
|
|
+ function getScope() {
|
|
|
+ if( _cachedScope != null ) return _cachedScope;
|
|
|
+ var scope = [];
|
|
|
+ var line = line;
|
|
|
+ while( true ) {
|
|
|
+ var p = Std.downcast(line.table, SubTable);
|
|
|
+ if( p == null ) break;
|
|
|
+ line = p.cell.line;
|
|
|
+ scope.unshift({ s : line.table.getRealSheet(), obj : line.obj });
|
|
|
+ }
|
|
|
+ return _cachedScope = scope;
|
|
|
+ }
|
|
|
+
|
|
|
+ function makeId( scopes : Array<{ s : cdb.Sheet, obj : Dynamic }>, scope : Int, id : String ) {
|
|
|
+ var ids = [];
|
|
|
+ if( id != null ) ids.push(id);
|
|
|
+ var pos = scopes.length;
|
|
|
+ while( true ) {
|
|
|
+ pos -= scope;
|
|
|
+ if( pos < 0 ) {
|
|
|
+ scopes = getScope();
|
|
|
+ pos += scopes.length;
|
|
|
+ }
|
|
|
+ var s = scopes[pos];
|
|
|
+ var pid = Reflect.field(s.obj, s.s.idCol.name);
|
|
|
+ if( pid == null ) return "";
|
|
|
+ ids.unshift(pid);
|
|
|
+ scope = s.s.idCol.scope;
|
|
|
+ if( scope == null ) break;
|
|
|
+ }
|
|
|
+ return ids.join(":");
|
|
|
+ }
|
|
|
+
|
|
|
+ function refScope( targetSheet : cdb.Sheet, currentSheet : cdb.Sheet, obj : Dynamic, localScope : Array<{ s : cdb.Sheet, obj : Dynamic }> ) {
|
|
|
+ var targetDepth = targetSheet.name.split("@").length;
|
|
|
+ var scope = getScope().concat(localScope);
|
|
|
+ if( scope.length < targetDepth )
|
|
|
+ scope.push({ s : currentSheet, obj : obj });
|
|
|
+ while( scope.length >= targetDepth )
|
|
|
+ scope.pop();
|
|
|
+ return scope;
|
|
|
+ }
|
|
|
+
|
|
|
+ function valueHtml( c : cdb.Data.Column, v : Dynamic, sheet : cdb.Sheet, obj : Dynamic, scope : Array<{ s : cdb.Sheet, obj : Dynamic }> ) : String {
|
|
|
if( v == null ) {
|
|
|
if( c.opt )
|
|
|
return " ";
|
|
@@ -128,7 +172,13 @@ class Cell extends Component {
|
|
|
v + "";
|
|
|
}
|
|
|
case TId:
|
|
|
- v == "" ? '<span class="error">#MISSING</span>' : (editor.base.getSheet(sheet.name).index.get(v).obj == obj ? v : '<span class="error">#DUP($v)</span>');
|
|
|
+ if( v == "" )
|
|
|
+ '<span class="error">#MISSING</span>';
|
|
|
+ else {
|
|
|
+ var id = c.scope != null ? makeId(scope,c.scope,v) : v;
|
|
|
+ var uniq = editor.base.getSheet(sheet.name).index.get(id);
|
|
|
+ uniq == null || uniq.obj == obj ? v : '<span class="error">#DUP($v)</span>';
|
|
|
+ }
|
|
|
case TString if( c.kind == Script ):
|
|
|
v == "" ? " " : colorizeScript(c,v);
|
|
|
case TString, TLayer(_):
|
|
@@ -138,7 +188,7 @@ class Cell extends Component {
|
|
|
'<span class="error">#MISSING</span>';
|
|
|
else {
|
|
|
var s = editor.base.getSheet(sname);
|
|
|
- var i = s.index.get(v);
|
|
|
+ var i = s.index.get(s.idCol.scope != null ? makeId(refScope(s,sheet,obj,scope),s.idCol.scope,v) : v);
|
|
|
i == null ? '<span class="error">#REF($v)</span>' : (i.ico == null ? "" : tileHtml(i.ico,true)+" ") + StringTools.htmlEscape(i.disp);
|
|
|
}
|
|
|
case TBool:
|
|
@@ -152,6 +202,7 @@ class Cell extends Component {
|
|
|
var ps = sheet.getSub(c);
|
|
|
var out : Array<String> = [];
|
|
|
var size = 0;
|
|
|
+ scope.push({ s : sheet, obj : obj });
|
|
|
for( v in a ) {
|
|
|
var vals = [];
|
|
|
for( c in ps.columns )
|
|
@@ -160,7 +211,7 @@ class Cell extends Component {
|
|
|
continue;
|
|
|
default:
|
|
|
if( !canViewSubColumn(ps, c.name) ) continue;
|
|
|
- var h = valueHtml(c, Reflect.field(v, c.name), ps, v);
|
|
|
+ var h = valueHtml(c, Reflect.field(v, c.name), ps, v, scope);
|
|
|
if( h != "" && h != " " )
|
|
|
vals.push(h);
|
|
|
}
|
|
@@ -179,18 +230,21 @@ class Cell extends Component {
|
|
|
size += vstr.length;
|
|
|
out.push(v);
|
|
|
}
|
|
|
+ scope.pop();
|
|
|
if( out.length == 0 )
|
|
|
return "";
|
|
|
return out.join(", ");
|
|
|
case TProperties:
|
|
|
var ps = sheet.getSub(c);
|
|
|
var out = [];
|
|
|
+ scope.push({ s : sheet, obj : obj });
|
|
|
for( c in ps.columns ) {
|
|
|
var pval = Reflect.field(v, c.name);
|
|
|
if( pval == null && c.opt ) continue;
|
|
|
if( !canViewSubColumn(ps, c.name) ) continue;
|
|
|
- out.push(c.name+" : "+valueHtml(c, pval, ps, v));
|
|
|
+ out.push(c.name+" : "+valueHtml(c, pval, ps, v, scope));
|
|
|
}
|
|
|
+ scope.pop();
|
|
|
return out.join("<br/>");
|
|
|
case TCustom(name):
|
|
|
var t = editor.base.getCustomType(name);
|
|
@@ -202,7 +256,7 @@ class Cell extends Component {
|
|
|
var out = [];
|
|
|
var pos = 1;
|
|
|
for( i in 1...a.length )
|
|
|
- out.push(valueHtml(cas.args[i-1], a[i], sheet, this));
|
|
|
+ out.push(valueHtml(cas.args[i-1], a[i], sheet, this, scope));
|
|
|
str += out.join(",");
|
|
|
str += ")";
|
|
|
}
|
|
@@ -401,7 +455,14 @@ class Cell extends Component {
|
|
|
element.addClass("edit");
|
|
|
|
|
|
var s = new Element("<select>");
|
|
|
- var elts = [for( d in sdat.all ){ id : d.id, ico : d.ico, text : d.disp }];
|
|
|
+ var isLocal = sdat.idCol.scope != null;
|
|
|
+ var elts;
|
|
|
+ if( isLocal ) {
|
|
|
+ var scope = refScope(sdat,table.getRealSheet(),line.obj,[]);
|
|
|
+ var prefix = makeId(scope, sdat.idCol.scope, null)+":";
|
|
|
+ elts = [for( d in sdat.all ) if( StringTools.startsWith(d.id,prefix) ) { id : d.id.split(":").pop(), ico : d.ico, text : d.disp }];
|
|
|
+ } else
|
|
|
+ elts = [for( d in sdat.all ) { id : d.id, ico : d.ico, text : d.disp }];
|
|
|
if( column.opt || currentValue == null || currentValue == "" )
|
|
|
elts.unshift( { id : "~", ico : null, text : "--- None ---" } );
|
|
|
element.append(s);
|
|
@@ -603,16 +664,24 @@ class Cell extends Component {
|
|
|
case TId:
|
|
|
var obj = line.obj;
|
|
|
var prevValue = value;
|
|
|
+ var realSheet = table.getRealSheet();
|
|
|
+ var isLocal = realSheet.idCol.scope != null;
|
|
|
+ var parentID = isLocal ? makeId([],realSheet.idCol.scope,null) : null;
|
|
|
// most likely our obj, unless there was a #DUP
|
|
|
- var prevObj = value != null ? table.sheet.index.get(value) : null;
|
|
|
+ var prevObj = value != null ? realSheet.index.get(isLocal ? parentID+":"+value : value) : null;
|
|
|
// have we already an obj mapped to the same id ?
|
|
|
- var prevTarget = table.sheet.index.get(newValue);
|
|
|
+ var prevTarget = realSheet.index.get(isLocal ? parentID+":"+newValue : newValue);
|
|
|
editor.beginChanges();
|
|
|
if( prevObj == null || prevObj.obj == obj ) {
|
|
|
// remap
|
|
|
var m = new Map();
|
|
|
m.set(value, newValue);
|
|
|
- editor.base.updateRefs(table.sheet, m);
|
|
|
+ if( isLocal ) {
|
|
|
+ var scope = getScope();
|
|
|
+ var parent = scope[scope.length - realSheet.idCol.scope];
|
|
|
+ editor.base.updateLocalRefs(realSheet, m, parent.obj, parent.s);
|
|
|
+ } else
|
|
|
+ editor.base.updateRefs(realSheet, m);
|
|
|
}
|
|
|
setValue(newValue);
|
|
|
editor.endChanges();
|