fix: Added functionality to remove taxonomies, fixes #1365

pull/1366/head
Iglocska 2016-07-12 16:56:20 +02:00
parent efee48557c
commit d6e1283c43
5 changed files with 59 additions and 4 deletions

View File

@ -204,4 +204,24 @@ class TaxonomiesController extends AppController {
$this->set('id', $id); $this->set('id', $id);
$this->render('ajax/taxonomy_mass_confirmation'); $this->render('ajax/taxonomy_mass_confirmation');
} }
public function delete($id) {
if ($this->request->is('post')) {
$result = $this->Taxonomy->delete($id, true);
if ($result) {
$this->Session->setFlash('Taxonomy successfuly deleted.');
$this->redirect(array('controller' => 'taxonomies', 'action' => 'index'));
} else {
$this->Session->setFlash('Taxonomy could not be deleted.');
$this->redirect(array('controller' => 'taxonomies', 'action' => 'index'));
}
} else {
if ($this->request->is('ajax')) {
$this->set('id', $id);
$this->render('ajax/taxonomy_delete_confirmation');
} else {
throw new MethodNotAllowedException('This function can only be reached via AJAX.');
}
}
}
} }

View File

@ -283,6 +283,7 @@
<li id='liindex'><a href="<?php echo $baseurl;?>/taxonomies/index">List Taxonomies</a></li> <li id='liindex'><a href="<?php echo $baseurl;?>/taxonomies/index">List Taxonomies</a></li>
<?php if ($menuItem === 'view'): ?> <?php if ($menuItem === 'view'): ?>
<li id='liview'><a href="">View Taxonomy</a></li> <li id='liview'><a href="">View Taxonomy</a></li>
<li id='lidelete'><a class="useCursorPointer" onClick="deleteObject('taxonomies', 'delete', '<?php echo h($id); ?>', '<?php echo h($id); ?>');">Delete Taxonomy</a></li>
<?php <?php
endif; endif;
if ($isSiteAdmin): if ($isSiteAdmin):

View File

@ -0,0 +1,33 @@
<div class="confirmation">
<?php
echo $this->Form->create('Taxonomy', array(
'style' => 'margin:0px;',
'id' => 'PromptForm',
'url' => array('controller' => 'taxonomies', 'action' => 'delete', $id)
));
?>
<legend>Taxonomy Deletion</legend>
<div style="padding-left:5px;padding-right:5px;padding-bottom:5px;">
<p>Are you sure you want to delete Taxonomy #<?php echo h($id); ?>?<br /> Associated tags will not be removed. You can reload the taxonomy at any time by updating your taxonomies.</p>
<table>
<tr>
<td style="vertical-align:top">
<?php
echo $this->Form->button('Yes', array(
'type' => 'submit',
'class' => 'btn btn-primary'
));
?>
</td>
<td style="width:540px;">
</td>
<td style="vertical-align:top;">
<span class="btn btn-inverse" id="PromptNoButton" onClick="cancelPrompt();">No</span>
</td>
</tr>
</table>
</div>
<?php
echo $this->Form->end();
?>
</div>

View File

@ -45,6 +45,7 @@ foreach ($taxonomies as $item): ?>
} }
?> ?>
<a href='<?php echo $baseurl."/taxonomies/view/". h($item['Taxonomy']['id']);?>' class = "icon-list-alt" title = "View"></a> <a href='<?php echo $baseurl."/taxonomies/view/". h($item['Taxonomy']['id']);?>' class = "icon-list-alt" title = "View"></a>
<span class="icon-trash useCursorPointer" onClick="deleteObject('taxonomies', 'delete', '<?php echo h($item['Taxonomy']['id']); ?>', '<?php echo h($item['Taxonomy']['id']); ?>');"></span>
</td> </td>
</tr><?php </tr><?php
endforeach; ?> endforeach; ?>

View File

@ -4,8 +4,8 @@ String.prototype.ucfirst = function() {
function deleteObject(type, action, id, event) { function deleteObject(type, action, id, event) {
var destination = 'attributes'; var destination = 'attributes';
if (type == 'shadow_attributes') destination = 'shadow_attributes'; var alternateDestinations = ['shadow_attributes', 'template_elements', 'taxonomies'];
else if (type == 'template_elements') destination = 'template_elements'; if (alternateDestinations.indexOf(type) > -1) destination = type;
url = "/" + destination + "/" + action + "/" + id; url = "/" + destination + "/" + action + "/" + id;
$.get(url, function(data) { $.get(url, function(data) {
$("#confirmation_box").fadeIn(); $("#confirmation_box").fadeIn();