[dw-free] Attach a note when transferring points
[commit: http://hg.dwscoalition.org/dw-free/rev/dd62b82c8a0c]
http://bugs.dwscoalition.org/show_bug.cgi?id=2866
Attach a note when transferring points; this will be sent in the email
notification.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2866
Attach a note when transferring points; this will be sent in the email
notification.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/en.dat
- cgi-bin/DW/Controller/Shop.pm
- views/shop/transferpoints.tt
- views/shop/transferpoints.tt.text
-------------------------------------------------------------------------------- diff -r c9fe0aa10ee5 -r dd62b82c8a0c bin/upgrading/en.dat --- a/bin/upgrading/en.dat Tue Sep 06 20:40:57 2011 +0800 +++ b/bin/upgrading/en.dat Tue Sep 06 21:04:34 2011 +0800 @@ -1374,10 +1374,20 @@ [[store]] +[[reason]] + Regards, The [[sitename]] Team . +esn.receivedpoints.reason<< +The following note was authored by the sender: + +[[reason]] + +-- +. + esn.receivedpoints.subject=You have received [[sitename]] Points! esn.receivedpoints.user.body<< @@ -1389,6 +1399,8 @@ [[store]] +[[reason]] + Regards, The [[sitename]] Team . diff -r c9fe0aa10ee5 -r dd62b82c8a0c cgi-bin/DW/Controller/Shop.pm --- a/cgi-bin/DW/Controller/Shop.pm Tue Sep 06 20:40:57 2011 +0800 +++ b/cgi-bin/DW/Controller/Shop.pm Tue Sep 06 21:04:34 2011 +0800 @@ -116,12 +116,17 @@ } } + # Note: DW::Shop::Item::Points->can_have_reason doesn't check args, + # but someone will suggest it do so in the future, so let's save time. + $rv->{can_have_reason} = $item->can_have_reason( user => $u, anon => $args->{anon} ); + } else { $errs{foruser} = LJ::Lang::ml( 'shop.item.points.canbeadded.itemerror' ); } - # copy down anon value + # copy down anon value and reason $rv->{anon} = $args->{anon} ? 1 : 0; + $rv->{reason} = LJ::strip_html( $args->{reason} ); # if this is a confirmation page, then confirm if there are no errors if ( $args->{confirm} && ! scalar keys %errs ) { @@ -129,14 +134,18 @@ $u->give_shop_points( amount => $points, reason => sprintf( 'transfer from %s(%d)', $remote->user, $remote->id ) ); $remote->give_shop_points( amount => -$points, reason => sprintf( 'transfer to %s(%d)', $u->user, $u->id ) ); + my $get_text = sub { LJ::Lang::get_text( $u->prop( 'browselang' ), $_[0], undef, $_[1] ) }; + # send notification ... my $e = $rv->{anon} ? 'anon' : 'user'; - my $body = LJ::Lang::get_text( $u->prop( 'browselang' ), "esn.receivedpoints.$e.body", undef, { + my $reason = ( $rv->{reason} && $rv->{can_have_reason} ) ? $get_text->( "esn.receivedpoints.reason", { reason => $rv->{reason} } ) : ''; + my $body = $get_text->( "esn.receivedpoints.$e.body", { user => $u->display_username, points => $points, from => $remote->display_username, sitename => $LJ::SITENAMESHORT, store => "$LJ::SITEROOT/shop/", + reason => $reason, } ); # FIXME: esnify the notification @@ -144,7 +153,7 @@ to => $u->email_raw, from => $LJ::ACCOUNTS_EMAIL, fromname => $LJ::SITENAME, - subject => LJ::Lang::get_text( $u->prop( 'browselang' ), 'esn.receivedpoints.subject', undef, { sitename => $LJ::SITENAMESHORT } ), + subject => $get_text->( 'esn.receivedpoints.subject', { sitename => $LJ::SITENAMESHORT } ), body => $body, } ); @@ -155,7 +164,7 @@ } elsif ( ! scalar keys %errs ) { $rv->{confirm} = 1; } - + } else { if ( my $for = $r->get_args->{for} ) { $rv->{foru} = LJ::load_user( $for ); @@ -165,6 +174,8 @@ $rv->{points} = $points+0 if $points > 0 && $points <= 5000; } + + $rv->{can_have_reason} = DW::Shop::Item::Points->can_have_reason; } return DW::Template->render_template( 'shop/transferpoints.tt', $rv ); @@ -213,7 +224,7 @@ $rv->{cart}->add_item( $item ); return $r->redirect( "$LJ::SITEROOT/shop" ); } - + } else { my $for = $r->get_args->{for}; diff -r c9fe0aa10ee5 -r dd62b82c8a0c views/shop/transferpoints.tt --- a/views/shop/transferpoints.tt Tue Sep 06 20:40:57 2011 +0800 +++ b/views/shop/transferpoints.tt Tue Sep 06 21:04:34 2011 +0800 @@ -16,12 +16,20 @@ ELSE; '.request.user' | ml(points = points, user = foru.ljuser_display, name=foru.name_html); END %]</p> + [% IF reason %] + [% IF can_have_reason %] + <p>[% '.note.y' | ml %]</p><q>[% reason | html_para %]</q> + [% ELSE %] + <p>[% '.note.n' | ml %]</p> + [% END %] + [% END %] <p>[% '.confirm2' | ml %]</p> <form method='post'> [% dw.form_auth %] <input type='hidden' name='foruser' value='[% foru.user %]' /> <input type='hidden' name='points' value='[% points %]' /> + <input type='hidden' name='reason' value="[% reason | html %]" /> <input type='hidden' name='anon' value='[% anon %]' /> <input type='hidden' name='confirm' value='1' /> <input type='submit' value='[% '.btn.confirm' | ml %]' /> @@ -46,13 +54,18 @@ </td></tr> [% ELSE %] <tr><td>[% '.buying.for' | ml %]</td><td><input type='text' name='foruser' maxlength='25' size='15' /> - [% IF errs.foruser %]<br /><strong>[% errs.foruser %][% END %] + [% IF errs.foruser %]<br /><strong>[% errs.foruser %]</strong>[% END %] </td></tr> [% END %] <tr><td>[% '.buying.points' | ml %]</td><td><input type='text' name='points' id='points' maxlength='4' size='10' value='[% points %]' /> [% '.buying.points.range' | ml %] - [% IF errs.points %]<br /><strong>[% errs.points %][% END %] + [% IF errs.points %]<br /><strong>[% errs.points %]</strong>[% END %] </td></tr> + [% IF can_have_reason %] + <tr><td>[% '.buying.note' | ml %]</td><td> + [% form.textarea(name = 'reason', rows = '6', cols = '60', wrap = 'soft') %] + </td></tr> + [% END %] <tr><td></td><td><input type='checkbox' name='anon' id='anon'> <label for='anon'>[% '.anon' | ml %]</label></td></tr> <tr><td></td><td><input type='submit' value='[% '.btn.transfer' | ml %]' /></td></tr> </table> diff -r c9fe0aa10ee5 -r dd62b82c8a0c views/shop/transferpoints.tt.text --- a/views/shop/transferpoints.tt.text Tue Sep 06 20:40:57 2011 +0800 +++ b/views/shop/transferpoints.tt.text Tue Sep 06 21:04:34 2011 +0800 @@ -13,12 +13,18 @@ .buying.for=Transfer To: +.buying.note=Note (Optional): + .buying.points=Points to Transfer: .buying.points.range=(1 to 5,000 points) .confirm2=If you are sure you wish to do this, please click the button below. +.note.n=The ability to send a note is not allowed for this transaction. + +.note.y=The following note will be sent to the recipient: + .request.anon=You have requested to anonymously transfer [[points]] [[?points|point|points]] to [[name]] ([[user]]). They will not know the points came from you. .request.user=You have requested to transfer [[points]] [[?points|point|points]] to [[name]] ([[user]]). --------------------------------------------------------------------------------