-
Notifications
You must be signed in to change notification settings - Fork 6
/
individual.js
129 lines (107 loc) · 3.94 KB
/
individual.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import * as UI from 'solid-ui'
import { authn, store } from 'solid-logic'
import { renderMugshotGallery } from './mugshotGallery'
import { renderWebIdControl, renderPublicIdControl } from './webidControl'
import { renderGroupMemberships } from './groupMembershipControl.js'
import textOfForms from './lib/forms'
import VCARD_ONTOLOGY_TEXT from './lib/vcard.js'
const $rdf = UI.rdf
const ns = UI.ns
const kb = store
const style = UI.style
export function loadTurtleText (kb, thing, text) {
const doc = thing.doc()
if (!kb.holds(undefined, undefined, undefined, doc)) {
// If not loaded already
$rdf.parse(text, kb, doc.uri, 'text/turtle') // Load directly
}
}
// Render Individual card
export async function renderIndividual (dom, div, subject, dataBrowserContext) {
// //////////////////// DRAG and Drop for mugshot image
function complain (message) {
console.log(message)
div.appendChild(UI.widgets.errorMessageBlock(dom, message, 'pink'))
}
function spacer () {
div
.appendChild(dom.createElement('div'))
.setAttribute('style', 'height: 1em')
}
function complainIfBad (ok, body) {
if (!ok) {
complain('Error: ' + body)
}
}
/// ///////////////////////////
const t = kb.findTypeURIs(subject)
const isOrganization = !!(t[ns.vcard('Organization').uri] || t[ns.schema('Organization').uri])
const editable = kb.updater.editable(subject.doc().uri, kb)
const individualForm = kb.sym(
'https://solid.github.io/solid-panes/contact/individualForm.ttl#form1'
)
loadTurtleText(kb, individualForm, textOfForms)
const orgDetailsForm = kb.sym( // orgDetailsForm organizationForm
'https://solid.github.io/solid-panes/contact/individualForm.ttl#orgDetailsForm'
)
// Ontology metadata for this pane we bundle with the JS
const vcardOnt = UI.ns.vcard('Type').doc()
if (!kb.holds(undefined, undefined, undefined, vcardOnt)) {
// If not loaded already
$rdf.parse(VCARD_ONTOLOGY_TEXT, kb, vcardOnt.uri, 'text/turtle') // Load ontology directly
}
try {
await kb.fetcher.load(subject.doc())
} catch (err) {
complain('Error: Failed to load contact card: ' + err)
} // end of try catch on load
div.style = style.paneDivStyle || 'padding: 0.5em 1.5em 1em 1.5em;'
authn.checkUser() // kick off async operation @@@ use async version
div.appendChild(renderMugshotGallery(dom, subject))
const form = isOrganization ? orgDetailsForm : individualForm
UI.widgets.appendForm(
dom,
div,
{},
subject,
form,
subject.doc(),
complainIfBad
)
spacer()
div.appendChild(await renderGroupMemberships(subject, dataBrowserContext))
spacer()
// Auto complete searches in a table
// Prefer the fom below renderPublicIdControl
/*
if (isOrganization) {
const publicDataTable = div.appendChild(dom.createElement('table'))
async function publicDataSearchRow (name) {
async function autoCompleteDone (object, _name) {
right.innerHTML = ''
right.appendchild(UI.widgets.personTR(dom, object))
}
const row = dom.createElement('tr')
const left = row.appendChild(dom.createElement('td'))
left.textContent = name
const right = row.appendChild(dom.createElement('td'))
right.appendChild(await renderAutoComplete(dom, subject, ns.owl('sameAs'), autoCompleteDone))
return row
}
publicDataTable.appendChild(await publicDataSearchRow('dbpedia'))
}
*/
// Allow to attach documents etc to the contact card
UI.widgets.attachmentList(dom, subject, div, {
modify: editable
// promptIcon: UI.icons.iconBase + 'noun_681601.svg',
// predicate: UI.ns.vcard('url') // @@@@@@@@@ ,--- no, the vcard ontology structure uses a bnode.
})
spacer()
if (isOrganization) {
div.appendChild(await renderPublicIdControl(subject, dataBrowserContext))
} else {
div.appendChild(await renderWebIdControl(subject, dataBrowserContext))
}
// div.appendChild(dom.createElement('hr'))
} // renderIndividual