solid-ui 2.4.22-4f620aea → 2.4.22-580e8bf6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +287 -99
- package/dist/main.js.map +1 -1
- package/lib/utils/label.js +1 -1
- package/lib/utils/label.js.map +1 -1
- package/lib/versionInfo.js +2 -2
- package/lib/versionInfo.js.map +1 -1
- package/lib/widgets/forms.js +285 -97
- package/lib/widgets/forms.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -15172,7 +15172,7 @@ function slice(s, suffix) {
|
|
|
15172
15172
|
|
|
15173
15173
|
function getWellKnownLabel(thing) {
|
|
15174
15174
|
return _solidLogic.store.any(thing, UI.ns.ui('label')) || // Prioritize ui:label
|
|
15175
|
-
_solidLogic.store.any(thing, UI.ns.link('message')) || _solidLogic.store.any(thing, UI.ns.vcard('fn')) || _solidLogic.store.any(thing, UI.ns.foaf('name')) || _solidLogic.store.any(thing, UI.ns.dct('title')) || _solidLogic.store.any(thing, UI.ns.dc('title')) || _solidLogic.store.any(thing, UI.ns.rss('title')) || _solidLogic.store.any(thing, UI.ns.contact('fullName')) || _solidLogic.store.any(thing, _solidLogic.store.sym('http://www.w3.org/2001/04/roadmap/org#name')) || _solidLogic.store.any(thing, UI.ns.cal('summary')) || _solidLogic.store.any(thing, UI.ns.foaf('nick')) || _solidLogic.store.any(thing, UI.ns.as('name')) || _solidLogic.store.any(thing, UI.ns.schema('name')) || _solidLogic.store.any(thing, UI.ns.rdfs('label'));
|
|
15175
|
+
_solidLogic.store.any(thing, UI.ns.link('message')) || _solidLogic.store.any(thing, UI.ns.vcard('fn')) || _solidLogic.store.any(thing, UI.ns.foaf('name')) || _solidLogic.store.any(thing, UI.ns.dct('title')) || _solidLogic.store.any(thing, UI.ns.dc('title')) || _solidLogic.store.any(thing, UI.ns.rss('title')) || _solidLogic.store.any(thing, UI.ns.contact('fullName')) || _solidLogic.store.any(thing, _solidLogic.store.sym('http://www.w3.org/2001/04/roadmap/org#name')) || _solidLogic.store.any(thing, UI.ns.cal('summary')) || _solidLogic.store.any(thing, UI.ns.foaf('nick')) || _solidLogic.store.any(thing, UI.ns.as('name')) || _solidLogic.store.any(thing, UI.ns.schema('name')) || _solidLogic.store.any(thing, UI.ns.rdfs('label')) || _solidLogic.store.any(thing, _solidLogic.store.sym('http://www.w3.org/2004/02/skos/core#prefLabel'));
|
|
15176
15176
|
}
|
|
15177
15177
|
//# sourceMappingURL=label.js.map
|
|
15178
15178
|
|
|
@@ -15192,8 +15192,8 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
15192
15192
|
}));
|
|
15193
15193
|
exports.versionInfo = void 0;
|
|
15194
15194
|
var versionInfo = {
|
|
15195
|
-
buildTime: '2022-05-
|
|
15196
|
-
commit: '
|
|
15195
|
+
buildTime: '2022-05-19T17:29:45Z',
|
|
15196
|
+
commit: '580e8bf6997815d2b72b0898141a77e3a759185c',
|
|
15197
15197
|
npmInfo: {
|
|
15198
15198
|
'solid-ui': '2.4.22',
|
|
15199
15199
|
npm: '6.14.17',
|
|
@@ -17149,6 +17149,7 @@ exports.findClosest = findClosest;
|
|
|
17149
17149
|
exports.formsFor = formsFor;
|
|
17150
17150
|
exports.makeDescription = makeDescription;
|
|
17151
17151
|
exports.makeSelectForCategory = makeSelectForCategory;
|
|
17152
|
+
exports.makeSelectForChoice = makeSelectForChoice;
|
|
17152
17153
|
exports.makeSelectForNestedCategory = makeSelectForNestedCategory;
|
|
17153
17154
|
exports.makeSelectForOptions = makeSelectForOptions;
|
|
17154
17155
|
exports.newButton = newButton;
|
|
@@ -17260,6 +17261,7 @@ _fieldFunction.field[ns.ui('Form').uri] = _fieldFunction.field[ns.ui('Group').ur
|
|
|
17260
17261
|
var ui = ns.ui;
|
|
17261
17262
|
if (container) container.appendChild(box); // Prevent loops
|
|
17262
17263
|
|
|
17264
|
+
if (!form) return;
|
|
17263
17265
|
var key = subject.toNT() + '|' + form.toNT();
|
|
17264
17266
|
|
|
17265
17267
|
if (already[key]) {
|
|
@@ -18147,8 +18149,6 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
|
|
|
18147
18149
|
var kb = _solidLogic.store;
|
|
18148
18150
|
var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
|
|
18149
18151
|
|
|
18150
|
-
var uiMultipleInUse = false; // this signals to ui:choice that it is part of a ui:multiple
|
|
18151
|
-
|
|
18152
18152
|
var multiSelect = false;
|
|
18153
18153
|
var p;
|
|
18154
18154
|
var box = dom.createElement('div');
|
|
@@ -18178,91 +18178,77 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
|
|
|
18178
18178
|
|
|
18179
18179
|
var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
|
|
18180
18180
|
|
|
18181
|
-
var possible = [];
|
|
18182
|
-
var possibleProperties;
|
|
18183
|
-
var firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *'; // if we do NOT have a container it means it is a ui:Multiple
|
|
18184
|
-
// only important for the first option text in select
|
|
18185
|
-
|
|
18186
|
-
if (!container) {
|
|
18187
|
-
uiMultipleInUse = true;
|
|
18188
|
-
firstSelectOptionText = utils.label(subject, true);
|
|
18189
|
-
}
|
|
18190
|
-
|
|
18191
|
-
if (subject.termType === 'BlankNode') {
|
|
18192
|
-
firstSelectOptionText = '* Select for ' + utils.label(property) + ' *';
|
|
18193
|
-
}
|
|
18194
|
-
|
|
18195
18181
|
var opts = {
|
|
18196
18182
|
form: form,
|
|
18197
18183
|
subForm: subForm,
|
|
18198
18184
|
multiSelect: multiSelect,
|
|
18199
|
-
firstSelectOptionText: firstSelectOptionText,
|
|
18200
|
-
uiMultipleInUse: uiMultipleInUse,
|
|
18201
18185
|
disambiguate: false
|
|
18202
18186
|
};
|
|
18203
|
-
possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
|
|
18204
18187
|
|
|
18205
|
-
|
|
18206
|
-
possible
|
|
18207
|
-
|
|
18188
|
+
function getSelectorOptions() {
|
|
18189
|
+
var possible = [];
|
|
18190
|
+
var possibleProperties;
|
|
18191
|
+
possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
|
|
18208
18192
|
|
|
18193
|
+
for (var x in kb.findMembersNT(uiFrom)) {
|
|
18194
|
+
possible.push(kb.fromNT(x));
|
|
18195
|
+
} // Use rdfs
|
|
18209
18196
|
|
|
18210
|
-
if (uiFrom.sameTerm(ns.rdfs('Class'))) {
|
|
18211
|
-
for (p in buttons.allClassURIs()) {
|
|
18212
|
-
possible.push(kb.sym(p));
|
|
18213
|
-
} // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
|
|
18214
18197
|
|
|
18215
|
-
|
|
18216
|
-
|
|
18198
|
+
if (uiFrom.sameTerm(ns.rdfs('Class'))) {
|
|
18199
|
+
for (p in buttons.allClassURIs()) {
|
|
18200
|
+
possible.push(kb.sym(p));
|
|
18201
|
+
} // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
|
|
18217
18202
|
|
|
18218
|
-
|
|
18219
|
-
|
|
18220
|
-
}
|
|
18203
|
+
} else if (uiFrom.sameTerm(ns.rdf('Property'))) {
|
|
18204
|
+
possibleProperties = buttons.propertyTriage(kb);
|
|
18221
18205
|
|
|
18222
|
-
|
|
18223
|
-
|
|
18224
|
-
|
|
18206
|
+
for (p in possibleProperties.op) {
|
|
18207
|
+
possible.push(kb.fromNT(p));
|
|
18208
|
+
}
|
|
18209
|
+
|
|
18210
|
+
for (p in possibleProperties.dp) {
|
|
18211
|
+
possible.push(kb.fromNT(p));
|
|
18212
|
+
}
|
|
18225
18213
|
|
|
18226
|
-
|
|
18227
|
-
|
|
18228
|
-
|
|
18214
|
+
opts.disambiguate = true; // This is a big class, and the labels won't be enough.
|
|
18215
|
+
} else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
|
|
18216
|
+
possibleProperties = buttons.propertyTriage(kb);
|
|
18229
18217
|
|
|
18230
|
-
|
|
18231
|
-
|
|
18232
|
-
|
|
18218
|
+
for (p in possibleProperties.op) {
|
|
18219
|
+
possible.push(kb.fromNT(p));
|
|
18220
|
+
}
|
|
18233
18221
|
|
|
18234
|
-
|
|
18235
|
-
|
|
18236
|
-
|
|
18222
|
+
opts.disambiguate = true;
|
|
18223
|
+
} else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
|
|
18224
|
+
possibleProperties = buttons.propertyTriage(kb);
|
|
18237
18225
|
|
|
18238
|
-
|
|
18239
|
-
|
|
18226
|
+
for (p in possibleProperties.dp) {
|
|
18227
|
+
possible.push(kb.fromNT(p));
|
|
18228
|
+
}
|
|
18229
|
+
|
|
18230
|
+
opts.disambiguate = true;
|
|
18240
18231
|
}
|
|
18241
18232
|
|
|
18242
|
-
|
|
18243
|
-
}
|
|
18233
|
+
return sortByLabel(possible);
|
|
18234
|
+
} // TODO: this checks for any occurrence, regardless of true or false setting
|
|
18244
18235
|
|
|
18245
|
-
var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurrence, regardless of true or false setting
|
|
18246
18236
|
|
|
18247
18237
|
if (kb.any(form, ui('canMintNew'))) {
|
|
18248
18238
|
opts.mint = '* Create new *'; // @@ could be better
|
|
18249
18239
|
}
|
|
18250
18240
|
|
|
18251
|
-
var selector
|
|
18252
|
-
rhs.appendChild(selector);
|
|
18253
|
-
var object;
|
|
18241
|
+
var selector;
|
|
18254
18242
|
|
|
18255
|
-
|
|
18256
|
-
|
|
18257
|
-
|
|
18258
|
-
|
|
18259
|
-
|
|
18260
|
-
|
|
18261
|
-
if (object && subForm) {
|
|
18262
|
-
removeNextSiblingsAfterElement(selector);
|
|
18263
|
-
addSubFormChoice(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
|
|
18264
|
-
}
|
|
18243
|
+
rhs.refresh = function () {
|
|
18244
|
+
var selectorOptions = getSelectorOptions();
|
|
18245
|
+
selector = makeSelectForChoice(dom, rhs, kb, subject, property, selectorOptions, uiFrom, opts, dataDoc, callbackFunction);
|
|
18246
|
+
rhs.innerHTML = '';
|
|
18247
|
+
rhs.appendChild(selector);
|
|
18248
|
+
};
|
|
18265
18249
|
|
|
18250
|
+
rhs.refresh();
|
|
18251
|
+
if (selector && selector.refresh) selector.refresh();
|
|
18266
18252
|
return box;
|
|
18267
18253
|
};
|
|
18268
18254
|
/**
|
|
@@ -18619,10 +18605,9 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
|
|
|
18619
18605
|
// @param subject - a term, the subject of the statement(s) being edited.
|
|
18620
18606
|
// @param predicate - a term, the predicate of the statement(s) being edited
|
|
18621
18607
|
// @param possible - a list of terms, the possible value the object can take
|
|
18622
|
-
// @param options.
|
|
18623
|
-
// @param options.
|
|
18624
|
-
// option for none selected (for non
|
|
18625
|
-
// @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
|
|
18608
|
+
// @param options.multiple - Boolean - Whether more than one at a time is allowed
|
|
18609
|
+
// @param options.nullLabel - a string to be displayed as the
|
|
18610
|
+
// option for none selected (for non multiple)
|
|
18626
18611
|
// @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
|
|
18627
18612
|
// @param options.subForm - If mint, then the form to be used for minting the new thing
|
|
18628
18613
|
// @param dataDoc - The web document being edited
|
|
@@ -18630,7 +18615,7 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
|
|
|
18630
18615
|
*/
|
|
18631
18616
|
|
|
18632
18617
|
|
|
18633
|
-
function makeSelectForOptions(dom, kb, subject, predicate, possible,
|
|
18618
|
+
function makeSelectForOptions(dom, kb, subject, predicate, possible, options, dataDoc, callbackFunction) {
|
|
18634
18619
|
log.debug('Select list length now ' + possible.length);
|
|
18635
18620
|
var n = 0;
|
|
18636
18621
|
var uris = {}; // Count them
|
|
@@ -18673,6 +18658,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
18673
18658
|
actual = getActual();
|
|
18674
18659
|
|
|
18675
18660
|
var onChange = function onChange(_e) {
|
|
18661
|
+
select.disabled = true; // until data written back - gives user feedback too
|
|
18662
|
+
|
|
18676
18663
|
var ds = [];
|
|
18677
18664
|
var is = [];
|
|
18678
18665
|
|
|
@@ -18703,14 +18690,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
18703
18690
|
newObject = newThing(dataDoc);
|
|
18704
18691
|
}
|
|
18705
18692
|
|
|
18706
|
-
is.push($rdf.st(subject, predicate,
|
|
18707
|
-
if (uiFrom) is.push($rdf.st(newObject, ns.rdf('type'), kb.sym(uiFrom), dataDoc)); // not sure if this 'if' is used because I cannot find mintStatementsFun
|
|
18693
|
+
is.push($rdf.st(subject, predicate, newObject, dataDoc)); // not sure if this 'if' is used because I cannot find mintStatementsFun
|
|
18708
18694
|
|
|
18709
18695
|
if (options.mintStatementsFun) {
|
|
18710
18696
|
is = is.concat(options.mintStatementsFun(newObject));
|
|
18711
18697
|
}
|
|
18712
|
-
|
|
18713
|
-
select.currentURI = newObject;
|
|
18714
18698
|
}
|
|
18715
18699
|
|
|
18716
18700
|
if (!opt.AJAR_uri) continue; // a prompt or mint
|
|
@@ -18718,7 +18702,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
18718
18702
|
if (opt.selected && !(opt.AJAR_uri in actual)) {
|
|
18719
18703
|
// new class
|
|
18720
18704
|
is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
|
|
18721
|
-
|
|
18705
|
+
}
|
|
18706
|
+
|
|
18707
|
+
if (!opt.selected && opt.AJAR_uri in actual) {
|
|
18708
|
+
// old class
|
|
18709
|
+
removeValue(kb.sym(opt.AJAR_uri));
|
|
18722
18710
|
}
|
|
18723
18711
|
|
|
18724
18712
|
if (opt.selected) select.currentURI = opt.AJAR_uri;
|
|
@@ -18738,29 +18726,38 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
18738
18726
|
sel = sel.superSelect;
|
|
18739
18727
|
}
|
|
18740
18728
|
|
|
18741
|
-
|
|
18729
|
+
function doneNew(ok, _body) {
|
|
18730
|
+
callbackFunction(ok, {
|
|
18731
|
+
widget: 'select',
|
|
18732
|
+
event: 'new'
|
|
18733
|
+
});
|
|
18734
|
+
}
|
|
18735
|
+
|
|
18736
|
+
log.info('selectForOptions: data doc = ' + dataDoc);
|
|
18737
|
+
kb.updater.update(ds, is, function (uri, ok, body) {
|
|
18738
|
+
actual = getActual(); // refresh
|
|
18742
18739
|
|
|
18743
|
-
removeNextSiblingsAfterElement(select);
|
|
18744
|
-
addSubFormChoice(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
|
|
18745
18740
|
if (ok) {
|
|
18746
|
-
|
|
18747
|
-
actual = getActual(); // refresh
|
|
18741
|
+
select.disabled = false; // data written back
|
|
18748
18742
|
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
|
|
18752
|
-
|
|
18753
|
-
event: 'new'
|
|
18754
|
-
});
|
|
18743
|
+
if (newObject) {
|
|
18744
|
+
var fn = (0, _fieldFunction.fieldFunction)(dom, options.subForm);
|
|
18745
|
+
fn(dom, select.parentNode, {}, newObject, options.subForm, dataDoc, doneNew);
|
|
18746
|
+
}
|
|
18755
18747
|
} else {
|
|
18756
|
-
select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in
|
|
18748
|
+
return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
|
|
18757
18749
|
}
|
|
18750
|
+
|
|
18751
|
+
if (callbackFunction) callbackFunction(ok, {
|
|
18752
|
+
widget: 'select',
|
|
18753
|
+
event: 'change'
|
|
18754
|
+
});
|
|
18758
18755
|
});
|
|
18759
18756
|
};
|
|
18760
18757
|
|
|
18761
18758
|
var select = dom.createElement('select');
|
|
18762
18759
|
select.setAttribute('style', style.formSelectSTyle);
|
|
18763
|
-
if (options.
|
|
18760
|
+
if (options.multiple) select.setAttribute('multiple', 'true');
|
|
18764
18761
|
select.currentURI = null;
|
|
18765
18762
|
|
|
18766
18763
|
select.refresh = function () {
|
|
@@ -18811,14 +18808,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
18811
18808
|
select.insertBefore(mint, select.firstChild);
|
|
18812
18809
|
}
|
|
18813
18810
|
|
|
18814
|
-
if (
|
|
18811
|
+
if (select.currentURI == null && !options.multiple) {
|
|
18815
18812
|
var prompt = dom.createElement('option');
|
|
18816
|
-
prompt.appendChild(dom.createTextNode(options.
|
|
18817
|
-
prompt.disabled = true;
|
|
18818
|
-
prompt.value = true;
|
|
18819
|
-
prompt.hidden = true;
|
|
18820
|
-
prompt.selected = true;
|
|
18813
|
+
prompt.appendChild(dom.createTextNode(options.nullLabel));
|
|
18821
18814
|
select.insertBefore(prompt, select.firstChild);
|
|
18815
|
+
prompt.selected = true;
|
|
18822
18816
|
}
|
|
18823
18817
|
|
|
18824
18818
|
if (editable) {
|
|
@@ -18837,11 +18831,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
18837
18831
|
function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
|
|
18838
18832
|
var du = kb.any(category, ns.owl('disjointUnionOf'));
|
|
18839
18833
|
var subs;
|
|
18840
|
-
var
|
|
18834
|
+
var multiple = false;
|
|
18841
18835
|
|
|
18842
18836
|
if (!du) {
|
|
18843
18837
|
subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
|
|
18844
|
-
|
|
18838
|
+
multiple = true;
|
|
18845
18839
|
} else {
|
|
18846
18840
|
subs = du.elements;
|
|
18847
18841
|
}
|
|
@@ -18849,15 +18843,16 @@ function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunc
|
|
|
18849
18843
|
log.debug('Select list length ' + subs.length);
|
|
18850
18844
|
|
|
18851
18845
|
if (subs.length === 0) {
|
|
18852
|
-
return (0, _error.errorMessageBlock)(dom, "Can't do " + (
|
|
18846
|
+
return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
|
|
18853
18847
|
}
|
|
18854
18848
|
|
|
18855
18849
|
if (subs.length === 1) {
|
|
18856
|
-
return (0, _error.errorMessageBlock)(dom, "Can't do " + (
|
|
18850
|
+
return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
|
|
18857
18851
|
}
|
|
18858
18852
|
|
|
18859
|
-
return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs,
|
|
18860
|
-
|
|
18853
|
+
return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
|
|
18854
|
+
multiple: multiple,
|
|
18855
|
+
nullPrompt: '--classify--'
|
|
18861
18856
|
}, dataDoc, callbackFunction);
|
|
18862
18857
|
}
|
|
18863
18858
|
/** Make SELECT element to select subclasses recurively
|
|
@@ -19047,6 +19042,199 @@ function newThing(doc) {
|
|
|
19047
19042
|
var now = new Date();
|
|
19048
19043
|
return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
|
|
19049
19044
|
}
|
|
19045
|
+
/** Make SELECT element to select options
|
|
19046
|
+
//
|
|
19047
|
+
// @param subject - a term, the subject of the statement(s) being edited.
|
|
19048
|
+
// @param predicate - a term, the predicate of the statement(s) being edited
|
|
19049
|
+
// @param possible - a list of terms, the possible value the object can take
|
|
19050
|
+
// @param options.multiSelect - Boolean - Whether more than one at a time is allowed
|
|
19051
|
+
// @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
|
|
19052
|
+
// @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
|
|
19053
|
+
// @param options.subForm - If mint, then the form to be used for minting the new thing
|
|
19054
|
+
// @param dataDoc - The web document being edited
|
|
19055
|
+
// @param callbackFunction - takes (boolean ok, string errorBody)
|
|
19056
|
+
*/
|
|
19057
|
+
|
|
19058
|
+
|
|
19059
|
+
function makeSelectForChoice(dom, container, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
|
|
19060
|
+
var n = 0;
|
|
19061
|
+
var uris = {}; // Count them
|
|
19062
|
+
|
|
19063
|
+
var editable = kb.updater.editable(dataDoc.uri);
|
|
19064
|
+
|
|
19065
|
+
for (var i = 0; i < possible.length; i++) {
|
|
19066
|
+
var sub = possible[i]; // @@ Maybe; make this so it works with blank nodes too
|
|
19067
|
+
|
|
19068
|
+
if (!sub.uri) debug.warn("makeSelectForOptions: option does not have an uri: ".concat(sub, ", with predicate: ").concat(predicate));
|
|
19069
|
+
if (!sub.uri || sub.uri in uris) continue;
|
|
19070
|
+
uris[sub.uri] = true;
|
|
19071
|
+
n++;
|
|
19072
|
+
} // uris is now the set of possible options
|
|
19073
|
+
|
|
19074
|
+
|
|
19075
|
+
if (n === 0 && !options.mint) {
|
|
19076
|
+
return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
|
|
19077
|
+
}
|
|
19078
|
+
|
|
19079
|
+
log.debug('makeSelectForOptions: dataDoc=' + dataDoc);
|
|
19080
|
+
|
|
19081
|
+
function determinFirstSelectOption() {
|
|
19082
|
+
var firstSelectOptionText = '--- classify ---';
|
|
19083
|
+
var option = dom.createElement('option');
|
|
19084
|
+
|
|
19085
|
+
if (predicate && !(predicate.termType === 'BlankNode')) {
|
|
19086
|
+
firstSelectOptionText = '* Select for property: ' + utils.label(predicate) + ' *';
|
|
19087
|
+
}
|
|
19088
|
+
|
|
19089
|
+
if (subject && !(subject.termType === 'BlankNode')) {
|
|
19090
|
+
firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *';
|
|
19091
|
+
}
|
|
19092
|
+
|
|
19093
|
+
option.appendChild(dom.createTextNode(firstSelectOptionText));
|
|
19094
|
+
option.disabled = true;
|
|
19095
|
+
option.value = true;
|
|
19096
|
+
option.hidden = true;
|
|
19097
|
+
option.selected = true;
|
|
19098
|
+
return option;
|
|
19099
|
+
}
|
|
19100
|
+
|
|
19101
|
+
var onChange = function onChange(_e) {
|
|
19102
|
+
select.refresh();
|
|
19103
|
+
};
|
|
19104
|
+
|
|
19105
|
+
var select = dom.createElement('select');
|
|
19106
|
+
select.setAttribute('style', style.formSelectSTyle);
|
|
19107
|
+
if (options.multiSelect) select.setAttribute('multiSelect', 'true');
|
|
19108
|
+
select.currentURI = null;
|
|
19109
|
+
var object = kb.any(subject, predicate);
|
|
19110
|
+
if (object) select.currentURI = object;
|
|
19111
|
+
|
|
19112
|
+
for (var uri in uris) {
|
|
19113
|
+
select.appendChild(createOption(uri));
|
|
19114
|
+
}
|
|
19115
|
+
|
|
19116
|
+
if (editable && options.mint) {
|
|
19117
|
+
var mint = dom.createElement('option');
|
|
19118
|
+
mint.appendChild(dom.createTextNode(options.mint));
|
|
19119
|
+
mint.AJAR_mint = true; // Flag it
|
|
19120
|
+
|
|
19121
|
+
select.insertBefore(mint, select.firstChild);
|
|
19122
|
+
}
|
|
19123
|
+
|
|
19124
|
+
if (select.children.length === 0) select.insertBefore(determinFirstSelectOption(), select.firstChild);
|
|
19125
|
+
|
|
19126
|
+
select.refresh = function () {
|
|
19127
|
+
select.disabled = true; // unlocked any conflict we had got into
|
|
19128
|
+
|
|
19129
|
+
var ds = [];
|
|
19130
|
+
var is = [];
|
|
19131
|
+
|
|
19132
|
+
var removeValue = function removeValue(t) {
|
|
19133
|
+
if (kb.holds(subject, predicate, t, dataDoc)) {
|
|
19134
|
+
ds.push($rdf.st(subject, predicate, t, dataDoc));
|
|
19135
|
+
}
|
|
19136
|
+
};
|
|
19137
|
+
|
|
19138
|
+
var newObject;
|
|
19139
|
+
|
|
19140
|
+
for (var _i3 = 0; _i3 < select.options.length; _i3++) {
|
|
19141
|
+
var opt = select.options[_i3];
|
|
19142
|
+
|
|
19143
|
+
if (opt.selected && opt.AJAR_mint) {
|
|
19144
|
+
// not sure if this 'if' is used because I cannot find mintClass
|
|
19145
|
+
if (options.mintClass) {
|
|
19146
|
+
var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
|
|
19147
|
+
if (!ok) {
|
|
19148
|
+
callbackFunction(ok, body, {
|
|
19149
|
+
change: 'new'
|
|
19150
|
+
}); // @@ if ok, need some form of refresh of the select for the new thing
|
|
19151
|
+
}
|
|
19152
|
+
});
|
|
19153
|
+
select.parentNode.appendChild(thisForm);
|
|
19154
|
+
newObject = thisForm.AJAR_subject;
|
|
19155
|
+
} else {
|
|
19156
|
+
newObject = newThing(dataDoc);
|
|
19157
|
+
}
|
|
19158
|
+
|
|
19159
|
+
is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
|
|
19160
|
+
if (uiFrom) is.push($rdf.st(newObject, ns.rdf('type'), kb.sym(uiFrom), dataDoc)); // not sure if this 'if' is used because I cannot find mintStatementsFun
|
|
19161
|
+
|
|
19162
|
+
if (options.mintStatementsFun) {
|
|
19163
|
+
is = is.concat(options.mintStatementsFun(newObject));
|
|
19164
|
+
}
|
|
19165
|
+
|
|
19166
|
+
select.currentURI = newObject;
|
|
19167
|
+
}
|
|
19168
|
+
|
|
19169
|
+
if (!opt.AJAR_uri) continue; // a prompt or mint
|
|
19170
|
+
|
|
19171
|
+
if (opt.selected) select.currentURI = opt.AJAR_uri;
|
|
19172
|
+
}
|
|
19173
|
+
|
|
19174
|
+
var sel = select.subSelect; // All subclasses must also go
|
|
19175
|
+
|
|
19176
|
+
while (sel && sel.currentURI) {
|
|
19177
|
+
removeValue(kb.sym(sel.currentURI));
|
|
19178
|
+
sel = sel.subSelect;
|
|
19179
|
+
}
|
|
19180
|
+
|
|
19181
|
+
sel = select.superSelect; // All superclasses are redundant
|
|
19182
|
+
|
|
19183
|
+
while (sel && sel.currentURI) {
|
|
19184
|
+
removeValue(kb.sym(sel.currentURI));
|
|
19185
|
+
sel = sel.superSelect;
|
|
19186
|
+
}
|
|
19187
|
+
|
|
19188
|
+
log.info('selectForOptions: data doc = ' + dataDoc);
|
|
19189
|
+
|
|
19190
|
+
if (select.currentURI) {
|
|
19191
|
+
removeNextSiblingsAfterElement(select);
|
|
19192
|
+
addSubFormChoice(dom, container, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
|
|
19193
|
+
if (ok) {
|
|
19194
|
+
kb.updater.update(ds, is, function (uri, success, errorBody) {
|
|
19195
|
+
if (!success) container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
|
|
19196
|
+
});
|
|
19197
|
+
if (callbackFunction) callbackFunction(ok, {
|
|
19198
|
+
widget: 'select',
|
|
19199
|
+
event: 'new'
|
|
19200
|
+
}); // widgets.refreshTree(container)
|
|
19201
|
+
} else {
|
|
19202
|
+
container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
|
|
19203
|
+
}
|
|
19204
|
+
});
|
|
19205
|
+
}
|
|
19206
|
+
|
|
19207
|
+
select.disabled = false;
|
|
19208
|
+
};
|
|
19209
|
+
|
|
19210
|
+
function createOption(uri) {
|
|
19211
|
+
var option = dom.createElement('option');
|
|
19212
|
+
var c = kb.sym(uri);
|
|
19213
|
+
|
|
19214
|
+
if (options.disambiguate) {
|
|
19215
|
+
option.appendChild(dom.createTextNode(utils.labelWithOntology(c, true))); // Init. cap
|
|
19216
|
+
} else {
|
|
19217
|
+
option.appendChild(dom.createTextNode(utils.label(c, true))); // Init.
|
|
19218
|
+
}
|
|
19219
|
+
|
|
19220
|
+
var backgroundColor = kb.any(c, kb.sym('http://www.w3.org/ns/ui#backgroundColor'));
|
|
19221
|
+
|
|
19222
|
+
if (backgroundColor) {
|
|
19223
|
+
option.setAttribute('style', 'background-color: ' + backgroundColor.value + '; ');
|
|
19224
|
+
}
|
|
19225
|
+
|
|
19226
|
+
option.AJAR_uri = uri;
|
|
19227
|
+
if (c.toString() === '' + select.currentURI) option.selected = true;
|
|
19228
|
+
return option;
|
|
19229
|
+
}
|
|
19230
|
+
|
|
19231
|
+
if (editable) {
|
|
19232
|
+
select.addEventListener('change', onChange, false);
|
|
19233
|
+
}
|
|
19234
|
+
|
|
19235
|
+
select.refresh();
|
|
19236
|
+
return select;
|
|
19237
|
+
} // makeSelectForChoice
|
|
19050
19238
|
//# sourceMappingURL=forms.js.map
|
|
19051
19239
|
|
|
19052
19240
|
/***/ }),
|