Skip to content

Commit

Permalink
ENHANCEMENT: Added the ability to confirm actions before executing, a…
Browse files Browse the repository at this point in the history
…nd added confirmation to the Remove action.
  • Loading branch information
ajshort committed Apr 5, 2011
1 parent 19fc616 commit 051c92a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion code/HasManyPickerField.php
Expand Up @@ -100,7 +100,7 @@ public function getItemsQuery() {
public function ItemActions($item) {
$actions = parent::ItemActions($item);
$actions->push(new ItemSetField_Action(
$this, 'Remove', 'Remove'
$this, 'Remove', 'Remove', true
));
return $actions;
}
Expand Down
13 changes: 12 additions & 1 deletion code/ItemSetField.php
Expand Up @@ -248,12 +248,19 @@ public function Attributes() {
}

class ItemSetField_Action extends ViewableData {
function __construct($itemSet, $action, $name) {

protected $itemSet;
protected $action;
protected $name;
protected $confirmed;

function __construct($itemSet, $action, $name, $confirmed = false) {
parent::__construct();

$this->itemSet = $itemSet;
$this->action = $action;
$this->name = $name;
$this->confirmed = $confirmed;
}

function setID($id) {
Expand All @@ -268,6 +275,10 @@ function Link() {
return Controller::join_links($this->itemSet->Link(), 'item', $this->ID, $this->action);
}

public function Confirmed() {
return $this->confirmed;
}

}

class ItemSetField_Item extends RequestHandler {
Expand Down
6 changes: 6 additions & 0 deletions javascript/ItemSetField.js
Expand Up @@ -82,6 +82,12 @@ $('a.itemsetfield-action').live('click', function() {
return false;
}

if (link.hasClass("ss-itemsetfield-confirmed")) {
if (!confirm(ss.i18n._t("ItemSetField.AREYOUSURE", "Are you sure?"))) {
return false;
}
}

link.text(ss.i18n._t('ItemSetField.LOADING', 'Loading...'));
link.addClass('ui-state-disabled');

Expand Down
4 changes: 2 additions & 2 deletions templates/ItemSetField_Item.ss
Expand Up @@ -3,12 +3,12 @@

<div class="itemsetfield-item-actions">
<% control Actions %>
<a class="itemsetfield-action" href="$Link">$Name</a>
<a class="itemsetfield-action <% if Confirmed %>ss-itemsetfield-confirmed<% end_if %>" href="$Link">$Name</a>
<% end_control %>
</div>

<% if DefaultAction %>
<a class="itemsetfield-action" href="$DefaultAction.Link">$Label</a>
<a class="itemsetfield-action <% if Confirmed %>ss-itemsetfield-confirmed<% end_if %>" href="$DefaultAction.Link">$Label</a>
<% else %>
$Label
<% end_if %>
Expand Down

0 comments on commit 051c92a

Please sign in to comment.