[ljcom] r11144: LJSUP-9901: Add ability to put entry fro...
Committer: anazarov
LJSUP-9901: Add ability to put entry from community to owner and maintainersU trunk/cgi-bin/LJ/Pay/SelfPromo.pm U trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm U trunk/htdocs/shop/selfpromo.bml.text.local U trunk/templates/Shop/SelfPromo.tmpl
Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm 2011-11-02 16:13:13 UTC (rev 11143)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm 2011-11-03 08:16:00 UTC (rev 11144)
@@ -285,6 +285,66 @@
return 1;
}
+sub poster_cancel_promo {
+ my ( $class, $entry ) = @_;
+
+ return unless $entry;
+
+ my $promo = $class->current_entry_info;
+ my $journal = $entry->journal;
+ my $poster = $entry->poster;
+
+ unless ( $promo
+ && $promo->journalid == $entry->journalid
+ && $promo->jitemid == $entry->jitemid )
+ {
+
+ # your princess is in another castle, sorry
+ return;
+ }
+
+
+ my $cart;
+ my $refund = $class->calculate_refund($promo);
+ my $promoter = $promo->promoter;
+
+ my $refund_remainder =
+ $refund % $LJ::SELF_PROMO_CONF->{'refund_step'};
+ my $refund_rounded = $refund - $refund_remainder;
+
+ my $remainder_to =
+ LJ::load_user( $LJ::SELF_PROMO_CONF->{'remainder_receiver'} );
+ my $remainder_userid = $remainder_to ? $remainder_to->userid : 0;
+
+ $cart = $class->create_shop_cart(
+ {
+ 'cart_owner' => $poster,
+ 'entry' => undef,
+ 'price' => 0,
+ 'profit' => 0,
+ 'rcptid' => $poster->userid,
+ 'refund' => $refund_rounded,
+ 'refund_userid' => $promoter->userid,
+ 'refund_promoid' => $promo->promoid,
+ 'remainder' => $refund_remainder,
+ 'remainder_userid' => $remainder_userid,
+ 'type' => 'poster_cancel',
+ }
+ );
+
+ $cart->set_method( LJ::Pay::Method::Free->code );
+ $cart->update( 'used' => 'N', 'mailed' => 'N' );
+ $cart->set_daterecv_epoch(time);
+
+ my ($item) = $cart->get_items;
+
+ $cart->update( 'used' => 'Y' );
+ $item->update( 'status' => 'pend' );
+ $item->deliver( $item->get_cart, time, sub { } );
+
+ return 1;
+}
+
sub withdraw_entry {
my ( $class, $entry ) = @_;
@@ -297,13 +357,6 @@
unless $promo->journalid == $entry->journalid
&& $promo->jitemid == $entry->jitemid;
- $class->deactivate_promo(
- $promo->promoid, $promoter,
- 'reason' => 'withdraw',
- 'entry' => $entry,
- 'entry_url' => $entry->url,
- );
-
$class->send_notification(
$promoter, 'deactivate',
'reason' => 'withdraw',
@@ -318,7 +371,22 @@
'entry_url' => $entry->url,
'duration' => $promo->exptime - $promo->started,
);
+
+ my $remote = LJ::get_remote();
+
+ # Poster cancels promo, need to pay refund to promoter
+ return $class->poster_cancel_promo($entry)
+ unless LJ::u_equals($remote, $promoter);
}
+
+ $class->deactivate_promo(
+ $promo->promoid, $promoter,
+ 'reason' => 'withdraw',
+ 'entry' => $entry,
+ 'entry_url' => $entry->url,
+ );
+
+ return 1;
}
sub current_entry {
Modified: trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm 2011-11-02 16:13:13 UTC (rev 11143)
+++ trunk/cgi-bin/LJ/Widget/Shop/View/SelfPromo.pm 2011-11-03 08:16:00 UTC (rev 11144)
@@ -30,6 +30,7 @@
my $ml_current_price = LJ::Lang::ml( '/shop/selfpromo.bml.current_price',
{ 'price' => $buyout_cost } );
my $hide_buyout = 0;
+ my $poster_cancel = 0;
my $data_selfpromo = LJ::PersonalStats->get_selfpromo_data;
foreach my $row (@$data_selfpromo) {
@@ -43,6 +44,7 @@
my $can_withdraw = LJ::u_equals($promo->promoter, $remote) || LJ::u_equals($promo->poster, $remote);
$hide_buyout = $can_withdraw;
$row->{'can_withdraw'} = $can_withdraw;
+ $poster_cancel = 1 if not LJ::u_equals($promo->promoter, $promo->poster) and LJ::u_equals($promo->poster, $remote);
# if for some reason the entry has already expired, this silently
# casts its remaining time to zero:
@@ -61,12 +63,14 @@
}
LJ::need_string('/shop/selfpromo.bml.confirm.delete.promoted');
+ LJ::need_string('/shop/selfpromo.bml.confirm.poster.cancel');
return {
'ml_current_price' => $ml_current_price,
'buyout_cost' => LJ::Request->post_param('price') || $buyout_cost,
'data_selfpromo' => $data_selfpromo,
'hide_buyout' => $hide_buyout,
+ 'poster_cancel' => $poster_cancel,
'form_disabled' => !$remote ? 1 : 0,
};
}
Modified: trunk/htdocs/shop/selfpromo.bml.text.local
===================================================================
--- trunk/htdocs/shop/selfpromo.bml.text.local 2011-11-02 16:13:13 UTC (rev 11143)
+++ trunk/htdocs/shop/selfpromo.bml.text.local 2011-11-03 08:16:00 UTC (rev 11144)
@@ -12,6 +12,8 @@
.confirm.delete.promoted=Your promo will be cancelled without a refund. Are you sure?
+.confirm.poster.cancel=Promo will be cancelled. Are you sure?
+
.current_price|staleness=1
.current_price=[[price]] [[?price|LJ Token|LJ Tokens|LJ Tokens]]
Modified: trunk/templates/Shop/SelfPromo.tmpl
===================================================================
--- trunk/templates/Shop/SelfPromo.tmpl 2011-11-02 16:13:13 UTC (rev 11143)
+++ trunk/templates/Shop/SelfPromo.tmpl 2011-11-03 08:16:00 UTC (rev 11144)
@@ -103,9 +103,15 @@
});
$('#selfpromo-withdraw-button').click(function(e) {
+ <TMPL_IF poster_cancel>
+ if (!confirm(Site.ml_text['/shop/selfpromo.bml.confirm.poster.cancel'])) {
+ return false;
+ }
+ <TMPL_ELSE>
if (!confirm(Site.ml_text['/shop/selfpromo.bml.confirm.delete.promoted'])) {
return false;
}
+ </TMPL_IF>
});
$("#selfpromo-preview-button").click(function(e) {
