alchemy-chimera 0.5.4 → 1.0.2
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 +39 -4
- package/assets/scripts/chimera/chimera.js +13 -288
- package/assets/stylesheets/chimera/chimera.scss +451 -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 +159 -614
- package/controller/chimera_static_controller.js +102 -9
- package/lib/chimera_config.js +138 -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 -622
- package/assets/scripts/chimera/chimera_field_wrapper.js +0 -558
- 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 -73
- 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 -160
- 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 -82
- 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 -12
- 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,259 @@
|
|
|
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
|
-
|
|
8
|
+
const Editor = Function.inherits('Alchemy.Controller.Chimera', 'Editor');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Set the title
|
|
12
|
+
*
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 1.0.1
|
|
15
|
+
* @version 1.0.1
|
|
16
|
+
*
|
|
17
|
+
* @param {String} title
|
|
18
|
+
*/
|
|
19
|
+
Editor.setMethod(function setTitle(title) {
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
let window_title,
|
|
22
|
+
page_title;
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
if (alchemy.plugins.chimera.title) {
|
|
25
|
+
window_title = alchemy.plugins.chimera.title || '';
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
if (title && window_title) {
|
|
28
|
+
window_title += ' | ';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
if (title) {
|
|
33
|
+
window_title += title;
|
|
34
|
+
}
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
this.addAction('record-edit', 'saveClose', {title: 'Save and close', icon: '<x-svg data-src="chimera/floppy"></x-svg>', handleManual: true, route_name: 'RecordAction'});
|
|
36
|
+
page_title = title;
|
|
27
37
|
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
38
|
+
this.set('page_title', page_title);
|
|
39
|
+
this.set('window_title', window_title || page_title);
|
|
30
40
|
});
|
|
31
41
|
|
|
32
42
|
/**
|
|
33
43
|
* The index action
|
|
34
44
|
*
|
|
35
|
-
* @author Jelle De Loecker <jelle@
|
|
45
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
36
46
|
* @since 0.1.0
|
|
37
|
-
* @version 0.1
|
|
47
|
+
* @version 1.0.1
|
|
38
48
|
*
|
|
39
49
|
* @param {Conduit} conduit
|
|
50
|
+
* @param {String} model_name
|
|
40
51
|
*/
|
|
41
|
-
Editor.setAction(function index(conduit) {
|
|
42
|
-
return this.doAction('listing', [conduit, 'list', 'index']);
|
|
43
|
-
});
|
|
52
|
+
Editor.setAction(function index(conduit, model_name) {
|
|
44
53
|
|
|
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;
|
|
54
|
+
let model = this.getModel(model_name);
|
|
64
55
|
|
|
65
|
-
|
|
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
|
-
}
|
|
56
|
+
let widget_config = model.chimera.getWidgetConfig('index', conduit);
|
|
71
57
|
|
|
72
|
-
|
|
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
|
-
}
|
|
58
|
+
this.setTitle(model_name.titleize());
|
|
81
59
|
|
|
82
|
-
|
|
83
|
-
model_title = model_name.titleize();
|
|
60
|
+
this.set('model_name', model_name);
|
|
84
61
|
|
|
85
|
-
|
|
86
|
-
model_plural = model_title.pluralize();
|
|
62
|
+
this.set('widget_config', widget_config);
|
|
87
63
|
|
|
88
|
-
|
|
89
|
-
model.disableTranslations();
|
|
90
|
-
|
|
91
|
-
// Set the page title
|
|
92
|
-
this.setTitle(model_plural);
|
|
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);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
let options = {
|
|
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;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Find the paginated records
|
|
120
|
-
that.components.paginate.find(model, options, function gotRecords(err, items) {
|
|
121
|
-
|
|
122
|
-
if (err) {
|
|
123
|
-
return conduit.error(err);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
that.conduit.set('available_records', items.available || 0);
|
|
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
|
-
});
|
|
64
|
+
this.render('chimera/editor/index');
|
|
151
65
|
});
|
|
152
66
|
|
|
153
67
|
/**
|
|
154
|
-
*
|
|
68
|
+
* The add action
|
|
69
|
+
*
|
|
70
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
71
|
+
* @since 0.1.0
|
|
72
|
+
* @version 1.0.2
|
|
155
73
|
*
|
|
156
|
-
* @param
|
|
74
|
+
* @param {Conduit} conduit
|
|
75
|
+
* @param {String} model_name
|
|
157
76
|
*/
|
|
158
|
-
Editor.setAction(function
|
|
77
|
+
Editor.setAction(async function add(conduit, model_name) {
|
|
159
78
|
|
|
160
|
-
|
|
161
|
-
model = this.getModel(subject),
|
|
162
|
-
data = {name: conduit.body.text, title: conduit.body.text};
|
|
79
|
+
let model = this.getModel(model_name);
|
|
163
80
|
|
|
164
|
-
model.
|
|
81
|
+
model.translateItems = false;
|
|
165
82
|
|
|
166
|
-
|
|
167
|
-
return conduit.error(err);
|
|
168
|
-
}
|
|
83
|
+
if (conduit.method == 'post') {
|
|
169
84
|
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
});
|
|
85
|
+
let record = model.createDocument();
|
|
173
86
|
|
|
174
|
-
|
|
175
|
-
* The add action
|
|
176
|
-
*
|
|
177
|
-
* @param {Conduit} conduit
|
|
178
|
-
*/
|
|
179
|
-
Editor.setAction(function add(conduit) {
|
|
87
|
+
record.setDataRecord(conduit.body[model_name]);
|
|
180
88
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
model_title,
|
|
184
|
-
model_name,
|
|
185
|
-
chimera,
|
|
186
|
-
model;
|
|
89
|
+
try {
|
|
90
|
+
await record.save();
|
|
187
91
|
|
|
188
|
-
|
|
189
|
-
|
|
92
|
+
let url = alchemy.routeUrl('Chimera.Editor#edit', {
|
|
93
|
+
model: model_name,
|
|
94
|
+
pk: record.$pk,
|
|
95
|
+
message: 'added'
|
|
96
|
+
});
|
|
190
97
|
|
|
191
|
-
|
|
192
|
-
|
|
98
|
+
return conduit.redirect(url);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
this.set('context_variables', {
|
|
101
|
+
form_violations : err,
|
|
102
|
+
record : record
|
|
103
|
+
});
|
|
104
|
+
}
|
|
193
105
|
}
|
|
194
106
|
|
|
195
|
-
|
|
196
|
-
model = this.getModel(model_name);
|
|
197
|
-
|
|
198
|
-
// And get the chimera instance
|
|
199
|
-
chimera = model.constructor.chimera;
|
|
107
|
+
let widget_config = model.chimera.getWidgetConfig('edit', conduit);
|
|
200
108
|
|
|
201
|
-
if (
|
|
202
|
-
|
|
109
|
+
if (!widget_config.class_names) {
|
|
110
|
+
widget_config.class_names = [];
|
|
203
111
|
}
|
|
204
112
|
|
|
205
|
-
|
|
206
|
-
model_title = model_name.titleize();
|
|
207
|
-
|
|
208
|
-
// And the plural form
|
|
209
|
-
model_plural = model_title.pluralize();
|
|
210
|
-
|
|
211
|
-
// Disable translation behaviour of the model
|
|
212
|
-
model.disableTranslations();
|
|
213
|
-
|
|
214
|
-
this.setTitle(model_title + ': Add');
|
|
215
|
-
|
|
216
|
-
let action_fields = chimera.getActionFields('edit'),
|
|
217
|
-
groups = action_fields.groups.clone(),
|
|
218
|
-
item = model.compose(),
|
|
219
|
-
id = item._id;
|
|
220
|
-
|
|
221
|
-
action_fields.processRecords(model, [item], function groupedRecords(err, groups) {
|
|
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());
|
|
113
|
+
widget_config.class_names.push('chimera-editor-widgets');
|
|
231
114
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
that.internal('model_name', model_name);
|
|
235
|
-
that.internal('record_id', id);
|
|
115
|
+
this.set('widget_config', widget_config);
|
|
116
|
+
this.setTitle(model.constructor.title + ' Add');
|
|
236
117
|
|
|
237
|
-
|
|
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
|
-
});
|
|
118
|
+
this.render('chimera/widgets');
|
|
244
119
|
});
|
|
245
120
|
|
|
246
121
|
/**
|
|
247
122
|
* The edit action
|
|
248
123
|
*
|
|
249
|
-
* @
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
var that = this,
|
|
254
|
-
modelName = conduit.routeParam('subject'),
|
|
255
|
-
model = this.getModel(modelName),
|
|
256
|
-
chimera = model.constructor.chimera,
|
|
257
|
-
id = conduit.routeParam('id');
|
|
258
|
-
|
|
259
|
-
model.disableTranslations();
|
|
260
|
-
|
|
261
|
-
var actionFields = chimera.getActionFields('edit'),
|
|
262
|
-
groups = actionFields.groups.clone();
|
|
263
|
-
|
|
264
|
-
model.find('first', {conditions: {_id: alchemy.castObjectId(id)}}, function(err, item) {
|
|
265
|
-
|
|
266
|
-
if (err) {
|
|
267
|
-
return conduit.error(err);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (!item) {
|
|
271
|
-
return conduit.notFound();
|
|
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
|
|
124
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
125
|
+
* @since 0.1.0
|
|
126
|
+
* @version 1.0.2
|
|
297
127
|
*
|
|
298
|
-
* @param
|
|
128
|
+
* @param {Conduit} conduit
|
|
129
|
+
* @param {String} model_name
|
|
130
|
+
* @param {String} pk_val
|
|
299
131
|
*/
|
|
300
|
-
Editor.setAction(function
|
|
132
|
+
Editor.setAction(async function edit(conduit, model_name, pk_val) {
|
|
301
133
|
|
|
302
|
-
|
|
303
|
-
action_fields,
|
|
304
|
-
model_name,
|
|
305
|
-
chimera,
|
|
306
|
-
groups,
|
|
307
|
-
model,
|
|
308
|
-
id;
|
|
134
|
+
let model = this.getModel(model_name);
|
|
309
135
|
|
|
310
|
-
|
|
311
|
-
model = this.getModel(model_name);
|
|
312
|
-
chimera = model.constructor.chimera;
|
|
313
|
-
id = conduit.routeParam('id');
|
|
136
|
+
model.translateItems = false;
|
|
314
137
|
|
|
315
|
-
|
|
316
|
-
|
|
138
|
+
let record = await model.findByPk(pk_val);
|
|
139
|
+
let message_type = conduit.param('message');
|
|
317
140
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
141
|
+
let context_variables = {
|
|
142
|
+
record,
|
|
143
|
+
};
|
|
321
144
|
|
|
322
|
-
|
|
323
|
-
model.find('first', {conditions: {_id: id}}, function gotRecord(err, item) {
|
|
145
|
+
if (conduit.method == 'post') {
|
|
324
146
|
|
|
325
|
-
|
|
326
|
-
return conduit.error(err);
|
|
327
|
-
}
|
|
147
|
+
Object.assign(record, conduit.body[model_name]);
|
|
328
148
|
|
|
329
|
-
|
|
330
|
-
|
|
149
|
+
try {
|
|
150
|
+
await record.save();
|
|
151
|
+
message_type = 'saved';
|
|
152
|
+
} catch (err) {
|
|
153
|
+
context_variables.form_violations = err;
|
|
331
154
|
}
|
|
332
|
-
|
|
333
|
-
action_fields.processRecords(model, [item], function groupedRecords(err, groups) {
|
|
334
|
-
|
|
335
|
-
if (err) {
|
|
336
|
-
return conduit.error(err);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
that.set('editor_action', 'peek');
|
|
340
|
-
that.set('prefixes', Prefix.getPrefixList());
|
|
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
|
-
});
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Reorder an array
|
|
356
|
-
*
|
|
357
|
-
* @author Jelle De Loecker <jelle@develry.be>
|
|
358
|
-
* @since 0.5.1
|
|
359
|
-
* @version 0.5.1
|
|
360
|
-
*
|
|
361
|
-
* @param {Array} arr The array to reorder
|
|
362
|
-
* @param {Object} query The query that should match the entries
|
|
363
|
-
* @param {Number} new_index The new index this should be moved to
|
|
364
|
-
*/
|
|
365
|
-
function reorderByQuery(arr, query, new_index, path) {
|
|
366
|
-
|
|
367
|
-
let entry = arr.findByPath(query);
|
|
368
|
-
|
|
369
|
-
if (!entry) {
|
|
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
155
|
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* The "reorder" method
|
|
384
|
-
*
|
|
385
|
-
* @param {Conduit} conduit
|
|
386
|
-
*/
|
|
387
|
-
Editor.setAction(async function reorder(conduit) {
|
|
388
|
-
|
|
389
|
-
var that = this,
|
|
390
|
-
model_name,
|
|
391
|
-
new_index,
|
|
392
|
-
model,
|
|
393
|
-
id;
|
|
394
156
|
|
|
395
|
-
|
|
396
|
-
model_name = conduit.routeParam('subject');
|
|
397
|
-
model = this.getModel(model_name);
|
|
398
|
-
id = conduit.routeParam('id');
|
|
157
|
+
this.set('context_variables', context_variables);
|
|
399
158
|
|
|
400
|
-
let
|
|
401
|
-
let records = await model.find('all', {fields: ['_id', 'order']});
|
|
159
|
+
let widget_config = model.chimera.getWidgetConfig('edit', conduit);
|
|
402
160
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
reorderByQuery(records, {_id: String(id)}, new_index, 'order');
|
|
406
|
-
|
|
407
|
-
for (let i = 0; i < records.length; i++) {
|
|
408
|
-
if (!records[i].hasChanged()) {
|
|
409
|
-
continue;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
await records[i].save();
|
|
161
|
+
if (!widget_config.class_names) {
|
|
162
|
+
widget_config.class_names = [];
|
|
413
163
|
}
|
|
414
164
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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;
|
|
165
|
+
if (message_type) {
|
|
166
|
+
if (message_type == 'added') {
|
|
167
|
+
this.set('message', 'Record has been added');
|
|
168
|
+
} else if (message_type == 'saved') {
|
|
169
|
+
this.set('message', 'Record has been saved');
|
|
444
170
|
}
|
|
445
|
-
|
|
446
|
-
results.push(entry);
|
|
447
171
|
}
|
|
448
172
|
|
|
449
|
-
|
|
450
|
-
items : results,
|
|
451
|
-
displayField : model.displayField
|
|
452
|
-
});
|
|
453
|
-
});
|
|
173
|
+
widget_config.class_names.push('chimera-editor-widgets');
|
|
454
174
|
|
|
455
|
-
|
|
456
|
-
|
|
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;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
model.disableTranslations();
|
|
475
|
-
|
|
476
|
-
// Some fields (like subschemas) require record info for related data
|
|
477
|
-
model.find('first', {conditions: {_id: id}, document: false}, function gotResult(err, items) {
|
|
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
|
-
}
|
|
175
|
+
this.set('widget_config', widget_config);
|
|
176
|
+
this.setTitle(model.constructor.title + ' Edit');
|
|
485
177
|
|
|
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
|
-
});
|
|
178
|
+
this.render('chimera/widgets');
|
|
494
179
|
});
|
|
495
180
|
|
|
496
181
|
/**
|
|
497
|
-
* The
|
|
182
|
+
* The records API action
|
|
498
183
|
*
|
|
499
|
-
* @
|
|
184
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
185
|
+
* @since 1.0.0
|
|
186
|
+
* @version 1.0.0
|
|
500
187
|
*
|
|
501
|
-
* @param
|
|
188
|
+
* @param {Conduit} conduit
|
|
189
|
+
* @param {String} model_name
|
|
502
190
|
*/
|
|
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();
|
|
191
|
+
Editor.setAction(async function records(conduit, model_name) {
|
|
512
192
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
let item = await model.findById(id);
|
|
193
|
+
let body = conduit.body,
|
|
194
|
+
model = this.getModel(model_name),
|
|
195
|
+
crit = model.find();
|
|
517
196
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
197
|
+
let page_size = body.page_size,
|
|
198
|
+
fields = body.fields,
|
|
199
|
+
page = body.page;
|
|
521
200
|
|
|
522
|
-
|
|
201
|
+
if (fields) {
|
|
523
202
|
|
|
524
|
-
|
|
525
|
-
|
|
203
|
+
// @TODO: fix FieldSet being sent with regular json?
|
|
204
|
+
if (fields.fields) {
|
|
205
|
+
fields = fields.fields;
|
|
526
206
|
}
|
|
527
207
|
|
|
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');
|
|
208
|
+
crit.select(fields);
|
|
593
209
|
}
|
|
594
210
|
|
|
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');
|
|
211
|
+
if (page) {
|
|
212
|
+
crit.page(page, page_size);
|
|
604
213
|
}
|
|
605
214
|
|
|
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;
|
|
215
|
+
if (body.sort && body.sort.field && body.sort.dir) {
|
|
216
|
+
crit.sort([body.sort.field, body.sort.dir]);
|
|
619
217
|
}
|
|
620
218
|
|
|
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
|
-
}
|
|
219
|
+
if (body.filters) {
|
|
220
|
+
let key,
|
|
221
|
+
val;
|
|
642
222
|
|
|
643
|
-
|
|
644
|
-
|
|
223
|
+
for (key in body.filters) {
|
|
224
|
+
val = body.filters[key];
|
|
645
225
|
|
|
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);
|
|
226
|
+
// The value should always be a string,
|
|
227
|
+
// so anything that is falsy can be ignored
|
|
228
|
+
if (!val) {
|
|
229
|
+
continue;
|
|
680
230
|
}
|
|
681
231
|
|
|
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();
|
|
232
|
+
val = RegExp.interpretWildcard('*' + val + '*');
|
|
233
|
+
crit.where(key).equals(val);
|
|
700
234
|
}
|
|
235
|
+
}
|
|
701
236
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
237
|
+
let records = await model.find('all', crit),
|
|
238
|
+
result = [],
|
|
239
|
+
record,
|
|
240
|
+
main;
|
|
241
|
+
|
|
242
|
+
for (record of records) {
|
|
243
|
+
|
|
244
|
+
record.$hold.actions = [
|
|
245
|
+
{
|
|
246
|
+
name : 'edit',
|
|
247
|
+
icon : 'edit',
|
|
248
|
+
url : alchemy.routeUrl('Chimera.Editor#edit', {
|
|
249
|
+
model : model_name,
|
|
250
|
+
pk : record.$pk,
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
];
|
|
712
254
|
}
|
|
713
255
|
|
|
256
|
+
conduit.end({
|
|
257
|
+
records : records
|
|
258
|
+
});
|
|
714
259
|
});
|