Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Hide delete button on non-deleteable statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbedard committed Apr 30, 2017
1 parent b3b1f72 commit 45bb023
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
16 changes: 9 additions & 7 deletions controllers/statuses/update.htm
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
class="btn btn-default">
Save and Close
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="Deleting Status..."
data-request-confirm="Delete this status?">
</button>
<?php if ($this->vars['formModel']->isDeleteable()): ?>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="Deleting Status..."
data-request-confirm="Delete this status?">
</button>
<?php endif ?>
<span class="btn-text">
or <a href="<?= Backend::url('bedard/shop/statuses') ?>">Cancel</a>
</span>
Expand Down
10 changes: 10 additions & 0 deletions models/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public function beforeSave()
$this->validateFlags();
}

/**
* Determine if the status can be deleted.
*
* @return boolean
*/
public function isDeleteable()
{
return ! $this->is_default && ! $this->is_abandoned;
}

/**
* Prevent the default status from being removed.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/models/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ public function test_the_only_default_status_cannot_be_turned_off()
$this->setExpectedException(ModelException::class);
$foo->save();
}

public function test_if_statuses_can_be_deleted()
{
$default = Factory::create(new Status, ['is_default' => 1]);
$abandoned = Factory::create(new Status, ['is_abandoned' => 1]);
$regular = Factory::create(new Status);

$this->assertFalse($default->isDeleteable());
$this->assertFalse($abandoned->isDeleteable());
$this->assertTrue($regular->isDeleteable());
}
}

0 comments on commit 45bb023

Please sign in to comment.