Dotclear

source: plugins/pages/js/list.js @ 3880:e6d1f6d9d7df

Revision 3880:e6d1f6d9d7df, 3.1 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use let and const rather than var (ES2015/ES6), use template string where is more efficient

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

Sites map