Permalink
Browse files

ENHANCEMENT: Added the ability to confirm actions before executing, a…

…nd added confirmation to the Remove action.
  • Loading branch information...
ajshort committed Apr 5, 2011
1 parent 19fc616 commit 051c92a9761cd8a486e0e7b24f3b204553d90039
Showing with 21 additions and 4 deletions.
  1. +1 −1 code/HasManyPickerField.php
  2. +12 −1 code/ItemSetField.php
  3. +6 −0 javascript/ItemSetField.js
  4. +2 −2 templates/ItemSetField_Item.ss
@@ -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;
}
View
@@ -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) {
@@ -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 {
@@ -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');
@@ -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 %>

0 comments on commit 051c92a

Please sign in to comment.