root / drupal7 / sites / all / modules / field_permissions / field_permissions.admin.js @ 1f142f4f
1 | 85ad3d82 | Assos Assos | (function ($) { |
---|---|---|---|
2 | |||
3 | Drupal.behaviors.fieldPermissionsSettings = { |
||
4 | attach: function (context) { |
||
5 | // For user fields, we want the "Create own value for field X" permission
|
||
6 | // row to only be displayed when it's meaningful (i.e., when the "Display
|
||
7 | // on user registration form" checkbox is checked).
|
||
8 | var $user_register_form_checkbox, $required_field_checkbox, $create_permission_row; |
||
9 | $user_register_form_checkbox = $('.form-item-instance-settings-user-register-form .form-checkbox', context); |
||
10 | if ($user_register_form_checkbox.length) { |
||
11 | // The "Required field" checkbox can cause the user registration checkbox
|
||
12 | // to change, so we need it also.
|
||
13 | $required_field_checkbox = $('.form-item-instance-required .form-checkbox', context); |
||
14 | if ($required_field_checkbox.length) { |
||
15 | // Get the permissions table row corresponding to the "Create own value
|
||
16 | // for field X" permission. The theme_user_admin_permissions() function
|
||
17 | // does not give us a good way to directly detect which row contains
|
||
18 | // the create permissions, so we have rely on the fact that it will be
|
||
19 | // the first row.
|
||
20 | $create_permission_row = $('table#permissions tbody tr', context).filter(':first'); |
||
21 | new Drupal.fieldPermissions.HideCreatePermission($user_register_form_checkbox, $required_field_checkbox, $create_permission_row); |
||
22 | } |
||
23 | } |
||
24 | } |
||
25 | }; |
||
26 | |||
27 | Drupal.fieldPermissions = {}; |
||
28 | |||
29 | /**
|
||
30 | * Constructor for the HideCreatePermission object.
|
||
31 | *
|
||
32 | * This object hides and shows the "Create own value for field X" permission
|
||
33 | * for user fields when it is appropriate to do so, depending on the state of
|
||
34 | * the "Display on user registration form" and "Required field" checkboxes.
|
||
35 | */
|
||
36 | Drupal.fieldPermissions.HideCreatePermission = function ($user_register_form_checkbox, $required_field_checkbox, $create_permission_row) { |
||
37 | this.$user_register_form_checkbox = $user_register_form_checkbox; |
||
38 | this.$create_permission_row = $create_permission_row; |
||
39 | // Start off by making sure the create permission row has the correct
|
||
40 | // visibility.
|
||
41 | this.setCreatePermissionVisibility();
|
||
42 | // Set the row's visibility again whenever the user registration checkbox
|
||
43 | // changes, or when the required field checkbox (which controls it) changes.
|
||
44 | $user_register_form_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this)); |
||
45 | $required_field_checkbox.bind('change', $.proxy(this.setCreatePermissionVisibility, this)); |
||
46 | }; |
||
47 | |||
48 | /**
|
||
49 | * Set the correct visibility of the "Create own value for field X" permission.
|
||
50 | */
|
||
51 | Drupal.fieldPermissions.HideCreatePermission.prototype.setCreatePermissionVisibility = function () { |
||
52 | // Granting permissions for "Create own value for field X" only makes sense
|
||
53 | // when the field is configured to appear on the user registration form, so
|
||
54 | // only show the row in the permissions table then.
|
||
55 | if (this.$user_register_form_checkbox.is(':checked')) { |
||
56 | this.$create_permission_row.show(); |
||
57 | } |
||
58 | else {
|
||
59 | this.$create_permission_row.hide(); |
||
60 | } |
||
61 | }; |
||
62 | |||
63 | })(jQuery); |