-
Notifications
You must be signed in to change notification settings - Fork 110
/
edit.js
47 lines (45 loc) · 1.47 KB
/
edit.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
import { Tinymce } from '../../../utils/tinymce';
import { eachLinks } from '../../../utils/links';
import { isObject, isString } from '../../../utils/isType';
import { renderNotice, renderAlert } from '../../../utils/notificationHelper';
import { scrollTo } from '../../../utils/scrollTo';
$(() => {
Tinymce.init({
selector: '.template',
init_instance_callback(editor) {
// When the text editor changes to blank, set the corresponding destroy
// field to true (if present).
editor.on('Change', () => {
const $texteditor = $(editor.targetElm);
const $fieldset = $texteditor.parents('fieldset');
const $hiddenField = $fieldset.find('input[type=hidden][id$="_destroy"]');
$hiddenField.val(editor.getContent() === '');
});
},
});
$('.edit_template').on('ajax:before', () => {
const links = {};
eachLinks((ctx, value) => {
links[ctx] = value;
}).done(() => {
$('#template-links').val(JSON.stringify(links));
});
});
$('.edit_template').on('ajax:success', (e, data) => {
if (isObject(data) && isString(data.msg)) {
if (data.status === 200) {
renderNotice(data.msg);
} else {
renderAlert(data.msg);
}
scrollTo('#notification-area');
}
});
$('.edit_template').on('ajax:error', (e, xhr) => {
const error = xhr.responseJSON;
if (isObject(error) && isString(error)) {
renderAlert(error.msg);
scrollTo('#notification-area');
}
});
});