solid-ui 2.4.22-a39ed737 → 2.4.22-a5a36443
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/README.md +23 -58
- package/dist/main.js +317 -175
- 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 +5 -5
- package/lib/versionInfo.js.map +1 -1
- package/lib/widgets/buttons.d.ts.map +1 -1
- package/lib/widgets/buttons.js +2 -0
- package/lib/widgets/buttons.js.map +1 -1
- package/lib/widgets/forms.js +309 -169
- package/lib/widgets/forms.js.map +1 -1
- package/package.json +1 -1
package/lib/widgets/forms.js
CHANGED
|
@@ -44,6 +44,7 @@ exports.findClosest = findClosest;
|
|
|
44
44
|
exports.formsFor = formsFor;
|
|
45
45
|
exports.makeDescription = makeDescription;
|
|
46
46
|
exports.makeSelectForCategory = makeSelectForCategory;
|
|
47
|
+
exports.makeSelectForChoice = makeSelectForChoice;
|
|
47
48
|
exports.makeSelectForNestedCategory = makeSelectForNestedCategory;
|
|
48
49
|
exports.makeSelectForOptions = makeSelectForOptions;
|
|
49
50
|
exports.newButton = newButton;
|
|
@@ -155,14 +156,16 @@ _fieldFunction.field[ns.ui('Form').uri] = _fieldFunction.field[ns.ui('Group').ur
|
|
|
155
156
|
var ui = ns.ui;
|
|
156
157
|
if (container) container.appendChild(box); // Prevent loops
|
|
157
158
|
|
|
159
|
+
if (!form) return;
|
|
158
160
|
var key = subject.toNT() + '|' + form.toNT();
|
|
159
161
|
|
|
160
162
|
if (already[key]) {
|
|
161
163
|
// been there done that
|
|
162
|
-
box.appendChild(dom.createTextNode('Group: see above ' + key));
|
|
163
|
-
|
|
164
|
+
box.appendChild(dom.createTextNode('Group: see above ' + key)); // TODO fix dependency cycle to solid-panes by calling outlineManager
|
|
165
|
+
// const plist = [$rdf.st(subject, ns.owl('sameAs'), subject)] // @@ need prev subject
|
|
166
|
+
// dom.outlineManager.appendPropertyTRs(box, plist)
|
|
167
|
+
// dom.appendChild(plist)
|
|
164
168
|
|
|
165
|
-
dom.outlineManager.appendPropertyTRs(box, plist);
|
|
166
169
|
return box;
|
|
167
170
|
}
|
|
168
171
|
|
|
@@ -263,47 +266,43 @@ _fieldFunction.field[ns.ui('Options').uri] = function (dom, container, already,
|
|
|
263
266
|
values = kb.each(subject, dependingOn);
|
|
264
267
|
}
|
|
265
268
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
for (var i = 0; i < cases.length; i++) {
|
|
270
|
-
var c = cases[i];
|
|
271
|
-
var tests = kb.each(c, ui('for'), null, formDoc); // There can be multiple 'for'
|
|
269
|
+
for (var i = 0; i < cases.length; i++) {
|
|
270
|
+
var c = cases[i];
|
|
271
|
+
var tests = kb.each(c, ui('for'), null, formDoc); // There can be multiple 'for'
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
var match = false;
|
|
274
274
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
for (var j = 0; j < tests.length; j++) {
|
|
276
|
+
var _iterator = _createForOfIteratorHelper(values),
|
|
277
|
+
_step;
|
|
278
278
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
try {
|
|
280
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
281
|
+
var value = _step.value;
|
|
282
|
+
var test = tests[j];
|
|
283
283
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
284
|
+
if (value.sameTerm(tests) || value.termType === test.termType && value.value === test.value) {
|
|
285
|
+
match = true;
|
|
287
286
|
}
|
|
288
|
-
} catch (err) {
|
|
289
|
-
_iterator.e(err);
|
|
290
|
-
} finally {
|
|
291
|
-
_iterator.f();
|
|
292
287
|
}
|
|
288
|
+
} catch (err) {
|
|
289
|
+
_iterator.e(err);
|
|
290
|
+
} finally {
|
|
291
|
+
_iterator.f();
|
|
293
292
|
}
|
|
293
|
+
}
|
|
294
294
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (!_field3) {
|
|
299
|
-
box.appendChild((0, _error.errorMessageBlock)(dom, 'No "use" part for case in form ' + form));
|
|
300
|
-
return box;
|
|
301
|
-
} else {
|
|
302
|
-
appendForm(dom, box, already, subject, _field3, dataDoc, callbackFunction);
|
|
303
|
-
}
|
|
295
|
+
if (match) {
|
|
296
|
+
var _field3 = kb.the(c, ui('use'));
|
|
304
297
|
|
|
305
|
-
|
|
298
|
+
if (!_field3) {
|
|
299
|
+
box.appendChild((0, _error.errorMessageBlock)(dom, 'No "use" part for case in form ' + form));
|
|
300
|
+
return box;
|
|
301
|
+
} else {
|
|
302
|
+
appendForm(dom, box, already, subject, _field3, dataDoc, callbackFunction);
|
|
306
303
|
}
|
|
304
|
+
|
|
305
|
+
break;
|
|
307
306
|
}
|
|
308
307
|
} // @@ Add box.refresh() to sync fields with values
|
|
309
308
|
|
|
@@ -591,7 +590,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
|
|
|
591
590
|
// delete button and move buttons
|
|
592
591
|
|
|
593
592
|
if (kb.updater.editable(dataDoc.uri)) {
|
|
594
|
-
buttons.deleteButtonWithCheck(dom, subField,
|
|
593
|
+
buttons.deleteButtonWithCheck(dom, subField, multipleUIlabel, deleteThisItem);
|
|
595
594
|
|
|
596
595
|
if (ordered) {
|
|
597
596
|
// Add controsl in a frame
|
|
@@ -642,7 +641,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
|
|
|
642
641
|
|
|
643
642
|
var _shim = dom.createElement('div');
|
|
644
643
|
|
|
645
|
-
_shim.appendChild(subField); // Subfield has its own
|
|
644
|
+
_shim.appendChild(subField); // Subfield has its own layout
|
|
646
645
|
|
|
647
646
|
|
|
648
647
|
frame.appendChild(_shim);
|
|
@@ -691,6 +690,8 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
|
|
|
691
690
|
return shim;
|
|
692
691
|
}
|
|
693
692
|
|
|
693
|
+
var multipleUIlabel = kb.any(form, ui('label'));
|
|
694
|
+
if (!multipleUIlabel) multipleUIlabel = utils.label(property);
|
|
694
695
|
var min = kb.any(form, ui('min')); // This is the minimum number -- default 0
|
|
695
696
|
|
|
696
697
|
min = min ? 0 + min.value : 0;
|
|
@@ -731,10 +732,9 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
|
|
|
731
732
|
img.setAttribute('src', plusIconURI); // plus sign
|
|
732
733
|
|
|
733
734
|
img.setAttribute('style', 'margin: 0.2em; width: 1.5em; height:1.5em');
|
|
734
|
-
img.title = 'Click to add
|
|
735
|
-
var prompt =
|
|
736
|
-
prompt.textContent = (values.length === 0 ? 'Add
|
|
737
|
-
|
|
735
|
+
img.title = 'Click to add another ' + multipleUIlabel;
|
|
736
|
+
var prompt = dom.createElement('span');
|
|
737
|
+
prompt.textContent = (values.length === 0 ? 'Add another ' : 'Add ') + multipleUIlabel;
|
|
738
738
|
tail.addEventListener('click', /*#__PURE__*/function () {
|
|
739
739
|
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_eventNotUsed) {
|
|
740
740
|
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
@@ -756,6 +756,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
|
|
|
756
756
|
return _ref3.apply(this, arguments);
|
|
757
757
|
};
|
|
758
758
|
}(), true);
|
|
759
|
+
tail.appendChild(prompt);
|
|
759
760
|
}
|
|
760
761
|
|
|
761
762
|
function createListIfNecessary() {
|
|
@@ -1030,16 +1031,16 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
|
|
|
1030
1031
|
** -- radio buttons
|
|
1031
1032
|
** -- auto-complete typing
|
|
1032
1033
|
**
|
|
1033
|
-
**
|
|
1034
|
+
** TODO: according to ontology ui:choice can also have ns.ui('default') - this is not implemented yet
|
|
1034
1035
|
*/
|
|
1035
1036
|
|
|
1036
1037
|
|
|
1037
1038
|
_fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, subject, form, dataDoc, callbackFunction) {
|
|
1038
1039
|
var ui = ns.ui;
|
|
1039
1040
|
var kb = _solidLogic.store;
|
|
1040
|
-
var multiple = false;
|
|
1041
1041
|
var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
|
|
1042
1042
|
|
|
1043
|
+
var multiSelect = false;
|
|
1043
1044
|
var p;
|
|
1044
1045
|
var box = dom.createElement('div');
|
|
1045
1046
|
box.setAttribute('class', 'choiceBox'); // Set flexDirection column?
|
|
@@ -1068,79 +1069,79 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
|
|
|
1068
1069
|
|
|
1069
1070
|
var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
|
|
1070
1071
|
|
|
1071
|
-
var possible = [];
|
|
1072
|
-
var possibleProperties;
|
|
1073
|
-
var firstSelectOptionText = '* Select from ' + utils.label(subject, true) + ' *';
|
|
1074
1072
|
var opts = {
|
|
1075
1073
|
form: form,
|
|
1076
1074
|
subForm: subForm,
|
|
1077
|
-
|
|
1078
|
-
firstSelectOptionText: firstSelectOptionText,
|
|
1075
|
+
multiSelect: multiSelect,
|
|
1079
1076
|
disambiguate: false
|
|
1080
1077
|
};
|
|
1081
|
-
possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
|
|
1082
1078
|
|
|
1083
|
-
|
|
1084
|
-
possible
|
|
1085
|
-
|
|
1079
|
+
function getSelectorOptions() {
|
|
1080
|
+
var possible = [];
|
|
1081
|
+
var possibleProperties;
|
|
1082
|
+
possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
|
|
1086
1083
|
|
|
1084
|
+
for (var x in kb.findMembersNT(uiFrom)) {
|
|
1085
|
+
possible.push(kb.fromNT(x));
|
|
1086
|
+
} // Use rdfs
|
|
1087
1087
|
|
|
1088
|
-
if (uiFrom.sameTerm(ns.rdfs('Class'))) {
|
|
1089
|
-
for (p in buttons.allClassURIs()) {
|
|
1090
|
-
possible.push(kb.sym(p));
|
|
1091
|
-
} // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
|
|
1092
1088
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1089
|
+
if (uiFrom.sameTerm(ns.rdfs('Class'))) {
|
|
1090
|
+
for (p in buttons.allClassURIs()) {
|
|
1091
|
+
possible.push(kb.sym(p));
|
|
1092
|
+
} // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
|
|
1095
1093
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
}
|
|
1094
|
+
} else if (uiFrom.sameTerm(ns.rdf('Property'))) {
|
|
1095
|
+
possibleProperties = buttons.propertyTriage(kb);
|
|
1099
1096
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1097
|
+
for (p in possibleProperties.op) {
|
|
1098
|
+
possible.push(kb.fromNT(p));
|
|
1099
|
+
}
|
|
1103
1100
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1101
|
+
for (p in possibleProperties.dp) {
|
|
1102
|
+
possible.push(kb.fromNT(p));
|
|
1103
|
+
}
|
|
1107
1104
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1105
|
+
opts.disambiguate = true; // This is a big class, and the labels won't be enough.
|
|
1106
|
+
} else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
|
|
1107
|
+
possibleProperties = buttons.propertyTriage(kb);
|
|
1111
1108
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1109
|
+
for (p in possibleProperties.op) {
|
|
1110
|
+
possible.push(kb.fromNT(p));
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
opts.disambiguate = true;
|
|
1114
|
+
} else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
|
|
1115
|
+
possibleProperties = buttons.propertyTriage(kb);
|
|
1116
|
+
|
|
1117
|
+
for (p in possibleProperties.dp) {
|
|
1118
|
+
possible.push(kb.fromNT(p));
|
|
1119
|
+
}
|
|
1115
1120
|
|
|
1116
|
-
|
|
1117
|
-
possible.push(kb.fromNT(p));
|
|
1121
|
+
opts.disambiguate = true;
|
|
1118
1122
|
}
|
|
1119
1123
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1124
|
+
var object = kb.any(subject, property);
|
|
1125
|
+
if (object) possible.push(object);
|
|
1126
|
+
return sortByLabel(possible);
|
|
1127
|
+
} // TODO: this checks for any occurrence, regardless of true or false setting
|
|
1122
1128
|
|
|
1123
|
-
var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurance regardles if it is set to true or false
|
|
1124
1129
|
|
|
1125
1130
|
if (kb.any(form, ui('canMintNew'))) {
|
|
1126
1131
|
opts.mint = '* Create new *'; // @@ could be better
|
|
1127
1132
|
}
|
|
1128
1133
|
|
|
1129
|
-
var selector
|
|
1130
|
-
rhs.appendChild(selector);
|
|
1131
|
-
var object;
|
|
1132
|
-
|
|
1133
|
-
if (selector.currentURI) {
|
|
1134
|
-
object = $rdf.sym(selector.currentURI);
|
|
1135
|
-
} else {
|
|
1136
|
-
object = kb.any(subject, property);
|
|
1137
|
-
}
|
|
1134
|
+
var selector;
|
|
1138
1135
|
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1136
|
+
rhs.refresh = function () {
|
|
1137
|
+
var selectorOptions = getSelectorOptions();
|
|
1138
|
+
selector = makeSelectForChoice(dom, rhs, kb, subject, property, selectorOptions, uiFrom, opts, dataDoc, callbackFunction);
|
|
1139
|
+
rhs.innerHTML = '';
|
|
1140
|
+
rhs.appendChild(selector);
|
|
1141
|
+
};
|
|
1143
1142
|
|
|
1143
|
+
rhs.refresh();
|
|
1144
|
+
if (selector && selector.refresh) selector.refresh();
|
|
1144
1145
|
return box;
|
|
1145
1146
|
};
|
|
1146
1147
|
/**
|
|
@@ -1361,7 +1362,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
|
|
|
1361
1362
|
b.setAttribute('type', 'button');
|
|
1362
1363
|
b.setAttribute('style', 'float: right;');
|
|
1363
1364
|
b.innerHTML = 'Goto ' + utils.label(theClass);
|
|
1364
|
-
b.addEventListener('click',
|
|
1365
|
+
b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
|
|
1366
|
+
function (_e) {
|
|
1365
1367
|
dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
|
|
1366
1368
|
}, false);
|
|
1367
1369
|
return box;
|
|
@@ -1496,17 +1498,15 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
|
|
|
1496
1498
|
// @param subject - a term, the subject of the statement(s) being edited.
|
|
1497
1499
|
// @param predicate - a term, the predicate of the statement(s) being edited
|
|
1498
1500
|
// @param possible - a list of terms, the possible value the object can take
|
|
1499
|
-
// @param options.
|
|
1500
|
-
// @param options.firstSelectOptionText - a string to be displayed as the
|
|
1501
|
+
// @param options.nullLabel - a string to be displayed as the
|
|
1501
1502
|
// option for none selected (for non multiple)
|
|
1502
|
-
// @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
|
|
1503
1503
|
// @param options.subForm - If mint, then the form to be used for minting the new thing
|
|
1504
1504
|
// @param dataDoc - The web document being edited
|
|
1505
1505
|
// @param callbackFunction - takes (boolean ok, string errorBody)
|
|
1506
1506
|
*/
|
|
1507
1507
|
|
|
1508
1508
|
|
|
1509
|
-
function makeSelectForOptions(dom, kb, subject, predicate, possible,
|
|
1509
|
+
function makeSelectForOptions(dom, kb, subject, predicate, possible, options, dataDoc, callbackFunction) {
|
|
1510
1510
|
log.debug('Select list length now ' + possible.length);
|
|
1511
1511
|
var n = 0;
|
|
1512
1512
|
var uris = {}; // Count them
|
|
@@ -1523,7 +1523,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1523
1523
|
} // uris is now the set of possible options
|
|
1524
1524
|
|
|
1525
1525
|
|
|
1526
|
-
if (n === 0
|
|
1526
|
+
if (n === 0) {
|
|
1527
1527
|
return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
|
|
1528
1528
|
}
|
|
1529
1529
|
|
|
@@ -1549,6 +1549,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1549
1549
|
actual = getActual();
|
|
1550
1550
|
|
|
1551
1551
|
var onChange = function onChange(_e) {
|
|
1552
|
+
select.disabled = true; // until data written back - gives user feedback too
|
|
1553
|
+
|
|
1552
1554
|
var ds = [];
|
|
1553
1555
|
var is = [];
|
|
1554
1556
|
|
|
@@ -1558,43 +1560,18 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1558
1560
|
}
|
|
1559
1561
|
};
|
|
1560
1562
|
|
|
1561
|
-
var newObject;
|
|
1562
|
-
|
|
1563
1563
|
for (var _i = 0; _i < select.options.length; _i++) {
|
|
1564
1564
|
var opt = select.options[_i];
|
|
1565
|
-
|
|
1566
|
-
if (opt.selected && opt.AJAR_mint) {
|
|
1567
|
-
// not sure if this 'if' is used because I cannot find mintClass
|
|
1568
|
-
if (options.mintClass) {
|
|
1569
|
-
var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
|
|
1570
|
-
if (!ok) {
|
|
1571
|
-
callbackFunction(ok, body, {
|
|
1572
|
-
change: 'new'
|
|
1573
|
-
}); // @@ if ok, need some form of refresh of the select for the new thing
|
|
1574
|
-
}
|
|
1575
|
-
});
|
|
1576
|
-
select.parentNode.appendChild(thisForm);
|
|
1577
|
-
newObject = thisForm.AJAR_subject;
|
|
1578
|
-
} else {
|
|
1579
|
-
newObject = newThing(dataDoc);
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
|
|
1583
|
-
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
|
|
1584
|
-
|
|
1585
|
-
if (options.mintStatementsFun) {
|
|
1586
|
-
is = is.concat(options.mintStatementsFun(newObject));
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
select.currentURI = newObject;
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
1565
|
if (!opt.AJAR_uri) continue; // a prompt or mint
|
|
1593
1566
|
|
|
1594
1567
|
if (opt.selected && !(opt.AJAR_uri in actual)) {
|
|
1595
1568
|
// new class
|
|
1596
1569
|
is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
|
|
1597
|
-
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
if (!opt.selected && opt.AJAR_uri in actual) {
|
|
1573
|
+
// old class
|
|
1574
|
+
removeValue(kb.sym(opt.AJAR_uri));
|
|
1598
1575
|
}
|
|
1599
1576
|
|
|
1600
1577
|
if (opt.selected) select.currentURI = opt.AJAR_uri;
|
|
@@ -1614,29 +1591,25 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1614
1591
|
sel = sel.superSelect;
|
|
1615
1592
|
}
|
|
1616
1593
|
|
|
1617
|
-
log.info('selectForOptions: data doc = ' + dataDoc);
|
|
1594
|
+
log.info('selectForOptions: data doc = ' + dataDoc);
|
|
1595
|
+
kb.updater.update(ds, is, function (uri, ok, body) {
|
|
1596
|
+
actual = getActual(); // refresh
|
|
1618
1597
|
|
|
1619
|
-
removeNextSiblingsAfterElement(select);
|
|
1620
|
-
addSubFormChoice(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
|
|
1621
1598
|
if (ok) {
|
|
1622
|
-
|
|
1623
|
-
actual = getActual(); // refresh
|
|
1624
|
-
|
|
1625
|
-
if (!success) select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
|
|
1626
|
-
});
|
|
1627
|
-
if (callbackFunction) callbackFunction(ok, {
|
|
1628
|
-
widget: 'select',
|
|
1629
|
-
event: 'new'
|
|
1630
|
-
});
|
|
1599
|
+
select.disabled = false; // data written back
|
|
1631
1600
|
} else {
|
|
1632
|
-
select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in
|
|
1601
|
+
return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
|
|
1633
1602
|
}
|
|
1603
|
+
|
|
1604
|
+
if (callbackFunction) callbackFunction(ok, {
|
|
1605
|
+
widget: 'select',
|
|
1606
|
+
event: 'change'
|
|
1607
|
+
});
|
|
1634
1608
|
});
|
|
1635
1609
|
};
|
|
1636
1610
|
|
|
1637
1611
|
var select = dom.createElement('select');
|
|
1638
1612
|
select.setAttribute('style', style.formSelectSTyle);
|
|
1639
|
-
if (options.multiple) select.setAttribute('multiple', 'true');
|
|
1640
1613
|
select.currentURI = null;
|
|
1641
1614
|
|
|
1642
1615
|
select.refresh = function () {
|
|
@@ -1679,22 +1652,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1679
1652
|
select.appendChild(option);
|
|
1680
1653
|
}
|
|
1681
1654
|
|
|
1682
|
-
if (
|
|
1683
|
-
var mint = dom.createElement('option');
|
|
1684
|
-
mint.appendChild(dom.createTextNode(options.mint));
|
|
1685
|
-
mint.AJAR_mint = true; // Flag it
|
|
1686
|
-
|
|
1687
|
-
select.insertBefore(mint, select.firstChild);
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
if (!select.currentURI && !options.multiple) {
|
|
1655
|
+
if (!select.currentURI) {
|
|
1691
1656
|
var prompt = dom.createElement('option');
|
|
1692
|
-
prompt.appendChild(dom.createTextNode(options.
|
|
1693
|
-
prompt.disabled = true;
|
|
1694
|
-
prompt.value = true;
|
|
1695
|
-
prompt.hidden = true;
|
|
1696
|
-
prompt.selected = true;
|
|
1657
|
+
prompt.appendChild(dom.createTextNode(options.nullLabel));
|
|
1697
1658
|
select.insertBefore(prompt, select.firstChild);
|
|
1659
|
+
prompt.selected = true;
|
|
1698
1660
|
}
|
|
1699
1661
|
|
|
1700
1662
|
if (editable) {
|
|
@@ -1713,27 +1675,16 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1713
1675
|
function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
|
|
1714
1676
|
var du = kb.any(category, ns.owl('disjointUnionOf'));
|
|
1715
1677
|
var subs;
|
|
1716
|
-
var multiple = false;
|
|
1717
1678
|
|
|
1718
1679
|
if (!du) {
|
|
1719
1680
|
subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
|
|
1720
|
-
multiple = true;
|
|
1721
1681
|
} else {
|
|
1722
1682
|
subs = du.elements;
|
|
1723
1683
|
}
|
|
1724
1684
|
|
|
1725
1685
|
log.debug('Select list length ' + subs.length);
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
if (subs.length === 1) {
|
|
1732
|
-
return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
|
-
return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, null, {
|
|
1736
|
-
multiple: multiple
|
|
1686
|
+
return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
|
|
1687
|
+
nullLabel: '* Select type *'
|
|
1737
1688
|
}, dataDoc, callbackFunction);
|
|
1738
1689
|
}
|
|
1739
1690
|
/** Make SELECT element to select subclasses recurively
|
|
@@ -1767,8 +1718,7 @@ function makeSelectForNestedCategory(dom, kb, subject, category, dataDoc, callba
|
|
|
1767
1718
|
function onChange(ok, body) {
|
|
1768
1719
|
if (ok) update();
|
|
1769
1720
|
callbackFunction(ok, body);
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1721
|
+
}
|
|
1772
1722
|
|
|
1773
1723
|
var select = makeSelectForCategory(dom, kb, subject, category, dataDoc, onChange);
|
|
1774
1724
|
container.appendChild(select);
|
|
@@ -1923,4 +1873,194 @@ function newThing(doc) {
|
|
|
1923
1873
|
var now = new Date();
|
|
1924
1874
|
return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
|
|
1925
1875
|
}
|
|
1876
|
+
/** Make SELECT element to select options
|
|
1877
|
+
//
|
|
1878
|
+
// @param subject - a term, the subject of the statement(s) being edited.
|
|
1879
|
+
// @param predicate - a term, the predicate of the statement(s) being edited
|
|
1880
|
+
// @param possible - a list of terms, the possible value the object can take
|
|
1881
|
+
// @param options.multiSelect - Boolean - Whether more than one at a time is allowed
|
|
1882
|
+
// @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
|
|
1883
|
+
// @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
|
|
1884
|
+
// @param options.subForm - If mint, then the form to be used for minting the new thing
|
|
1885
|
+
// @param dataDoc - The web document being edited
|
|
1886
|
+
// @param callbackFunction - takes (boolean ok, string errorBody)
|
|
1887
|
+
*/
|
|
1888
|
+
|
|
1889
|
+
|
|
1890
|
+
function makeSelectForChoice(dom, container, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
|
|
1891
|
+
var n = 0;
|
|
1892
|
+
var uris = {}; // Count them
|
|
1893
|
+
|
|
1894
|
+
var editable = kb.updater.editable(dataDoc.uri);
|
|
1895
|
+
|
|
1896
|
+
for (var i = 0; i < possible.length; i++) {
|
|
1897
|
+
var sub = possible[i]; // @@ Maybe; make this so it works with blank nodes too
|
|
1898
|
+
|
|
1899
|
+
if (!sub.uri) debug.warn("makeSelectForOptions: option does not have an uri: ".concat(sub, ", with predicate: ").concat(predicate));
|
|
1900
|
+
if (!sub.uri || sub.uri in uris) continue;
|
|
1901
|
+
uris[sub.uri] = true;
|
|
1902
|
+
n++;
|
|
1903
|
+
} // uris is now the set of possible options
|
|
1904
|
+
|
|
1905
|
+
|
|
1906
|
+
if (n === 0 && !options.mint) {
|
|
1907
|
+
return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
log.debug('makeSelectForOptions: dataDoc=' + dataDoc);
|
|
1911
|
+
|
|
1912
|
+
function determinFirstSelectOption() {
|
|
1913
|
+
var firstSelectOptionText = '--- classify ---';
|
|
1914
|
+
var option = dom.createElement('option');
|
|
1915
|
+
|
|
1916
|
+
if (predicate && !(predicate.termType === 'BlankNode')) {
|
|
1917
|
+
firstSelectOptionText = '* Select for property: ' + utils.label(predicate) + ' *';
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
if (subject && !(subject.termType === 'BlankNode')) {
|
|
1921
|
+
firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *';
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
option.appendChild(dom.createTextNode(firstSelectOptionText));
|
|
1925
|
+
option.disabled = true;
|
|
1926
|
+
option.value = true;
|
|
1927
|
+
option.hidden = true;
|
|
1928
|
+
option.selected = true;
|
|
1929
|
+
return option;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
var onChange = function onChange(_e) {
|
|
1933
|
+
select.refresh();
|
|
1934
|
+
};
|
|
1935
|
+
|
|
1936
|
+
var select = dom.createElement('select');
|
|
1937
|
+
select.setAttribute('style', style.formSelectSTyle);
|
|
1938
|
+
if (options.multiSelect) select.setAttribute('multiSelect', 'true');
|
|
1939
|
+
select.currentURI = null;
|
|
1940
|
+
|
|
1941
|
+
for (var uri in uris) {
|
|
1942
|
+
select.appendChild(createOption(uri));
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
if (editable && options.mint) {
|
|
1946
|
+
var mint = dom.createElement('option');
|
|
1947
|
+
mint.appendChild(dom.createTextNode(options.mint));
|
|
1948
|
+
mint.AJAR_mint = true; // Flag it
|
|
1949
|
+
|
|
1950
|
+
select.insertBefore(mint, select.firstChild);
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
if (select.children.length === 0) select.insertBefore(determinFirstSelectOption(), select.firstChild);
|
|
1954
|
+
|
|
1955
|
+
select.refresh = function () {
|
|
1956
|
+
select.disabled = true; // unlocked any conflict we had got into
|
|
1957
|
+
|
|
1958
|
+
var ds = [];
|
|
1959
|
+
var is = [];
|
|
1960
|
+
|
|
1961
|
+
var removeValue = function removeValue(t) {
|
|
1962
|
+
if (kb.holds(subject, predicate, t, dataDoc)) {
|
|
1963
|
+
ds.push($rdf.st(subject, predicate, t, dataDoc));
|
|
1964
|
+
}
|
|
1965
|
+
};
|
|
1966
|
+
|
|
1967
|
+
var newObject;
|
|
1968
|
+
|
|
1969
|
+
for (var _i3 = 0; _i3 < select.options.length; _i3++) {
|
|
1970
|
+
var opt = select.options[_i3];
|
|
1971
|
+
|
|
1972
|
+
if (opt.selected && opt.AJAR_mint) {
|
|
1973
|
+
// not sure if this 'if' is used because I cannot find mintClass
|
|
1974
|
+
if (options.mintClass) {
|
|
1975
|
+
var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
|
|
1976
|
+
if (!ok) {
|
|
1977
|
+
callbackFunction(ok, body, {
|
|
1978
|
+
change: 'new'
|
|
1979
|
+
}); // @@ if ok, need some form of refresh of the select for the new thing
|
|
1980
|
+
}
|
|
1981
|
+
});
|
|
1982
|
+
select.parentNode.appendChild(thisForm);
|
|
1983
|
+
newObject = thisForm.AJAR_subject;
|
|
1984
|
+
} else {
|
|
1985
|
+
newObject = newThing(dataDoc);
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
|
|
1989
|
+
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
|
|
1990
|
+
|
|
1991
|
+
if (options.mintStatementsFun) {
|
|
1992
|
+
is = is.concat(options.mintStatementsFun(newObject));
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
select.currentURI = newObject;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
if (!opt.AJAR_uri) continue; // a prompt or mint
|
|
1999
|
+
|
|
2000
|
+
if (opt.selected) select.currentURI = opt.AJAR_uri;
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
var sel = select.subSelect; // All subclasses must also go
|
|
2004
|
+
|
|
2005
|
+
while (sel && sel.currentURI) {
|
|
2006
|
+
removeValue(kb.sym(sel.currentURI));
|
|
2007
|
+
sel = sel.subSelect;
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
sel = select.superSelect; // All superclasses are redundant
|
|
2011
|
+
|
|
2012
|
+
while (sel && sel.currentURI) {
|
|
2013
|
+
removeValue(kb.sym(sel.currentURI));
|
|
2014
|
+
sel = sel.superSelect;
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
log.info('selectForOptions: data doc = ' + dataDoc);
|
|
2018
|
+
|
|
2019
|
+
if (select.currentURI) {
|
|
2020
|
+
removeNextSiblingsAfterElement(select);
|
|
2021
|
+
addSubFormChoice(dom, container, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
|
|
2022
|
+
if (ok) {
|
|
2023
|
+
kb.updater.update(ds, is, function (uri, success, errorBody) {
|
|
2024
|
+
if (!success) container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
|
|
2025
|
+
});
|
|
2026
|
+
if (callbackFunction) callbackFunction(ok, {
|
|
2027
|
+
widget: 'select',
|
|
2028
|
+
event: 'new'
|
|
2029
|
+
}); // widgets.refreshTree(container)
|
|
2030
|
+
} else {
|
|
2031
|
+
container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
select.disabled = false;
|
|
2037
|
+
};
|
|
2038
|
+
|
|
2039
|
+
function createOption(uri) {
|
|
2040
|
+
var option = dom.createElement('option');
|
|
2041
|
+
var c = kb.sym(uri);
|
|
2042
|
+
|
|
2043
|
+
if (options.disambiguate) {
|
|
2044
|
+
option.appendChild(dom.createTextNode(utils.labelWithOntology(c, true))); // Init. cap
|
|
2045
|
+
} else {
|
|
2046
|
+
option.appendChild(dom.createTextNode(utils.label(c, true))); // Init.
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
var backgroundColor = kb.any(c, kb.sym('http://www.w3.org/ns/ui#backgroundColor'));
|
|
2050
|
+
|
|
2051
|
+
if (backgroundColor) {
|
|
2052
|
+
option.setAttribute('style', 'background-color: ' + backgroundColor.value + '; ');
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
option.AJAR_uri = uri;
|
|
2056
|
+
if (c.toString() === '' + select.currentURI) option.selected = true;
|
|
2057
|
+
return option;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
if (editable) {
|
|
2061
|
+
select.addEventListener('change', onChange, false);
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
return select;
|
|
2065
|
+
} // makeSelectForChoice
|
|
1926
2066
|
//# sourceMappingURL=forms.js.map
|