Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Make this listing editable via sprite

edited March 2013 in Apps

I would like these buttons: Sprite to allow my users to edit the listing they're currently viewing, instead of the page they're viewing. How would I do that?

Example: Listing

Clicking on the pencil above takes them to the edit page screen, but the page is just a holder for the app. How can I make it edit the current listing instead?

Comments

  • I've been thinking about a way to make these easier to reuse. For now, take a look at apps/admin/views/editable.html for how they're setup for pages. You can see how it's called in apps/admin/handlers/page.php. Basically, you would duplicate and tweak the view template, then:

    $lock = new Lock ('ModelName', $id);
    echo $tpl->render (
        'myapp/editable',
        array ('id' => $id, 'locked' => $lock->exists ()
    );
    
  • It works, but now there are two rows of buttons.

    It would be great if there were a way to disable the page buttons.

  • I think you may need to do that via Javascript:

    <script>
    $(function () {
        $('.admin-options:first').hide ();
    });
    </script>
    

    Hiding the main buttons does mean editing that page itself is only possible through the Tools > All Pages screen, so you could try something like repositioning it instead or styling them differently in some way (that may look weird though).

  • In this case it's OK because I don't really want the client editing the page, which just looks like this:

    page

  • The script works, thanks.

  • edited September 2015

    For now, take a look at apps/admin/views/editable.html for how they're setup for pages. You can see how it's called in apps/admin/handlers/page.php. Basically, you would duplicate and tweak the view template, then...

    Is this still the way to do this? I notice that there are new data-trigger="[aevd]" attributes in apps/admin/views/editable.html -- what do those do?

  • Also, how about adding add/edit/lock/version buttons to each item in a list of items, for example each event on an event listings page -- possible?

  • edited September 2015

    That was still the way I was doing it, but I just added a new admin/util/editbuttons helper to make things easier. Here's a usage example:

    1. Create the app:

    ./elefant crud-app book id title author isbn description:textarea
    

    2. Modify the books/index handler to fetch the books:

    <?php
    
    $page->title = __ ('Books');
    
    $books = books\Book::query ()
        ->order ('published', 'desc')
        ->fetch ();
    
    echo $tpl->render ('books/index', ['books' => $books]);
    

    3. Modify the books/index template to add the edit buttons:

    {% foreach books as book %}
    <div class="book">
        <h3>{{book->title}}</h3>
    
        {! admin/util/editbuttons
            ?id=[book->id]
            &class=books\Book
            &add=/books/add
            &edit=/books/edit
            &delete=/books/delete
            &versions=true
            &label=Book !}
    
        <p>{{book->description}}</p>
    </div>
    {% end %}
    

    That will insert the edit buttons tied to your new app, hiding them for non-admin users, and respecting edit locks as well.

    The data-trigger attributes are for keyboard shortcuts. To pull up a list of available shortcuts on the current page, use Ctrl+Shift+h.

  • That looks great!

  • One thing I'd like to add is the ability to inject additional buttons, maybe via an &extras=[extras] parameter where the [extras] would look something like this:

    $data['extras'] = [
        '/myapp/extra' => __ ('Extra Link'),
        '/myapp/extra2] => __ ('Extra 2')
    ];
    
  • edited September 2015

    That'd be cool. Might need to allow for choice of icon, too. Also, what about the ability not to include certain buttons -- if versions weren't being tracked, say? Or can we already do that just by not including versions=true?

  • Yep, you can omit any of the existing buttons just by leaving them out.

Sign In or Register to comment.