foldershare-8.x-1.2/js/foldershare.ui.sharedialog.js

js/foldershare.ui.sharedialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 * @file
 * Implements the FolderShare share dialog user interface.
 *
 * The dialog for the "Share" command presents a table of users and the
 * sharing permissions they have been granted. The dialog also contains
 * an auto-complete text field for entering the name of a new user to add
 * to the list. An "Add" button triggers the addition.
 *
 * This script supports the dialog by mapping a carriage return on the add
 * user text field into a trigger of the "Add" button.
 *
 * @ingroup foldershare
 * @see \Drupal\foldershare\Plugin\FolderShareCommand\Share
 * @see \Drupal\foldershare\Form\CommandFormWrapper
 */
(function($, Drupal) {
  Drupal.foldershare.ShareDialog = {
    /**
     * Attaches the module's UI behaviors.
     *
     * @param {Document} pageContext
     *   The page context for this call. Initially, this is the full document.
     *   Later, this is only portions of the document added via AJAX.
     * @param {object} settings
     *   The top-level Drupal settings object.
     *
     * @return {boolean}
     *   Always returns true.
     */
    attach(pageContext, settings) {
      const thisScript = Drupal.foldershare.ShareDialog;
 
      //
      // Test and exit
      // -------------
      // Quickly exit if the page context does not include the add-user form.
      const addUserForm = ".foldershare_share_add_user";
      let $addUserForm;
 
      if (typeof pageContext.tagName === "undefined") {
        // The full document. Search down.
        $addUserForm = $(addUserForm, pageContext);
      } else {
        // Above or below. Search up first, then down.
        $addUserForm = $(pageContext).parents(addUserForm);
        if ($addUserForm.length === 0) {
          $addUserForm = $(addUserForm, pageContext);
        }
      }
 
      if ($addUserForm.length === 0) {
        // Fail. The document does not contain the add-user form.
        return true;
      }
 
      //
      // Process top elements
      // --------------------
      // Process each add user form. There should be only one.
      const envList = [];
      $addUserForm.each((index, element) => {
        // Get the text field and button.
        const $addUserField = $('.foldershare_share_add_user_name', $(element)).eq(0);
        if ($addUserField.length === 0) {
          utility.printMalformedError("The UI add-user field is missing.");
          return false;
        }
 
        const $addUserButton = $('.foldershare_share_add_user_button', $(element)).eq(0);
        if ($addUserButton.length === 0) {
          utility.printMalformedError("The UI add-user button is missing.");
          return false;
        }
 
        // Attach a behavior to trigger the button on a carriage return.
        $addUserField.off("keypress.foldershare");
        $addUserField.on("keypress.foldershare", (ev) => {
          if (ev.keyCode == 13) {
            $addUserButton.prop("disabled", false);
            $addUserButton.click();
            ev.preventDefault();
            return false;
          }
        });
 
        // Attach a behavior to enable/disable the add button based on whether
        // the text field is empty.
        $addUserField.off("keyup.foldershare");
        $addUserField.on("keyup.foldershare", (ev) => {
          const name = $addUserField.val();
          if (name === null || name.length === 0) {
            $addUserButton.prop("disabled", true);
          } else {
            $addUserButton.prop("disabled", false);
          }
        });
 
        $addUserField.focus();
 
        // Enable/disable the add button initially based on whether the text
        // field is empty.
        const name = $addUserField.val();
        if (name === null || name.length === 0) {
          $addUserButton.prop("disabled", true);
        } else {
          $addUserButton.prop("disabled", false);
        }
      });
 
      return true;
    },
  };
 
  /*--------------------------------------------------------------------
   *
   * On Drupal ready behaviors.
   *
   * Set up behaviors to execute when the page is fully loaded, or whenever
   * AJAX sends a new page fragment.
   *
   *--------------------------------------------------------------------*/
 
  Drupal.behaviors.foldershare_ShareDialog = {
    attach(pageContext, settings) {
      Drupal.foldershare.ShareDialog.attach(pageContext, settings);
    }
  };
})(jQuery, Drupal);

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc