1 | /*global $, dotclear, jsToolBar */ |
---|
2 | 'use strict'; |
---|
3 | |
---|
4 | $(function() { |
---|
5 | function quickPost(f, status) { |
---|
6 | if ($.isFunction('jsToolBar') && (contentTb.getMode() == 'wysiwyg')) { |
---|
7 | contentTb.syncContents('iframe'); |
---|
8 | } |
---|
9 | |
---|
10 | var params = { |
---|
11 | f: 'quickPost', |
---|
12 | xd_check: dotclear.nonce, |
---|
13 | post_title: $('#post_title', f).val(), |
---|
14 | post_content: $('#post_content', f).val(), |
---|
15 | cat_id: $('#cat_id', f).val(), |
---|
16 | post_status: status, |
---|
17 | post_format: $('#post_format', f).val(), |
---|
18 | post_lang: $('#post_lang', f).val(), |
---|
19 | new_cat_title: $('#new_cat_title', f).val(), |
---|
20 | new_cat_parent: $('#new_cat_parent', f).val() |
---|
21 | }; |
---|
22 | |
---|
23 | $('p.qinfo', f).remove(); |
---|
24 | |
---|
25 | $.post('services.php', params, function(data) { |
---|
26 | var msg; |
---|
27 | if ($('rsp[status=failed]', data).length > 0) { |
---|
28 | msg = '<p class="qinfo"><strong>' + dotclear.msg.error + |
---|
29 | '</strong> ' + $('rsp', data).text() + '</p>'; |
---|
30 | } else { |
---|
31 | msg = '<p class="qinfo">' + dotclear.msg.entry_created + |
---|
32 | ' - <a href="post.php?id=' + $('rsp>post', data).attr('id') + '">' + |
---|
33 | dotclear.msg.edit_entry + '</a>'; |
---|
34 | if ($('rsp>post', data).attr('post_status') == 1) { |
---|
35 | msg += ' - <a href="' + $('rsp>post', data).attr('post_url') + '">' + |
---|
36 | dotclear.msg.view_entry + '</a>'; |
---|
37 | } |
---|
38 | msg += '</p>'; |
---|
39 | $('#post_title', f).val(''); |
---|
40 | $('#post_content', f).val(''); |
---|
41 | $('#post_content', f).change(); |
---|
42 | if ($.isFunction('jsToolBar') && (contentTb.getMode() == 'wysiwyg')) { |
---|
43 | contentTb.syncContents('textarea'); |
---|
44 | } |
---|
45 | $('#cat_id', f).val('0'); |
---|
46 | $('#new_cat_title', f).val(''); |
---|
47 | $('#new_cat_parent', f).val('0'); |
---|
48 | } |
---|
49 | |
---|
50 | $('fieldset', f).prepend(msg); |
---|
51 | }); |
---|
52 | } |
---|
53 | |
---|
54 | var f = $('#quick-entry'); |
---|
55 | if (f.length > 0) { |
---|
56 | if ($.isFunction(jsToolBar)) { |
---|
57 | var contentTb = new jsToolBar($('#post_content', f)[0]); |
---|
58 | contentTb.switchMode($('#post_format', f).val()); |
---|
59 | } |
---|
60 | |
---|
61 | $('input[name=save]', f).click(function() { |
---|
62 | quickPost(f, -2); |
---|
63 | return false; |
---|
64 | }); |
---|
65 | |
---|
66 | if ($('input[name=save-publish]', f).length > 0) { |
---|
67 | var btn = $('<input type="submit" value="' + $('input[name=save-publish]', f).val() + '" />'); |
---|
68 | $('input[name=save-publish]', f).remove(); |
---|
69 | $('input[name=save]', f).after(btn).after(' '); |
---|
70 | btn.click(function() { |
---|
71 | quickPost(f, 1); |
---|
72 | return false; |
---|
73 | }); |
---|
74 | } |
---|
75 | |
---|
76 | $('#new_cat').toggleWithLegend($('#new_cat').parent().children().not('#new_cat'), { |
---|
77 | // no cookie on new category as we don't use this every day |
---|
78 | legend_click: true |
---|
79 | }); |
---|
80 | } |
---|
81 | |
---|
82 | // allow to hide quick entry div, and remember choice |
---|
83 | $('#quick h3').toggleWithLegend($('#quick').children().not('h3'), { |
---|
84 | legend_click: true, |
---|
85 | user_pref: 'dcx_quick_entry' |
---|
86 | }); |
---|
87 | |
---|
88 | // check if core update available |
---|
89 | var params = { |
---|
90 | f: 'checkCoreUpdate', |
---|
91 | xd_check: dotclear.nonce |
---|
92 | }; |
---|
93 | $.post('services.php', params, function(data) { |
---|
94 | if ($('rsp[status=failed]', data).length > 0) { |
---|
95 | // Silently fail as a forced checked my be done with admin update page |
---|
96 | } else { |
---|
97 | if ($('rsp>update', data).attr('check') == 1) { |
---|
98 | // Something has to be displayed |
---|
99 | var xml = $('rsp>update', data).attr('ret'); |
---|
100 | $('#content h2').after(xml); |
---|
101 | } |
---|
102 | } |
---|
103 | }); |
---|
104 | |
---|
105 | // check if some news are available |
---|
106 | params = { |
---|
107 | f: 'checkNewsUpdate', |
---|
108 | xd_check: dotclear.nonce |
---|
109 | }; |
---|
110 | $.post('services.php', params, function(data) { |
---|
111 | if ($('rsp[status=failed]', data).length > 0) { |
---|
112 | // Silently fail |
---|
113 | } else { |
---|
114 | if ($('rsp>news', data).attr('check') == 1) { |
---|
115 | // Something has to be displayed |
---|
116 | var xml = $('rsp>news', data).attr('ret'); |
---|
117 | if ($('#dashboard-boxes').length == 0) { |
---|
118 | // Create the #dashboard-boxes container |
---|
119 | $('#dashboard-main').append('<div id="dashboard-boxes"></div>'); |
---|
120 | } |
---|
121 | if ($('#dashboard-boxes div.db-items').length == 0) { |
---|
122 | // Create the #dashboard-boxes div.db-items container |
---|
123 | $('#dashboard-boxes').prepend('<div class="db-items"></div>'); |
---|
124 | } |
---|
125 | $('#dashboard-boxes div.db-items').prepend(xml); |
---|
126 | } |
---|
127 | } |
---|
128 | }); |
---|
129 | }); |
---|