Git Product home page Git Product logo

silverstripe-gridfield-betterbuttons's Introduction

Much of this module is getting merged into core

silverstripe/silverstripe-admin#436

But I want to use it now!

If you're looking to use it in SS4 ahead of the merge, you can use this branch.

Build Status

Screenshot

Modifies the detail form of GridFields to use more user-friendly actions, including:

  • Save and add another: Create a record, and go right to adding another one, without having to click the back button, and then add again.
  • Save and close: Save the record and go back to list view
  • User-friendly delete: Extracted from the tray of constructive actions and moved away so is less likely to be clicked accidentally. Includes inline confirmation of action instead of browser alert box.
  • Screenshot
  • Cancel: Same as the back button, but in a more convenient location
  • Previous/Next record: Navigate to the previous or next record in the list without returning to list view
  • Frontend Links: If your DataObject has a Link() method, get links to the draft site and published site to view the record in context in a single click
  • Screenshot
  • Versioning: Save, Save & Publish, Rollback, Unpublish
  • Screenshot
  • Configurable UI: Add buttons to the top (utilities) or bottom (actions).
  • Disambiguated tabs: In model admin, the top tabs toggle between the models. On the detail view, they toggle between the groups of fields, creating a confusing user exierience. Better Buttons groups the fields as they are in CMSMain, using a tabset within the main editing area.
  • Screenshot
  • Add your own custom actions!

Create custom actions the detail view

Screenshot

Requirements

SilverStripe 4.0 or higher

Installation

composer require unclecheese/betterbuttons 2.x-dev

Customising the button collections

Preferences for which buttons should appear where will vary from user to user. BetterButtons comes with a default set of button collections for the "create" and "edit" views in a GridField detail form, but these can be easily overridden in a config.yml file.

The default configuration:

BetterButtonsUtils:
  edit:
    BetterButtonPrevNextAction: true
    BetterButton_New: true
  versioned_edit:
    BetterButtonPrevNextAction: true
    BetterButton_New: true

BetterButtonsActions:
  create:
    BetterButton_Save: true
    BetterButton_SaveAndClose: true

  edit:
    BetterButton_Save: true
    BetterButton_SaveAndClose: true
    BetterButton_Delete: true
    BetterButtonFrontendLinksAction: true

  versioned_create:
    BetterButton_SaveDraft: true
    BetterButton_Publish: true
  versioned_edit:
    BetterButton_SaveDraft: true
    BetterButton_Publish: true
    Group_Versioning: true
    BetterButton_Delete: true
    BetterButtonFrontendLinksAction: true

BetterButtonsGroups:
  SaveAnd:
    label: Save and...
    buttons:
      BetterButton_SaveAndAdd: true
      BetterButton_SaveAndClose: true
      BetterButton_SaveAndNext: true
      BetterButton_SaveAndPrev: true
  Versioning:
    label: Versioning...
    buttons:
      BetterButton_Rollback: true
      BetterButton_Unpublish: true

Each button type is assigned a symbol in the YAML definition. It can be placed anywhere any number of times. Further, it can be placed in a named group, provided that group has been defined in the BetterButtonsGroups node. A button group is a single button with a label that exposes a series of options on click.

Because of the idiosyncracies of the Config layer merging arrays, the buttons must be defined as on or off (true or false). To remove a button from the default configuration, you must explicitly set it to false in your project configuration. Here is an example custom configuration.

BetterButtonsActions:
  edit:
    BetterButton_Save: false
    Group_SaveAnd: false
    Group_MyGroup: true
BetterButtonsGroups:
  MyGroup:
    label: This is a group
    buttons:
      BetterButton_Save: true
      BetterButton_SaveAndNext: true

When creating groups, be sure not to duplicate any buttons that are outside the group, as form fields with the same name cannot appear twice in a form.

Creating a custom action

In the example below, we'll create a custom action in the GridField detail form that updates a DataObject to be "approved" or "denied."

We can add the action in one of two places:

  • Actions at the bottom of the form (e.g. save, cancel)
  • Utils at the top right of the form (e.g. new record, prev/next)

First, we'll overload the model's getBetterButtonsActions or getBetterButtonsUtils method, depending on where we want the button to appear in the UI.

    public function getBetterButtonsActions() {
        $fields = parent::getBetterButtonsActions();
        if($this->IsApproved) {
            $fields->push(BetterButtonCustomAction::create('deny', 'Deny'));
        }
        else {
            $fields->push(BetterButtonCustomAction::create('approve', 'Approve'));
        }
        return $fields;
    }

The BetterButtonCustomAction object takes parameters for the method name ("deny" or "approve") to invoke on the model, as well as a label for the button.

Now let's add the methods to the DataObject.

    public function approve() {
        $this->IsApproved = true;
        $this->write();
    }

    public function deny() {
        $this->IsApproved = false;
        $this->write();
    }

Lastly, for security reasons, we need to whitelist these methods as callable by the GridField form. This works a lot like $allowed_actions in controllers.

    private static $better_buttons_actions = array (
        'approve',
        'deny'
    );

Now we have a new button in the UI!

Screenshot

Customising the user experience

Let's ensure that the form refreshes after clicking "approve" or "deny".

  $fields->push(
    BetterButtonCustomAction::create('deny', 'Deny')
      ->setRedirectType(BetterButtonCustomAction::REFRESH)
  );

The redirect type can use the constants:

BetterButtonCustomAction::REFRESH
BetterButtonCustomAction::GOBACK

To refresh the form, or go back to list view, respectively.

Additionally, we can add a success message that will render on completion of the action by returning a message in our method.

    public function deny() {
        $this->IsApproved = false;
        $this->write();

        return 'Denied for publication';
    }

Defining arbitrary links

Sometimes, you might not want to sent a request to the controller at all. For that, there's the much simpler BetterButtonLink class.

    $fields->push(
        new BetterButtonLink(
          'View on Meetup.com',
           $this->MeetUpLink
        )
    );

Screenshot

Creating nested forms

You may have an action that needs to prompt for user input, for example "Send this customer message" on an Order record. For complex actions like these, you can use BetterButtonNestedForm.

	public function getBetterButtonsActions() {
		$f = parent::getBetterButtonsActions();
		$f->push(BetterButtonNestedForm::create('sendmessage','Send this customer a message', FieldList::create(
			TextareaField::create('Content')
		)));

		return $f;
	}

In this case, your action handler receives $data and $form, just like a controller would.

    public function sendmessage ($data, $form) {
    	$message = Message::create(array (
    		'OrderID' => $this->ID,
    		'Content' => $data['Content']
    	));

    	$message->write();
    	$form->sessionMessage('Message sent','good');
    }

Disabling Better Buttons

Sometimes you might find it necessary to disable better buttons on certain classes. You can do this by changing the static better_buttons_enabled to be false via YML configuration.

MyBetterButtonLessClass
  better_buttons_enabled: false

silverstripe-gridfield-betterbuttons's People

Contributors

3dgoo avatar adamjudd avatar andrewhoule avatar cameronbourgeois avatar chillu avatar christopherdarling avatar colintucker avatar dhensby avatar fonsekaean avatar hailwood avatar hdpero avatar irkeepin avatar leapfrognz avatar lekoala avatar martinduparc avatar mattybalaam avatar mediabeastnz avatar mellm0 avatar mjvcallibrity avatar ntd avatar pathum avatar reflektera avatar robbieaverill avatar shrikefin avatar stevie-mayhew avatar sunnysideup avatar taitava avatar tony13tv avatar tylerkidd avatar unclecheese avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

silverstripe-gridfield-betterbuttons's Issues

Clarification of LICENSE

Hey @unclecheese, Composer says BSD-3-Clause, bundled LICENSE is GNU. Can you clarify which license this is under? They're compatible as far as I'm aware but just FYI.

Causes bug when used with newsletter module

I'm not sure which module is strictly to blame, but the newsletter module relies on a button called "action_doSave" that is apparently not available when adding a newsletter when this module is installed.

To replicate, install this module and https://github.com/silverstripe-labs/silverstripe-newsletter and try to add a new newsletter.

The error thrown is:

Fatal error: Call to a member function setTitle() on a non-object in /Users/naomiguyer/Sites/privacy/newsletter/code/form/gridfield/NewsletterGridFieldDetailForm.php on line 19

Which relates to this code:

if (empty($this->record->Status) || $this->record->Status == "Draft") {
// save draft button
$actions->fieldByName("action_doSave")
    ->setTitle(_t('Newsletter.SAVE', "Save"))
    ->removeExtraClass('ss-ui-action-constructive')
    ->setAttribute('data-icon', 'addpage');

Editing newsletters appears to work fine.

Unpublish appears even when item isn't yet published

Noticed this one today - BetterButton_Unpublish appears even with a versioned item that isn't published. I tried duplicating the shouldDisplay() function from BetterButton_Rollback but just got this error in the modeladmin:

Fatal error: Call to undefined method NullHTTPRequest::recordIsPublished() in ...\betterbuttons\code\BetterButton.php on line 314

Looking at the stack trace it's coming from addButtonToForm() in GridFieldBetterButtonsItemRequest.php around line 67.

I was trying to add this:

public function shouldDisplay() 
{
    return $this->request->recordIsPublished();
}

Anyone see anything obvious why that wouldn't work?

Modeladmin: buttons do not keep filter alive

Once any of the buttons is clicked in detailsview, the filtering state is lost in ModelAdmin. The default (back)links in ModelAdmin do preserve the filterstatus (in a querystring).

I'm not sure if this is a BetterButtons issue only or actually a GridField issue, and/or attempts have been made to fix this or how hard that would be :) Willing to help though, if you think this doable or if maybe someone can point me in the right direction?

No Buttons

I'm developing a new site & thought I'd add this. I've installed the module, but no new buttons are showing up.

I'm installing via composer:

"silverstripe/cms": "3.1.*@stable",
"silverstripe/framework": "3.1.*@stable",
"unclecheese/betterbuttons": "1.2.*",

here is how i am defining the field

$fields->tab("Slides")    
                 ->grid("Slide","Slide", $this->owner->Slides(), GridFieldConfig_RecordEditor::create())
                    ->configure()->addDragAndDrop("SortOrder")->end();; 

or, in a different project that I thought had this working, but checking shows no buttons (same ss & module versions):

$fields->addFieldToTab("Root.Features", GridField::create('Features','', $this->Features(), GridFieldConfig_RecordEditor::create()));

A few other folks are having the same troubles:
http://www.silverstripe.org/customising-the-cms/show/20984?start=8

I think I have used this before & they just appear, right? I don't have to set anything up when defining the fields in the php?

Viewing source on the gridfield edit screen shows an empty div for the buttons (.better-buttons-utils) but no buttons.

Versioned DataObject save buttons write to wrong tables when reading mode set to ‘live’

Expected behavior is:

  • “Save Draft” writes to Stage table
  • “Publish” publishes from Stage table to Live table

This behavior is observed when the global variable “reading mode” is set to “Stage.”

But when reading mode is set to Live, the following unexpected behavior occurs:

  • “Save Draft” writes directly to Live table, without changing Stage
  • “Publish” writes directly to Live table, but then publishes Stage onto Live, immediately reversing the change

Other, less predictable unexpected behavior has been observed in “Live” mode, but the above is the most consistent.

Compounding the problem is that it is far from obvious how this “reading mode” switches between Stage and Live, or how to tell which one we are in. This may be a secondary issue residing in the SilverStripe core.

It may be helpful to know that these issues were encountered after implementing Versioned on a pre-existing project (where the original data models were generated without Versioned being turned on). BetterButtons was part of this project from the beginning, however.

"Save and go to previous record" button disabled unless item is on first GridField page

To reproduce:

  1. Add BetterButton_SaveAndPrev: true to the BetterButtonsActions: edit: config.
  2. Setup a gridfield that has pagination for multiple pages.
  3. Navigate to any page other than "page 1".
  4. Click on an item to enter the edit from.

What happens:
The "Save and go to previous record" button is disabled.

What I expect to happen:
The "Save and go to previous record" button not to be disabled as previous items do exist.

SilverStripe 3.1.13
BetterButtons 1.2.8

Internal Server Error when delete

When I click the Delete button and then the confirmation Yes, Delete this item I got an internal server error.
This is what I see in the apache error log:

PHP Fatal error: collateDataFields() I noticed that a field called 'action_doSaveAndQuit' appears twice in your form: '(unknown form)'. One is a 'UncleCheese\BetterButtons\Buttons\Button_SaveAndClose' and the other is a 'UncleCheese\BetterButtons\Buttons\Button_SaveAndClose' in /home/sites/development/000_SILVERSTRIPE/www/framework/forms/CompositeField.php on line 167, referer: http://www.domain.com/admin/carousel/Carousel/EditForm/field/Carousel/item/8/edit

Button_SaveAndAdd doesn't exist

Hi there, in a few installs of 3.1.8 I receive this error

[User Error] Uncaught Exception: The button type Button_SaveAndAdd doesn't exist.
GET /admin/products/Product/EditForm/field/Product/item/new?isDevtoken=09613ef391c5c062e7aafbdf7be6a848&flushtoken=fc2bb11c0d7788faa3a80596678fd91b&flush=1
Line 143 in /srv/gas/public_html/silverstripe-gridfield-betterbuttons/code/extensions/BetterButtonDataObject.php

if I add

BetterButtonsActions:
  create:
    Button_SaveAndAdd: true
    Button_Save: true
    Button_SaveAndClose: true

to my config.yml. I'm not sure why Button_SaveAndAdd is an issue, when it's also part of the module's config and that throws no errors. Thanks!

BetterButtonCustomAction successMessage no longer used

I've noticed successMessage is no longer used by the BetterButtonCustomAction to return messages. Instead the action function return string is used as the message.

There is still successMessage code in the BetterButtonCustomAction class, which is no longer used to set the return message.

The read me document also shows an example of using setSuccessMessage which no longer works:

BetterButtonCustomAction::create('deny', 'Deny')
    ->setRedirectType(BetterButtonCustomAction::REFRESH)
    ->setSuccessMessage('Denied for publication')

Should this code be removed and documentation updated?

I'm happy to make the changes and submit a pull request if you like.

Character encoding

Hi! I came across some character encoding issue.

First, we have an action in a DataObject subclass:

$this->send_action = BetterButtonCustomAction::create('send_notification', _t('Notification.SEND', 'Send this notification'));

The action 'callback' makes a call to a webservice which returns ($result_message) a message id in order to show i18n'ed messages:

$this->send_action->setSuccessMessage(_t($result_message));

The localized text has a latin word 'Notificación'. Although that word is shown correctly across all the CMS, it's not correctly displayed in the "toast" message.

BTW, I managed to solved it:

$this->send_action->setSuccessMessage(rawurldecode(iconv('UTF-8', 'ISO-8859-1', _t($result_message))));

(also tried only with rawurldecode since I've seen it in SS sources, but no success.)

Anyone?

Crashing newsletter module

Betterbuttons are preventing newsleter module from creating new newsletter. Renaming action from save to doSave should fix it.

Draft and Live preview links showing where they shouldn't be

From what I can see, if a DataObject has a Link() method, draft and live preview links are shown in the grid field form actions. This shouldn't be applied to some classes ie. File and subclasses of. And some of my DOs have Link methods that are external links.

Perhaps defining an exclude_classes config would be a good solution?

Error when using Versioned dataobject without Live stage

If a dataobject uses the Versioned extension without using Stage/Live, the module fails. The shop module uses this configuration for ProductVariations so they have a version history. In this case the extension is initialized like so:

    static $versioning = array(
        'Stage'
    );

    static $extensions = array(
        "Versioned('Stage')"
    );

The following error is then given when you try to edit one of these objects from modeladmin with the betterbuttons module installed:

[User Error] Uncaught Exception: Object->__call(): the method 'isnew' does not exist on 'ProductVariation'

If the isNew method is added to the model, there's still an error caused by the following query (GridFieldBetterButtonsItemRequest.php, 505):

        return (bool) DB::query("SELECT \"ID\" FROM \"{$table}_Live\" WHERE \"ID\" = {$this->owner->record->ID}")->value();

Basically, the module assumes that the object is a SiteTree if it has a Versioned extension. I tried to find a workaround and couldn't find a satisfactory one. Versioned apparently doesn't have any way for an outside object to find out whether the Live stage is enabled or not, which seems to be a weakness in it's api.

The only solution I can think of is to check for SiteTree instead of Versioned and/or to submit a pull to silverstripe-framework with a more complete api for Versioned.

Fatal error on the GridFieldDetailFormTest

After installing the betterbuttons module the framework test "GridFieldDetailFormTest" will produce an fatal error.

Fatal error: Call to a member function push() on null in /var/www/www.myproject.com/htdocs/framework/forms/gridfield/GridFieldDetailForm.php on line 653

Using a clean 3.1.8 installation of silverstripe.

PHP Fatal error: Allowed memory size of X bytes exhausted - getPreviousRecordID and getNextRecordID

Hi,

I have a table with millions of records and start to receive 'PHP Fatal error: Allowed memory size of X bytes exhausted'. After some digging I found the problem in getPreviousRecordID and getNextRecordID (GridFieldBetterButtonsItemRequest). I saw the comment 'WARNING: This does not respect the mutated state of the list (e.g. sorting or filtering).' and think if it's so why you need all the records to get the next/previous ID. You can use something like this:

public function getPreviousRecordID() {
        if (empty($this->owner->record))
            return false;

        $strClass = get_class($this->owner->record);
        $next = DataObject::get($strClass, 'ID < ' . intval($this->owner->record->ID),'ID DESC')->limit(1)->column('ID');
        return isset($next[0])
            ? $next[0]
            : false;
}

public function getNextRecordID() {
    if (empty($this->owner->record))
        return false;

    $strClass = get_class($this->owner->record);
    $next = DataObject::get($strClass, 'ID > ' . intval($this->owner->record->ID),'ID ASC')->limit(1)->column('ID');
    return isset($next[0])
        ? $next[0]
        : false;
}

It will be faster and will not require so much memory.

CMS Requirement?

Is there a reason this module requires the CMS in Composer.json?

I wanted to install it on my framework-only web app, and it's gone and installed the CMS which I don't need.

$this doesn't contains the proper content in custom actions when saving a new record

In documentation there's a function approve() that when called and we are in a new record (not in an update), the db properties in the $this variable are empty.

When approve is called over an existing record, $this contains all the properties filled, but when in a new record, the properties are empty.

I'm guessing that there should be another way to get access to the content of the object pre-save but I don't see how!

public function approve() {
$aux = $this->Title; //is empty in new record but filled in an existing one
$this->IsApproved = true;
$this->write();
}

"Unpublish" completely removes page from site

I've come across a little issue under 'Versioning'. Articles are managed in a ModelAdmin environment with the use of BetterButtons. You have the option to 'Cancel Draft Changes' or 'Unpublish'. When clicking onto 'Unpublish', you'd expect the page to be just deleted from the "Live" stage of the website. After clicking onto 'Unpublish' the usual 'Delete' button would appear on the far-right. But the thing is, the 'Delete' is redundant always as the page has been removed. Because when you click onto 'Unpublish' you delete the page on both of the Draft and Live Stage sites. So when you have content that you just wanted to publish later but you accidentally published it by clicking "Save and Publish" and you click 'Unpublish' so you can still keep the page as a draft but removed from the live site. You've lost everything. All traces of the page you worked has been wiped.

Publish and go to next/prev + add new

When managing versioned records (pages) via modeladmin, i lack the options to Publish and go to next/prev and adding new.
Same stuff as we have with the SaveAnd group, just for versioned.

Is this something that can be added or is there some reason it's not in the module?

CustomAction saving current form and setting one field

Hello guys,

how to create custom action which will save actual (changed) form in modeladmin, but before save changes one field (Status) to specified number?

I have few statuses for an dataobject and i want quick "Publish" button changing Status automaticly, but without need of saving dataobject before.

Thanks!

Fatal error: Object::add_extension() - Extension "GridFieldDetailForm_ItemRequest" is not a subclass of Extension in C:\wamp\www\framework\core\Object.php on line 467

Hi Aaron!

There is a problem with the latest version 3.1 from github:
https://github.com/silverstripe/silverstripe-cms/tree/3.1
https://github.com/silverstripe/sapphire/tree/3.1

http://127.0.0.1/dev/build?flush=all

Fatal error: Object::add_extension() - Extension "GridFieldDetailForm_ItemRequest" is not a subclass of Extension in C:\wamp\www\framework\core\Object.php on line 467

You must change the way to add an extension (_config.php):

Behavior of the button 'Save and add file(s)'

Hi Aaron!

The first thing to tell you that this is a wonderful module. :)
Thanks for your work.
Maybe I'm wrong, but the behavior of the button 'Save and add file(s)' is not as expected.
When I click on that button the record is saved, but I can not continue entering new records without having to back to the list of records.
After clicking on that button, if I make any changes to that form I'm editing the same record just saved.
I am using the latest version of SilverStripe 3.1 from:
https://github.com/silverstripe/silverstripe-cms/tree/3.1
https://github.com/silverstripe/sapphire/tree/3.1

Thanks,
Regards,
Jose A.

canCreate() doesn't work with `Save Add New`

Hey,

I am using canCreate() to enforce that the user cannot create more than 4 data objects, but if they create 4 in a row using better buttons Save add new, once the 4th DO is saved, it'll take them to the fifth one regardless and let them save an empty DO.

Thanks.

crash on opening Pages in ModelAdmin

The error must have appeared within the last days, because I updated the repo often.

I got crashes with the following error message when trying to open the Gridfield Detail View of a Page in ModelAdmin:

( ! ) Fatal error: Call to a member function getVersionedStages() on a non-object in .../gridfield-betterbuttons/code/extensions/BetterButtonDataObject.php on line 169
Thats in the function

public function checkVersioned() {
        return $this->owner->hasExtension('Versioned') &&
               count($this->owner->record->getVersionedStages()) > 1;
    }

When I remove the ->record from the given line, the error disappears.

BetterButtonLink attempts to open link in CMS

I'm using the BetterButtonLink to give the CMS user access to preview a PDF, however, when this happens it tries to open the PDF in the CMS admin via an AJAX request which results in encoded text being displayed.

Is there a way to force opening in a new tab?

Redirect to a specific tab with BetterButtonCustomAction

It would be great to be able to redirect to a specific tab with BetterButtonCustomAction.

I have tried the following:

<?php

class MyDataObject extends DataObject {

    private static $better_buttons_actions = array (
        'customaction'
    );

    public function customaction($action, $controller, $request) {

        $action->setRedirectURL(
            $controller->getEditLink() . '#Root_TabName'
        );

        return 'Success';
    }

}

This correctly sets the URL but it does not go to the correct tab.

Is it possible to have this kind of functionality added in?

Incorrect "Save draft" and "Save & publish" button states

While using BetterButtons in ModelAdmin for a SiteTree object, I've observed the following:

For a New Record

Immediately after clicking the Add New button, the save buttons display like this:

However, the record has never been saved, and isn't yet stored in the database, so the buttons should be like this:

Note: There are 2 issues here:

  1. Both buttons are grey with a green tick, instead of being fully green with no tick.
  2. The 'Save' button says 'Saved', instead of 'Save Draft' (as it's not yet saved)

After Clicking 'Save Draft'

I've made some edits in the WYSIWYG editor, and both buttons are correctly indicating there are changes to be saved or published:

However, if I click the 'Save draft' button the following is displayed:

Note, the 'Save & publish' button has the correct title, but it is incorrectly displaying in grey with a green tick. At this state it should look like this:

Viewing versioned DataObject in Live mode does not show most recent draft

I notice this behavior when I do the following:

  • set reading mode to Live (for example, by navigating to a URL with ?stage=Live)
  • open an existing versioned DataObject
  • make changes and save as draft
  • navigate away, and then back to this DataObject

At that point, the changes I had just made do not display. I am assuming this is because the reading mode is set to Live, and the cms is displaying the most recent published version, which does not include my draft changes.

It seems to me that expected behavior would be for the cms to display the most recent draft version by default. This would match the behavior of the Pages section of the cms, where the most recent draft version is shown regardless of reading mode.

Poking around the code a bit, I was able to get my expected behavior by adding this code:

        // If this is a pre-existing record, check to see if it is on the latest version
        // If not, replace the form data with data from the latest version
        if($this->owner->record->ID && !$this->owner->record->isLatestVersion()) {
            $record = Versioned::get_latest_version($this->owner->record->ClassName, $this->owner->record->ID);
            $form->loadDataFrom($record);
        }

at this location: https://github.com/unclecheese/silverstripe-gridfield-betterbuttons/blob/master/code/extensions/GridFieldBetterButtonsItemRequest.php#L101

I'm not sure if that's the best way to fix the issue, but it did seem to produce my expected behavior in the tests I ran. I am happy to do a pull request, but wanted to make sure I was on the right track as to where and how to accomplish this first.

Javascript error generated.

Stack Trace:

Stack Trace:
.error@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:551
$.widget.bridge/$.fn[name]/<@
http://localhost/ss3modules/framework/thirdparty/jquery-ui/jquery-ui.js?m=1366655292:521
.each@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:660
jQuery.prototype.each@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:271
$.widget.bridge/$.fn[name]@
http://localhost/ss3modules/framework/thirdparty/jquery-ui/jquery-ui.js?m=1366655292:516
.onmatch/<@
http://localhost/ss3modules/silverstripe-gridfield-betterbuttons/javascript/dropdown_form_action.js?m=1368811473:54
.each@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:660
jQuery.prototype.each@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:271
.onmatch@
http://localhost/ss3modules/silverstripe-gridfield-betterbuttons/javascript/dropdown_form_action.js?m=1368811473:53
.bind_condesc/proxy@
http://localhost/ss3modules/framework/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js?m=1366655292:1867
@
http://localhost/ss3modules/framework/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js?m=1366655292:2055
jQuery.event.dispatch@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:3332
jQuery.event.add/eventHandle@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:2941
jQuery.event.trigger@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:3210
.triggerHandler@
http://localhost/ss3modules/framework/thirdparty/jquery/jquery.js?m=1366655292:3874
ChangeDetails<.triggerEvent@
http://localhost/ss3modules/framework/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js?m=1366655292:1358
@
http://localhost/ss3modules/framework/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js?m=1366655292:1364

I'm not really seeing as to why this happens though.

$allowed_actions must be public

When running dev/build I received the following error:

Fatal error: Access level to GridFieldBetterButtonsItemRequest::$allowed_actions must be public (as in class DataExtension) in /var/www/silverstripe/betterbuttons/code/GridFieldBetterButtonsItemRequest.php on line 331

changing line 18 of GridFieldBetterButtonsItemRequest.php
from:
private static $allowed_actions
to:
public static $allowed_actions
cleared it up, but I'm still not seeing any extra buttons on my gridfield item forms :-(
I'm running in dev mode, but there are no error messages in the log file

Access level error?

I'm getting this error when trying use the basic install of this extension:

[09-Sep-2013 01:32:33 UTC] PHP Fatal error: Access level to GridFieldBetterButtonsItemRequest::$allowed_actions must be public (as in class DataExtension) in /Applications/MAMP/htdocs/wpccc/silverstripe-gridfield-betterbuttons/code/GridFieldBetterButtonsItemRequest.php on line 13

Any ideas? thanks in advance

Redirect to DataObject edit page inside BetterButton custom action

I'm trying to create a custom button that clones a DataObject.
Everything is working fine but at the end I would like to redirect the user to the newly created DataObject edit page instead of refresh/go back. Like stated here it's not possible.

Here is my custom button code:

class GridFieldCloneBetterButton extends DataExtension {

    private static $better_buttons_actions = array(
        'clone_do'
    );

    public function updateBetterButtonsActions($actions) {
        $actions->push(
            BetterButtonCustomAction::create('clone_do', 'Clone')
                ->setSuccessMessage('Object cloned')
                ->setRedirectType(BetterButtonCustomAction::GOBACK)
        );
        return $actions;
    }

    public function clone_do() {
        $current_record = $this->owner;
        $clone = $this->owner->duplicate();
    }

}

Versioning - Draft versions not saving and publishing issues

Hey there,
My project uses better buttons to manage "ArticlePage" which is an extension of "Page" in a separate ModelAdmin section of the admin backend. Project uses SilverStripe 3.1.12.

I've had an issue with my project where content is publishing to the website but it seems to skip the "save as draft" process so when updating a pages' title which then usually updates the URL if you choose to do that. The previous URL that was assigned with the page breaks (404 - page not found) because of the updated URL change.

But in the normal way of how you can manage pages in the default "Pages" section of the admin, the new pages you create which you may later update (which may change the URL) would redirect the previous URL used to the new version of such page.

Another issue I've run into is that some changes I do to an article and click onto "Save and Publish" does not keep some of the changes made.

Also - may or may not be related to the module, but in the "Managed Models" screen it will only show Published article pages in the list and not any draft publishes. Is there any way to make both Draft and Published content to appear in the list?

New Record button steals default action

When creating a record with BetterButtons installed, a "new record" button appears in the top right of the CMS.

When hitting the enter key to submit the form, the "new record" button is used and data is lost.

This is because the button is inserted at the top of the form - instead, it should be at the end.

Tested on Chrome 41 - windows 8.1 x64

Saving record triggers Datepicker

If I have a Datepicker field on my form it behaves erratically in combination with this module. When I only had the DateField with the datepicker in the form the datepicker kept reopening. Now when I have several fields that's not an issue but when clicking one of the new action buttons the datepicker opens again and stays open on the next page. The behaviour is gone though so clicking on it will actually follow whatever link is in the datepicker.

Default State automatically Save and Publishes

Just bringing the email as an issue here just to see if anyone else has this issue and has an idea on how to patch the problem I'm having.

Betterbuttons default state (add new) automatically Save and Publishes article pages before they are filled with data. Even if you click onto Save (and not Publish) the page is published straight away. As a side note, is there a way to integrate embargo and expiry with better buttons using the ModelAdmin function? I'm unable to have it save as draft and then publish. Only can do this using the 'Pages' section of the backend.

I'm using SilverStripe 3.1.6 with these modules mentioned above.

MultiClass

Hi,

any way to get the new Record button handle multipleclasses coming from grdifieldextensions?

Issues With Veriosn Dataobjects

When using ModelAdmin to control veriosned DataObjects, the betterbuttons override the save and publish. Save only affects the draft version

Filter List and Next Button

Hello,
Thanks for this great module, exactly what i needed!!

However, I've noticed that when using better buttons within Model Admin with a filtered list and go into detail view, the first record the Next/Prev buttons work fine and take you to the next filtered result but as soon as you go through to the next/prev record the filter is reset and you go back to the unfiltered list. You can see the filters being dropped from the URL.

New menu is poorer UX - Ability to choose default button?

Ooo no, I've just seen the new popup menu, it looks pretty but for me it has removed the main reason I loved this module. Having a "Save & Close" button gave users the ability to save & go back in a single click, instead of first saving, then clicking back. The new popup menu reverts "Save & Close" to being 2 clicks, which for me kind of defeats the purpose of the "Save & Close" feature. :(

I understand that different use cases will have different preferred save actions, for me the "Save & Close" action makes sense to be default in the vast majority of cases, would it be possible to have the ability to choose which action is the default? The default action would then have it's own button, with the rest in the popup menu.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.