-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
51 lines (45 loc) · 1.3 KB
/
content.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
(function($) {
$(document).ready(function() {
var form = $('#content_edit_form, #content_create_form');
$('#save_submit', form).click(function() {
var id = $('#content_edit_form #entity_id').val();
var endpoint = '/content/save';
if (id) {
endpoint += '/' + id;
}
var content = {
title: $('#content_title', form).val(),
teaser: $('#content_teaser', form).val(),
body: $('#content_body', form).val(),
status: $('#content_status', form).is(':checked'),
promote: $('#content_promote', form).is(':checked'),
}
$(document).trigger('ophal:entity:save', {context: form, entity: content});
/* Fetch auth token */
$.ajax({
type: 'POST',
url: endpoint,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(content),
dataType: 'json',
processData: false,
success: function (data) {
if (data.success) {
window.location = '/content/' + data.id;
}
else {
if (data.success) {
alert('Operation failed! Reason: ' + data.error);
}
else {
alert('Operation failed!');
}
}
},
error: function() {
alert('Operation error. Please try again later.');
},
});
});
});
})(jQuery);