Dotclear

source: plugins/pages/js/list.js @ 3709:c88e69474c34

Revision 3709:c88e69474c34, 3.6 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

use strict and no more linter warnings/errors as far as possible, switch from inline js to separate loaded file

Line 
1/*global $, dotclear */
2'use strict';
3
4dotclear.viewPostContent = function(line, action) {
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 && (action == 'toggle' || action == 'open')) {
14    tr = document.createElement('tr');
15    tr.id = 'pe' + postId;
16    var td = document.createElement('td');
17    td.colSpan = 8;
18    td.className = 'expand';
19    tr.appendChild(td);
20
21    // Get post content
22    $.get('services.php', {
23      f: 'getPostById',
24      id: postId,
25      post_type: ''
26    }, function(data) {
27      var rsp = $(data).children('rsp')[0];
28
29      if (rsp.attributes[0].value == 'ok') {
30        var post = $(rsp).find('post_display_content').text();
31        var post_excerpt = $(rsp).find('post_display_excerpt').text();
32        var res = '';
33
34        if (post) {
35          if (post_excerpt) {
36            res += post_excerpt + '<hr />';
37          }
38          res += post;
39          $(td).append(res);
40        }
41      } else {
42        window.alert($(rsp).find('message').text());
43      }
44    });
45
46    $(line).addClass('expand');
47    line.parentNode.insertBefore(tr, line.nextSibling);
48  } else if (tr && tr.style.display == 'none' && (action == 'toggle' || action == 'open')) {
49    $(tr).css('display', 'table-row');
50    $(line).addClass('expand');
51  } else if (tr && tr.style.display != 'none' && (action == 'toggle' || action == 'close')) {
52    $(tr).css('display', 'none');
53    $(line).removeClass('expand');
54  }
55};
56
57$(function() {
58  $('#pageslist tr.line').prepend('<td class="expander"></td>');
59  $('#form-entries tr:not(.line) th:first').attr('colspan', 4);
60  $.expandContent({
61    line: $('#form-entries tr:not(.line)'),
62    lines: $('#form-entries tr.line'),
63    callback: dotclear.viewPostContent
64  });
65  $('.checkboxes-helpers').each(function() {
66    var p = $('<p></p>');
67    $(this).prepend(p);
68    dotclear.checkboxesHelpers(p, undefined, '#pageslist td input[type=checkbox]', '#form-entries #do-action');
69  });
70  $('#pageslist td input[type=checkbox]').enableShiftClick();
71  dotclear.condSubmit('#pageslist td input[type=checkbox]', '#form-entries #do-action');
72
73  $('#pageslist tr.line td:not(.expander)').mousedown(function() {
74    $('#pageslist tr.line').each(function() {
75      var td = this.firstChild;
76      dotclear.viewPostContent(td.firstChild, td.firstChild.line, 'close');
77    });
78    $('#pageslist tr:not(.line)').remove();
79  });
80
81  $('#pageslist').sortable({
82    cursor: 'move',
83    stop: function() {
84      $('#pageslist tr td input.position').each(function(i) {
85        $(this).val(i + 1);
86      });
87    }
88  });
89  $('#pageslist tr').hover(function() {
90    $(this).css({
91      'cursor': 'move'
92    });
93  }, function() {
94    $(this).css({
95      'cursor': 'auto'
96    });
97  });
98  $('#pageslist tr td input.position').hide();
99  $('#pageslist tr td.handle').addClass('handler');
100
101  $('form input[type=submit]').click(function() {
102    $('input[type=submit]', $(this).parents('form')).removeAttr('clicked');
103    $(this).attr('clicked', 'true');
104  });
105
106  $('#form-entries').submit(function() {
107    var action = $(this).find('select[name="action"]').val();
108    var checked = false;
109    if ($('input[name="reorder"][clicked=true]').val()) {
110      return true;
111    }
112    $(this).find('input[name="entries[]"]').each(function() {
113      if (this.checked) {
114        checked = true;
115      }
116    });
117
118    if (!checked) {
119      return false;
120    }
121
122    if (action == 'delete') {
123      return window.confirm(dotclear.msg.confirm_delete_posts.replace('%s', $('input[name="entries[]"]:checked').size()));
124    }
125
126    return true;
127  });
128});
Note: See TracBrowser for help on using the repository browser.

Sites map