Committer: nnikulochkina
LJSUP-12917: Add RESERVED and INCOMING tabs to user wallet pageU trunk/cgi-bin/LJ/Widget/Shop/History.pm U trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm U trunk/cgi-bin/LJ/Widget/Shop.pm U trunk/templates/Shop/History.tmpl U trunk/templates/Shop/Wallet.tmpl
Modified: trunk/cgi-bin/LJ/Widget/Shop/History.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/Shop/History.pm 2012-07-18 10:16:25 UTC (rev 12306) +++ trunk/cgi-bin/LJ/Widget/Shop/History.pm 2012-07-18 13:22:23 UTC (rev 12307) @@ -16,66 +16,6 @@ sub get_template_file { 'History' } sub show_right_sidebar { 0 } -# TODO: refactor this chunk of code somewhere else? ratings -# also use this type of pagination, so it may be pretty useful -sub paging_params { - my ( $self, %args ) = @_; - - my $prefix = $args{'param_prefix'}; - my $pagenum = $args{'pagenum'}; - my $pagecount = $args{'pagecount'}; - my $cb_page_link = $args{'cb_page_link'}; - - return () unless $pagecount > 1; - - my %ret = ( "${prefix}show_paging" => 1 ); - - if ( $pagenum > 1 ) { - $ret{"${prefix}previous_page"} = $cb_page_link->( $pagenum - 1 ); - } - - if ( $pagenum < $pagecount ) { - $ret{"${prefix}next_page"} = $cb_page_link->( $pagenum + 1 ); - } - - my $start_page = $pagenum - 1; - if ( $start_page <= 2 ) { - $start_page = 1; - } else { - $ret{"${prefix}first_page"} = $cb_page_link->(1); - } - - my $end_page = $pagenum + 1; - if ( $end_page >= $pagecount - 1 ) { - $end_page = $pagecount; - } else { - $ret{"${prefix}last_page"} = $cb_page_link->($pagecount); - $ret{"${prefix}last_page_num"} = $pagecount; - } - - if ( $end_page - $start_page <= 1 ) { - if ( $start_page > 1 ) { - $start_page--; - } - - if ( $end_page < $pagecount ) { - $end_page++; - } - } - - my @pages_display; - foreach my $page ( $start_page .. $end_page ) { - push @pages_display, { - 'page_num' => $page, - 'page_link' => $cb_page_link->($page), - 'page_current' => ( $page == $pagenum ), - }; - } - $ret{"${prefix}pages"} = \@pages_display; - - return %ret; -} - sub get_orders_history { my ($self) = @_; @@ -152,7 +92,6 @@ } my %paging_params = $self->paging_params( - 'param_prefix' => 'orders_', 'pagenum' => $pagenum, 'pagecount' => $pagecount, 'cb_page_link' => sub { @@ -369,7 +308,6 @@ } my %paging_params = $self->paging_params( - 'param_prefix' => 'wallet_', 'pagenum' => $pagenum, 'pagecount' => $pagecount, 'cb_page_link' => sub { Modified: trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm 2012-07-18 10:16:25 UTC (rev 12306) +++ trunk/cgi-bin/LJ/Widget/Shop/View/Wallet.pm 2012-07-18 13:22:23 UTC (rev 12307) @@ -16,6 +16,8 @@ sub require_remote { 1 } sub require_cart { 1 } +use constant PAGE_SIZE => 5; + sub get_page_params { my ($self) = @_; @@ -119,22 +121,53 @@ $show_tab = 'buy' unless $free_tokens_status; } - my ($blockings, $accounts); + my ($blockings, $accounts, %paging_params); my ($total_blocked, $total_balance); if ($show_tab =~ /incoming/) { - my $res = eval{LJ::Pay::Wallet::Blocking->get_incoming_blockings($remote)}; + my $pagenum = int( LJ::Request->get_param('page') || 1 ); + + my $res = eval{LJ::Pay::Wallet::Blocking->get_incoming_blockings( + $remote, + pagesize => PAGE_SIZE, + pagenum => $pagenum, + )}; + $blockings = $res->{items} if $res; + + %paging_params = $self->paging_params( + 'pagenum' => $pagenum, + 'pagecount' => $res->{pagecount}, + 'cb_page_link' => sub { + my ($page) = @_; + return "$LJ::SITEROOT/shop/tokens.bml?show=incoming&page=$page"; + }, + ); } if ($show_tab =~ /reserved/) { - my $res = eval{LJ::Pay::Wallet::Account->get_user_active_accounts($remote)}; + my $pagenum = int( LJ::Request->get_param('page') || 1 ); + + my $res = eval{LJ::Pay::Wallet::Account->get_user_active_accounts( + $remote, + pagesize => PAGE_SIZE, + pagenum => $pagenum, + )}; $accounts = $res->{items} if $res; + ($total_blocked, $total_balance) = ($res->{total_blocked}, $res->{total_balance}); + + %paging_params = $self->paging_params( + 'pagenum' => $pagenum, + 'pagecount' => $res->{pagecount}, + 'cb_page_link' => sub { + my ($page) = @_; + return "$LJ::SITEROOT/shop/tokens.bml?show=reserved&page=$page"; + }, + ); } - # reserved my $transac_id = 0; my $sid = $LJ::FREE_TOKENS->{'freetopay'}->{'sid'}; @@ -163,6 +196,7 @@ 'total_blocked' => $total_blocked, 'total_balance' => $total_balance, 'accounts' => $accounts, + %paging_params, 'tab_buy_active' => $show_tab eq 'buy', 'tab_send_active' => $show_tab eq 'send', Modified: trunk/cgi-bin/LJ/Widget/Shop.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/Shop.pm 2012-07-18 10:16:25 UTC (rev 12306) +++ trunk/cgi-bin/LJ/Widget/Shop.pm 2012-07-18 13:22:23 UTC (rev 12307) @@ -450,8 +450,6 @@ with the GET parameters and either a) redirect the user to another page, or b) die to indicate the error happened. -=back - =cut sub get_page_params { @@ -463,6 +461,76 @@ my ($self) = @_; } +=item * + +paging_params: calculate paging params + +=back + +=cut + +# This function was moved from LJ::Shop::History + +# TODO: refactor this chunk of code somewhere else? ratings +# also use this type of pagination, so it may be pretty useful +sub paging_params { + my ( $self, %args ) = @_; + + my $prefix = $args{'param_prefix'} || ''; + my $pagenum = $args{'pagenum'}; + my $pagecount = $args{'pagecount'}; + my $cb_page_link = $args{'cb_page_link'}; + + return () unless $pagecount > 1; + + my %ret = ( "${prefix}show_paging" => 1 ); + + if ( $pagenum > 1 ) { + $ret{"${prefix}previous_page"} = $cb_page_link->( $pagenum - 1 ); + } + + if ( $pagenum < $pagecount ) { + $ret{"${prefix}next_page"} = $cb_page_link->( $pagenum + 1 ); + } + + my $start_page = $pagenum - 1; + if ( $start_page <= 2 ) { + $start_page = 1; + } else { + $ret{"${prefix}first_page"} = $cb_page_link->(1); + } + + my $end_page = $pagenum + 1; + if ( $end_page >= $pagecount - 1 ) { + $end_page = $pagecount; + } else { + $ret{"${prefix}last_page"} = $cb_page_link->($pagecount); + $ret{"${prefix}last_page_num"} = $pagecount; + } + + if ( $end_page - $start_page <= 1 ) { + if ( $start_page > 1 ) { + $start_page--; + } + + if ( $end_page < $pagecount ) { + $end_page++; + } + } + + my @pages_display; + foreach my $page ( $start_page .. $end_page ) { + push @pages_display, { + 'page_num' => $page, + 'page_link' => $cb_page_link->($page), + 'page_current' => ( $page == $pagenum ), + }; + } + $ret{"${prefix}pages"} = \@pages_display; + + return %ret; +} + =head2 Final ones =over 2 Modified: trunk/templates/Shop/History.tmpl =================================================================== --- trunk/templates/Shop/History.tmpl 2012-07-18 10:16:25 UTC (rev 12306) +++ trunk/templates/Shop/History.tmpl 2012-07-18 13:22:23 UTC (rev 12307) @@ -41,37 +41,7 @@ </TMPL_LOOP> </table> - <TMPL_IF orders_show_paging> - <p class="b-history-paging"> - <span><TMPL_VAR expr="ml('shop.history.paging.title')"></span> - - <TMPL_IF orders_previous_page> - <a href="<TMPL_VAR orders_previous_page ESCAPE=HTML>" class="b-history-paging-prev"><TMPL_VAR expr="ml('shop.history.paging.previous')"></a> - </TMPL_IF> - - <TMPL_IF orders_first_page> - <a href="<TMPL_VAR orders_first_page ESCAPE=HTML>" class="b-history-paging-counter">1</a> - … - </TMPL_IF> - - <TMPL_LOOP orders_pages> - <TMPL_IF page_current> - <strong><TMPL_VAR page_num></strong> - <TMPL_ELSE> - <a href="<TMPL_VAR page_link ESCAPE=HTML>" class="b-history-paging-counter"><TMPL_VAR page_num></a> - </TMPL_IF> - </TMPL_LOOP> - - <TMPL_IF orders_last_page> - … - <a href="<TMPL_VAR orders_last_page ESCAPE=HTML>" class="b-history-paging-counter"><TMPL_VAR orders_last_page_num></a> - </TMPL_IF> - - <TMPL_IF orders_next_page> - <a href="<TMPL_VAR orders_next_page ESCAPE=HTML>" class="b-history-paging-next"><TMPL_VAR expr="ml('shop.history.paging.next')"></a> - </TMPL_IF> - </p> - </TMPL_IF> + <TMPL_INCLUDE 'Paging.tmpl'> </div> <TMPL_IF name="tab_wallet_active"> <div id="tab_wallet" class="b-payment-history-wallet"> @@ -96,37 +66,7 @@ </tr> </TMPL_LOOP> </table> - <TMPL_IF wallet_show_paging> - <p class="b-history-paging"> - <span><TMPL_VAR expr="ml('shop.history.paging.title')"></span> - - <TMPL_IF wallet_previous_page> - <a href="<TMPL_VAR wallet_previous_page ESCAPE=HTML>" class="b-history-paging-prev"><TMPL_VAR expr="ml('shop.history.paging.previous')"></a> - </TMPL_IF> - - <TMPL_IF wallet_first_page> - <a href="<TMPL_VAR wallet_first_page ESCAPE=HTML>" class="b-history-paging-counter">1</a> - … - </TMPL_IF> - - <TMPL_LOOP wallet_pages> - <TMPL_IF page_current> - <strong><TMPL_VAR page_num></strong> - <TMPL_ELSE> - <a href="<TMPL_VAR page_link ESCAPE=HTML>" class="b-history-paging-counter"><TMPL_VAR page_num></a> - </TMPL_IF> - </TMPL_LOOP> - - <TMPL_IF wallet_last_page> - … - <a href="<TMPL_VAR wallet_last_page ESCAPE=HTML>" class="b-history-paging-counter"><TMPL_VAR wallet_last_page_num></a> - </TMPL_IF> - - <TMPL_IF wallet_next_page> - <a href="<TMPL_VAR wallet_next_page ESCAPE=HTML>" class="b-history-paging-next"><TMPL_VAR expr="ml('shop.history.paging.next')"></a> - </TMPL_IF> - </p> - </TMPL_IF> + <TMPL_INCLUDE 'Paging.tmpl'> </div> <TMPL_IF name="tab_loyalty_active"> <div id="tab_loyalty" class="b-payment-history-loyalty"> Modified: trunk/templates/Shop/Wallet.tmpl =================================================================== --- trunk/templates/Shop/Wallet.tmpl 2012-07-18 10:16:25 UTC (rev 12306) +++ trunk/templates/Shop/Wallet.tmpl 2012-07-18 13:22:23 UTC (rev 12307) @@ -36,20 +36,22 @@ <TMPL_VAR expr="ml('wallet.bml.landing.tab.send')"> </a> </li> + <TMPL_UNLESS wallet_ext_disabled> <li class="m-buy-types-item - <TMPL_IF tab_send_active> current</TMPL_IF> + <TMPL_IF tab_reserved_active> current</TMPL_IF> "> <a href="<TMPL_VAR self_uri>?show=reserved"> <TMPL_VAR expr="ml('wallet.bml.landing.tab.reserved')"> </a> </li> <li class="m-buy-types-item - <TMPL_IF tab_send_active> current</TMPL_IF> + <TMPL_IF tab_incoming_active> current</TMPL_IF> "> <a href="<TMPL_VAR self_uri>?show=incoming"> <TMPL_VAR expr="ml('wallet.bml.landing.tab.incoming')"> </a> </li> + </TMPL_IF> <TMPL_IF free_tokens_enabled> <li class="m-buy-types-item last <TMPL_IF tab_tokens_free> current</TMPL_IF> @@ -125,43 +127,44 @@ </fieldset> </form> </li> - <TMPL_IF tab_reserved_active> - <li class="<TMPL_IF tab_send_active> current</TMPL_IF>"> - <form action="" method="post" id="shop_reserved_token"> - <table class="b-tokens-reserved b-tokens-items"> - <tr> - <th> - <tmpl_var expr="ml('wallet.bml.reserved.subject')"> - <p><tmpl_var expr="ml('wallet.bml.reserved.reservation')"></p> - </th> - <th> - <tmpl_var expr="ml('wallet.bml.reserved.blocked')"> - <p><tmpl_var expr="ml('wallet.bml.reserved.tokens')"></p> - </th> - <th> - <tmpl_var expr="ml('wallet.bml.reserved.balance')"> - <p><tmpl_var expr="ml('wallet.bml.reserved.tokens')"></p> - </th> - </tr> - <TMPL_LOOP accounts> - <tr <TMPL_IF __odd__> class="odd" </TMPL_IF>> - <td class="b-tokens-items-subject"><input type="checkbox" /><tmpl_var desc></td> - <td class="b-tokens-items-amount"><tmpl_var blocked></td> - <td class="b-tokens-items-amount"><tmpl_var balance></td> - </tr> - </TMPL_LOOP> - <tr class="b-shop-tokens-total"> - <td class="b-tokens-items-button"><input type="submit" value="<tmpl_var expr="ml('wallet.bml.reserved.takeoff')">" class="b-input-tokens-total" /> <strong><tmpl_var expr="ml('wallet.bml.reserved.total')"></strong></td> - <td class="b-tokens-items-amount"><tmpl_var total_blocked></td> - <td class="b-tokens-items-amount"><tmpl_var total_balance></td> - </tr> - </table> - </form> - </li> - </TMPL_IF> <TMPL_UNLESS wallet_ext_disabled> + <TMPL_IF tab_reserved_active> + <li class="current"> + <form action="" method="post" id="shop_reserved_token"> + <table class="b-tokens-reserved b-tokens-items"> + <tr> + <th> + <tmpl_var expr="ml('wallet.bml.reserved.subject')"> + <p><tmpl_var expr="ml('wallet.bml.reserved.reservation')"></p> + </th> + <th> + <tmpl_var expr="ml('wallet.bml.reserved.blocked')"> + <p><tmpl_var expr="ml('wallet.bml.reserved.tokens')"></p> + </th> + <th> + <tmpl_var expr="ml('wallet.bml.reserved.balance')"> + <p><tmpl_var expr="ml('wallet.bml.reserved.tokens')"></p> + </th> + </tr> + <TMPL_LOOP accounts> + <tr <TMPL_IF __odd__> class="odd" </TMPL_IF>> + <td class="b-tokens-items-subject"><input type="checkbox" /><tmpl_var desc></td> + <td class="b-tokens-items-amount"><tmpl_var blocked></td> + <td class="b-tokens-items-amount"><tmpl_var balance></td> + </tr> + </TMPL_LOOP> + <tr class="b-shop-tokens-total"> + <td class="b-tokens-items-button"><input type="submit" value="<tmpl_var expr="ml('wallet.bml.reserved.takeoff')">" class="b-input-tokens-total" /> <strong><tmpl_var expr="ml('wallet.bml.reserved.total')"></strong></td> + <td class="b-tokens-items-amount"><tmpl_var total_blocked></td> + <td class="b-tokens-items-amount"><tmpl_var total_balance></td> + </tr> + </table> + </form> + </li> + <TMPL_INCLUDE 'Paging.tmpl'> + </TMPL_IF> <TMPL_IF tab_incoming_active> - <li class="<TMPL_IF tab_send_active> current</TMPL_IF>"> + <li class=" current"> <form action="" method="post" id="shop_incoming_token"> <table class="b-tokens-incoming b-tokens-items"> <tr> @@ -183,6 +186,7 @@ <div class="b-buy-total"></div> </form> </li> + <TMPL_INCLUDE 'Paging.tmpl'> </TMPL_IF> </TMPL_UNLESS> <TMPL_IF free_tokens_enabled>