[Rt-commit] rt branch, 4.2/cf-input-name-sub, repushed
? sunnavy
sunnavy at bestpractical.com
Sat Jan 4 19:51:47 EST 2014
The branch 4.2/cf-input-name-sub was deleted and repushed:
was 4f8a0edc2743eb1622dc9203506bd4aaf1c51a08
now 573fbee7aeedf4edadbf82b9433418af951a5e65
1: 4f8a0ed ! 1: 573fbee refactor cf input name and abstract a sub to get it
@@ -11,7 +11,16 @@
* the new sub mimics old naming convension for back compatibility.
* old $NamePrefix is still supported(if the new added arg $Name is not set)
- * ...-Values-Magic is widened to ...-Magic(so there will be ...-Value-Magic, ...-Upload-Magic, etc)
+ * ...-Values-Magic is widened to ...-Magic(so there will be ...-Value-Magic,
+ ...-Upload-Magic, etc because now we simply suffix "-Magic" to the input name)
+
+ this commit respects current inconsistent "-Value" vs "-Values" usage, but we
+ should fix it in the near futuer:
+
+ * cfs with single-value should be named as single "-Value" instead of "-Values"
+ e.g. Date, DateTime, single Select with render type "List" and maybe also
+ Text and WikiText
+ * upload cfs(Binary and Image) should be named as "-Uploads" if they are not single-valued.
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
--- a/lib/RT/Interface/Web.pm
@@ -20,9 +29,9 @@
return @rewritten;
}
-+=head2 GetCustomFieldInputName
-+
-+Returns the standard custom field input name.
++=head2 GetCustomFieldInputName(CustomField => $cf_object, Object => $object, Grouping => $grouping_name)
++
++Returns the standard custom field input name, which is complement to _ParseObjectCustomFieldArgs
+
+=cut
+
@@ -34,7 +43,8 @@
+ @_,
+ );
+
-+ my $name = join '-', 'Object', ref( $args{Object} ), ( $args{Object}->id || '' ),
++ my $name = join '-', 'Object', ref( $args{Object} ) || $args{CustomField}->ObjectTypeFromLookupType,
++ ( $args{Object} && $args{Object}->id ? $args{Object}->id : '' ),
+ 'CustomField' . ( $args{Grouping} ? ":$args{Grouping}" : '' ), $args{CustomField}->id;
+
+ if ( $args{CustomField}->Type eq 'Select' ) {
@@ -52,12 +62,12 @@
+ $name .= '-Values';
+ }
+ else {
-+ if ( $args{CustomField}->MaxValues != 1 ) {
++ if ( $args{CustomField}->SingleValue ) {
++ $name .= '-Value';
++ }
++ else {
+ $name .= '-Values';
+ }
-+ else {
-+ $name .= '-Value';
-+ }
+ }
+
+ return $name;
@@ -66,6 +76,14 @@
package HTML::Mason::Commands;
use vars qw/$r $m %session/;
+@@
+ foreach my $arg ( keys %$ARGSRef ) {
+
+ # format: Object-<object class>-<object id>-CustomField[:<grouping>]-<CF id>-<commands>
++ # you can use GetCustomFieldInputName to generate the complement input name
+ next unless $arg =~ /^Object-([\w:]+)-(\d*)-CustomField(?::(\w+))?-(\d+)-(.*)$/;
+
+ # For each of those objects, find out what custom fields we want to work with.
@@
# the browser gives you a blank value which causes CFs to be processed twice
if ( defined $args{'ARGS'}->{'Values'}
@@ -153,6 +171,7 @@
NamePrefix => $NamePrefix,
CustomField => $CustomField,
+ Name => $Name,
++ $CustomField->BasedOn && $Name ? ( BasedOnName => GetCustomFieldInputName(Object => $Object, CustomField => $CustomField->BasedOnObj, Grouping => $Grouping) ) : (),
);
</%INIT>
<%ARGS>
@@ -327,10 +346,10 @@
%#
%# END BPS TAGGED BLOCK }}}
-% my $name = $NamePrefix . $CustomField->Id . '-Value';
-+% my $name = $Name || $NamePrefix . $CustomField->Id . '-Value';
++% my $name = $Name || $NamePrefix . $CustomField->Id . ( $Multiple ? '-Values' : '-Value' );
% if ($Multiple) {
-<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>s" id="<%$name%>s" wrap="off" class="CF-<%$CustomField->id%>-Edit"><% defined($Default) ? $Default : '' %></textarea>
-+<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>" id="<%$name%>s" wrap="off" class="CF-<%$CustomField->id%>-Edit"><% defined($Default) ? $Default : '' %></textarea>
++<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>" id="<%$name%>" wrap="off" class="CF-<%$CustomField->id%>-Edit"><% defined($Default) ? $Default : '' %></textarea>
% } else {
<input name="<%$name%>" id="<%$name%>" size="<%$Cols%>" class="CF-<%$CustomField->id%>-Edit" value="<% defined($Default) ? $Default : ''%>" />
% }
@@ -389,18 +408,19 @@
% if (!$HideCategory and @category and not $CustomField->BasedOnObj->id) {
%# XXX - Hide this select from w3m?
- <select onchange="filter_cascade_by_id(<% "$id-Values" |n,j%>, this.value)" name="<% $id %>-Category" class="CF-<%$CustomField->id%>-Edit">
-+ <select onchange="filter_cascade_by_id("<% $name %>", this.value)" name="<% $name %>-Category" class="CF-<%$CustomField->id%>-Edit">
++ <select onchange="filter_cascade_by_id(<% $name |n,j %>, this.value)" name="<% $name %>-Category" class="CF-<%$CustomField->id%>-Edit">
<option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
% foreach my $cat (@category) {
% my ($depth, $name) = @$cat;
@@
+ % }
+ </select><br />
% } elsif ($CustomField->BasedOnObj->id) {
++
<script type="text/javascript"><!--
jQuery( function () {
- var basedon = jQuery('[name^="<% $NamePrefix . $CustomField->BasedOnObj->id %>-Value"][type!="hidden"]:input:not(.hidden)');
-+% my $based_on_input_prefix = $Name;
-+% $based_on_input_prefix =~ s!(?<=-CustomField-)(\d+).*!$CustomField->BasedOnObj->id!e;
-+ var basedon = jQuery('[name^="<% $based_on_input_prefix %>-Value"][type!="hidden"]:input:not(.hidden)');
++ var basedon = jQuery('[name^="<% $BasedOnName || $NamePrefix . $CustomField->BasedOnObj->id . '-Value' |n %>"][type!="hidden"]:input:not(.hidden)');
basedon.each( function() {
var oldchange = jQuery(this).onchange;
jQuery(this).change( function () {
@@ -409,7 +429,7 @@
}
filter_cascade_by_id(
- <% "$id-Values" |n,j%>,
-+ "<% $name %>",
++ <% $name |n,j%>,
vals,
true
);
@@ -457,6 +477,7 @@
$CustomField => undef
$NamePrefix => undef
+$Name => undef
++$BasedOnName => undef
@Default => ()
$Values => undef
$Multiple => 0
@@ -516,6 +537,36 @@
$Default => undef
$Values => undef
$MaxValues => undef
+
+diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
+--- a/share/html/Ticket/Create.html
++++ b/share/html/Ticket/Create.html
+@@
+ }
+
+ if ( @cf_values > 1 && $cf->Type eq 'Select' ) {
+- $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = \@cf_values;
++ $clone->{GetCustomFieldInputName( CustomField => $cf )} = \@cf_values;
+ }
+ else {
+- $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
++ $clone->{GetCustomFieldInputName( CustomField => $cf )} = join "\n",
+ @cf_values;
+ }
+ }
+
+diff --git a/share/html/m/ticket/create b/share/html/m/ticket/create
+--- a/share/html/m/ticket/create
++++ b/share/html/m/ticket/create
+@@
+ while ( my $cf_value = $cf_values->Next ) {
+ push @cf_values, $cf_value->Content;
+ }
+- $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
++ $clone->{GetCustomFieldInputName( CustomField => $cf )} = join "\n",
+ @cf_values;
+ }
+
diff --git a/t/web/cf_pattern.t b/t/web/cf_pattern.t
--- a/t/web/cf_pattern.t
More information about the rt-commit
mailing list