Dotclear

source: admin/js/_plugins.js @ 3880:e6d1f6d9d7df

Revision 3880:e6d1f6d9d7df, 2.0 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
4$(function() {
5  // expand a module line
6  $('table.modules.expandable tr.line').each(function() {
7    $('td.module-name, th.module-name', this).toggleWithLegend($(this).next('.module-more'), {
8      img_on_txt: dotclear.img_plus_txt,
9      img_on_alt: dotclear.img_plus_alt,
10      img_off_txt: dotclear.img_minus_txt,
11      img_off_alt: dotclear.img_minus_alt,
12      legend_click: true
13    });
14  });
15
16  // checkboxes selection
17  $('.checkboxes-helpers').each(function() {
18    dotclear.checkboxesHelpers(this);
19  });
20
21  // actions tests
22  $('.modules-form-actions').each(function() {
23    const rxActionType = /^[^\[]+/;
24    const rxActionValue = /([^\[]+)\]$/;
25    const checkboxes = $(this).find('input[type=checkbox]');
26
27    // check if submit is a global action or one line action
28    $('input[type=submit]', this).click(function() {
29      const keyword = $(this).attr('name');
30      if (!keyword) {
31        return true;
32      }
33      const maction = keyword.match(rxActionType);
34      const action = maction[0];
35      const mvalues = keyword.match(rxActionValue);
36
37      // action on multiple modules
38      if (!mvalues) {
39        let checked = false;
40
41        // check if there is checkboxes in form
42        if (checkboxes.length > 0) {
43          // check if there is at least one checkbox checked
44          $(checkboxes).each(function() {
45            if (this.checked) {
46              checked = true;
47            }
48          });
49          if (!checked) {
50            //alert(dotclear.msg.no_selection);
51            return false;
52          }
53        }
54
55        // confirm delete
56        if (action == 'delete') {
57          return window.confirm(dotclear.msg.confirm_delete_plugins);
58        }
59
60        // action on one module
61      } else {
62        const module = mvalues[1];
63
64        // confirm delete
65        if (action == 'delete') {
66          return window.confirm(dotclear.msg.confirm_delete_plugin.replace('%s', module));
67        }
68      }
69
70      return true;
71    });
72  });
73});
Note: See TracBrowser for help on using the repository browser.

Sites map