Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
216 additions
and
48 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
application/extensions/UserPermissionsWidget/UserPermissionsWidget.php
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,18 @@ | ||
<?php | ||
|
||
class UserPermissionsWidget extends CWidget | ||
{ | ||
/** @var array[] */ | ||
public $aPermissions; | ||
|
||
/** | ||
* @todo Classes instead of switch. | ||
*/ | ||
public function run() | ||
{ | ||
if(empty($this->aPermissions)) { | ||
return; | ||
} | ||
$this->render('table', ['aPermissions' => $this->aPermissions]); | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
application/extensions/UserPermissionsWidget/assets/script.js
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,146 @@ | ||
var LS = LS || { | ||
onDocumentReady: {} | ||
}; | ||
|
||
$(document).on('ready pjax:scriptcomplete', function(){ | ||
$(':checkbox:not(:checked)[data-indeterminate=1]').prop('indeterminate', true) | ||
|
||
$(".surveysecurity").tablesorter({ | ||
widgets: ['zebra'], | ||
sortList: [[2,0]], | ||
headers: { 19: { sorter: false} } | ||
}); | ||
|
||
|
||
$(".table-permissions-set").tablesorter({ | ||
widgets: ['zebra'], | ||
headers: { 0: { sorter: false}, | ||
2: { sorter: false}, | ||
3: { sorter: false}, | ||
4: { sorter: false}, | ||
5: { sorter: false}, | ||
6: { sorter: false}, | ||
7: { sorter: false}, | ||
8: { sorter: false} | ||
} | ||
}); | ||
|
||
$(".markrow").click( | ||
function(){ | ||
$(this).removeClass('mixed'); | ||
$(this).closest('tr').find('input').prop('checked',$(this).prop('checked')).prop('indeterminate',false); | ||
updateAllCheckboxes(); | ||
} | ||
) | ||
|
||
// mark all checkboxes | ||
$(".markall").click( | ||
function(){ | ||
$(this).removeClass('mixed'); | ||
var checked = $(this).prop('checked'); | ||
$('.table-permissions-set tbody tr').each(function(){ | ||
var rowSelector = $(this).find('input'); | ||
$(rowSelector).prop('checked',checked).prop('indeterminate',false); | ||
}); | ||
} | ||
) | ||
|
||
$('.extended input').click( | ||
function(){ | ||
if ($(this).closest('tr').find('.extended input:checked').size()==$(this).closest('tr').find('.extended input').size()) | ||
{ | ||
$(this).closest('tr').find('.markrow').prop('checked',true).removeClass('mixed'); | ||
} | ||
else if ($(this).closest('tr').find('.extended input:checked').size()==0) | ||
{ | ||
$(this).closest('tr').find('.markrow').prop('checked',false).removeClass('mixed'); | ||
} | ||
else | ||
{ | ||
$(this).closest('tr').find('.markrow').prop('checked',true).addClass('mixed'); | ||
} | ||
updateAllCheckboxes(); | ||
} | ||
) | ||
|
||
if (Cookies.get('surveysecurityas')!='true') | ||
{ | ||
$('.table-permissions-set .extended').hide(); | ||
} | ||
/* Show on the all comuln the state of included checkbox */ | ||
$('.table-permissions-set tbody tr').each(function(){ | ||
if ($(this).find('.extended input:checkbox:checked').length == $(this).find('.extended input:checkbox').length) { | ||
/* All is checked */ | ||
$(this).find('.markrow').prop('checked',true).removeClass('mixed'); | ||
} else if (!$(this).find('.extended input:checkbox:checked').length) { | ||
/* None is checked */ | ||
if ($(this).find('.extended input:checkbox[data-indeterminate="1"]').length == $(this).find('.extended input:checkbox').length) { | ||
$(this).find('.markrow').prop('indeterminate',true).removeClass('mixed'); | ||
} else if(!$(this).find('.extended input:checkbox[data-indeterminate="1"]').length) { | ||
$(this).find('.markrow').prop('indeterminate',false).removeClass('mixed'); | ||
} else { | ||
$(this).find('.markrow').prop('indeterminate',true).addClass('mixed'); | ||
} | ||
|
||
} else { | ||
/* Partially checked */ | ||
$(this).find('.markrow').prop('checked',true).addClass('mixed'); | ||
} | ||
}) | ||
|
||
$('#btnToggleAdvanced').click(function(){ | ||
extendoptionsvisible=$('.table-permissions-set .extended').is(':visible'); | ||
if (extendoptionsvisible==false) | ||
{ | ||
$('.table-permissions-set .extended').fadeIn('slow'); | ||
} | ||
else | ||
{ | ||
$('.table-permissions-set .extended').fadeOut(); | ||
} | ||
updateExtendedButton(!extendoptionsvisible); | ||
Cookies.set('surveysecurityas',!extendoptionsvisible); | ||
}); | ||
updateExtendedButton(true); | ||
|
||
updateAllCheckboxes(); | ||
}); | ||
|
||
function updateExtendedButton(bVisible) | ||
{ | ||
if (bVisible==true) | ||
{ | ||
$('#btnToggleAdvanced').val('<<'); | ||
} | ||
else | ||
{ | ||
$('#btnToggleAdvanced').val('>>'); | ||
} | ||
|
||
} | ||
|
||
function updateAllCheckboxes(){ | ||
var iFullCheckedRows = 0; | ||
var iHalfCheckedRows = 0; | ||
var iNoCheckedRows = 0; | ||
$('.table-permissions-set tbody tr').each(function(){ | ||
var rowSelector = $(this).find('.markrow'); | ||
if (rowSelector.prop('checked') === true && !rowSelector.hasClass('mixed')){ | ||
iFullCheckedRows += 1; | ||
} else if (rowSelector.prop('checked') === true && rowSelector.hasClass('mixed')){ | ||
iHalfCheckedRows += 1; | ||
} else if (rowSelector.prop('checked') === false){ | ||
iNoCheckedRows += 1; | ||
} | ||
}); | ||
|
||
var markAllSelector = $('.table-permissions-set thead tr').find('.markall'); | ||
|
||
if (iFullCheckedRows > 0 && iHalfCheckedRows == 0 && iNoCheckedRows == 0){ | ||
markAllSelector.prop('checked',true).removeClass('mixed'); | ||
} else if (iFullCheckedRows > 0 || iHalfCheckedRows > 0){ | ||
markAllSelector.prop('checked',true).addClass('mixed'); | ||
} else { | ||
markAllSelector.prop('checked',false).removeClass('mixed'); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
application/extensions/UserPermissionsWidget/views/table.php
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,48 @@ | ||
<table class='table table-striped table-permissions-set'> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th> | ||
<?php eT("Permission");?> | ||
</th> | ||
<th> | ||
<input type="checkbox" class="markall" name='markall' /> | ||
<input type='button' id='btnToggleAdvanced' value='<<' class='btn btn-default' /> | ||
</th> | ||
<th class='extended'><?php eT("Create");?></th> | ||
<th class='extended'><?php eT("View/read");?></th> | ||
<th class='extended'><?php eT("Update");?></th> | ||
<th class='extended'><?php eT("Delete");?></th> | ||
<th class='extended'><?php eT("Import");?></th> | ||
<th class='extended'><?php eT("Export");?></th> | ||
</tr> | ||
</thead> | ||
<tbody><?php foreach ($aPermissions as $sPermission => $aCurrentPermissions): ?> | ||
<tr> | ||
<td><?= $aCurrentPermissions['description'] ?></td> | ||
<td><?= $aCurrentPermissions['title'] ?></td> | ||
<td><?php echo CHtml::checkBox("all_$sPermission",false, array('class' => 'markrow')) ?></td> | ||
<?php foreach ($aCurrentPermissions['current'] as $sKey =>$aValues): ?> | ||
<td class='extended'><?php if($aCurrentPermissions[$sKey]) { | ||
echo CHtml::checkBox( | ||
"set[{$aCurrentPermissions['entity']}][{$sPermission}][$sKey]", | ||
$aValues['checked'], | ||
array( | ||
'value' => 1, | ||
'data-indeterminate' => $aValues['indeterminate'], | ||
'id' => CHtml::getIdByName("set[{$aCurrentPermissions['entity']}][{$sPermission}][$sKey]"), | ||
'uncheckValue' => 0, | ||
/* See issue #14551 : https://bugs.limesurvey.org/view.php?id=14551 */ | ||
'disabled' => $aValues['disabled'], | ||
) | ||
); | ||
}?> | ||
</td> | ||
<?php endforeach;?> | ||
</tr> | ||
<?php endforeach;?></tbody> | ||
</table> | ||
<?php | ||
App()->getClientScript()->registerPackage('jquery-tablesorter'); | ||
App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(Yii::getPathOfAlias('ext.UserPermissionsWidget.assets'). '/script.js')); | ||
?> |
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