| Author |
Message |
|
| Guest |
Posted: Sat Aug 18, 2007 7:05 am |
|
|
|
Guest
|
This patch adds Next and Previous links to the list pages which only
appear when there are next and previous pages, respectively, to the list
output. Also, after editing or adding a new record the redirect to list
returns the browser to the page containing that record.
Jeff.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Sun Aug 19, 2007 4:41 am |
|
|
|
Guest
|
Thanks!
On 8/18/07, jm <jeffm@ghostgun.com> wrote:
> This patch adds Next and Previous links to the list pages which only
> appear when there are next and previous pages, respectively, to the list
> output. Also, after editing or adding a new record the redirect to list
> returns the browser to the page containing that record.
>
>
> Jeff.
>
> >
>
> diff -Naur erlyweb-0.6.1.orig/src/erlyweb/erlyweb_controller.erl erlyweb-0.6.1/src/erlyweb/erlyweb_controller.erl
> --- erlyweb-0.6.1.orig/src/erlyweb/erlyweb_controller.erl Sat Aug 11 23:02:58 2007
> +++ erlyweb-0.6.1/src/erlyweb/erlyweb_controller.erl Sat Aug 18 16:41:13 2007
> @@ -32,7 +32,30 @@
> list(A, Model, Page) when is_integer(Page) ->
> Records = Model:find_range((Page - 1) * ?RECORDS_PER_PAGE,
> ?RECORDS_PER_PAGE),
> -
> + %% This function makes the previos link
> + PageLink = fun(PageNum, Text) ->
> + erlyweb_html:a(
> + [case erlyweb:get_app_root(A) of
> + "/" -> "";
> + Root -> Root
> + end,
> + atom_to_list(Model),
> + <<"list">>,
> + Model:field_to_iolist(PageNum)], Text)
> + end,
> + MaxPage = Model:count() div ?RECORDS_PER_PAGE + 1,
> + PrevLink = fun(Text) ->
> + case Page of
> + 1 -> <<"">>;
> + Num -> PageLink(Num - 1, Text)
> + end
> + end,
> + NextLink = fun(Text) ->
> + case Page of
> + Num when Num >= MaxPage -> <<"">>;
> + Num -> PageLink(Num + 1, Text)
> + end
> + end,
> %% this function makes the 'edit' links in the record ids
> ToIoListFun =
> fun(Val, Field) ->
> @@ -50,10 +73,12 @@
> default
> end
> end,
> - {data, {erlyweb:get_app_root(A),
> - atom_to_list(Model),
> - Model:db_field_names_bin(),
> - Model:to_iolist(Records, ToIoListFun)}}.
> + {data,
> + {erlyweb:get_app_root(A),
> + atom_to_list(Model),
> + PrevLink, NextLink,
> + Model:db_field_names_bin(),
> + Model:to_iolist(Records, ToIoListFun)}}.
>
> new(A, Model) ->
> Rec = Model:new(),
> @@ -86,7 +111,8 @@
> NewVals = yaws_api:parse_post(A),
> Record1 = Model:set_fields_from_strs(Record, NewVals),
> Model:save(Record1),
> - {ewr, Model, list}
> + Page = (Model:id(Record) - 1) div ?RECORDS_PER_PAGE + 1,
> + {ewr, Model, list, [Model:field_to_iolist(Page)]}
> end.
>
> delete(A, Model, Id) ->
> diff -Naur erlyweb-0.6.1.orig/src/erlyweb/erlyweb_view.et erlyweb-0.6.1/src/erlyweb/erlyweb_view.et
> --- erlyweb-0.6.1.orig/src/erlyweb/erlyweb_view.et Sat Aug 11 23:02:58 2007
> +++ erlyweb-0.6.1/src/erlyweb/erlyweb_view.et Sat Aug 18 16:00:57 2007
> @@ -14,9 +14,10 @@
> %>
> <% Data %>
>
> -<%@ list({AppRoot, Model, Fields, Records}) %>
> +<%@ list({AppRoot, Model, PrevLink, NextLink, Fields, Records}) %>
> <% a([AppRoot, Model, <<"new">>], <<"create new">>) %><br><br>
> Records of '<% Model %>'<br/>
> +<% PrevLink(<<"Previous">>) %> <% NextLink(<<"Next">>) %>
> <% table(Records, Fields) %>
>
> <%@ new({_AppRoot, Model, _Id, Action, FieldData}) %>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Tue Aug 21, 2007 5:00 am |
|
|
|
Guest
|
Yariv Sadan wrote:
> Thanks!
>
Found a bug when adding new entries. This will teach me to do more
though testing. I should have read the id from saved record. ie,
in erlyweb_controller:new_or_edit(A, Model, Record)
Saved = Model:save(Record1),
io:format("~p:~p ~p:id(~p) ~p~n",
[?MODULE, ?LINE, Model, Saved, Model:id(Saved)]),
Page = (Model:id(Saved) - 1) div ?RECORDS_PER_PAGE + 1,
Oh well.
Jeff.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Tue Aug 21, 2007 5:14 pm |
|
|
|
Guest
|
The release I made last night didn't contain your patch, so I'll it to
the next version.
Yariv
> Found a bug when adding new entries. This will teach me to do more
> though testing. I should have read the id from saved record. ie,
> in erlyweb_controller:new_or_edit(A, Model, Record)
>
> Saved = Model:save(Record1),
> io:format("~p:~p ~p:id(~p) ~p~n",
> [?MODULE, ?LINE, Model, Saved, Model:id(Saved)]),
> Page = (Model:id(Saved) - 1) div ?RECORDS_PER_PAGE + 1,
>
>
> Oh well.
>
> Jeff.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---
Post recived from mailinglist |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|