Forums / Setup & design / User control over folder sort-order

User control over folder sort-order

Author Message

Russell Michell

Wednesday 22 October 2008 8:53:05 pm

Hi folks,

Has anyone managed to integrate a user-controlled sort function for their folder-like content-objects?

I would like to add a "sort listing" drop-down menu to the website-toolbar for each folder content object. The options would comprise the standard eZ sort types ("Published", "Name", "Priority" etc) which, when selected by a logged-in user to the <b>website interface</b>, re-sorted the listed items of that folder and saved this selection/preference to the DB, to "remember" the sort order for all subsequent visitors to that folder.

I know how to add new datatypes to a content class and use their data in a template when the data comes from someone using the admin interface - and to add a user-input datatype of type "Selection", but how would I do the following for the regular, website interface?

1). Add a javascript onchange() event to the "Selection" datatype for example, to submit the selection? There don't seem to be any 3rd party datatypes that do this, and am not sure how to write one - can anyone recommend an up-to-date tutorial for 4.0.1?

2). Once submitted, I guess it's just a case of taking the data from the menu and using it to do the sort in the fetch for an override for that template and submitting to the DB right? Or might there be more to it than that? What might the template-code look like to submit --> receive -> insert the data?

Sorry for all the questions and thank you for your time :-)
Russ

Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom

Believe nothing, consider everything.

Gaetano Giunta

Thursday 23 October 2008 3:59:02 am

In the standard admin interface you can already set the sort order for any kind of container object, without adding extra attributes.

You can then fetch the current node and use its .sort_array attribute in the current template to fetch the children and display them in the exact same order as defined in the admin interface.

I think you might easily replicate this by extending the website toolbar, except for the 'custom' sort order, which needs a more complex, ajaxy interface:
- look at the form fields and submit target present in the admin interface for changing sort order
- replicate them in the toolbar (after checking of course if current user has enough perms)
- you should be done
- only thing that might be tricky to set up: redirection to current page after post. maybe achievable via an xhr-post?

Principal Consultant International Business
Member of the Community Project Board

Russell Michell

Thursday 23 October 2008 6:32:36 pm

Hi Gaetano and thanks.

I have created an override for website_toolbar.tpl and added the code from admin edit.tpl and my menu shows up in the website UI just fine. If I need to add a JS onchange() event, that would be easy enough to do now.

But I am confused on 2 things:

1). In which kernel script do I add a new if/else block to deal with the POSTed data?

* content/edit.php
* content/module.php
* content/action.php

...each of which seem to take HTTP POST vars from website_toolbar.tpl.

2). The other thing is the default selection in my menu is taken from code in the admin templates and is therefore set by the folder <b>class</b> not an <b>instance</b> of that class (My folder content-object). So how could I submit and save folder sort-order data for the object, such that it overrides the sort order for the folder class?

I hope I'm being clear enough. I would have thought eZ would be able to do something like this out of the box. Heck, even Plone does (..and what a dog <b>that is</b>...!)

Any other guidance on this would be very gratefully received :-)

Thank you very much,
Russ

Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom

Believe nothing, consider everything.

Yannick Komotir

Friday 24 October 2008 1:27:10 am

Hi,
compared to what has been said here, I think something will not work

In the standard admin interface you can already set the sort order for any kind of container object, without adding extra attributes.

You can then fetch the current node and use its .sort_array attribute in the current template to fetch the children and display them in the exact same order as defined in the admin interface.

In this way the sort will be apply for all user , i think that it must create another table, which will store the various preferences of users.

Regards,

<|- Software Engineer @ eZ Publish developpers -|>
@ http://twitter.com/yannixk

Gaetano Giunta

Friday 24 October 2008 1:55:45 am

@Yannick - you are completely right: the solution I proposed is to change the sort order on a folder in a way that all visitors will see the same sort order.

The original post said:
<i>to "remember" the sort order for all subsequent visitors to that folder</i>
but possibly the intent was " for all subsequent visits to that folder"?

In that case, I think using the "ezpreference" feature would be a good option.

Principal Consultant International Business
Member of the Community Project Board

Gaetano Giunta

Friday 24 October 2008 2:16:50 am

@Russ: I gave a very short look at the code from the admin template.

I would start to experiment with:
- posting to "content/action"
- adding a hidden field "ContentNodeID" with the current node id (this deals with node vs. class if I got it right)
- adding a hidden field "ContentObjectID"
- using "SetSorting" as name of the submit button
- using "SortingField" as name of the selector for sort order

By default you should end up being redirected to the full view of the current node.

No need to hack any php file ;)

Principal Consultant International Business
Member of the Community Project Board

Russell Michell

Wednesday 29 October 2008 7:29:36 pm

@Gaetano: Thanks for your help, it works great. All I had to do differently was to ensure a sort direction was passed to content/action too.

For anyone that comes across this thread, here's the template code in an override for: website_toolbar.tpl:

<!-- Custom sort-field -->
{def $content_containers = array('folder','smart_folder')}
{if $content_containers|contains( $content_object.content_class.identifier )}
<form method="post" action={"content/action"|ezurl} class="left">
  <input type="hidden" name="HasMainAssignment" value="1" />
  <input type="hidden" name="ContentObjectID" value="{$content_object.id}" />
  <input type="hidden" name="NodeID" value="{$current_node.node_id}" />
  <input type="hidden" name="ContentNodeID" value="{$current_node.node_id}" />
  <input type="hidden" name="SortingOrder" value="" />
    {def $sort_fields=fetch( content, available_sort_fields )
    $title='Use this to set the default sorting method for the sub items of this content-object.'|i18n( 'design/admin/class/edit' )|wash }

    <select name="SortingField" title="{$title}">
        <option value="" selected="selected">Order by</option>
    {foreach $sort_fields as $sf_key => $sf_item}
        <option value="{$sf_key}" {if eq( $sf_key, $current_node.sort_field )}selected="selected"{/if}>{$sf_item}</option>
    {/foreach}
      <select name="SortingOrder">
      <option value="">Sort Direction</option>
      <option value="1" {if eq(1,$current_node.sort_order)}selected="selected"{/if}>Ascending</option>
      <option value="0" {if eq(0,$current_node.sort_order)}selected="selected"{/if}>Descending</option>
      </select>
    </select>

  <input type="image" src={"websitetoolbar/ezwt-icon-sorting.gif"|ezimage} name="SetSorting" title="{'Sort Folder View'|i18n( 'design/ezwebin/parts/website_toolbar' )}" />
{undef}
{undef}
</form>
{/if}

Thanks again :-)
Russ

Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom

Believe nothing, consider everything.

André R.

Thursday 30 October 2008 12:54:35 am

Some small notices: {undef} without the variable(s) you want to undef, will undefined all variables within the scope(~the current template). And it seems like your nesting of def / undef isn't correct.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Andreas Adelsberger

Thursday 30 October 2008 1:59:57 am

Hi, this is a nice enhancement for the website toolbar, but you can't edit the priority. Maybe we could list the children under the toolbar or in a popup to change and save priority settings.

I put a link in the toolbar "priority" and then inluded the admin template in the frontend to the set pritority of the children, but this template has too much possibilities.

Maybe I find some time to enhance this.

greetz Andi

---------------------------------------
Styleflasher New Media OG
Websites. Games/Multimedia.

André R.

Thursday 30 October 2008 1:54:44 pm

Andi:
There is a patch+screenshoot for it in the issue:
http://issues.ez.no/IssueView.php?Id=13849&activeItem=1

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Yannick Komotir

Friday 31 October 2008 6:07:16 am

@Gaetano :
Sorry i had not understood his concern, your answer is excellent! very great! I kept well in my pad.

{undef} without the variable(s) you want to undef, will undefined all variables within the scope(~the current template)
 

I have also noted

<|- Software Engineer @ eZ Publish developpers -|>
@ http://twitter.com/yannixk