-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added feature to hide element based on write_permission attribute
- Loading branch information
1 parent
55ae328
commit 0240a93
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(function ($, Drupal, drupalSettings) { | ||
|
||
if (!drupalSettings.csisHelpers) { | ||
return; | ||
} | ||
|
||
Drupal.behaviors.csis_permission_control = { | ||
attach: function (context, settings) { | ||
// search for all elements containing that class (will be buttons or links) | ||
$('.token-field-check-permissions', context).once('checkPermissions').each(function () { | ||
//console.debug('checking permissions'); | ||
|
||
// get write permissions for current user based on their role in the group | ||
var writePermissions = drupalSettings.csisHelpers.studyInfo.write_permissions | ||
|
||
// if user can't write to this group/node then hide the element | ||
// hiding is in this case enough since Drupal itself will also check permissions | ||
// when a form is called and block users without necessary permissions | ||
if (writePermissions == 0) { | ||
$(this).hide(); | ||
} | ||
|
||
}); | ||
} | ||
}; | ||
})(jQuery, Drupal, drupalSettings); | ||
|