solid-ui 2.4.22-3e0d1a42 → 2.4.22-4485d5d9
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 +310 -180
- 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 +302 -174
- 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
|
|
|
@@ -692,8 +691,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
|
|
|
692
691
|
}
|
|
693
692
|
|
|
694
693
|
var multipleUIlabel = kb.any(form, ui('label'));
|
|
695
|
-
if (!multipleUIlabel) multipleUIlabel = utils.label(property
|
|
696
|
-
|
|
694
|
+
if (!multipleUIlabel) multipleUIlabel = utils.label(property);
|
|
697
695
|
var min = kb.any(form, ui('min')); // This is the minimum number -- default 0
|
|
698
696
|
|
|
699
697
|
min = min ? 0 + min.value : 0;
|
|
@@ -1033,6 +1031,7 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
|
|
|
1033
1031
|
** -- radio buttons
|
|
1034
1032
|
** -- auto-complete typing
|
|
1035
1033
|
**
|
|
1034
|
+
** TODO: according to ontology ui:choice can also have ns.ui('default') - this is not implemented yet
|
|
1036
1035
|
*/
|
|
1037
1036
|
|
|
1038
1037
|
|
|
@@ -1041,8 +1040,6 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
|
|
|
1041
1040
|
var kb = _solidLogic.store;
|
|
1042
1041
|
var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
|
|
1043
1042
|
|
|
1044
|
-
var uiMultipleInUse = false; // this signals to ui:choice that it is part of a ui:multiple
|
|
1045
|
-
|
|
1046
1043
|
var multiSelect = false;
|
|
1047
1044
|
var p;
|
|
1048
1045
|
var box = dom.createElement('div');
|
|
@@ -1072,87 +1069,77 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
|
|
|
1072
1069
|
|
|
1073
1070
|
var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
|
|
1074
1071
|
|
|
1075
|
-
var possible = [];
|
|
1076
|
-
var possibleProperties;
|
|
1077
|
-
var firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *'; // if we do NOT have a container it means it is a ui:Multiple
|
|
1078
|
-
// only important for the first option text in select
|
|
1079
|
-
|
|
1080
|
-
if (!container) {
|
|
1081
|
-
uiMultipleInUse = true;
|
|
1082
|
-
firstSelectOptionText = utils.label(subject, true);
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
1072
|
var opts = {
|
|
1086
1073
|
form: form,
|
|
1087
1074
|
subForm: subForm,
|
|
1088
1075
|
multiSelect: multiSelect,
|
|
1089
|
-
firstSelectOptionText: firstSelectOptionText,
|
|
1090
|
-
uiMultipleInUse: uiMultipleInUse,
|
|
1091
1076
|
disambiguate: false
|
|
1092
1077
|
};
|
|
1093
|
-
possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
|
|
1094
1078
|
|
|
1095
|
-
|
|
1096
|
-
possible
|
|
1097
|
-
|
|
1079
|
+
function getSelectorOptions() {
|
|
1080
|
+
var possible = [];
|
|
1081
|
+
var possibleProperties;
|
|
1082
|
+
possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
|
|
1098
1083
|
|
|
1084
|
+
for (var x in kb.findMembersNT(uiFrom)) {
|
|
1085
|
+
possible.push(kb.fromNT(x));
|
|
1086
|
+
} // Use rdfs
|
|
1099
1087
|
|
|
1100
|
-
if (uiFrom.sameTerm(ns.rdfs('Class'))) {
|
|
1101
|
-
for (p in buttons.allClassURIs()) {
|
|
1102
|
-
possible.push(kb.sym(p));
|
|
1103
|
-
} // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
|
|
1104
1088
|
|
|
1105
|
-
|
|
1106
|
-
|
|
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)
|
|
1107
1093
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
}
|
|
1094
|
+
} else if (uiFrom.sameTerm(ns.rdf('Property'))) {
|
|
1095
|
+
possibleProperties = buttons.propertyTriage(kb);
|
|
1111
1096
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1097
|
+
for (p in possibleProperties.op) {
|
|
1098
|
+
possible.push(kb.fromNT(p));
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
for (p in possibleProperties.dp) {
|
|
1102
|
+
possible.push(kb.fromNT(p));
|
|
1103
|
+
}
|
|
1115
1104
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
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);
|
|
1119
1108
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
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);
|
|
1123
1116
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1117
|
+
for (p in possibleProperties.dp) {
|
|
1118
|
+
possible.push(kb.fromNT(p));
|
|
1119
|
+
}
|
|
1127
1120
|
|
|
1128
|
-
|
|
1129
|
-
possible.push(kb.fromNT(p));
|
|
1121
|
+
opts.disambiguate = true;
|
|
1130
1122
|
}
|
|
1131
1123
|
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1124
|
+
return sortByLabel(possible);
|
|
1125
|
+
} // TODO: this checks for any occurrence, regardless of true or false setting
|
|
1134
1126
|
|
|
1135
|
-
var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurrence, regardless of true or false setting
|
|
1136
1127
|
|
|
1137
1128
|
if (kb.any(form, ui('canMintNew'))) {
|
|
1138
1129
|
opts.mint = '* Create new *'; // @@ could be better
|
|
1139
1130
|
}
|
|
1140
1131
|
|
|
1141
|
-
var selector
|
|
1142
|
-
rhs.appendChild(selector);
|
|
1143
|
-
var object;
|
|
1132
|
+
var selector;
|
|
1144
1133
|
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
if (object && subForm) {
|
|
1152
|
-
removeNextSiblingsAfterElement(selector);
|
|
1153
|
-
addSubFormChoice(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
|
|
1154
|
-
}
|
|
1134
|
+
rhs.refresh = function () {
|
|
1135
|
+
var selectorOptions = getSelectorOptions();
|
|
1136
|
+
selector = makeSelectForChoice(dom, rhs, kb, subject, property, selectorOptions, uiFrom, opts, dataDoc, callbackFunction);
|
|
1137
|
+
rhs.innerHTML = '';
|
|
1138
|
+
rhs.appendChild(selector);
|
|
1139
|
+
};
|
|
1155
1140
|
|
|
1141
|
+
rhs.refresh();
|
|
1142
|
+
if (selector && selector.refresh) selector.refresh();
|
|
1156
1143
|
return box;
|
|
1157
1144
|
};
|
|
1158
1145
|
/**
|
|
@@ -1373,7 +1360,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
|
|
|
1373
1360
|
b.setAttribute('type', 'button');
|
|
1374
1361
|
b.setAttribute('style', 'float: right;');
|
|
1375
1362
|
b.innerHTML = 'Goto ' + utils.label(theClass);
|
|
1376
|
-
b.addEventListener('click',
|
|
1363
|
+
b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
|
|
1364
|
+
function (_e) {
|
|
1377
1365
|
dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
|
|
1378
1366
|
}, false);
|
|
1379
1367
|
return box;
|
|
@@ -1508,18 +1496,15 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
|
|
|
1508
1496
|
// @param subject - a term, the subject of the statement(s) being edited.
|
|
1509
1497
|
// @param predicate - a term, the predicate of the statement(s) being edited
|
|
1510
1498
|
// @param possible - a list of terms, the possible value the object can take
|
|
1511
|
-
// @param options.
|
|
1512
|
-
//
|
|
1513
|
-
// option for none selected (for non multiSelect)
|
|
1514
|
-
// @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
|
|
1515
|
-
// @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
|
|
1499
|
+
// @param options.nullLabel - a string to be displayed as the
|
|
1500
|
+
// option for none selected (for non multiple)
|
|
1516
1501
|
// @param options.subForm - If mint, then the form to be used for minting the new thing
|
|
1517
1502
|
// @param dataDoc - The web document being edited
|
|
1518
1503
|
// @param callbackFunction - takes (boolean ok, string errorBody)
|
|
1519
1504
|
*/
|
|
1520
1505
|
|
|
1521
1506
|
|
|
1522
|
-
function makeSelectForOptions(dom, kb, subject, predicate, possible,
|
|
1507
|
+
function makeSelectForOptions(dom, kb, subject, predicate, possible, options, dataDoc, callbackFunction) {
|
|
1523
1508
|
log.debug('Select list length now ' + possible.length);
|
|
1524
1509
|
var n = 0;
|
|
1525
1510
|
var uris = {}; // Count them
|
|
@@ -1536,7 +1521,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1536
1521
|
} // uris is now the set of possible options
|
|
1537
1522
|
|
|
1538
1523
|
|
|
1539
|
-
if (n === 0
|
|
1524
|
+
if (n === 0) {
|
|
1540
1525
|
return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
|
|
1541
1526
|
}
|
|
1542
1527
|
|
|
@@ -1562,6 +1547,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1562
1547
|
actual = getActual();
|
|
1563
1548
|
|
|
1564
1549
|
var onChange = function onChange(_e) {
|
|
1550
|
+
select.disabled = true; // until data written back - gives user feedback too
|
|
1551
|
+
|
|
1565
1552
|
var ds = [];
|
|
1566
1553
|
var is = [];
|
|
1567
1554
|
|
|
@@ -1571,43 +1558,18 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1571
1558
|
}
|
|
1572
1559
|
};
|
|
1573
1560
|
|
|
1574
|
-
var newObject;
|
|
1575
|
-
|
|
1576
1561
|
for (var _i = 0; _i < select.options.length; _i++) {
|
|
1577
1562
|
var opt = select.options[_i];
|
|
1578
|
-
|
|
1579
|
-
if (opt.selected && opt.AJAR_mint) {
|
|
1580
|
-
// not sure if this 'if' is used because I cannot find mintClass
|
|
1581
|
-
if (options.mintClass) {
|
|
1582
|
-
var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
|
|
1583
|
-
if (!ok) {
|
|
1584
|
-
callbackFunction(ok, body, {
|
|
1585
|
-
change: 'new'
|
|
1586
|
-
}); // @@ if ok, need some form of refresh of the select for the new thing
|
|
1587
|
-
}
|
|
1588
|
-
});
|
|
1589
|
-
select.parentNode.appendChild(thisForm);
|
|
1590
|
-
newObject = thisForm.AJAR_subject;
|
|
1591
|
-
} else {
|
|
1592
|
-
newObject = newThing(dataDoc);
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
|
|
1596
|
-
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
|
|
1597
|
-
|
|
1598
|
-
if (options.mintStatementsFun) {
|
|
1599
|
-
is = is.concat(options.mintStatementsFun(newObject));
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
|
-
select.currentURI = newObject;
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
1563
|
if (!opt.AJAR_uri) continue; // a prompt or mint
|
|
1606
1564
|
|
|
1607
1565
|
if (opt.selected && !(opt.AJAR_uri in actual)) {
|
|
1608
1566
|
// new class
|
|
1609
1567
|
is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
|
|
1610
|
-
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
if (!opt.selected && opt.AJAR_uri in actual) {
|
|
1571
|
+
// old class
|
|
1572
|
+
removeValue(kb.sym(opt.AJAR_uri));
|
|
1611
1573
|
}
|
|
1612
1574
|
|
|
1613
1575
|
if (opt.selected) select.currentURI = opt.AJAR_uri;
|
|
@@ -1627,29 +1589,25 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1627
1589
|
sel = sel.superSelect;
|
|
1628
1590
|
}
|
|
1629
1591
|
|
|
1630
|
-
log.info('selectForOptions: data doc = ' + dataDoc);
|
|
1592
|
+
log.info('selectForOptions: data doc = ' + dataDoc);
|
|
1593
|
+
kb.updater.update(ds, is, function (uri, ok, body) {
|
|
1594
|
+
actual = getActual(); // refresh
|
|
1631
1595
|
|
|
1632
|
-
removeNextSiblingsAfterElement(select);
|
|
1633
|
-
addSubFormChoice(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
|
|
1634
1596
|
if (ok) {
|
|
1635
|
-
|
|
1636
|
-
actual = getActual(); // refresh
|
|
1637
|
-
|
|
1638
|
-
if (!success) select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
|
|
1639
|
-
});
|
|
1640
|
-
if (callbackFunction) callbackFunction(ok, {
|
|
1641
|
-
widget: 'select',
|
|
1642
|
-
event: 'new'
|
|
1643
|
-
});
|
|
1597
|
+
select.disabled = false; // data written back
|
|
1644
1598
|
} else {
|
|
1645
|
-
select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in
|
|
1599
|
+
return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
|
|
1646
1600
|
}
|
|
1601
|
+
|
|
1602
|
+
if (callbackFunction) callbackFunction(ok, {
|
|
1603
|
+
widget: 'select',
|
|
1604
|
+
event: 'change'
|
|
1605
|
+
});
|
|
1647
1606
|
});
|
|
1648
1607
|
};
|
|
1649
1608
|
|
|
1650
1609
|
var select = dom.createElement('select');
|
|
1651
1610
|
select.setAttribute('style', style.formSelectSTyle);
|
|
1652
|
-
if (options.multiSelect) select.setAttribute('multiSelect', 'true');
|
|
1653
1611
|
select.currentURI = null;
|
|
1654
1612
|
|
|
1655
1613
|
select.refresh = function () {
|
|
@@ -1692,22 +1650,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1692
1650
|
select.appendChild(option);
|
|
1693
1651
|
}
|
|
1694
1652
|
|
|
1695
|
-
if (
|
|
1696
|
-
var mint = dom.createElement('option');
|
|
1697
|
-
mint.appendChild(dom.createTextNode(options.mint));
|
|
1698
|
-
mint.AJAR_mint = true; // Flag it
|
|
1699
|
-
|
|
1700
|
-
select.insertBefore(mint, select.firstChild);
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
if (!select.currentURI && options.uiMultipleInUse) {
|
|
1653
|
+
if (!select.currentURI) {
|
|
1704
1654
|
var prompt = dom.createElement('option');
|
|
1705
|
-
prompt.appendChild(dom.createTextNode(options.
|
|
1706
|
-
prompt.disabled = true;
|
|
1707
|
-
prompt.value = true;
|
|
1708
|
-
prompt.hidden = true;
|
|
1709
|
-
prompt.selected = true;
|
|
1655
|
+
prompt.appendChild(dom.createTextNode(options.nullLabel));
|
|
1710
1656
|
select.insertBefore(prompt, select.firstChild);
|
|
1657
|
+
prompt.selected = true;
|
|
1711
1658
|
}
|
|
1712
1659
|
|
|
1713
1660
|
if (editable) {
|
|
@@ -1726,27 +1673,16 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
|
|
|
1726
1673
|
function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
|
|
1727
1674
|
var du = kb.any(category, ns.owl('disjointUnionOf'));
|
|
1728
1675
|
var subs;
|
|
1729
|
-
var multiSelect = false;
|
|
1730
1676
|
|
|
1731
1677
|
if (!du) {
|
|
1732
1678
|
subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
|
|
1733
|
-
multiSelect = true;
|
|
1734
1679
|
} else {
|
|
1735
1680
|
subs = du.elements;
|
|
1736
1681
|
}
|
|
1737
1682
|
|
|
1738
1683
|
log.debug('Select list length ' + subs.length);
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
if (subs.length === 1) {
|
|
1745
|
-
return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, null, {
|
|
1749
|
-
multiSelect: multiSelect
|
|
1684
|
+
return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
|
|
1685
|
+
nullLabel: '* Select type *'
|
|
1750
1686
|
}, dataDoc, callbackFunction);
|
|
1751
1687
|
}
|
|
1752
1688
|
/** Make SELECT element to select subclasses recurively
|
|
@@ -1780,8 +1716,7 @@ function makeSelectForNestedCategory(dom, kb, subject, category, dataDoc, callba
|
|
|
1780
1716
|
function onChange(ok, body) {
|
|
1781
1717
|
if (ok) update();
|
|
1782
1718
|
callbackFunction(ok, body);
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1719
|
+
}
|
|
1785
1720
|
|
|
1786
1721
|
var select = makeSelectForCategory(dom, kb, subject, category, dataDoc, onChange);
|
|
1787
1722
|
container.appendChild(select);
|
|
@@ -1936,4 +1871,197 @@ function newThing(doc) {
|
|
|
1936
1871
|
var now = new Date();
|
|
1937
1872
|
return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
|
|
1938
1873
|
}
|
|
1874
|
+
/** Make SELECT element to select options
|
|
1875
|
+
//
|
|
1876
|
+
// @param subject - a term, the subject of the statement(s) being edited.
|
|
1877
|
+
// @param predicate - a term, the predicate of the statement(s) being edited
|
|
1878
|
+
// @param possible - a list of terms, the possible value the object can take
|
|
1879
|
+
// @param options.multiSelect - Boolean - Whether more than one at a time is allowed
|
|
1880
|
+
// @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
|
|
1881
|
+
// @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
|
|
1882
|
+
// @param options.subForm - If mint, then the form to be used for minting the new thing
|
|
1883
|
+
// @param dataDoc - The web document being edited
|
|
1884
|
+
// @param callbackFunction - takes (boolean ok, string errorBody)
|
|
1885
|
+
*/
|
|
1886
|
+
|
|
1887
|
+
|
|
1888
|
+
function makeSelectForChoice(dom, container, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
|
|
1889
|
+
var n = 0;
|
|
1890
|
+
var uris = {}; // Count them
|
|
1891
|
+
|
|
1892
|
+
var editable = kb.updater.editable(dataDoc.uri);
|
|
1893
|
+
|
|
1894
|
+
for (var i = 0; i < possible.length; i++) {
|
|
1895
|
+
var sub = possible[i]; // @@ Maybe; make this so it works with blank nodes too
|
|
1896
|
+
|
|
1897
|
+
if (!sub.uri) debug.warn("makeSelectForOptions: option does not have an uri: ".concat(sub, ", with predicate: ").concat(predicate));
|
|
1898
|
+
if (!sub.uri || sub.uri in uris) continue;
|
|
1899
|
+
uris[sub.uri] = true;
|
|
1900
|
+
n++;
|
|
1901
|
+
} // uris is now the set of possible options
|
|
1902
|
+
|
|
1903
|
+
|
|
1904
|
+
if (n === 0 && !options.mint) {
|
|
1905
|
+
return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
log.debug('makeSelectForOptions: dataDoc=' + dataDoc);
|
|
1909
|
+
|
|
1910
|
+
function determinFirstSelectOption() {
|
|
1911
|
+
var firstSelectOptionText = '--- classify ---';
|
|
1912
|
+
var option = dom.createElement('option');
|
|
1913
|
+
|
|
1914
|
+
if (predicate && !(predicate.termType === 'BlankNode')) {
|
|
1915
|
+
firstSelectOptionText = '* Select for property: ' + utils.label(predicate) + ' *';
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
if (subject && !(subject.termType === 'BlankNode')) {
|
|
1919
|
+
firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *';
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
option.appendChild(dom.createTextNode(firstSelectOptionText));
|
|
1923
|
+
option.disabled = true;
|
|
1924
|
+
option.value = true;
|
|
1925
|
+
option.hidden = true;
|
|
1926
|
+
option.selected = true;
|
|
1927
|
+
return option;
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
var onChange = function onChange(_e) {
|
|
1931
|
+
select.refresh();
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1934
|
+
var select = dom.createElement('select');
|
|
1935
|
+
select.setAttribute('style', style.formSelectSTyle);
|
|
1936
|
+
if (options.multiSelect) select.setAttribute('multiSelect', 'true');
|
|
1937
|
+
select.currentURI = null;
|
|
1938
|
+
var object = kb.any(subject, predicate);
|
|
1939
|
+
if (object) select.currentURI = object;
|
|
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
|
+
select.refresh();
|
|
2065
|
+
return select;
|
|
2066
|
+
} // makeSelectForChoice
|
|
1939
2067
|
//# sourceMappingURL=forms.js.map
|