Merge pull request #3658 from ancailliau/issue-3639

Fixes issue #3639
pull/4263/head
Steve Clement 2019-03-03 07:35:13 +05:30 committed by GitHub
commit f03c519038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 246 additions and 0 deletions

View File

@ -429,8 +429,12 @@ class ACLComponent extends Component
'enable' => array(),
'index' => array('*'),
'taxonomyMassConfirmation' => array('perm_tagger'),
'taxonomyMassHide' => array('perm_tagger'),
'taxonomyMassUnhide' => array('perm_tagger'),
'update' => array(),
'view' => array('*'),
'unhideTag' => array('perm_tagger'),
'hideTag' => array('perm_tagger'),
),
'templateElements' => array(
'add' => array('perm_template'),

View File

@ -254,6 +254,66 @@ class TaxonomiesController extends AppController
$this->redirect($this->referer());
}
public function hideTag($taxonomy_id = false)
{
if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) {
throw new NotFoundException('You don\'t have permission to do that.');
}
if ($taxonomy_id) {
$result = $this->Taxonomy->hideTags($taxonomy_id);
} else {
if (isset($this->request->data['Taxonomy'])) {
$this->request->data['Tag'] = $this->request->data['Taxonomy'];
unset($this->request->data['Taxonomy']);
}
if (isset($this->request->data['Tag']['request'])) {
$this->request->data['Tag'] = $this->request->data['Tag']['request'];
}
if (!isset($this->request->data['Tag']['nameList'])) {
$this->request->data['Tag']['nameList'] = array($this->request->data['Tag']['name']);
} else {
$this->request->data['Tag']['nameList'] = json_decode($this->request->data['Tag']['nameList'], true);
}
$result = $this->Taxonomy->hideTags($this->request->data['Tag']['taxonomy_id'], $this->request->data['Tag']['nameList']);
}
if ($result) {
$this->Flash->success('The tag(s) has been saved.');
} else {
$this->Flash->error('The tag(s) could not be saved. Please, try again.');
}
$this->redirect($this->referer());
}
public function unhideTag($taxonomy_id = false)
{
if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) {
throw new NotFoundException('You don\'t have permission to do that.');
}
if ($taxonomy_id) {
$result = $this->Taxonomy->unhideTags($taxonomy_id);
} else {
if (isset($this->request->data['Taxonomy'])) {
$this->request->data['Tag'] = $this->request->data['Taxonomy'];
unset($this->request->data['Taxonomy']);
}
if (isset($this->request->data['Tag']['request'])) {
$this->request->data['Tag'] = $this->request->data['Tag']['request'];
}
if (!isset($this->request->data['Tag']['nameList'])) {
$this->request->data['Tag']['nameList'] = array($this->request->data['Tag']['name']);
} else {
$this->request->data['Tag']['nameList'] = json_decode($this->request->data['Tag']['nameList'], true);
}
$result = $this->Taxonomy->unhideTags($this->request->data['Tag']['taxonomy_id'], $this->request->data['Tag']['nameList']);
}
if ($result) {
$this->Flash->success('The tag(s) has been saved.');
} else {
$this->Flash->error('The tag(s) could not be saved. Please, try again.');
}
$this->redirect($this->referer());
}
public function disableTag($taxonomy_id = false)
{
if ((!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) || !$this->request->is('post')) {
@ -293,6 +353,24 @@ class TaxonomiesController extends AppController
$this->render('ajax/taxonomy_mass_confirmation');
}
public function taxonomyMassHide($id)
{
if (!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) {
throw new NotFoundException('You don\'t have permission to do that.');
}
$this->set('id', $id);
$this->render('ajax/taxonomy_mass_hide');
}
public function taxonomyMassUnhide($id)
{
if (!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) {
throw new NotFoundException('You don\'t have permission to do that.');
}
$this->set('id', $id);
$this->render('ajax/taxonomy_mass_unhide');
}
public function delete($id)
{
if ($this->request->is('post')) {

View File

@ -362,6 +362,72 @@ class Taxonomy extends AppModel
return true;
}
public function hideTags($id, $tagList = false)
{
if ($tagList && !is_array($tagList)) {
$tagList = array($tagList);
}
$this->Tag = ClassRegistry::init('Tag');
App::uses('ColourPaletteTool', 'Tools');
$paletteTool = new ColourPaletteTool();
$taxonomy = $this->__getTaxonomy($id, array('full' => true));
$tags = $this->Tag->getTagsForNamespace($taxonomy['Taxonomy']['namespace']);
$colours = $paletteTool->generatePaletteFromString($taxonomy['Taxonomy']['namespace'], count($taxonomy['entries']));
foreach ($taxonomy['entries'] as $k => $entry) {
$colour = $colours[$k];
if (isset($entry['colour']) && !empty($entry['colour'])) {
$colour = $entry['colour'];
}
if ($tagList) {
foreach ($tagList as $tagName) {
if ($tagName === $entry['tag']) {
if (isset($tags[strtoupper($entry['tag'])])) {
$this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $tagName, $colour, 1);
}
}
}
} else {
if (isset($tags[strtoupper($entry['tag'])])) {
$this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $entry['tag'], $colour, 1);
}
}
}
return true;
}
public function unhideTags($id, $tagList = false)
{
if ($tagList && !is_array($tagList)) {
$tagList = array($tagList);
}
$this->Tag = ClassRegistry::init('Tag');
App::uses('ColourPaletteTool', 'Tools');
$paletteTool = new ColourPaletteTool();
$taxonomy = $this->__getTaxonomy($id, array('full' => true));
$tags = $this->Tag->getTagsForNamespace($taxonomy['Taxonomy']['namespace']);
$colours = $paletteTool->generatePaletteFromString($taxonomy['Taxonomy']['namespace'], count($taxonomy['entries']));
foreach ($taxonomy['entries'] as $k => $entry) {
$colour = $colours[$k];
if (isset($entry['colour']) && !empty($entry['colour'])) {
$colour = $entry['colour'];
}
if ($tagList) {
foreach ($tagList as $tagName) {
if ($tagName === $entry['tag']) {
if (isset($tags[strtoupper($entry['tag'])])) {
$this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $tagName, $colour, 0);
}
}
}
} else {
if (isset($tags[strtoupper($entry['tag'])])) {
$this->Tag->quickEdit($tags[strtoupper($entry['tag'])], $entry['tag'], $colour, 0);
}
}
}
return true;
}
public function listTaxonomies($options = array('full' => false, 'enabled' => false))
{
$recursive = -1;

View File

@ -0,0 +1,37 @@
<div class="confirmation">
<?php
echo $this->Form->create('Taxonomy', array('style' => 'margin:0px;', 'id' => 'PromptForm', 'url' => '/taxonomies/hideTag'));
?>
<div class="hidden">
<?php
echo $this->Form->input('nameList', array('value' => '{}'));
?>
</div>
<?php
echo $this->Form->input('taxonomy_id', array('type' => 'hidden', 'value' => $id));
?>
<legend><?php echo __('Hide Tags');?></legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<p><?php echo __('Are you sure you want to hide all selected tags?');?></p>
<table>
<tr>
<td style="vertical-align:top">
<span id="PromptYesButton" role="button" tabindex="0" aria-label="<?php echo __('Hide all selected tags');?>" title="<?php echo __('Hide all selected tags');?>" class="btn btn-primary" onClick="submitMassTaxonomyTag();"><?php echo __('Yes');?></span>
</td>
<td style="width:540px;">
</td>
<td style="vertical-align:top;">
<span role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" title="<?php echo __('Cancel');?>" class="btn btn-inverse" id="PromptNoButton" onClick="cancelPrompt();"><?php echo __('No');?></span>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
$(document).ready(function(){
getSelectedTaxonomyNames();
});
</script>
<?php
echo $this->Form->end();
?>
</div>

View File

@ -0,0 +1,37 @@
<div class="confirmation">
<?php
echo $this->Form->create('Taxonomy', array('style' => 'margin:0px;', 'id' => 'PromptForm', 'url' => '/taxonomies/unhideTag'));
?>
<div class="hidden">
<?php
echo $this->Form->input('nameList', array('value' => '{}'));
?>
</div>
<?php
echo $this->Form->input('taxonomy_id', array('type' => 'hidden', 'value' => $id));
?>
<legend><?php echo __('Unhide Tags');?></legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<p><?php echo __('Are you sure you want to unhide all selected tags?');?></p>
<table>
<tr>
<td style="vertical-align:top">
<span id="PromptYesButton" role="button" tabindex="0" aria-label="<?php echo __('Unhide all selected tags');?>" title="<?php echo __('Unhide all selected tags');?>" class="btn btn-primary" onClick="submitMassTaxonomyTag();"><?php echo __('Yes');?></span>
</td>
<td style="width:540px;">
</td>
<td style="vertical-align:top;">
<span role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" title="<?php echo __('Cancel');?>" class="btn btn-inverse" id="PromptNoButton" onClick="cancelPrompt();"><?php echo __('No');?></span>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
$(document).ready(function(){
getSelectedTaxonomyNames();
});
</script>
<?php
echo $this->Form->end();
?>
</div>

View File

@ -64,6 +64,16 @@
<div style="float:right !important;overflow:hidden;border:0px;padding:0px;padding-right:200px;">
<input type="text" id="quickFilterField" class="tabMenuFilterField taxFilter" value="<?php echo h($filter);?>" /><span id="quickFilterButton" class="useCursorPointer taxFilterButton" onClick='quickFilterTaxonomy("<?php echo h($taxonomy['id']);?>");'><?php echo __('Filter');?></span>
</div>
<span class="tabMenuFixed tabMenuFixedLeft tabMenuSides useCursorPointer noPrint mass-select" style="margin-left:50px;">
<span id="multi-edit-button" title="<?php echo __('Hide selected tags');?>" role="button" tabindex="1" aria-label="<?php echo __('Hide selected tags');?>" class="useCursorPointer" onClick="hideSelectedTags(<?php echo $taxonomy['id']; ?>);">
<?php echo __('Hide selected tags');?>
</span>
</span>
<span class="tabMenuFixed tabMenuFixedLeft tabMenuSides useCursorPointer noPrint mass-select">
<span id="multi-edit-button" title="<?php echo __('Unhide selected tags');?>" role="button" tabindex="2" aria-label="<?php echo __('Unhide selected tags');?>" class="useCursorPointer" onClick="unhideSelectedTags(<?php echo $taxonomy['id']; ?>);">
<?php echo __('Unhide selected tags');?>
</span>
</span>
</div>
<table class="table table-striped table-hover table-condensed">
<tr>

View File

@ -877,6 +877,20 @@ function addSelectedTaxonomies(taxonomy) {
});
}
function hideSelectedTags(taxonomy) {
$.get("/taxonomies/taxonomyMassHide/"+taxonomy, function(data) {
$("#confirmation_box").html(data);
openPopup("#confirmation_box");
});
}
function unhideSelectedTags(taxonomy) {
$.get("/taxonomies/taxonomyMassUnhide/"+taxonomy, function(data) {
$("#confirmation_box").html(data);
openPopup("#confirmation_box");
});
}
function submitMassTaxonomyTag() {
$('#PromptForm').submit();
}