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