1 | /*global $, dotclear, getData */ |
---|
2 | 'use strict'; |
---|
3 | |
---|
4 | Object.assign(dotclear.msg, getData('pages_list')); |
---|
5 | |
---|
6 | dotclear.viewPostContent = function(line, action, e) { |
---|
7 | action = action || 'toggle'; |
---|
8 | if ($(line).attr('id') == undefined) { |
---|
9 | return; |
---|
10 | } |
---|
11 | |
---|
12 | const postId = $(line).attr('id').substr(1); |
---|
13 | const lineId = `pe${postId}`; |
---|
14 | let tr = document.getElementById(lineId); |
---|
15 | |
---|
16 | if (!tr) { |
---|
17 | // Get post content if possible |
---|
18 | dotclear.getEntryContent(postId, function(content) { |
---|
19 | if (content) { |
---|
20 | // Content found |
---|
21 | tr = document.createElement('tr'); |
---|
22 | tr.id = lineId; |
---|
23 | const td = document.createElement('td'); |
---|
24 | td.colSpan = $(line).children('td').length; |
---|
25 | td.className = 'expand'; |
---|
26 | tr.appendChild(td); |
---|
27 | $(td).append(content); |
---|
28 | $(line).addClass('expand'); |
---|
29 | line.parentNode.insertBefore(tr, line.nextSibling); |
---|
30 | } else { |
---|
31 | $(line).toggleClass('expand'); |
---|
32 | } |
---|
33 | }, { |
---|
34 | type: 'page', |
---|
35 | clean: (e.metaKey) |
---|
36 | }); |
---|
37 | } else { |
---|
38 | $(tr).toggle(); |
---|
39 | $(line).toggleClass('expand'); |
---|
40 | } |
---|
41 | }; |
---|
42 | |
---|
43 | $(function() { |
---|
44 | $('#pageslist tr.line').prepend('<td class="expander"></td>'); |
---|
45 | $('#form-entries tr:not(.line) th:first').attr('colspan', 4); |
---|
46 | $.expandContent({ |
---|
47 | line: $('#form-entries tr:not(.line)'), |
---|
48 | lines: $('#form-entries tr.line'), |
---|
49 | callback: dotclear.viewPostContent |
---|
50 | }); |
---|
51 | $('.checkboxes-helpers').each(function() { |
---|
52 | const p = $('<p></p>'); |
---|
53 | $(this).prepend(p); |
---|
54 | dotclear.checkboxesHelpers(p, undefined, '#pageslist td input[type=checkbox]', '#form-entries #do-action'); |
---|
55 | }); |
---|
56 | $('#pageslist td input[type=checkbox]').enableShiftClick(); |
---|
57 | dotclear.condSubmit('#pageslist td input[type=checkbox]', '#form-entries #do-action'); |
---|
58 | |
---|
59 | $('#pageslist tr.line td:not(.expander)').mousedown(function() { |
---|
60 | $('#pageslist tr.line').each(function() { |
---|
61 | const td = this.firstChild; |
---|
62 | dotclear.viewPostContent(td.firstChild, td.firstChild.line, 'close'); |
---|
63 | }); |
---|
64 | $('#pageslist tr:not(.line)').remove(); |
---|
65 | }); |
---|
66 | |
---|
67 | $('#pageslist').sortable({ |
---|
68 | cursor: 'move', |
---|
69 | stop: function() { |
---|
70 | $('#pageslist tr td input.position').each(function(i) { |
---|
71 | $(this).val(i + 1); |
---|
72 | }); |
---|
73 | } |
---|
74 | }); |
---|
75 | $('#pageslist tr').hover(function() { |
---|
76 | $(this).css({ |
---|
77 | 'cursor': 'move' |
---|
78 | }); |
---|
79 | }, function() { |
---|
80 | $(this).css({ |
---|
81 | 'cursor': 'auto' |
---|
82 | }); |
---|
83 | }); |
---|
84 | $('#pageslist tr td input.position').hide(); |
---|
85 | $('#pageslist tr td.handle').addClass('handler'); |
---|
86 | |
---|
87 | $('form input[type=submit]').click(function() { |
---|
88 | $('input[type=submit]', $(this).parents('form')).removeAttr('clicked'); |
---|
89 | $(this).attr('clicked', 'true'); |
---|
90 | }); |
---|
91 | |
---|
92 | $('#form-entries').submit(function() { |
---|
93 | const action = $(this).find('select[name="action"]').val(); |
---|
94 | let checked = false; |
---|
95 | if ($('input[name="reorder"][clicked=true]').val()) { |
---|
96 | return true; |
---|
97 | } |
---|
98 | $(this).find('input[name="entries[]"]').each(function() { |
---|
99 | if (this.checked) { |
---|
100 | checked = true; |
---|
101 | } |
---|
102 | }); |
---|
103 | |
---|
104 | if (!checked) { |
---|
105 | return false; |
---|
106 | } |
---|
107 | |
---|
108 | if (action == 'delete') { |
---|
109 | return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s', $('input[name="entries[]"]:checked').size())); |
---|
110 | } |
---|
111 | |
---|
112 | return true; |
---|
113 | }); |
---|
114 | }); |
---|