1 | /*global $, dotclear, editor, confirmClosePage, getData */ |
---|
2 | 'use strict'; |
---|
3 | |
---|
4 | // Get locales and setting |
---|
5 | Object.assign(dotclear.msg, getData('theme_editor_msg')); |
---|
6 | Object.assign(dotclear, getData('dotclear_colorsyntax')); |
---|
7 | |
---|
8 | $(function() { |
---|
9 | // Cope with saving |
---|
10 | let msg = false; |
---|
11 | $('#file-form input[name="write"]').click(function(e) { |
---|
12 | const f = this.form; |
---|
13 | |
---|
14 | const data = { |
---|
15 | file_content: (!dotclear.colorsyntax ? $(f).find('#file_content').get(0).value : editor.getValue()), |
---|
16 | xd_check: $(f).find('input[name="xd_check"]').get(0).value, |
---|
17 | write: 1 |
---|
18 | }; |
---|
19 | |
---|
20 | if (msg == false) { |
---|
21 | msg = $('<p style="font-weight:bold; color:red;"></p>'); |
---|
22 | $('#file_content').parent().after(msg); |
---|
23 | } |
---|
24 | |
---|
25 | msg.text(dotclear.msg.saving_document); |
---|
26 | |
---|
27 | $.post(document.location.href, data, function(res) { |
---|
28 | const err = $(res).find('div.error li:first'); |
---|
29 | if (err.length > 0) { |
---|
30 | msg.text(dotclear.msg.error_occurred + ' ' + err.text()); |
---|
31 | return; |
---|
32 | } else { |
---|
33 | msg.text(dotclear.msg.document_saved); |
---|
34 | $('#file-chooser').empty(); |
---|
35 | $(res).find('#file-chooser').children().appendTo('#file-chooser'); |
---|
36 | |
---|
37 | if ($.isFunction(confirmClosePage.getCurrentForms)) { |
---|
38 | confirmClosePage.forms = []; |
---|
39 | confirmClosePage.getCurrentForms(); |
---|
40 | } |
---|
41 | } |
---|
42 | }); |
---|
43 | |
---|
44 | e.preventDefault(); |
---|
45 | }); |
---|
46 | |
---|
47 | // Confirm for deleting current file |
---|
48 | $('#file-form input[name="delete"]').click(function() { |
---|
49 | return window.confirm(dotclear.msg.confirm_reset_file); |
---|
50 | }); |
---|
51 | |
---|
52 | }); |
---|