Just checked in a bunch of new stuff:
Custom DOM Actions
A lot of people have been asking about how to create a custom action on the list view of a DOM in addition to edit, delete, and recently, duplicate. In the following example, I'll show you how to add a custom action to a Listing object that sets its status to "Approved" or "Unapproved" by clicking an an icon in the DOM, without having to edit the record in the popup.
Listing.php
public function customDOMActions()
{
$title = $this->Approved ? "Disapprove" : "Approve";
$image = $this->Approved ? "delete.png" : "accept.png";
return new DataObjectManagerAction(
$title,
"/ListingPage_Controller/approve/$this->ID",
"refresh",
"/mysite/images/$image"
);
}
public function toggleApproved()
{
if($this->getField('Approved') == 1)
$this->setField('Approved',0);
else
$this->setField('Approved',1);
$this->write();
}
We create a function with the name "customDOMActions" in the DataObject. The name of this function is compulsory. If you have multiple custom actions, you can return them in a DataObjectSet. The arguments for a DataObjectManagerAction are as follows:
$title : The title of the action. In this case, "approve" or "disapprove"
$link : Link to the action. We'll handle the request on the ListingPage controller
$behaviour : Options for the behavior of this action:
- "refresh" : Runs the action and refreshes the DOM on success.
- "popup" : Load the link into a popup window (like edit view)
- "delete" : Remove the record from the DOM after executing the link
$icon : URL to the icon for the action
In the function toggleApprove we run a simple update that toggles the object status.
Now we'll handle the custom action request in a custom controller.
Listing_Controller
class Listing_Controller extends Controller {
static $url_handlers = array(
'approve/$ID' => 'handleApprove'
);
public function handleApprove($request)
{
if($listing = DataObject::get_by_id("Listing",$request->param('ID'))) {
$listing->toggleApproved();
}
}
}
That's it! You can now click the approve/disapprove icon in your list view to update the record without instantiating a popup. There are many other applications for this feature. This is just one of many possibilities.
Many thanks to forum member Nick Jacobs for sponsoring this feature.
New Popup Form Styling
Updated CSS of the DOM popup to place the pagination and save button in a fixed position at the bottom of the frame, so they are always visible regardless of your scroll. Also add a transparent PNG to help ease the bottom of the viewport and bring some definition to the actions bar against the fieldset.
Bug Fix: DOM Items Lose Sort in Popup Pagination
Fixed this issue. You can now act on the DOM sort or pagination and the records retain their order when paginated in the popup with the prev/next buttons.