alchemy-chimera 0.5.3 → 1.0.1
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 +33 -0
- package/assets/scripts/chimera/chimera.js +13 -288
- package/assets/stylesheets/chimera/chimera.scss +273 -0
- package/bootstrap.js +6 -302
- package/config/routes.js +53 -5
- package/controller/00-chimera_controller.js +16 -0
- package/controller/chimera_editor_controller.js +161 -615
- package/controller/chimera_static_controller.js +102 -9
- package/lib/chimera_config.js +107 -163
- package/model/model.js +1 -1
- package/package.json +8 -12
- package/view/chimera/dashboard.hwk +8 -0
- package/view/chimera/editor/index.hwk +20 -0
- package/view/chimera/sidebar.hwk +4 -0
- package/view/chimera/widgets.hwk +8 -0
- package/view/layouts/chimera_base.hwk +15 -0
- package/view/layouts/chimera_basics.hwk +15 -0
- package/view/layouts/chimera_body.hwk +24 -0
- package/assets/scripts/chimera/assoc_field.js +0 -311
- package/assets/scripts/chimera/boolean_field.js +0 -53
- package/assets/scripts/chimera/chimera_field.js +0 -617
- package/assets/scripts/chimera/chimera_field_wrapper.js +0 -557
- package/assets/scripts/chimera/date_field.js +0 -170
- package/assets/scripts/chimera/geopoint_field.js +0 -147
- package/assets/scripts/chimera/medium-button.js +0 -6
- package/assets/scripts/chimera/object_field.js +0 -51
- package/assets/scripts/chimera/page-editor.js +0 -3
- package/assets/scripts/chimera/password_field.js +0 -54
- package/assets/scripts/chimera/schema_field.js +0 -300
- package/assets/scripts/chimera/text_field.js +0 -119
- package/assets/scripts/rome/rome.js +0 -4978
- package/assets/scripts/vex/vex.dialog.js +0 -151
- package/assets/scripts/vex/vex.js +0 -193
- package/assets/stylesheets/chimera/chimera.less +0 -1075
- package/assets/stylesheets/chimera_old/chimera.less +0 -351
- package/assets/stylesheets/chimera_old/core.less +0 -315
- package/assets/stylesheets/chimera_old/font.less +0 -38
- package/assets/stylesheets/chimera_old/mixins.less +0 -35
- package/assets/stylesheets/chimera_old/page-editor.less +0 -23
- package/assets/stylesheets/rome/rome.less +0 -130
- package/assets/stylesheets/vex/vex-theme-bottom-right-corner.less +0 -613
- package/assets/stylesheets/vex/vex.default.less +0 -501
- package/assets/stylesheets/vex/vex.flat.less +0 -443
- package/assets/stylesheets/vex/vex.less +0 -320
- package/controller/chimera_page_controller.js +0 -14
- package/controller/chimera_settings_controller.js +0 -129
- package/controller/tasks_chimera_controller.js +0 -106
- package/helper/chimera_helper.js +0 -202
- package/lib/chimera_action_fields.js +0 -292
- package/lib/chimera_field/belongsto_chimera_field.js +0 -155
- package/lib/chimera_field/boolean_chimera_field.js +0 -19
- package/lib/chimera_field/date_chimera_field.js +0 -20
- package/lib/chimera_field/datetime_chimera_field.js +0 -20
- package/lib/chimera_field/enum_chimera_field.js +0 -131
- package/lib/chimera_field/geopoint_chimera_field.js +0 -20
- package/lib/chimera_field/habtm_chimera_field.js +0 -55
- package/lib/chimera_field/hasoneparent_chimera_field.js +0 -18
- package/lib/chimera_field/html_chimera_field.js +0 -20
- package/lib/chimera_field/object_chimera_field.js +0 -18
- package/lib/chimera_field/password_chimera_field.js +0 -18
- package/lib/chimera_field/schema_chimera_field.js +0 -149
- package/lib/chimera_field/text_chimera_field.js +0 -20
- package/lib/chimera_field/time_chimera_field.js +0 -18
- package/lib/chimera_field.js +0 -208
- package/model/setting_model.js +0 -51
- package/public/chimera/codedor.svg +0 -28
- package/view/chimera/dashboard.ejs +0 -5
- package/view/chimera/editor/add.ejs +0 -32
- package/view/chimera/editor/edit.ejs +0 -33
- package/view/chimera/editor/index.ejs +0 -87
- package/view/chimera/editor/remove.ejs +0 -23
- package/view/chimera/editor/view.ejs +0 -54
- package/view/chimera/elements/editor_actions.ejs +0 -4
- package/view/chimera/elements/empty +0 -0
- package/view/chimera/field_wrappers/_entries.ejs +0 -91
- package/view/chimera/field_wrappers/_wrapper.ejs +0 -78
- package/view/chimera/field_wrappers/date_edit.ejs +0 -23
- package/view/chimera/field_wrappers/date_list.ejs +0 -3
- package/view/chimera/field_wrappers/date_view.ejs +0 -16
- package/view/chimera/field_wrappers/default_edit.ejs +0 -22
- package/view/chimera/field_wrappers/default_list.ejs +0 -3
- package/view/chimera/field_wrappers/default_peek.ejs +0 -3
- package/view/chimera/field_wrappers/default_view.ejs +0 -14
- package/view/chimera/field_wrappers/geopoint_edit.ejs +0 -25
- package/view/chimera/field_wrappers/geopoint_list.ejs +0 -5
- package/view/chimera/field_wrappers/geopoint_view.ejs +0 -18
- package/view/chimera/field_wrappers/schema_edit.ejs +0 -19
- package/view/chimera/field_wrappers/text_edit.ejs +0 -22
- package/view/chimera/field_wrappers/text_list.ejs +0 -1
- package/view/chimera/fields/belongsto_edit.ejs +0 -4
- package/view/chimera/fields/belongsto_list.ejs +0 -1
- package/view/chimera/fields/belongsto_peek.ejs +0 -1
- package/view/chimera/fields/boolean_edit.ejs +0 -17
- package/view/chimera/fields/boolean_list.ejs +0 -3
- package/view/chimera/fields/boolean_view.ejs +0 -3
- package/view/chimera/fields/date_edit.ejs +0 -14
- package/view/chimera/fields/date_list.ejs +0 -9
- package/view/chimera/fields/date_peek.ejs +0 -9
- package/view/chimera/fields/date_view.ejs +0 -9
- package/view/chimera/fields/datetime_edit.ejs +0 -24
- package/view/chimera/fields/datetime_list.ejs +0 -9
- package/view/chimera/fields/datetime_view.ejs +0 -10
- package/view/chimera/fields/default_edit.ejs +0 -10
- package/view/chimera/fields/default_list.ejs +0 -15
- package/view/chimera/fields/default_view.ejs +0 -1
- package/view/chimera/fields/enum_edit.ejs +0 -10
- package/view/chimera/fields/geopoint_edit.ejs +0 -10
- package/view/chimera/fields/geopoint_list.ejs +0 -9
- package/view/chimera/fields/geopoint_view.ejs +0 -9
- package/view/chimera/fields/habtm_edit.ejs +0 -5
- package/view/chimera/fields/hasoneparent_edit.ejs +0 -6
- package/view/chimera/fields/hasoneparent_list.ejs +0 -1
- package/view/chimera/fields/object_edit.ejs +0 -8
- package/view/chimera/fields/password_edit.ejs +0 -11
- package/view/chimera/fields/schema_edit.ejs +0 -14
- package/view/chimera/fields/text_edit.ejs +0 -5
- package/view/chimera/fields/text_list.ejs +0 -9
- package/view/chimera/fields/text_view.ejs +0 -3
- package/view/chimera/fields/time_edit.ejs +0 -15
- package/view/chimera/fields/time_list.ejs +0 -9
- package/view/chimera/fields/time_view.ejs +0 -9
- package/view/chimera/page/edit.ejs +0 -18
- package/view/chimera/page_editor.ejs +0 -5
- package/view/chimera/sidebar.ejs +0 -40
- package/view/chimera/tasks/index.ejs +0 -114
- package/view/layouts/chimera.ejs +0 -12
- package/view/layouts/chimera_base.ejs +0 -11
- package/view/layouts/chimera_body.ejs +0 -43
|
@@ -1,714 +1,260 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Chimera Editor Controller class
|
|
3
3
|
*
|
|
4
|
-
* @author Jelle De Loecker <jelle@
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
5
|
* @since 0.2.0
|
|
6
|
-
* @version 0.
|
|
6
|
+
* @version 1.0.0
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Editor.super.call(this, conduit, options);
|
|
11
|
-
|
|
12
|
-
this.addComponent('paginate');
|
|
13
|
-
|
|
14
|
-
this.addAction('model', 'index', {title: 'Index', icon: '<x-svg data-src="chimera/list"></x-svg>'});
|
|
15
|
-
this.addAction('model', 'add', {title: 'Add', icon: '<x-svg data-src="chimera/plus"></x-svg>'});
|
|
16
|
-
|
|
17
|
-
this.addAction('model-list', 'add', {title: 'Add', icon: '<x-svg data-src="chimera/plus"></x-svg>', route_name: 'ModelAction'});
|
|
18
|
-
|
|
19
|
-
this.addAction('draft', 'save', {title: 'Save', icon: '<x-svg data-src="chimera/floppy"></x-svg>', handleManual: true});
|
|
20
|
-
|
|
21
|
-
this.addAction('record', 'edit', {title: 'Edit', icon: '<x-svg data-src="chimera/edit"></x-svg>'});
|
|
22
|
-
this.addAction('record', 'view', {title: 'View', icon: '<x-svg data-src="chimera/eye"></x-svg>'});
|
|
23
|
-
this.addAction('record', 'remove', {title: 'Remove', icon: '<x-svg data-src="chimera/garbage"></x-svg>'});
|
|
24
|
-
|
|
25
|
-
this.addAction('record-edit', 'save', {title: 'Save', icon: '<x-svg data-src="chimera/floppy"></x-svg>', handleManual: true, route_name: 'RecordAction'});
|
|
26
|
-
this.addAction('record-edit', 'saveClose', {title: 'Save and close', icon: '<x-svg data-src="chimera/floppy"></x-svg>', handleManual: true, route_name: 'RecordAction'});
|
|
27
|
-
|
|
28
|
-
this.addAction('record-draft', 'save', {title: 'Save', icon: '<x-svg data-src="chimera/floppy"></x-svg>', handleManual: true, route_name: 'RecordAction'});
|
|
29
|
-
this.addAction('record-draft', 'saveClose', {title: 'Save and close', icon: '<x-svg data-src="chimera/floppy"></x-svg>', handleManual: true, route_name: 'RecordAction'});
|
|
30
|
-
});
|
|
8
|
+
const Editor = Function.inherits('Alchemy.Controller.Chimera', 'Editor');
|
|
31
9
|
|
|
32
10
|
/**
|
|
33
|
-
*
|
|
11
|
+
* Set the title
|
|
34
12
|
*
|
|
35
|
-
* @author Jelle De Loecker <jelle@
|
|
36
|
-
* @since 0.1
|
|
37
|
-
* @version 0.1
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 1.0.1
|
|
15
|
+
* @version 1.0.1
|
|
38
16
|
*
|
|
39
|
-
* @param {
|
|
17
|
+
* @param {String} title
|
|
40
18
|
*/
|
|
41
|
-
Editor.
|
|
42
|
-
return this.doAction('listing', [conduit, 'list', 'index']);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The generic listing method
|
|
47
|
-
*
|
|
48
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
49
|
-
* @since 0.1.0
|
|
50
|
-
* @version 0.5.1
|
|
51
|
-
*
|
|
52
|
-
* @param {Conduit} conduit
|
|
53
|
-
* @param {String} type
|
|
54
|
-
* @param {String} view
|
|
55
|
-
*/
|
|
56
|
-
Editor.setAction(function listing(conduit, type, view) {
|
|
57
|
-
|
|
58
|
-
var that = this,
|
|
59
|
-
model_plural,
|
|
60
|
-
model_title,
|
|
61
|
-
model_name,
|
|
62
|
-
chimera,
|
|
63
|
-
model;
|
|
64
|
-
|
|
65
|
-
// Get the name of the model
|
|
66
|
-
model_name = conduit.routeParam('subject');
|
|
67
|
-
|
|
68
|
-
if (!model_name) {
|
|
69
|
-
return conduit.error(new Error('No model name was given, nothing to list'));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Get the actual model
|
|
73
|
-
model = this.getModel(model_name);
|
|
74
|
-
|
|
75
|
-
// And get the chimera instance
|
|
76
|
-
chimera = model.constructor.chimera;
|
|
77
|
-
|
|
78
|
-
if (chimera == null) {
|
|
79
|
-
return conduit.error(new Error('Model "' + model_name + '" has no chimera configuration'));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Get the model title
|
|
83
|
-
model_title = model_name.titleize();
|
|
19
|
+
Editor.setMethod(function setTitle(title) {
|
|
84
20
|
|
|
85
|
-
|
|
86
|
-
|
|
21
|
+
let window_title,
|
|
22
|
+
page_title;
|
|
87
23
|
|
|
88
|
-
|
|
89
|
-
|
|
24
|
+
if (alchemy.plugins.chimera.title) {
|
|
25
|
+
window_title = alchemy.plugins.chimera.title || '';
|
|
90
26
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (view == null) {
|
|
95
|
-
view = type;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let action_fields = chimera.getActionFields(type),
|
|
99
|
-
general = action_fields.getGroup('general'),
|
|
100
|
-
sorted = general.getSorted(false),
|
|
101
|
-
fields = [],
|
|
102
|
-
i;
|
|
103
|
-
|
|
104
|
-
for (i = 0; i < sorted.length; i++) {
|
|
105
|
-
fields.push(sorted[i].path);
|
|
27
|
+
if (title && window_title) {
|
|
28
|
+
window_title += ' | ';
|
|
29
|
+
}
|
|
106
30
|
}
|
|
107
31
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
fields : fields,
|
|
111
|
-
pageSize : 10
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// Hacky way of stopping pagination
|
|
115
|
-
if (action_fields.options.paginate === false) {
|
|
116
|
-
options.pageSize = 999;
|
|
32
|
+
if (title) {
|
|
33
|
+
window_title += title;
|
|
117
34
|
}
|
|
118
35
|
|
|
119
|
-
|
|
120
|
-
that.components.paginate.find(model, options, function gotRecords(err, items) {
|
|
121
|
-
|
|
122
|
-
if (err) {
|
|
123
|
-
return conduit.error(err);
|
|
124
|
-
}
|
|
36
|
+
page_title = title;
|
|
125
37
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
action_fields.processRecords('general', model, items, function groupedRecords(err, results) {
|
|
129
|
-
|
|
130
|
-
if (err) {
|
|
131
|
-
return conduit.error(err);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
that.set('prefixes', Prefix.getPrefixList());
|
|
135
|
-
that.set('fields', general);
|
|
136
|
-
that.set('records', results.general);
|
|
137
|
-
that.set('actions', that.getActions());
|
|
138
|
-
that.set('show_index_filters', model.chimera.show_index_filters);
|
|
139
|
-
|
|
140
|
-
that.set('model_title', model_title);
|
|
141
|
-
that.set('model_name', model_name);
|
|
142
|
-
that.internal('model_name', model_name);
|
|
143
|
-
|
|
144
|
-
// Deprecated modelName
|
|
145
|
-
that.set('modelName', model_name);
|
|
146
|
-
that.internal('modelName', model_name);
|
|
147
|
-
|
|
148
|
-
that.render('chimera/editor/' + view);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
38
|
+
this.set('page_title', page_title);
|
|
39
|
+
this.set('window_title', window_title || page_title);
|
|
151
40
|
});
|
|
152
41
|
|
|
153
42
|
/**
|
|
154
|
-
*
|
|
43
|
+
* The index action
|
|
155
44
|
*
|
|
156
|
-
* @
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var that = this,
|
|
161
|
-
model = this.getModel(subject),
|
|
162
|
-
data = {name: conduit.body.text, title: conduit.body.text};
|
|
163
|
-
|
|
164
|
-
model.save(data, function saved(err, doc) {
|
|
165
|
-
|
|
166
|
-
if (err) {
|
|
167
|
-
return conduit.error(err);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
conduit.end({_id: doc._id});
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* The add action
|
|
45
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
46
|
+
* @since 0.1.0
|
|
47
|
+
* @version 1.0.1
|
|
176
48
|
*
|
|
177
|
-
* @param
|
|
49
|
+
* @param {Conduit} conduit
|
|
50
|
+
* @param {String} model_name
|
|
178
51
|
*/
|
|
179
|
-
Editor.setAction(function
|
|
180
|
-
|
|
181
|
-
var that = this,
|
|
182
|
-
model_plural,
|
|
183
|
-
model_title,
|
|
184
|
-
model_name,
|
|
185
|
-
chimera,
|
|
186
|
-
model;
|
|
187
|
-
|
|
188
|
-
// Get the name of the model
|
|
189
|
-
model_name = conduit.routeParam('subject');
|
|
190
|
-
|
|
191
|
-
if (!model_name) {
|
|
192
|
-
return conduit.error(new Error('No model name was given, nothing to list'));
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Get the actual model
|
|
196
|
-
model = this.getModel(model_name);
|
|
197
|
-
|
|
198
|
-
// And get the chimera instance
|
|
199
|
-
chimera = model.constructor.chimera;
|
|
200
|
-
|
|
201
|
-
if (chimera == null) {
|
|
202
|
-
return conduit.error(new Error('Model "' + model_name + '" has no chimera configuration'));
|
|
203
|
-
}
|
|
52
|
+
Editor.setAction(function index(conduit, model_name) {
|
|
204
53
|
|
|
205
|
-
|
|
206
|
-
model_title = model_name.titleize();
|
|
54
|
+
let model = this.getModel(model_name);
|
|
207
55
|
|
|
208
|
-
|
|
209
|
-
model_plural = model_title.pluralize();
|
|
56
|
+
let widget_config = model.chimera.getWidgetConfig('index', conduit);
|
|
210
57
|
|
|
211
|
-
|
|
212
|
-
model.disableTranslations();
|
|
58
|
+
this.setTitle(model_name.titleize());
|
|
213
59
|
|
|
214
|
-
this.
|
|
60
|
+
this.set('model_name', model_name);
|
|
215
61
|
|
|
216
|
-
|
|
217
|
-
groups = action_fields.groups.clone(),
|
|
218
|
-
item = model.compose(),
|
|
219
|
-
id = item._id;
|
|
62
|
+
this.set('widget_config', widget_config);
|
|
220
63
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (err) {
|
|
224
|
-
throw err;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
that.set('editor_action', 'add');
|
|
228
|
-
that.set('prefixes', Prefix.getPrefixList());
|
|
229
|
-
that.set('groups', groups);
|
|
230
|
-
that.set('actions', that.getActions());
|
|
231
|
-
|
|
232
|
-
that.set('model_title', model_title);
|
|
233
|
-
that.set('model_name', model_name);
|
|
234
|
-
that.internal('model_name', model_name);
|
|
235
|
-
that.internal('record_id', id);
|
|
236
|
-
|
|
237
|
-
// Deprecated variable names
|
|
238
|
-
that.set('modelName', model_name);
|
|
239
|
-
that.internal('modelName', model_name);
|
|
240
|
-
that.internal('recordId', id);
|
|
241
|
-
|
|
242
|
-
that.render('chimera/editor/add');
|
|
243
|
-
});
|
|
64
|
+
this.render('chimera/editor/index');
|
|
244
65
|
});
|
|
245
66
|
|
|
246
67
|
/**
|
|
247
|
-
* The
|
|
68
|
+
* The add action
|
|
69
|
+
*
|
|
70
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
71
|
+
* @since 0.1.0
|
|
72
|
+
* @version 1.0.1
|
|
248
73
|
*
|
|
249
|
-
* @param
|
|
74
|
+
* @param {Conduit} conduit
|
|
75
|
+
* @param {String} model_name
|
|
250
76
|
*/
|
|
251
|
-
Editor.setAction(function
|
|
77
|
+
Editor.setAction(async function add(conduit, model_name) {
|
|
252
78
|
|
|
253
|
-
|
|
254
|
-
modelName = conduit.routeParam('subject'),
|
|
255
|
-
model = this.getModel(modelName),
|
|
256
|
-
chimera = model.constructor.chimera,
|
|
257
|
-
id = conduit.routeParam('id');
|
|
79
|
+
let model = this.getModel(model_name);
|
|
258
80
|
|
|
259
|
-
model.
|
|
81
|
+
model.translateItems = false;
|
|
260
82
|
|
|
261
|
-
|
|
262
|
-
groups = actionFields.groups.clone();
|
|
83
|
+
if (conduit.method == 'post') {
|
|
263
84
|
|
|
264
|
-
|
|
85
|
+
let record = model.createDocument();
|
|
265
86
|
|
|
266
|
-
|
|
267
|
-
return conduit.error(err);
|
|
268
|
-
}
|
|
87
|
+
record.setDataRecord(conduit.body[model_name]);
|
|
269
88
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
actionFields.processRecords(model, [item], function groupedRecords(err, groups) {
|
|
275
|
-
|
|
276
|
-
if (err) {
|
|
277
|
-
return conduit.error(err);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
that.set('editor_action', 'edit');
|
|
281
|
-
that.set('prefixes', Prefix.getPrefixList());
|
|
282
|
-
that.set('groups', groups);
|
|
283
|
-
that.set('actions', that.getActions());
|
|
284
|
-
that.set('modelName', modelName);
|
|
285
|
-
that.set('display_field_value', item.getDisplayFieldValue({prefer: 'name'}));
|
|
286
|
-
that.set('pagetitle', modelName.humanize() + ': Edit');
|
|
287
|
-
that.internal('modelName', modelName);
|
|
288
|
-
that.internal('recordId', id);
|
|
289
|
-
|
|
290
|
-
that.render('chimera/editor/edit');
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* The "peek" method
|
|
297
|
-
*
|
|
298
|
-
* @param {Conduit} conduit
|
|
299
|
-
*/
|
|
300
|
-
Editor.setAction(function peek(conduit) {
|
|
301
|
-
|
|
302
|
-
var that = this,
|
|
303
|
-
action_fields,
|
|
304
|
-
model_name,
|
|
305
|
-
chimera,
|
|
306
|
-
groups,
|
|
307
|
-
model,
|
|
308
|
-
id;
|
|
309
|
-
|
|
310
|
-
model_name = conduit.routeParam('subject');
|
|
311
|
-
model = this.getModel(model_name);
|
|
312
|
-
chimera = model.constructor.chimera;
|
|
313
|
-
id = conduit.routeParam('id');
|
|
89
|
+
try {
|
|
90
|
+
await record.save();
|
|
314
91
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
groups = action_fields.groups.clone();
|
|
92
|
+
let url = alchemy.routeUrl('Chimera.Editor#edit', {
|
|
93
|
+
model: model_name,
|
|
94
|
+
pk: record.$pk,
|
|
95
|
+
message: 'added'
|
|
96
|
+
});
|
|
321
97
|
|
|
322
|
-
|
|
323
|
-
|
|
98
|
+
return conduit.redirect(url);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
// @TODO: set this in the context somehow?
|
|
101
|
+
this.set('record_violations', err);
|
|
324
102
|
|
|
325
|
-
|
|
326
|
-
|
|
103
|
+
this.set('context_variables', {
|
|
104
|
+
record : record
|
|
105
|
+
});
|
|
327
106
|
}
|
|
107
|
+
}
|
|
328
108
|
|
|
329
|
-
|
|
330
|
-
return conduit.notFound();
|
|
331
|
-
}
|
|
109
|
+
let widget_config = model.chimera.getWidgetConfig('edit', conduit);
|
|
332
110
|
|
|
333
|
-
|
|
111
|
+
if (!widget_config.class_names) {
|
|
112
|
+
widget_config.class_names = [];
|
|
113
|
+
}
|
|
334
114
|
|
|
335
|
-
|
|
336
|
-
return conduit.error(err);
|
|
337
|
-
}
|
|
115
|
+
widget_config.class_names.push('chimera-editor-widgets');
|
|
338
116
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
that.set('groups', groups);
|
|
342
|
-
that.set('actions', that.getActions());
|
|
343
|
-
that.set('modelName', model_name);
|
|
344
|
-
that.set('display_field_value', item.getDisplayFieldValue({prefer: 'name'}));
|
|
345
|
-
that.internal('modelName', model_name);
|
|
346
|
-
that.internal('recordId', id);
|
|
347
|
-
|
|
348
|
-
that.render('chimera/editor/peek');
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
});
|
|
117
|
+
this.set('widget_config', widget_config);
|
|
118
|
+
this.setTitle(model.constructor.title + ' Add');
|
|
352
119
|
|
|
120
|
+
this.render('chimera/widgets');
|
|
121
|
+
});
|
|
353
122
|
|
|
354
123
|
/**
|
|
355
|
-
*
|
|
124
|
+
* The edit action
|
|
356
125
|
*
|
|
357
|
-
* @author Jelle De Loecker <jelle@
|
|
358
|
-
* @since 0.
|
|
359
|
-
* @version 0.
|
|
126
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
127
|
+
* @since 0.1.0
|
|
128
|
+
* @version 1.0.1
|
|
360
129
|
*
|
|
361
|
-
* @param {
|
|
362
|
-
* @param {
|
|
363
|
-
* @param {
|
|
130
|
+
* @param {Conduit} conduit
|
|
131
|
+
* @param {String} model_name
|
|
132
|
+
* @param {String} pk_val
|
|
364
133
|
*/
|
|
365
|
-
function
|
|
134
|
+
Editor.setAction(async function edit(conduit, model_name, pk_val) {
|
|
366
135
|
|
|
367
|
-
let
|
|
136
|
+
let model = this.getModel(model_name);
|
|
368
137
|
|
|
369
|
-
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
arr.move(entry, new_index);
|
|
374
|
-
|
|
375
|
-
let i;
|
|
376
|
-
|
|
377
|
-
for (i = 0; i < arr.length; i++) {
|
|
378
|
-
Object.setPath(arr[i], path, i);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* The "reorder" method
|
|
384
|
-
*
|
|
385
|
-
* @param {Conduit} conduit
|
|
386
|
-
*/
|
|
387
|
-
Editor.setAction(async function reorder(conduit) {
|
|
138
|
+
model.translateItems = false;
|
|
388
139
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
new_index,
|
|
392
|
-
model,
|
|
393
|
-
id;
|
|
140
|
+
let record = await model.findByPk(pk_val);
|
|
141
|
+
let message_type = conduit.param('message');
|
|
394
142
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
id = conduit.routeParam('id');
|
|
399
|
-
|
|
400
|
-
let record = await model.findById(id);
|
|
401
|
-
let records = await model.find('all', {fields: ['_id', 'order']});
|
|
143
|
+
this.set('context_variables', {
|
|
144
|
+
record : record
|
|
145
|
+
});
|
|
402
146
|
|
|
403
|
-
|
|
147
|
+
if (conduit.method == 'post') {
|
|
404
148
|
|
|
405
|
-
|
|
149
|
+
Object.assign(record, conduit.body[model_name]);
|
|
406
150
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
151
|
+
try {
|
|
152
|
+
await record.save();
|
|
153
|
+
message_type = 'saved';
|
|
154
|
+
} catch (err) {
|
|
155
|
+
// @TODO: set this in the context somehow?
|
|
156
|
+
this.set('record_violations', err);
|
|
410
157
|
}
|
|
411
|
-
|
|
412
|
-
await records[i].save();
|
|
413
158
|
}
|
|
414
159
|
|
|
415
|
-
|
|
416
|
-
});
|
|
160
|
+
let widget_config = model.chimera.getWidgetConfig('edit', conduit);
|
|
417
161
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
*
|
|
421
|
-
* @param {Conduit} conduit
|
|
422
|
-
*/
|
|
423
|
-
Editor.setAction(async function model_assoc_data(conduit) {
|
|
424
|
-
|
|
425
|
-
var model = Model.get(conduit.routeParam('subject')),
|
|
426
|
-
options;
|
|
427
|
-
|
|
428
|
-
let records = await model.find('all'),
|
|
429
|
-
results = [],
|
|
430
|
-
response = {};
|
|
431
|
-
|
|
432
|
-
for (let i = 0; i < records.length; i++) {
|
|
433
|
-
let record = records[i];
|
|
434
|
-
|
|
435
|
-
let entry = {
|
|
436
|
-
_id : record._id
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
if (record[model.displayField]) {
|
|
440
|
-
entry[model.displayField] = record[model.displayField];
|
|
441
|
-
} else {
|
|
442
|
-
entry.title = record.title;
|
|
443
|
-
entry.name = record.name;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
results.push(entry);
|
|
162
|
+
if (!widget_config.class_names) {
|
|
163
|
+
widget_config.class_names = [];
|
|
447
164
|
}
|
|
448
165
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* The related_data action for a certain field
|
|
457
|
-
*
|
|
458
|
-
* @param {Conduit} conduit
|
|
459
|
-
*/
|
|
460
|
-
Editor.setAction(function related_data(conduit) {
|
|
461
|
-
|
|
462
|
-
var that = this,
|
|
463
|
-
modelName = conduit.routeParam('subject'),
|
|
464
|
-
model = this.getModel(modelName),
|
|
465
|
-
chimera = model.constructor.chimera,
|
|
466
|
-
options = {},
|
|
467
|
-
id = conduit.routeParam('id'),
|
|
468
|
-
field;
|
|
469
|
-
|
|
470
|
-
if (conduit.param('display_field_only')) {
|
|
471
|
-
options.display_field_only = true;
|
|
166
|
+
if (message_type) {
|
|
167
|
+
if (message_type == 'added') {
|
|
168
|
+
this.set('message', 'Record has been added');
|
|
169
|
+
} else if (message_type == 'saved') {
|
|
170
|
+
this.set('message', 'Record has been saved');
|
|
171
|
+
}
|
|
472
172
|
}
|
|
473
173
|
|
|
474
|
-
|
|
174
|
+
widget_config.class_names.push('chimera-editor-widgets');
|
|
475
175
|
|
|
476
|
-
|
|
477
|
-
model.
|
|
478
|
-
|
|
479
|
-
var nested_in = conduit.param('nested_in'),
|
|
480
|
-
fieldpath = conduit.param('fieldpath');
|
|
481
|
-
|
|
482
|
-
if (nested_in) {
|
|
483
|
-
fieldpath = nested_in + '.' + fieldpath;
|
|
484
|
-
}
|
|
176
|
+
this.set('widget_config', widget_config);
|
|
177
|
+
this.setTitle(model.constructor.title + ' Edit');
|
|
485
178
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (!field) {
|
|
489
|
-
conduit.notFound(new Error('Could not find field "' + fieldpath + '"'));
|
|
490
|
-
} else {
|
|
491
|
-
field.sendRelatedData(conduit, items[0], options);
|
|
492
|
-
}
|
|
493
|
-
});
|
|
179
|
+
this.render('chimera/widgets');
|
|
494
180
|
});
|
|
495
181
|
|
|
496
182
|
/**
|
|
497
|
-
* The
|
|
183
|
+
* The records API action
|
|
498
184
|
*
|
|
499
|
-
* @
|
|
185
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
186
|
+
* @since 1.0.0
|
|
187
|
+
* @version 1.0.0
|
|
500
188
|
*
|
|
501
|
-
* @param
|
|
189
|
+
* @param {Conduit} conduit
|
|
190
|
+
* @param {String} model_name
|
|
502
191
|
*/
|
|
503
|
-
Editor.setAction(async function
|
|
504
|
-
|
|
505
|
-
var that = this,
|
|
506
|
-
modelName = conduit.routeParam('subject'),
|
|
507
|
-
model = this.getModel(modelName),
|
|
508
|
-
chimera = model.constructor.chimera,
|
|
509
|
-
id = conduit.routeParam('id');
|
|
510
|
-
|
|
511
|
-
model.disableTranslations();
|
|
192
|
+
Editor.setAction(async function records(conduit, model_name) {
|
|
512
193
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
let item = await model.findById(id);
|
|
194
|
+
let body = conduit.body,
|
|
195
|
+
model = this.getModel(model_name),
|
|
196
|
+
crit = model.find();
|
|
517
197
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
198
|
+
let page_size = body.page_size,
|
|
199
|
+
fields = body.fields,
|
|
200
|
+
page = body.page;
|
|
521
201
|
|
|
522
|
-
|
|
202
|
+
if (fields) {
|
|
523
203
|
|
|
524
|
-
|
|
525
|
-
|
|
204
|
+
// @TODO: fix FieldSet being sent with regular json?
|
|
205
|
+
if (fields.fields) {
|
|
206
|
+
fields = fields.fields;
|
|
526
207
|
}
|
|
527
208
|
|
|
528
|
-
|
|
529
|
-
that.set('prefixes', Prefix.getPrefixList());
|
|
530
|
-
that.set('groups', groups);
|
|
531
|
-
that.set('actions', that.getActions());
|
|
532
|
-
that.set('modelName', modelName);
|
|
533
|
-
that.set('pageTitle', modelName.humanize());
|
|
534
|
-
that.set('display_field_value', item.getDisplayFieldValue({prefer: 'name'}));
|
|
535
|
-
that.internal('modelName', modelName);
|
|
536
|
-
that.internal('recordId', id);
|
|
537
|
-
that.internal('chimeraReadOnly', true);
|
|
538
|
-
|
|
539
|
-
that.render('chimera/editor/view');
|
|
540
|
-
});
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* The save action
|
|
545
|
-
*
|
|
546
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
547
|
-
* @since 0.1.0
|
|
548
|
-
* @version 0.5.1
|
|
549
|
-
*
|
|
550
|
-
* @param {Conduit} conduit
|
|
551
|
-
*/
|
|
552
|
-
Editor.setAction(function save(conduit) {
|
|
553
|
-
this.save(conduit, false);
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* The save & close action
|
|
558
|
-
*
|
|
559
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
560
|
-
* @since 0.5.1
|
|
561
|
-
* @version 0.5.1
|
|
562
|
-
*
|
|
563
|
-
* @param {Conduit} conduit
|
|
564
|
-
*/
|
|
565
|
-
Editor.setAction(function saveClose(conduit) {
|
|
566
|
-
this.save(conduit, true);
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* Save a record
|
|
571
|
-
*
|
|
572
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
573
|
-
* @since 0.5.1
|
|
574
|
-
* @version 0.5.1
|
|
575
|
-
*
|
|
576
|
-
* @param {Conduit} conduit
|
|
577
|
-
*/
|
|
578
|
-
Editor.setMethod(function save(conduit, go_to_index) {
|
|
579
|
-
|
|
580
|
-
var that = this,
|
|
581
|
-
actionFields,
|
|
582
|
-
modelName,
|
|
583
|
-
chimera,
|
|
584
|
-
options,
|
|
585
|
-
groups,
|
|
586
|
-
record,
|
|
587
|
-
model,
|
|
588
|
-
data,
|
|
589
|
-
id;
|
|
590
|
-
|
|
591
|
-
if (conduit.method != 'post') {
|
|
592
|
-
return conduit.error('Use POST method to apply changes');
|
|
209
|
+
crit.select(fields);
|
|
593
210
|
}
|
|
594
211
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
model.disableTranslations();
|
|
598
|
-
|
|
599
|
-
chimera = model.constructor.chimera;
|
|
600
|
-
data = conduit.body.data;
|
|
601
|
-
|
|
602
|
-
if (!data) {
|
|
603
|
-
return conduit.error('Data was not found in POST body');
|
|
212
|
+
if (page) {
|
|
213
|
+
crit.page(page, page_size);
|
|
604
214
|
}
|
|
605
215
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
actionFields = chimera.getActionFields('edit');
|
|
609
|
-
groups = actionFields.groups.clone();
|
|
610
|
-
|
|
611
|
-
record = data[modelName.classify()];
|
|
612
|
-
record._id = alchemy.castObjectId(id);
|
|
613
|
-
|
|
614
|
-
options = {};
|
|
615
|
-
|
|
616
|
-
// Force create, even though an _id could be given
|
|
617
|
-
if (conduit.body.create === true) {
|
|
618
|
-
options.create = true;
|
|
216
|
+
if (body.sort && body.sort.field && body.sort.dir) {
|
|
217
|
+
crit.sort([body.sort.field, body.sort.dir]);
|
|
619
218
|
}
|
|
620
219
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
conduit.flash('Could not save record: ' + err, {className: 'chimera-fail'});
|
|
625
|
-
return conduit.error(err);
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
let result = items[0];
|
|
629
|
-
|
|
630
|
-
let route_params = Object.assign({}, conduit.params);
|
|
631
|
-
|
|
632
|
-
conduit.flash('Record has been saved', {className: 'chimera-success'});
|
|
633
|
-
|
|
634
|
-
if (go_to_index) {
|
|
635
|
-
route_params.action = 'index';
|
|
636
|
-
|
|
637
|
-
return conduit.redirect({
|
|
638
|
-
headers : conduit.headers,
|
|
639
|
-
url : Router.getUrl('ModelAction', route_params)
|
|
640
|
-
});
|
|
641
|
-
}
|
|
220
|
+
if (body.filters) {
|
|
221
|
+
let key,
|
|
222
|
+
val;
|
|
642
223
|
|
|
643
|
-
|
|
644
|
-
|
|
224
|
+
for (key in body.filters) {
|
|
225
|
+
val = body.filters[key];
|
|
645
226
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
return conduit.redirect({
|
|
652
|
-
headers : conduit.headers,
|
|
653
|
-
url : Router.getUrl('RecordAction', route_params)
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
that.doAction('edit', [conduit]);
|
|
658
|
-
});
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* The remove action
|
|
663
|
-
*
|
|
664
|
-
* @param {Conduit} conduit
|
|
665
|
-
*/
|
|
666
|
-
Editor.setAction(async function remove(conduit) {
|
|
667
|
-
|
|
668
|
-
var that = this,
|
|
669
|
-
model_name = conduit.routeParam('subject'),
|
|
670
|
-
model = this.getModel(model_name),
|
|
671
|
-
id = conduit.routeParam('id');
|
|
672
|
-
|
|
673
|
-
model.disableTranslations();
|
|
674
|
-
|
|
675
|
-
if (conduit.body.sure === 'yes') {
|
|
676
|
-
model.remove(id, function onRemoved(err) {
|
|
677
|
-
|
|
678
|
-
if (err) {
|
|
679
|
-
return conduit.error(err);
|
|
227
|
+
// The value should always be a string,
|
|
228
|
+
// so anything that is falsy can be ignored
|
|
229
|
+
if (!val) {
|
|
230
|
+
continue;
|
|
680
231
|
}
|
|
681
232
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
let route_params = Object.assign({}, conduit.params);
|
|
686
|
-
route_params.action = 'index';
|
|
687
|
-
delete route_params.id;
|
|
688
|
-
|
|
689
|
-
return conduit.redirect({
|
|
690
|
-
headers : conduit.headers,
|
|
691
|
-
url : Router.getUrl('ModelAction', route_params)
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
|
-
} else {
|
|
695
|
-
|
|
696
|
-
let item = await model.findById(id);
|
|
697
|
-
|
|
698
|
-
if (!item) {
|
|
699
|
-
return conduit.notFound();
|
|
233
|
+
val = RegExp.interpretWildcard('*' + val + '*');
|
|
234
|
+
crit.where(key).equals(val);
|
|
700
235
|
}
|
|
236
|
+
}
|
|
701
237
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
238
|
+
let records = await model.find('all', crit),
|
|
239
|
+
result = [],
|
|
240
|
+
record,
|
|
241
|
+
main;
|
|
242
|
+
|
|
243
|
+
for (record of records) {
|
|
244
|
+
|
|
245
|
+
record.$hold.actions = [
|
|
246
|
+
{
|
|
247
|
+
name : 'edit',
|
|
248
|
+
icon : 'edit',
|
|
249
|
+
url : alchemy.routeUrl('Chimera.Editor#edit', {
|
|
250
|
+
model : model_name,
|
|
251
|
+
pk : record.$pk,
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
];
|
|
712
255
|
}
|
|
713
256
|
|
|
257
|
+
conduit.end({
|
|
258
|
+
records : records
|
|
259
|
+
});
|
|
714
260
|
});
|