alchemy-widget 0.2.6 → 0.2.8
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/CHANGELOG.md +10 -0
- package/README.md +0 -0
- package/assets/stylesheets/alchemy_widgets.scss +72 -0
- package/bootstrap.js +0 -0
- package/controller/alchemy_widgets_controller.js +0 -0
- package/element/00-widget_base_element.js +0 -0
- package/element/05-widget_element.js +0 -0
- package/element/10-container_elements.js +0 -0
- package/element/11-alchemy_widgets_list_element.js +0 -0
- package/element/20-add_area_element.js +0 -0
- package/element/30-base_toolbar_element.js +231 -0
- package/element/editor_toolbar_element.js +30 -0
- package/element/table_of_contents_element.js +0 -0
- package/element/user_avatar_element.js +137 -0
- package/element/user_avatar_group_element.js +131 -0
- package/element/widget_actionbar_element.js +0 -0
- package/element/widget_context_element.js +0 -0
- package/element/widget_toolbar_element.js +40 -20
- package/helper/document_watcher.js +284 -0
- package/helper/editor_toolbar_manager.js +296 -0
- package/helper/widget_action.js +0 -0
- package/helper/widgets/00-widget.js +3 -3
- package/helper/widgets/01-container.js +0 -0
- package/helper/widgets/05-column.js +0 -0
- package/helper/widgets/05-list.js +0 -0
- package/helper/widgets/05-row.js +0 -0
- package/helper/widgets/alchemy_field_widget.js +0 -0
- package/helper/widgets/alchemy_form_widget.js +0 -0
- package/helper/widgets/alchemy_table_widget.js +0 -0
- package/helper/widgets/alchemy_tabs_widget.js +0 -0
- package/helper/widgets/hawkejs_template.js +0 -0
- package/helper/widgets/header.js +0 -0
- package/helper/widgets/html.js +0 -0
- package/helper/widgets/markdown.js +65 -11
- package/helper/widgets/partial.js +0 -0
- package/helper/widgets/sourcecode.js +0 -0
- package/helper/widgets/table_of_contents.js +0 -0
- package/helper/widgets/text.js +0 -0
- package/helper/widgets_helper.js +0 -0
- package/helper_field/widget.js +0 -0
- package/helper_field/widgets.js +0 -0
- package/lib/conduit_extras.js +65 -0
- package/package.json +3 -3
- package/view/elements/table_of_contents.hwk +0 -0
- package/view/form/inputs/edit/widget.hwk +0 -0
- package/view/form/inputs/edit/widgets.hwk +0 -0
- package/view/widget/elements/al_editor_toolbar.hwk +3 -0
- package/view/widget/elements/al_user_avatar.hwk +5 -0
- package/view/widget/elements/al_widget_toolbar.hwk +7 -1
- package/view/widget/widget_config.hwk +0 -0
|
@@ -5,25 +5,7 @@
|
|
|
5
5
|
* @since 0.2.0
|
|
6
6
|
* @version 0.2.0
|
|
7
7
|
*/
|
|
8
|
-
let Toolbar = Function.inherits('Alchemy.Element.
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The stylesheet to load for this element
|
|
12
|
-
*
|
|
13
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
-
* @since 0.2.0
|
|
15
|
-
* @version 0.2.0
|
|
16
|
-
*/
|
|
17
|
-
Toolbar.setStylesheetFile('alchemy_widgets');
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Set the custom element prefix
|
|
21
|
-
*
|
|
22
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
-
* @since 0.2.0
|
|
24
|
-
* @version 0.2.0
|
|
25
|
-
*/
|
|
26
|
-
Toolbar.setStatic('custom_element_prefix', 'al');
|
|
8
|
+
let Toolbar = Function.inherits('Alchemy.Element.Widget.BaseToolbar', 'WidgetToolbar');
|
|
27
9
|
|
|
28
10
|
/**
|
|
29
11
|
* The template to use for the content of this element
|
|
@@ -287,6 +269,28 @@ Toolbar.setMethod(async function saveAllAndUpdateButtonStates(before_stop) {
|
|
|
287
269
|
*/
|
|
288
270
|
Toolbar.setMethod(function introduced() {
|
|
289
271
|
|
|
272
|
+
let set_manager_id = null;
|
|
273
|
+
|
|
274
|
+
const setManager = (manager) => {
|
|
275
|
+
|
|
276
|
+
if (set_manager_id) {
|
|
277
|
+
clearTimeout(set_manager_id);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
set_manager_id = setTimeout(() => {
|
|
281
|
+
this.prepareToolbarManager(manager);
|
|
282
|
+
}, 250);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
if (this.toolbar_manager) {
|
|
286
|
+
this.prepareToolbarManager(this.toolbar_manager);
|
|
287
|
+
} else {
|
|
288
|
+
let manager = hawkejs.scene.exposed.toolbar_manager;
|
|
289
|
+
if (manager) {
|
|
290
|
+
this.prepareToolbarManager(manager);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
290
294
|
this.button_start.addEventListener('activate', async e => {
|
|
291
295
|
this.startEditing();
|
|
292
296
|
});
|
|
@@ -307,8 +311,24 @@ Toolbar.setMethod(function introduced() {
|
|
|
307
311
|
}
|
|
308
312
|
});
|
|
309
313
|
|
|
310
|
-
hawkejs.scene.on('
|
|
314
|
+
hawkejs.scene.on('rendered', (variables, renderer) => {
|
|
315
|
+
if (variables.toolbar_manager) {
|
|
316
|
+
setManager(variables.toolbar_manager);
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
hawkejs.scene.on('opening_url', (href, options) => {
|
|
321
|
+
|
|
322
|
+
// Ignore segments & other renders
|
|
323
|
+
if (options?.history === false) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
311
327
|
this.stopEditing();
|
|
328
|
+
|
|
329
|
+
if (this.toolbar_manager) {
|
|
330
|
+
this.toolbar_manager.queueClearDocumentWatcher(500);
|
|
331
|
+
}
|
|
312
332
|
});
|
|
313
333
|
});
|
|
314
334
|
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const DOC_MAP = new Classes.WeakValueMap();
|
|
2
|
+
|
|
3
|
+
// A list of vibrant colours to choose from
|
|
4
|
+
const COLOURS = [
|
|
5
|
+
'#0095e8', // Blue
|
|
6
|
+
'#47be7d', // Green
|
|
7
|
+
'#5014d0', // Purple
|
|
8
|
+
'#f1bc00', // Yellow
|
|
9
|
+
'#d9214e', // Red
|
|
10
|
+
'#00a6a6', // Cyan
|
|
11
|
+
'#ff7f00', // Orange
|
|
12
|
+
'#20c997', // Teal
|
|
13
|
+
'#6610f2', // Indigo
|
|
14
|
+
'#e83e8c', // Pink
|
|
15
|
+
'#6f42c1', // Violet
|
|
16
|
+
'#9c27b0', // Periwinkle
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The syncable DocumentWatcher class:
|
|
21
|
+
* keeps track of how many people are viewing a document
|
|
22
|
+
*
|
|
23
|
+
* @constructor
|
|
24
|
+
*
|
|
25
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
26
|
+
* @since 0.2.7
|
|
27
|
+
* @version 0.2.7
|
|
28
|
+
*/
|
|
29
|
+
const DocumentWatcher = Function.inherits('Alchemy.Syncable', 'Alchemy.Widget', function DocumentWatcher() {
|
|
30
|
+
DocumentWatcher.super.call(this, 'document_watcher');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create a watcher for the given document
|
|
35
|
+
*
|
|
36
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
37
|
+
* @since 0.2.7
|
|
38
|
+
* @version 0.2.7
|
|
39
|
+
*
|
|
40
|
+
* @param {String} model
|
|
41
|
+
* @param {*} pk
|
|
42
|
+
*/
|
|
43
|
+
DocumentWatcher.setStatic(function create(model, pk) {
|
|
44
|
+
|
|
45
|
+
if (typeof model != 'string') {
|
|
46
|
+
model = model.model_name;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let id = model + ':' + pk,
|
|
50
|
+
watcher = DOC_MAP.get(id);
|
|
51
|
+
|
|
52
|
+
if (!watcher) {
|
|
53
|
+
watcher = new DocumentWatcher();
|
|
54
|
+
watcher.setDocument(model, pk);
|
|
55
|
+
DOC_MAP.set(id, watcher);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return watcher;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (Blast.isNode) {
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Add a viewer based on the conduit
|
|
65
|
+
*
|
|
66
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
67
|
+
* @since 0.2.7
|
|
68
|
+
* @version 0.2.7
|
|
69
|
+
*
|
|
70
|
+
* @param {Alchemy.Conduit} conduit
|
|
71
|
+
*/
|
|
72
|
+
DocumentWatcher.setTypedMethod([Types.Alchemy.Conduit], function addWatcher(conduit) {
|
|
73
|
+
|
|
74
|
+
let user_id = '' + conduit.getUserId(),
|
|
75
|
+
scene_id = conduit.scene_id;
|
|
76
|
+
|
|
77
|
+
this.addWatcher(user_id, scene_id);
|
|
78
|
+
|
|
79
|
+
// Watchers should also be registered as a client
|
|
80
|
+
this.registerClient(conduit);
|
|
81
|
+
|
|
82
|
+
let scene = conduit.scene;
|
|
83
|
+
|
|
84
|
+
if (scene) {
|
|
85
|
+
scene.on('destroyed', () => {
|
|
86
|
+
this.removeWatcher(user_id, scene_id);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Remove a viewer based on the conduit
|
|
93
|
+
*
|
|
94
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
95
|
+
* @since 0.2.7
|
|
96
|
+
* @version 0.2.7
|
|
97
|
+
*
|
|
98
|
+
* @param {Alchemy.Conduit} conduit
|
|
99
|
+
*/
|
|
100
|
+
DocumentWatcher.setTypedMethod([Types.Alchemy.Conduit], function removeWatcher(conduit) {
|
|
101
|
+
let user_id = '' + conduit.getUserId(),
|
|
102
|
+
scene_id = conduit.scene_id;
|
|
103
|
+
|
|
104
|
+
this.removeWatcher(user_id, scene_id);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Add the model property
|
|
110
|
+
*
|
|
111
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
112
|
+
* @since 0.2.7
|
|
113
|
+
* @version 0.2.7
|
|
114
|
+
*/
|
|
115
|
+
DocumentWatcher.setStateProperty('model', {allow_client_set: false});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Add the pk property
|
|
119
|
+
*
|
|
120
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
121
|
+
* @since 0.2.7
|
|
122
|
+
* @version 0.2.7
|
|
123
|
+
*/
|
|
124
|
+
DocumentWatcher.setStateProperty('pk', {allow_client_set: false});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Add the title property
|
|
128
|
+
*
|
|
129
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
130
|
+
* @since 0.2.7
|
|
131
|
+
* @version 0.2.7
|
|
132
|
+
*/
|
|
133
|
+
DocumentWatcher.setStateProperty('title', {allow_client_set: false});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Add the viewers property
|
|
137
|
+
*
|
|
138
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
139
|
+
* @since 0.2.7
|
|
140
|
+
* @version 0.2.7
|
|
141
|
+
*/
|
|
142
|
+
DocumentWatcher.setStateProperty('viewers', {
|
|
143
|
+
allow_client_set: false,
|
|
144
|
+
default: () => [],
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Set the model and primary key
|
|
149
|
+
*
|
|
150
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
151
|
+
* @since 0.2.7
|
|
152
|
+
* @version 0.2.7
|
|
153
|
+
*
|
|
154
|
+
* @param {String} model
|
|
155
|
+
* @param {*} pk
|
|
156
|
+
*/
|
|
157
|
+
DocumentWatcher.setMethod(function setDocument(model, pk) {
|
|
158
|
+
this.state.model = model;
|
|
159
|
+
this.state.pk = pk;
|
|
160
|
+
|
|
161
|
+
if (model && pk) {
|
|
162
|
+
this.id = model + ':' + pk;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Add a viewer
|
|
168
|
+
*
|
|
169
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
170
|
+
* @since 0.2.7
|
|
171
|
+
* @version 0.2.7
|
|
172
|
+
*
|
|
173
|
+
* @param {user_id} user_id
|
|
174
|
+
*/
|
|
175
|
+
DocumentWatcher.setSyncMethod([Types.String, Types.String], async function addWatcher(user_id, scene_id) {
|
|
176
|
+
|
|
177
|
+
let viewers = this.viewers,
|
|
178
|
+
entry;
|
|
179
|
+
|
|
180
|
+
for (entry of viewers) {
|
|
181
|
+
if (entry.user_id == user_id) {
|
|
182
|
+
entry.scenes.push(scene_id);
|
|
183
|
+
this.emitViewers();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
entry = {
|
|
189
|
+
user_id : user_id,
|
|
190
|
+
scenes : [scene_id],
|
|
191
|
+
info : null,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
viewers.push(entry);
|
|
195
|
+
|
|
196
|
+
let info = await this.getUserInfo(user_id);
|
|
197
|
+
entry.info = info || false;
|
|
198
|
+
|
|
199
|
+
this.emitViewers();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Emit the viewers property change, if they're all ready
|
|
204
|
+
*
|
|
205
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
206
|
+
* @since 0.2.7
|
|
207
|
+
* @version 0.2.7
|
|
208
|
+
*/
|
|
209
|
+
DocumentWatcher.setMethod(function emitViewers() {
|
|
210
|
+
this.emitPropertyChange('viewers');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Remove a viewer
|
|
215
|
+
*
|
|
216
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
217
|
+
* @since 0.2.7
|
|
218
|
+
* @version 0.2.7
|
|
219
|
+
*
|
|
220
|
+
* @param {user_id} user_id
|
|
221
|
+
*/
|
|
222
|
+
DocumentWatcher.setSyncMethod([Types.String, Types.String], async function removeWatcher(user_id, scene_id) {
|
|
223
|
+
|
|
224
|
+
let viewers = this.viewers,
|
|
225
|
+
entry;
|
|
226
|
+
|
|
227
|
+
let user_to_remove;
|
|
228
|
+
|
|
229
|
+
for (entry of viewers) {
|
|
230
|
+
if (entry.user_id == user_id) {
|
|
231
|
+
|
|
232
|
+
let index = entry.scenes.indexOf(scene_id);
|
|
233
|
+
|
|
234
|
+
if (index > -1) {
|
|
235
|
+
entry.scenes.splice(index, 1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (entry.scenes.length == 0) {
|
|
239
|
+
user_to_remove = entry;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (user_to_remove) {
|
|
245
|
+
let index = viewers.indexOf(user_to_remove);
|
|
246
|
+
viewers.splice(index, 1);
|
|
247
|
+
this.emitViewers();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get information about an author
|
|
253
|
+
*
|
|
254
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
255
|
+
* @since 0.2.7
|
|
256
|
+
* @version 0.2.7
|
|
257
|
+
*
|
|
258
|
+
* @param {String} user_id
|
|
259
|
+
*/
|
|
260
|
+
DocumentWatcher.setUpstreamMethod(async function getUserInfo(user_id) {
|
|
261
|
+
|
|
262
|
+
if (!user_id) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let document = await Model.get('User').findByPk(user_id);
|
|
267
|
+
|
|
268
|
+
if (!document) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Get a colour from the COLOURS array based on the user's id
|
|
273
|
+
let color = COLOURS[parseInt(user_id.slice(-4), 16) % COLOURS.length];
|
|
274
|
+
|
|
275
|
+
let result = {
|
|
276
|
+
pk : document.$pk,
|
|
277
|
+
first_name : document.first_name || document.firstname,
|
|
278
|
+
last_name : document.last_name || document.lastname,
|
|
279
|
+
username : document.username,
|
|
280
|
+
color : color,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
return result;
|
|
284
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
const SCENE_MAP = new Map(),
|
|
2
|
+
CLEAR_DOC_ID = Symbol('clear_doc_id');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The syncable EditorToolbarManager class:
|
|
6
|
+
* handles a user's toolbar
|
|
7
|
+
*
|
|
8
|
+
* @constructor
|
|
9
|
+
*
|
|
10
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
11
|
+
* @since 0.2.7
|
|
12
|
+
* @version 0.2.7
|
|
13
|
+
*/
|
|
14
|
+
const EditorToolbarManager = Function.inherits('Alchemy.Syncable', 'Alchemy.Widget', function EditorToolbarManager() {
|
|
15
|
+
EditorToolbarManager.super.call(this, 'editor_toolbar_manager');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (Blast.isNode) {
|
|
19
|
+
/**
|
|
20
|
+
* Create a manager for the given conduit
|
|
21
|
+
* (It should be linked to a user's tab/scene)
|
|
22
|
+
*
|
|
23
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
|
+
* @since 0.2.7
|
|
25
|
+
* @version 0.2.7
|
|
26
|
+
*
|
|
27
|
+
* @param {Conduit} conduit
|
|
28
|
+
*
|
|
29
|
+
* @return {EditorToolbarManager}
|
|
30
|
+
*/
|
|
31
|
+
EditorToolbarManager.setStatic(function create(conduit) {
|
|
32
|
+
|
|
33
|
+
if (!conduit?.scene_id) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let id = conduit.scene_id,
|
|
38
|
+
ref = SCENE_MAP.get(id),
|
|
39
|
+
manager;
|
|
40
|
+
|
|
41
|
+
if (ref) {
|
|
42
|
+
manager = ref.deref();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!manager) {
|
|
46
|
+
manager = new EditorToolbarManager();
|
|
47
|
+
manager.id = id;
|
|
48
|
+
manager.registerClient(conduit);
|
|
49
|
+
manager.conduit = conduit;
|
|
50
|
+
|
|
51
|
+
ref = new WeakRef(manager);
|
|
52
|
+
SCENE_MAP.set(id, ref);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (manager.conduit != conduit) {
|
|
56
|
+
// Don't create a shim like this,
|
|
57
|
+
// all the other important properties will be "frozen"
|
|
58
|
+
//manager = Object.create(manager);
|
|
59
|
+
manager.conduit = conduit;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return manager;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Add the document_watcher property
|
|
68
|
+
*
|
|
69
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
70
|
+
* @since 0.2.7
|
|
71
|
+
* @version 0.2.7
|
|
72
|
+
*/
|
|
73
|
+
EditorToolbarManager.setStateProperty('document_watcher', {allow_client_set: false});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Add the model_name property
|
|
77
|
+
*
|
|
78
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
79
|
+
* @since 0.2.7
|
|
80
|
+
* @version 0.2.7
|
|
81
|
+
*/
|
|
82
|
+
EditorToolbarManager.setStateProperty('model_name', {allow_client_set: false});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Add the title property
|
|
86
|
+
*
|
|
87
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
88
|
+
* @since 0.2.7
|
|
89
|
+
* @version 0.2.7
|
|
90
|
+
*/
|
|
91
|
+
EditorToolbarManager.setStateProperty('title', {allow_client_set: false});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Add the scenario property
|
|
95
|
+
*
|
|
96
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
97
|
+
* @since 0.2.7
|
|
98
|
+
* @version 0.2.7
|
|
99
|
+
*/
|
|
100
|
+
EditorToolbarManager.setStateProperty('scenario');
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Clear the model fallback
|
|
104
|
+
*
|
|
105
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
106
|
+
* @since 0.2.7
|
|
107
|
+
* @version 0.2.7
|
|
108
|
+
*
|
|
109
|
+
* @param {String} model_name
|
|
110
|
+
*/
|
|
111
|
+
EditorToolbarManager.setMethod(function clearModelFallback() {
|
|
112
|
+
|
|
113
|
+
if (!this.fallback_id) {
|
|
114
|
+
this.fallback_id = 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.fallback_id++;
|
|
118
|
+
|
|
119
|
+
return this.fallback_id;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* If a response is sent through the conduit, and no model & document is set,
|
|
124
|
+
* make it clear those values.
|
|
125
|
+
*
|
|
126
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
127
|
+
* @since 0.2.7
|
|
128
|
+
* @version 0.2.7
|
|
129
|
+
*
|
|
130
|
+
* @param {String} model_name
|
|
131
|
+
*/
|
|
132
|
+
EditorToolbarManager.setMethod(function queueModelFallback(model_name) {
|
|
133
|
+
|
|
134
|
+
let current_id = this.clearModelFallback();
|
|
135
|
+
|
|
136
|
+
this.conduit.on('ending', () => {
|
|
137
|
+
if (this.fallback_id == current_id) {
|
|
138
|
+
this.setDocument(null);
|
|
139
|
+
this.setModel(model_name);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Set the current model
|
|
146
|
+
*
|
|
147
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
148
|
+
* @since 0.2.7
|
|
149
|
+
* @version 0.2.7
|
|
150
|
+
*
|
|
151
|
+
* @param {String} model_name
|
|
152
|
+
*/
|
|
153
|
+
EditorToolbarManager.setTypedMethod([Types.String.optional().nullable()], function setModel(model_name) {
|
|
154
|
+
|
|
155
|
+
this.clearModelFallback();
|
|
156
|
+
|
|
157
|
+
let old_model = this.state.model_name;
|
|
158
|
+
|
|
159
|
+
this.state.model_name = model_name;
|
|
160
|
+
|
|
161
|
+
if (old_model != model_name) {
|
|
162
|
+
this.emitPropertyChange('model_name');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (Blast.isNode && model_name) {
|
|
166
|
+
this.addTemplateToRender('buttons', 'chimera/toolbar/create_button', {
|
|
167
|
+
model_name: model_name.underscore(),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Set the document
|
|
174
|
+
*
|
|
175
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
176
|
+
* @since 0.2.7
|
|
177
|
+
* @version 0.2.7
|
|
178
|
+
*
|
|
179
|
+
* @param {Alchemy.Document} doc
|
|
180
|
+
*
|
|
181
|
+
* @return {DocumentWatcher}
|
|
182
|
+
*/
|
|
183
|
+
EditorToolbarManager.setMethod(function setDocument(doc) {
|
|
184
|
+
|
|
185
|
+
this.clearModelFallback();
|
|
186
|
+
|
|
187
|
+
this.clearArea('buttons');
|
|
188
|
+
|
|
189
|
+
if (!doc) {
|
|
190
|
+
this.setDocumentWatcher(null);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let model = doc.$model,
|
|
195
|
+
model_name = doc.$model_name,
|
|
196
|
+
pk_val = doc.$pk;
|
|
197
|
+
|
|
198
|
+
let document_watcher = Classes.Alchemy.Widget.DocumentWatcher.create(model_name, pk_val);
|
|
199
|
+
document_watcher.setProperty('title', ''+pk_val);
|
|
200
|
+
|
|
201
|
+
this.setDocumentWatcher(document_watcher);
|
|
202
|
+
|
|
203
|
+
if (this.scenario != 'chimera') {
|
|
204
|
+
this.addTemplateToRender('buttons', 'chimera/toolbar/edit_in_chimera_button', {
|
|
205
|
+
model_name: model_name.underscore(),
|
|
206
|
+
record_pk: pk_val,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (model.chimera.record_preview) {
|
|
211
|
+
if (this.scenario == 'chimera') {
|
|
212
|
+
this.addTemplateToRender('buttons', 'chimera/toolbar/preview_button', {
|
|
213
|
+
model_name: model_name.underscore(),
|
|
214
|
+
record_pk: pk_val,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return document_watcher;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Clear an area
|
|
224
|
+
*
|
|
225
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
226
|
+
* @since 0.2.7
|
|
227
|
+
* @version 0.2.7
|
|
228
|
+
*/
|
|
229
|
+
EditorToolbarManager.setMethod(function clearArea(area) {
|
|
230
|
+
this.clearQueue('render_template');
|
|
231
|
+
this.pushQueue('clear_area', area);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Add a template to the toolbar
|
|
236
|
+
*
|
|
237
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
238
|
+
* @since 0.2.7
|
|
239
|
+
* @version 0.2.7
|
|
240
|
+
*/
|
|
241
|
+
EditorToolbarManager.setMethod(function addTemplateToRender(area, template, variables) {
|
|
242
|
+
this.pushQueue('render_template', area, template, variables);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Set the document watcher to use
|
|
247
|
+
*
|
|
248
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
249
|
+
* @since 0.2.7
|
|
250
|
+
* @version 0.2.7
|
|
251
|
+
*
|
|
252
|
+
* @param {Alchemy.Widget.DocumentWatcher} watcher
|
|
253
|
+
*/
|
|
254
|
+
EditorToolbarManager.setSyncMethod(function setDocumentWatcher(watcher) {
|
|
255
|
+
|
|
256
|
+
if (this[CLEAR_DOC_ID]) {
|
|
257
|
+
clearTimeout(this[CLEAR_DOC_ID]);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let old_watcher = this.state.document_watcher;
|
|
261
|
+
|
|
262
|
+
this.state.document_watcher = watcher;
|
|
263
|
+
|
|
264
|
+
if (Blast.isNode) {
|
|
265
|
+
|
|
266
|
+
if (old_watcher) {
|
|
267
|
+
old_watcher.removeWatcher(this.conduit);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (watcher) {
|
|
271
|
+
watcher.registerClient(this.conduit);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
this.emitPropertyChange('document_watcher');
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Queue clearing the document watcher
|
|
280
|
+
*
|
|
281
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
282
|
+
* @since 0.2.7
|
|
283
|
+
* @version 0.2.7
|
|
284
|
+
*/
|
|
285
|
+
EditorToolbarManager.setMethod(function queueClearDocumentWatcher(timeout = 500) {
|
|
286
|
+
|
|
287
|
+
if (this[CLEAR_DOC_ID]) {
|
|
288
|
+
clearTimeout(this[CLEAR_DOC_ID]);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
this[CLEAR_DOC_ID] = setTimeout(() => {
|
|
292
|
+
if (this.state.document_watcher) {
|
|
293
|
+
this.setDocumentWatcher(null);
|
|
294
|
+
}
|
|
295
|
+
}, timeout);
|
|
296
|
+
});
|
package/helper/widget_action.js
CHANGED
|
File without changes
|
|
@@ -818,16 +818,16 @@ Widget.setMethod(function queueVisibilityUpdate() {
|
|
|
818
818
|
*
|
|
819
819
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
820
820
|
* @since 0.2.1
|
|
821
|
-
* @version 0.2.
|
|
821
|
+
* @version 0.2.7
|
|
822
822
|
*/
|
|
823
823
|
Widget.setMethod(function checkVisibility() {
|
|
824
824
|
|
|
825
825
|
let should_be_hidden = this.is_hidden;
|
|
826
826
|
|
|
827
827
|
if (this.editing) {
|
|
828
|
-
this.widget.
|
|
828
|
+
this.widget.hideForEveryone(false);
|
|
829
829
|
} else {
|
|
830
|
-
this.widget.
|
|
830
|
+
this.widget.hideForEveryone(should_be_hidden);
|
|
831
831
|
}
|
|
832
832
|
|
|
833
833
|
if (should_be_hidden) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/helper/widgets/05-row.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/helper/widgets/header.js
CHANGED
|
File without changes
|
package/helper/widgets/html.js
CHANGED
|
File without changes
|