-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
101 lines (91 loc) · 2.52 KB
/
index.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
module.exports = {
moogBundle: {
directory: 'lib/modules',
modules: [
'apostrophe-dialog-box-modal',
'apostrophe-dialog-box-pages',
// improvements
'apostrophe-dialog-box-apos-pages',
// 'apostrophe-dialog-box-apos-widgets',
'apostrophe-dialog-box-apos-doc-type-manager',
// modules that should opt-out
'apostrophe-dialog-box-apos-files',
'apostrophe-dialog-box-apos-groups',
'apostrophe-dialog-box-apos-images',
'apostrophe-dialog-box-apos-users',
'apostrophe-dialog-box-apos-rich-text-widgets'
]
},
name: 'apostrophe-dialog-box',
extend: 'apostrophe-pieces',
label: 'Dialog Box',
alias: 'dialog',
pluralLabel: 'Dialog Boxes',
dialogBox: false,
addFields: [
{
name: 'template',
label: 'Template',
type: 'select',
choices: [ {
label: 'Default',
value: 'default'
} ]
}
],
removeFields: [ 'tags' ],
construct: function(self, options) {
options.arrangeFields = options.arrangeFields.concat([
{
name: 'basics',
label: 'Basics',
fields: [ 'title', 'template' ]
},
{
name: 'admin',
label: 'Admin',
fields: [ 'published', 'slug', 'trash' ]
}
]);
require('./lib/routes')(self, options);
require('./lib/api')(self, options);
},
afterConstruct: async function(self) {
self.addRoutes();
self.pushAsset('script', 'always', { when: 'lean' });
self.pushAsset('script', 'user', { when: 'user' });
self.pushAsset('script', 'modal', { when: 'user' });
self.pushAsset('stylesheet', 'dialog');
self.apos.templates.prepend('body', req => {
const page = req.data.page;
if (!page) {
return;
}
if (page.type === 'apostrophe-dialog-box-page' && req.data) {
return self.render(
req,
'apostrophe-dialog-box:dialogs/list_all.html',
{
pieces: req.data.pieces || []
}
);
}
const dialogs = Object.assign([], page.dialogs || []);
const global =
req.data.global && req.data.global.dialogs
? req.data.global.dialogs
: [];
for (const globalDialog of global) {
const inArray = !!dialogs.find(
dialog => dialog.dialogId === globalDialog.dialogId
);
if (!inArray) {
dialogs.push(globalDialog);
}
}
return self.render(req, 'apostrophe-dialog-box:dialogs/list.html', {
dialogs: dialogs
});
});
}
};