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