Merge pull request #24114 from Hystepik/develop#1
New : expand/collapse groups permission module
This commit is contained in:
commit
c557f0dd2d
@ -255,12 +255,18 @@ if ($object->id > 0) {
|
|||||||
print '/';
|
print '/';
|
||||||
print '<a class="reposition commonlink" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&&token='.newToken().'&entity='.$entity.'&module=allmodules&confirm=yes">'.$langs->trans("None")."</a>";
|
print '<a class="reposition commonlink" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&&token='.newToken().'&entity='.$entity.'&module=allmodules&confirm=yes">'.$langs->trans("None")."</a>";
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
} else {
|
||||||
|
print '<td></td>';
|
||||||
}
|
}
|
||||||
print '<td class="center" width="24"> </td>';
|
print '<td class="center" width="24"></td>';
|
||||||
print '<td>'.$langs->trans("Permissions").'</td>';
|
//print '<td>'.$langs->trans("Permissions").'</td>';
|
||||||
if ($user->admin) {
|
print '<td class="center"></td>';
|
||||||
print '<td class="right"></td>';
|
|
||||||
}
|
print '<td class="right nowrap">';
|
||||||
|
print '<a class="showallperms" title="'.dol_escape_htmltag($langs->trans("ShowAllPerms")).'" alt="'.dol_escape_htmltag($langs->trans("ShowAllPerms")).'" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a>';
|
||||||
|
print ' | ';
|
||||||
|
print '<a class="hideallperms" title="'.dol_escape_htmltag($langs->trans("HideAllPerms")).'" alt="'.dol_escape_htmltag($langs->trans("HideAllPerms")).'" href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a>';
|
||||||
|
print '</td>';
|
||||||
print '</tr>'."\n";
|
print '</tr>'."\n";
|
||||||
|
|
||||||
$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
|
$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
|
||||||
@ -275,9 +281,12 @@ if ($object->id > 0) {
|
|||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$num = $db->num_rows($result);
|
$num = $db->num_rows($result);
|
||||||
$i = 0;
|
$i = 0;$j = 0;
|
||||||
$oldmod = '';
|
$oldmod = '';
|
||||||
|
|
||||||
|
$cookietohidegroup = (empty($_COOKIE["DOLUSER_PERMS_HIDE_GRP"]) ? '' : preg_replace('/^,/', '', $_COOKIE["DOLUSER_PERMS_HIDE_GRP"]));
|
||||||
|
$cookietohidegrouparray = explode(',', $cookietohidegroup);
|
||||||
|
|
||||||
while ($i < $num) {
|
while ($i < $num) {
|
||||||
$obj = $db->fetch_object($result);
|
$obj = $db->fetch_object($result);
|
||||||
|
|
||||||
@ -289,48 +298,78 @@ if ($object->id > 0) {
|
|||||||
|
|
||||||
$objMod = $modules[$obj->module];
|
$objMod = $modules[$obj->module];
|
||||||
|
|
||||||
|
if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
|
||||||
|
$ishidden = GETPOST('forbreakperms_'.$obj->module, 'int');
|
||||||
|
} elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
|
||||||
|
$ishidden = 1;
|
||||||
|
} else {
|
||||||
|
$ishidden = 0;
|
||||||
|
}
|
||||||
|
$isexpanded = ! $ishidden;
|
||||||
|
|
||||||
// Break found, it's a new module to catch
|
// Break found, it's a new module to catch
|
||||||
if (isset($obj->module) && ($oldmod <> $obj->module)) {
|
if (isset($obj->module) && ($oldmod <> $obj->module)) {
|
||||||
$oldmod = $obj->module;
|
$oldmod = $obj->module;
|
||||||
|
|
||||||
|
$j++;
|
||||||
|
if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
|
||||||
|
$ishidden = GETPOST('forbreakperms_'.$obj->module, 'int');
|
||||||
|
} elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
|
||||||
|
$ishidden = 1;
|
||||||
|
} else {
|
||||||
|
$ishidden = 0;
|
||||||
|
}
|
||||||
|
$isexpanded = ! $ishidden;
|
||||||
// Break detected, we get objMod
|
// Break detected, we get objMod
|
||||||
$objMod = $modules[$obj->module];
|
$objMod = $modules[$obj->module];
|
||||||
$picto = ($objMod->picto ? $objMod->picto : 'generic');
|
$picto = ($objMod->picto ? $objMod->picto : 'generic');
|
||||||
|
|
||||||
// Show break line
|
// Show break line
|
||||||
print '<tr class="oddeven trforbreak">';
|
print '<tr class="oddeven trforbreakperms" data-hide-perms="'.$obj->module.'" data-j="'.$j.'">';
|
||||||
print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
|
// Picto and label of module
|
||||||
|
print '<td class="maxwidthonsmartphone tdoverflowonsmartphone tdforbreakperms" data-hide-perms="'.$obj->module.'">';
|
||||||
print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
|
print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
|
||||||
print '<a name="'.$objMod->getName().'"></a>';
|
print '<a name="'.$objMod->getName().'"></a>';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
// Permission and tick (2 columns)
|
||||||
if ($caneditperms) {
|
if ($caneditperms) {
|
||||||
print '<td class="center nowrap">';
|
print '<td class="center wraponsmartphone">';
|
||||||
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.$langs->trans("All").'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&entity='.$entity.'&module='.$obj->module.'&token='.newToken().'">'.$langs->trans("All")."</a>";
|
print '<span class="permtohide_'.$obj->module.'" '.(!$isexpanded ? ' style="display:none"' : '').'>';
|
||||||
print '/';
|
print '<a class="reposition alink addexpandedmodulesinparamlist" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&token='.newToken().'&entity='.$entity.'&module='.$obj->module.'&confirm=yes&updatedmodulename='.$obj->module.'">'.$langs->trans("All")."</a>";
|
||||||
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.$langs->trans("None").'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&entity='.$entity.'&module='.$obj->module.'&token='.newToken().'">'.$langs->trans("None")."</a>";
|
print ' / ';
|
||||||
|
print '<a class="reposition alink addexpandedmodulesinparamlist" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&token='.newToken().'&entity='.$entity.'&module='.$obj->module.'&confirm=yes&updatedmodulename='.$obj->module.'">'.$langs->trans("None")."</a>";
|
||||||
|
print '</span>';
|
||||||
|
print '</td>';
|
||||||
|
print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
} else {
|
} else {
|
||||||
print '<td> </td>';
|
print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'"></td>';
|
||||||
|
print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'"></td>';
|
||||||
}
|
}
|
||||||
print '<td> </td>';
|
// Description of permission (2 columns)
|
||||||
print '<td> </td>';
|
print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'"></td>';
|
||||||
|
print '<td class="maxwidthonsmartphone right tdforbreakperms" data-hide-perms="'.$obj->module.'">';
|
||||||
// Permission id
|
print '<div class="switchfolderperms folderperms_'.$obj->module.'"'.($isexpanded ? ' style="display:none;"' : '').'>';
|
||||||
if ($user->admin) {
|
print img_picto('', 'folder', 'class="marginright"');
|
||||||
print '<td class="right"></td>';
|
print '</div>';
|
||||||
}
|
print '<div class="switchfolderperms folderopenperms_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none;"' : '').'>';
|
||||||
|
print img_picto('', 'folder-open', 'class="marginright"');
|
||||||
|
print '</div>';
|
||||||
|
print '</td>'; //Add picto + / - when open en closed
|
||||||
print '</tr>'."\n";
|
print '</tr>'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
|
print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
|
||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven trtohide_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none"' : '').'>';
|
||||||
|
|
||||||
|
|
||||||
// Picto and label of module
|
// Picto and label of module
|
||||||
print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
|
print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
|
||||||
|
print '<input type="hidden" name="forbreakperms_'.$obj->module.'" id="idforbreakperms_'.$obj->module.'" css="cssforfieldishiden" data-j="'.$j.'" value="'.($isexpanded ? '0' : "1").'">';
|
||||||
//print img_object('', $picto, 'class="inline-block pictoobjectwidth"').' '.$objMod->getName();
|
//print img_object('', $picto, 'class="inline-block pictoobjectwidth"').' '.$objMod->getName();
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
|
// Permission and tick (2 columns)
|
||||||
if (!empty($permsgroupbyentity[$entity]) && is_array($permsgroupbyentity[$entity])) {
|
if (!empty($permsgroupbyentity[$entity]) && is_array($permsgroupbyentity[$entity])) {
|
||||||
if (in_array($obj->id, $permsgroupbyentity[$entity])) {
|
if (in_array($obj->id, $permsgroupbyentity[$entity])) {
|
||||||
// Own permission by group
|
// Own permission by group
|
||||||
@ -360,11 +399,13 @@ if ($object->id > 0) {
|
|||||||
//print img_edit_add($langs->trans("Add"));
|
//print img_edit_add($langs->trans("Add"));
|
||||||
print img_picto($langs->trans("Add"), 'switch_off');
|
print img_picto($langs->trans("Add"), 'switch_off');
|
||||||
print '</a></td>';
|
print '</a></td>';
|
||||||
|
} else {
|
||||||
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
print '<td> </td>';
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Description of permission
|
// Description of permission (2 columns)
|
||||||
$permlabel = (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ($langs->trans("PermissionAdvanced".$obj->id) != ("PermissionAdvanced".$obj->id)) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != ("Permission".$obj->id)) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label)));
|
$permlabel = (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ($langs->trans("PermissionAdvanced".$obj->id) != ("PermissionAdvanced".$obj->id)) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != ("Permission".$obj->id)) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label)));
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print $permlabel;
|
print $permlabel;
|
||||||
@ -383,6 +424,8 @@ if ($object->id > 0) {
|
|||||||
print $form->textwithpicto('', $htmltext);
|
print $form->textwithpicto('', $htmltext);
|
||||||
//print '<span class="opacitymedium">'.$obj->id.'</span>';
|
//print '<span class="opacitymedium">'.$obj->id.'</span>';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
} else {
|
||||||
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print '</tr>'."\n";
|
print '</tr>'."\n";
|
||||||
@ -393,6 +436,82 @@ if ($object->id > 0) {
|
|||||||
print '</table>';
|
print '</table>';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
|
print '<script>';
|
||||||
|
print '$(".tdforbreakperms:not(.alink)").on("click", function(){
|
||||||
|
console.log("Click on tdforbreakperms");
|
||||||
|
moduletohide = $(this).data("hide-perms");
|
||||||
|
j = $(this).data("j");
|
||||||
|
if ($("#idforbreakperms_"+moduletohide).val() == 1) {
|
||||||
|
console.log("idforbreakperms_"+moduletohide+" has value hidden=1");
|
||||||
|
$(".trtohide_"+moduletohide).show();
|
||||||
|
$(".permtoshow_"+moduletohide).hide();
|
||||||
|
$(".permtohide_"+moduletohide).show();
|
||||||
|
$(".folderperms_"+moduletohide).hide();
|
||||||
|
$(".folderopenperms_"+moduletohide).show();
|
||||||
|
$("#idforbreakperms_"+moduletohide).val("0");
|
||||||
|
} else {
|
||||||
|
console.log("idforbreakperms_"+moduletohide+" has value hidden=0");
|
||||||
|
$(".trtohide_"+moduletohide).hide();
|
||||||
|
$(".folderopenperms_"+moduletohide).hide();
|
||||||
|
$(".folderperms_"+moduletohide).show();
|
||||||
|
$(".permtoshow_"+moduletohide).show();
|
||||||
|
$(".permtohide_"+moduletohide).hide();
|
||||||
|
$("#idforbreakperms_"+moduletohide).val("1");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now rebuild the value for cookie
|
||||||
|
var hideuserperm="";
|
||||||
|
$(".trforbreakperms").each(function(index) {
|
||||||
|
//console.log( index + ": " + $( this ).data("j") + " " + $( this ).data("hide-perms") + " " + $("input[data-j="+(index+1)+"]").val());
|
||||||
|
if ($("input[data-j="+(index+1)+"]").val() == 1) {
|
||||||
|
hideuserperm=hideuserperm+","+(index+1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// set cookie by js
|
||||||
|
date = new Date(); date.setTime(date.getTime()+(30*86400000));
|
||||||
|
if (hideuserperm) {
|
||||||
|
console.log("set cookie DOLUSER_PERMS_HIDE_GRP="+hideuserperm);
|
||||||
|
document.cookie = "DOLUSER_PERMS_HIDE_GRP=" + hideuserperm + "; expires=" + date.toGMTString() + "; path=/ ";
|
||||||
|
} else {
|
||||||
|
console.log("delete cookie DOLUSER_PERMS_HIDE_GRP");
|
||||||
|
document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
|
||||||
|
}
|
||||||
|
});';
|
||||||
|
|
||||||
|
// Button expand / collapse all
|
||||||
|
print '$(".showallperms").on("click", function(){
|
||||||
|
console.log("Click on showallperms");
|
||||||
|
|
||||||
|
console.log("delete cookie DOLUSER_PERMS_HIDE_GRP from showallperms click");
|
||||||
|
document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
|
||||||
|
$(".tdforbreakperms").each( function(){
|
||||||
|
moduletohide = $(this).data("hide-perms");
|
||||||
|
//console.log(moduletohide);
|
||||||
|
if ($("#idforbreakperms_"+moduletohide).val() != 0) {
|
||||||
|
$(this).trigger("click"); // emulate the click, so the cooki will be resaved
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".hideallperms").on("click", function(){
|
||||||
|
console.log("Click on hideallperms");
|
||||||
|
|
||||||
|
$(".tdforbreakperms").each( function(){
|
||||||
|
moduletohide = $(this).data("hide-perms");
|
||||||
|
//console.log(moduletohide);
|
||||||
|
if ($("#idforbreakperms_"+moduletohide).val() != 1) {
|
||||||
|
$(this).trigger("click"); // emulate the click, so the cooki will be resaved
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});';
|
||||||
|
print "\n";
|
||||||
|
print '</script>';
|
||||||
|
|
||||||
|
print '<style>';
|
||||||
|
print '.switchfolderperms{
|
||||||
|
cursor: pointer;
|
||||||
|
}';
|
||||||
|
print '</style>';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user