X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Felements%2Ftr-select-reason.html;h=9a430222c8b6ffe5ae0b39b46918a1253dda4e04;hp=6c66e81706b12651d78381e55911a3ca35a09c2d;hb=ff27c3f36240aee48ed50153dd5d8fe3ac3f2443;hpb=ce98306f315a53f2ac4b8c010341c4f84bf728a8 diff --git a/httemplate/elements/tr-select-reason.html b/httemplate/elements/tr-select-reason.html index 6c66e8170..9a430222c 100755 --- a/httemplate/elements/tr-select-reason.html +++ b/httemplate/elements/tr-select-reason.html @@ -1,94 +1,214 @@ +<%doc> +Example: + + include( '/elements/tr-select-reason.html', + + #required + 'field' => 'reasonnum', + 'reason_class' => 'C', # one of those in %FS::reason_type::class_name + + #recommended + 'cgi' => $cgi, #easiest way for things to be properly "sticky" on errors + + #optional + 'control_button' => 'element_name', #button to be enabled when a reason is + #selected + 'id' => 'element_id', + + #deprecated ways to keep things "sticky" on errors + # (requires duplicate code in each using file to parse cgi params) + 'curr_value' => $curr_value, + 'curr_value' => { + 'typenum' => $typenum, + 'reason' => $reason, + }, + + ) + + + +% # note style improvements. +% # - no more conditionally included code here +% # - callers are not expected to pass javascript fragments +% # - no redundant checking of ACLs or parameters +% # - form fields are grouped for easy management +% # - use the standard select-table widget instead of ad hoc crap +<& /elements/xmlhttp.html, + url => $p . 'misc/xmlhttp-reason-hint.html', + subs => [ 'get_hint' ], +&> - - Reason - - - - +%# sadly can't just use add_inline here, as we have non-text fields +<& tr-select-table.html, + 'label' => 'Reason', + 'field' => $name, + 'id' => $id, + 'table' => 'reason', + 'records' => \@reasons, + 'label_callback' => sub { my $reason = shift; + $reason->type . ' : ' . $reason->reason }, + 'disable_empty' => 1, + 'pre_options' => [ 0 => 'Select reason...' ], + 'post_options' => \@post_options, + 'curr_value' => $init_reason, + 'onchange' => $id.'_changed()', +&> - - -

Reason Type

- - - - - +% # "add new reason" fields +% # should be a
, but that doesn't fit well into the table + +% if ( $curuser->access_right($add_access_right) ) { + + + + <& tr-input-text.html, + label => 'New reason', + field => $id.'_new_reason' + &> + +% my @types = qsearch( 'reason_type', { 'class' => $class } ); +% if (scalar(@types) < 1) { # we should never reach this + + + +% } elsif (scalar(@types) == 1) { + <& tr-fixed.html, + label => 'Reason type', + field => $id.'_new_reason_type', + curr_value => $types[0]->typenum, + formatted_value => $types[0]->type, + &> +% } else { # more than one type, the normal case + <& tr-select-table.html, + label => 'Reason type', + field => $id.'_new_reason_type', + table => 'reason_type', + name_col => 'type', + hashref => { 'class' => $class }, + disable_empty => 1, + &> +% } # scalar(@types) + +% if ( $class eq 'C' ) { + <& tr-checkbox.html, + label => 'Credit the unused portion of service when canceling', + field => $id.'_new_unused_credit', + value => 'Y' + &> +% } +% if ( $class eq 'S' ) { + <& tr-checkbox.html, + label => 'Credit the unused portion of service when suspending', + field => $id.'_new_unused_credit', + value => 'Y' + &> + <& tr-select-table.html, + label => 'Charge a suspension fee', + field => $id.'_new_feepart', + table => 'part_fee', + hashref => { disabled => '' }, + name_col => 'itemdesc', + value_col => 'feepart', + empty_label => 'none', + &> + <& tr-select.html, + label => 'When this package is', + field => $id.'_new_fee_on_unsuspend', + options => [ '', 'Y' ], + labels => { '' => 'suspended', 'Y' => 'unsuspended' }, + &> + <& tr-checkbox.html, + label => 'Delay fee until the next bill', + field => $id.'_new_fee_hold', + value => 'Y', + &> +%# deprecated, but still accessible through the "Suspend Reasons" UI +%# <& tr-select-part_pkg.html, +%# label => 'Charge this fee when unsuspending', +%# field => $id.'_new_unsuspend_pkgpart', +%# hashref => { disabled => '', freq => '0' }, +%# empty_label => 'none', +%# &> +%# <& tr-checkbox.html, +%# label => 'Hold unsuspension fee until the next bill', +%# field => $id.'_new_unsuspend_hold', +%# value => 'Y', +%# &> +% } +
+

<% mt('No reason types. Please add some.') |h %>

+
+ + +% } # if the current user can add a reason + +% # container for hints (hints themselves come from xmlhttp-reason-hint) - -

New Reason

+ - <%init> -my($name, $class, $init_reason, $init_type, $init_newreason) = @_; -my($extra_sql, $curuser, $access_right, $display, $disabled); - -if ($class eq 'C') { - $access_right='Add on-the-fly cancel reason'; -}elsif ($class eq 'S') { - $access_right='Add on-the-fly suspend reason'; -}else{ - print "illegal class: $class"; -} -if ($init_reason == -1){ - $display = 'inline'; - $disabled = 'false'; -}else{ - $display = 'none'; - $disabled = 'true'; +my $curuser = $FS::CurrentUser::CurrentUser; +my %opt = @_; + +my $name = $opt{'field'}; +my $class = $opt{'reason_class'}; + +my $init_reason; +if ( $opt{'cgi'} ) { + $init_reason = $opt{'cgi'}->param($name); } +$init_reason ||= $opt{'curr_value'}; -$extra_sql = "WHERE class = '$class' ORDER BY reason_type"; -$curuser = $FS::CurrentUser::CurrentUser; +my $id = $opt{'id'} || $name; +$id =~ s/\./_/g; # for edit/part_event - +my $add_access_right = $FS::reason_type::class_add_access_right{$class} + or die "unknown class: $class"; + +my @reasons = qsearch({ + 'table' => 'reason', + 'addl_from' => ' LEFT JOIN reason_type'. + ' ON (reason.reason_type = reason_type.typenum)', + 'hashref' => { disabled => '' }, + 'extra_sql' => " AND reason_type.class = '$class'", + 'order_by' => ' ORDER BY type, reason', +}); +my @post_options; +if ( $curuser->access_right($add_access_right) ) { + @post_options = ( -1 => 'Add new reason' ); +} + +