From 455556cc709f205cb63d42cfe941bb874f36c2f5 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 21 Jan 2009 02:02:09 +0000 Subject: [PATCH] fix (hopefully last of the) customize package bogosity in 1.9, RT#4662 --- httemplate/edit/elements/edit.html | 12 ++++---- httemplate/edit/part_pkg.cgi | 59 +++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 6c70d66e6..617855888 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -36,7 +36,7 @@ Example: #fixed - display fixed value from object or here #fixed-country #fixed-state - 'value' => 'Y', #for checkbox, title, fixed, fixedhidden + 'value' => 'Y', #for checkbox, title, fixed, hidden 'disabled' => 0, 'onchange' => 'javascript_function', @@ -107,7 +107,10 @@ Example: 'new_object_callback' #run when adding - 'new_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; }, + 'new_callback' => sub { my( $cgi, $object, $fields_listref, $optref ) = @_; }, + + #run when cloning + 'clone_callback' => sub { my( $cgi, $object, $fields_listref, $optref ) = @_; }, #run before display to return a different value 'value_callback' => sub { my( $columname, $value ) = @_; }, @@ -210,7 +213,7 @@ Example: % 'size' => $f->{'size'}, % 'maxlength' => $f->{'maxlength'}, % -% #checkbox, title, fixed, fixedhidden +% #checkbox, title, fixed, hidden % #& deprecated weird value hashref used only by reason.html % 'value' => $f->{'value'}, % @@ -592,8 +595,7 @@ if ( $cgi->param('error') ) { $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } }); - #XXX document me - &{$opt{'clone_callback'}}($cgi, $object, $fields) + &{$opt{'clone_callback'}}($cgi, $object, $fields, \%opt ) if $opt{'clone_callback'}; #$object->$pkey(''); diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index f79e759fa..6de0b3211 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -10,6 +10,7 @@ 'new_hashref_callback' => $new_hashref_callback, 'new_object_callback' => $new_object_callback, 'new_callback' => $new_callback, + 'clone_callback' => $clone_callback, 'edit_callback' => $edit_callback, 'error_callback' => $error_callback, @@ -193,8 +194,6 @@ my $taxproducts = $conf->exists('enable_taxproducts'); my @agent_type = (); my %tax_override = (); -my $clone_part_pkg = ''; - my %taxproductnums = map { ($_->classnum => 1) } qsearch('usage_class', { 'disabled' => '' }); @@ -227,7 +226,6 @@ my $error_callback = sub { $tax_override{$_} = $cgi->param('tax_override_$_') foreach(grep { /^tax_override_(\w+)$/ } $cgi->param); $opt->{action} = 'Custom' if $cgi->param('clone'); - $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } ); $recur_disabled = $cgi->param('freq') ? 0 : 1; @@ -255,21 +253,9 @@ my $new_hashref_callback = sub { { 'plan' => 'flat' }; }; my $new_object_callback = sub { my( $cgi, $hashref, $fields, $opt ) = @_; - my $part_pkg = ''; - if ( $cgi->param('clone') ) { - $opt->{action} = 'Custom'; - $clone_part_pkg = qsearchs('part_pkg', { pkgpart=>$cgi->param('clone') } ); - $part_pkg = $clone_part_pkg->clone; - $part_pkg->disabled('Y'); - %options = $clone_part_pkg->options; - $part_pkg->set($_ => $options{$_}) - foreach (qw( setup_fee recur_fee )); - $recur_disabled = $part_pkg->freq ? 0 : 1; - } else { - $part_pkg = FS::part_pkg->new( $hashref ); - $part_pkg->set($_ => '0') - foreach (qw( setup_fee recur_fee )); - } + my $part_pkg = FS::part_pkg->new( $hashref ); + $part_pkg->set($_ => '0') + foreach (qw( setup_fee recur_fee )); $part_pkg; @@ -313,6 +299,26 @@ my $new_callback = sub { }; +my $clone_callback = sub { + my( $cgi, $object, $fields, $opt ) = @_; + + $opt->{action} = 'Custom'; + + #my $part_pkg = $clone_part_pkg->clone; + #this is all clone did anyway + $object->comment( '(CUSTOM) '. $object->comment ) + unless $object->comment =~ /^\(CUSTOM\) /; + + $object->disabled('Y'); + + %options = $object->options; + + $object->set($_ => $options{$_}) + foreach (qw( setup_fee recur_fee )); + + $recur_disabled = $object->freq ? 0 : 1; +}; + my $m2_error_callback_maker = sub { my $link_type = shift; #yay closures return sub { @@ -486,11 +492,18 @@ my $html_bottom = sub { layer_callback => $layer_callback, ); - include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ). - ''; + my $return = + include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ). + ''; + + $return; }; -- 2.11.0