ok, this will be kinda complicated if you want to do it right.
First off, if you want it to remain static after its customized you''ll
need
to store it in the db, but also you could store it as a cookie to prevent
one extra table read per page when browsing your site.
however, if you don''t care if the user losses their settings whenever
they
delete their cookies then by all means...
what you need to do is:
a) create a db table with an id the menu link names, where they point at and
a default order id they go in (keep in mind that this is all off the top of
my head)
b) create a db table with the user id, and then a second column to store
their settings ie user_menu and in this column you will store a hash of the
link items (menu_item_id, hash) thus making the cookie rather easy to create
later on.
so basically after they get their menu sorted you just post the array
containing menu_item_id and the order number to the server for the entire
sortable list and then on the server loop through the posted array and
create your hash :
for($x=0;$x<sizeof($_POST[menu_items];$x++){
$hash .=
$x[<menu_item_id>].'',''.$x[<position>].''|'';
}
store the hash in the db -- replace into <user_menu_table> (replace into
is
a short cut to avoid checking for a record to update it.)
after all this is said and done have yer ajax write the cookie on output.
of course you can put expiration dates in there for log in times to delete
unused records and various other things.
as for the cookie thing when they call the page have the php check for a
cookie with the menu info, if it exists, parse the cookie, else read the
users row from the db and then create the menu
like i said, this is completely off the top of my head, but the logic is
basically there.
On 8/23/07, ddshizn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
<ddshizn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> Sorry, i''m new to javascript/ajax but how would i go about saving
the
> state of a sortable element on page refresh?
>
> currently i have a menu that is sortable, so i can drag and drop it
> and then move it into a new position.
>
> however, i''m not certain how to save it. I would assume it would
> involve cookies(as i will want it to be on seperate visits as well), i
> also have a mysql database, so if that would work as well for storing
> it for longer periods of times.
>
> But i''m not sure when to create the cookie, what to store in it,
and
> then how to load it for the application so it will load on page
> load(the site is in php if that helps).
>
> Again, sorry for the inexperience, but I haven''t been having much
luck
> yet.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---