forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.js
More file actions
236 lines (215 loc) · 8.32 KB
/
create.js
File metadata and controls
236 lines (215 loc) · 8.32 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* create.js UI to craete new objects in the solid-app-set world
**
*/
// const error = require('./widgets/error')
// const widgets = require('./widgets/index')
// const utils = require('./utils')
// const UI = require('solid-ui')
const UI = {
authn: require('./signin'),
icons: require('./iconBase'),
log: require('./log'),
ns: require('./ns'),
store: require('./store'),
style: require('./style'),
utils: require('./utils'),
widgets: require('./widgets')
}
const kb = UI.store
module.exports = {
newThingUI
}
/* newThingUI -- return UI for user to select a new object, folder, etc
**
** context must include: dom, div,
** optional: folder: NamedNode -- the folder where the thing is bring put
** (suppresses asking for a full URI or workspace)
**
*/
function newThingUI (context, thePanes) {
const dom = context.dom
const div = context.div
if (context.me && !context.me.uri) throw new Error('newThingUI: Invalid userid: ' + context.me)
var iconStyle = 'padding: 0.7em; width: 2em; height: 2em;' // was: 'padding: 1em; width: 3em; height: 3em;'
var star = div.appendChild(dom.createElement('img'))
var visible = false // the inividual tools tools
// noun_272948.svg = black star
// noun_34653_green.svg = green plus
star.setAttribute('src', UI.icons.iconBase + 'noun_34653_green.svg')
star.setAttribute('style', iconStyle)
star.setAttribute('title', 'Add another tool to the meeting')
var complain = function complain (message) {
var pre = div.appendChild(dom.createElement('pre'))
pre.setAttribute('style', 'background-color: pink')
pre.appendChild(dom.createTextNode(message))
}
var selectNewTool = function (event) {
visible = !visible
star.setAttribute('style', iconStyle + (visible ? 'background-color: yellow;' : ''))
styleTheIcons(visible ? '' : 'display: none;')
}
star.addEventListener('click', selectNewTool)
function makeNewAppInstance (options) {
return new Promise(function (resolve, reject) {
var selectUI // , selectUIParent
function callbackWS (ws, newBase) {
UI.authn.logInLoadProfile(context).then(context => {
var newPaneOptions = {
newBase: newBase,
workspace: ws
}
for (var opt in options) { // get div, dom, me, folder, pane, refreshTable
newPaneOptions[opt] = options[opt]
}
console.log('newThingUI: Minting new ' + newPaneOptions.pane.name + ' at ' + newPaneOptions.newBase)
options.pane.mintNew(newPaneOptions)
.then(function (newPaneOptions) {
if (!newPaneOptions || !newPaneOptions.newInstance) {
throw new Error('Cannot mint new - missing newInstance')
}
if (newPaneOptions.folder) {
kb.add(newPaneOptions.folder, UI.ns.ldp('contains'), kb.sym(newPaneOptions.newBase),
newPaneOptions.folder.doc()) // Ping the patch system?
if (newPaneOptions.refreshTarget) {
newPaneOptions.refreshTarget.refresh() // Refresh the cntaining display
}
// selectUI.parentNode.removeChild(selectUI) It removes itself
} else {
var p = options.div.appendChild(dom.createElement('p'))
p.setAttribute('style', 'font-size: 120%;')
// Make link to new thing
p.innerHTML =
"Your <a target='_blank' href='" + newPaneOptions.newInstance.uri + "'><b>new " + options.noun + '</b></a> is ready to be set up. ' +
"<br/><br/><a target='_blank' href='" + newPaneOptions.newInstance.uri + "'>Go to your new " + options.noun + '.</a>'
// selectUI.parentNode.removeChild(selectUI) // Clean up
// selectUIParent.removeChild(selectUI) // Clean up
}
selectNewTool() // toggle star to plain and menu vanish again
})
.catch(function (err) {
complain(err)
reject(err)
})
}, err => { // login fails
complain('Error logging on: ' + err)
})
} // callbackWS
var pa = options.pane
options.appPathSegment = 'edu.mit.solid.pane.' + pa.name
options.noun = pa.mintClass ? UI.utils.label(pa.mintClass) : pa.name
if (!options.folder) { // No folder given? Ask user for full URI
selectUI = UI.authn.selectWorkspace(dom, options, callbackWS)
options.div.appendChild(selectUI)
// selectUIParent = options.div
} else {
var gotName = function (name) {
if (!name) {
// selectUIParent.removeChild(selectUI) itremves itself if cancelled
selectNewTool() // toggle star to plain and menu vanish again
} else {
var uri = options.folder.uri
if (!uri.endsWith('/')) {
uri = uri + '/'
}
uri = uri + encodeURIComponent(name) + '/'
callbackWS(null, uri)
}
}
UI.widgets.askName(dom, UI.store, options.div, UI.ns.foaf('name'), null, options.noun).then(gotName)
// selectUI = getNameForm(dom, UI.store, options.noun, gotName)
// options.div.appendChild(selectUI)
// selectUIParent = options.div
}
}
)
} // makeNewAppInstance
var iconArray = []
for (var pn in thePanes) {
var pane = thePanes[pn]
if (pane.mintNew) {
var icon = context.div.appendChild(dom.createElement('img'))
icon.setAttribute('src', pane.icon)
var noun = pane.mintClass ? UI.utils.label(pane.mintClass) : (pane.name + ' @@')
icon.setAttribute('title', 'Make new ' + noun)
icon.setAttribute('style', iconStyle + 'display: none;')
iconArray.push(icon)
var foo = function (pane, icon, noun) {
var iconEle = icon
var thisPane = pane
var thisNoun = noun
if (!icon.disabled) {
icon.addEventListener('click', function (e) {
selectTool(iconEle)
var options = {
event: e,
folder: context.folder,
iconEle: iconEle,
pane: thisPane,
noun: thisNoun,
noIndexHTML: true, // do NOT @@ for now write a HTML file
div: context.div,
me: context.me,
dom: context.dom,
refreshTarget: context.refreshTarget
}
makeNewAppInstance(options)
})
}
} // foo
foo(pane, icon, noun)
}
}
var styleTheIcons = function (style) {
for (var i = 0; i < iconArray.length; i++) {
var st = iconStyle + style
if (iconArray[i].disabled) { // @@ unused
st += 'opacity: 0.3;'
}
iconArray[i].setAttribute('style', st) // eg 'background-color: #ccc;'
}
}
var selectTool = function (icon) {
styleTheIcons('display: none;') // 'background-color: #ccc;'
icon.setAttribute('style', iconStyle + 'background-color: yellow;')
}
}
// Form to get the name of a new thing before we create it
//
// Used in contacts for new groups, individuals.
//
/*
function getNameForm (dom, kb, classLabel, gotNameCallback) {
var form = dom.createElement('div') // form is broken as HTML behaviour can resurface on js error
form.innerHTML = '<p>Name of new ' + classLabel + ':</p>'
var namefield = dom.createElement('input')
namefield.setAttribute('type', 'text')
namefield.setAttribute('size', '30')
namefield.setAttribute('style', UI.style.textInputStyle)
namefield.setAttribute('maxLength', '2048') // No arbitrary limits
namefield.select() // focus next user input
var gotName = function () {
namefield.setAttribute('class', 'pendingedit')
namefield.disabled = true
continueButton.disabled = true
cancel.disabled = true
gotNameCallback(true, namefield.value)
}
namefield.addEventListener('keyup', function (e) {
if (e.keyCode === 13) {
gotName()
}
}, false)
form.appendChild(namefield)
form.appendChild(dom.createElement('br'))
var cancel = form.appendChild(UI.widgets.cancelButton(dom))
cancel.addEventListener('click', function (e) {
form.parentNode.removeChild(form)
gotNameCallback(false)
}, false)
var continueButton = form.appendChild(UI.widgets.continueButton(dom))
continueButton.addEventListener('click', function (e) {
gotName()
}, false)
return form
}
*/