[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.5-144-gbd623f7

Alex M Vandiver alexmv at bestpractical.com
Fri Sep 25 14:05:01 EDT 2009


The branch, 3.8-trunk has been updated
       via  bd623f761cb921ed6fa3be9ad44cf34b910c1464 (commit)
       via  7e430d0d46394bc0482a3db1f54a50d9d1334d09 (commit)
       via  fd95bc993fb71079c60b823f190cfc23a953d460 (commit)
       via  addb5821719c29056fd95b05b6ff0ca27774580e (commit)
       via  8f25aa7ff98e235a9c551dd9a0acae1ae998e567 (commit)
       via  a4316f96d2df88053da3284cf729ce300db5b59a (commit)
       via  93c87efa9e1347aea6c60a20b0e3bcaaa757990a (commit)
       via  1df624d927e81c066637b1d698adcab117eaed59 (commit)
       via  9006e7a0ea92c0775b7425bf931c7a81f100001b (commit)
       via  0c0a64fb608535820ce693b5fe326f3e3f986f14 (commit)
       via  9ba7d4c4f978d5689c7810bbfc90ee2c092129f1 (commit)
      from  6ec681b2b01c7fdf6fcdb20ee4f7fc42b316c26a (commit)

Summary of changes:
 etc/upgrade/split-out-cf-categories.pl             |  115 ++++++++++++++++++++
 lib/RT/CustomField_Overlay.pm                      |   45 ++++++++
 share/html/Admin/CustomFields/Modify.html          |   17 +++-
 share/html/Admin/Elements/AddCustomFieldValue      |   14 +++-
 share/html/Admin/Elements/EditCustomFieldValues    |   20 +++-
 .../Refresh => Admin/Elements/SelectCustomField}   |   30 +++---
 share/html/Elements/EditCustomFieldSelect          |   58 ++++++----
 share/html/NoAuth/js/cascaded.js                   |    9 ++-
 8 files changed, 266 insertions(+), 42 deletions(-)
 create mode 100644 etc/upgrade/split-out-cf-categories.pl
 copy share/html/{Elements/Refresh => Admin/Elements/SelectCustomField} (73%)
 mode change 100755 => 100644

- Log -----------------------------------------------------------------
commit bd623f761cb921ed6fa3be9ad44cf34b910c1464
Merge: 6ec681b 7e430d0
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Sep 25 14:04:30 2009 -0400

    Merge branch 'hierarchical-cf' into 3.8-trunk

diff --cc etc/upgrade/split-out-cf-categories.pl
index 0000000,27cb6d3..dd2b74d
mode 000000,100644..100644
--- a/etc/upgrade/split-out-cf-categories.pl
+++ b/etc/upgrade/split-out-cf-categories.pl
@@@ -1,0 -1,115 +1,115 @@@
+ #!/usr/bin/perl
+ 
+ use strict;
+ use warnings;
+ 
+ use RT;
+ RT::LoadConfig();
+ RT->Config->Set('LogToScreen' => 'debug');
+ RT::Init();
+ 
+ $| = 1;
+ 
+ $RT::Handle->BeginTransaction();
+ 
+ use RT::CustomFields;
+ my $CFs = RT::CustomFields->new( $RT::SystemUser );
+ $CFs->UnLimit;
+ $CFs->Limit( FIELD => 'Type', VALUE => 'Select' );
+ 
+ while (my $cf  = $CFs->Next ) {
+     next if $cf->BasedOnObj->Id;
+     my @categories;
+     my %mapping;
+     my $values = $cf->Values;
+     while (my $value = $values->Next) {
+         next unless defined $value->Category and length $value->Category;
+         push @categories, $value->Category unless grep {$_ eq $value->Category} @categories;
+         $mapping{$value->Name} = $value->Category;
+     }
+     next unless @categories;
+ 
+     print "Found CF '@{[$cf->Name]}' with categories:\n";
+     print "  $_\n" for @categories;
+ 
+     print "Enter name of CF to create as category ('@{[$cf->Name]} category'): ";
+     my $newname = <>;
+     chomp $newname;
+     $newname = $cf->Name . " category" unless length $newname;
+ 
+     # bump the CF's sort oder up by one
+     $cf->SetSortOrder( ($cf->SortOrder || 0) + 1 );
+ 
+     # ..and add a new CF before it
+     my $new = RT::CustomField->new( $RT::SystemUser );
+     my ($id, $msg) = $new->Create(
+         Name => $newname,
+         Type => 'Select',
+         MaxValues => 1,
+         LookupType => $cf->LookupType,
+         SortOrder => $cf->SortOrder - 1,
+     );
+     die "Can't create custom field '$newname': $msg" unless $id;
+ 
+     # Set the CF to be based on what we just made
+     $cf->SetBasedOn( $new->Id );
+ 
+     # Apply it to all of the same things
+     {
+         my $ocfs = RT::ObjectCustomFields->new( $RT::SystemUser );
 -        $ocfs->LimitToCustomField( $cf->Id );    
++        $ocfs->LimitToCustomField( $cf->Id );
+         while (my $ocf = $ocfs->Next) {
+             my $newocf = RT::ObjectCustomField->new( $RT::SystemUser );
+             ($id, $msg) = $newocf->Create(
+                 SortOrder => $ocf->SortOrder,
+                 CustomField => $new->Id,
+                 ObjectId => $ocf->ObjectId,
+             );
+             die "Can't create ObjectCustomField: $msg" unless $id;
+         }
+     }
+ 
+     # Copy over all of the rights
+     {
+         my $acl = RT::ACL->new( $RT::SystemUser );
+         $acl->LimitToObject( $cf );
+         while (my $ace = $acl->Next) {
+             my $newace = RT::ACE->new( $RT::SystemUser );
+             ($id, $msg) = $newace->Create(
+                 PrincipalId => $ace->PrincipalId,
+                 PrincipalType => $ace->PrincipalType,
+                 RightName => $ace->RightName,
+                 Object => $new,
+             );
+             die "Can't assign rights: $msg" unless $id;
+         }
+     }
+ 
+     # Add values for all of the categories
+     for my $i (0..$#categories) {
+         ($id, $msg) = $new->AddValue(
+             Name => $categories[$i],
+             SortOrder => $i + 1,
+         );
+         die "Can't create custom field value: $msg" unless $id;
+     }
+ 
+     # Grovel through all ObjectCustomFieldValues, and add the
+     # appropriate category
+     {
+         my $ocfvs = RT::ObjectCustomFieldValues->new( $RT::SystemUser );
+         $ocfvs->LimitToCustomField( $cf->Id );
+         while (my $ocfv = $ocfvs->Next) {
+             next unless exists $mapping{$ocfv->Content};
+             my $newocfv = RT::ObjectCustomFieldValue->new( $RT::SystemUser );
+             ($id, $msg) = $newocfv->Create(
+                 CustomField => $new->Id,
+                 ObjectType => $ocfv->ObjectType,
+                 ObjectId   => $ocfv->ObjectId,
+                 Content    => $mapping{$ocfv->Content},
+             );
+         }
+     }
+ }
+ 
+ $RT::Handle->Commit;
diff --cc share/html/Elements/EditCustomFieldSelect
index 46b1afb,6b205cd..4aec2b0
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@@ -48,35 -48,41 +48,47 @@@
  %# Build up the set of cascading select boxes as "guides"
  %# each one limits the options of the final one a bit
  %# (perhaps by tweaking the .display style?)
- %       my $selected = 0;
- %       my @category;
- %       my $id = $NamePrefix . $CustomField->Id;
- %       my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
- %       if (@category) {
- <script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
- %#      XXX - Hide this select from w3m?
-       <select onchange="filter_cascade('<% $id %>-Values', this.value)" name="<% $id %>-Category" class="CF-<%$CustomField->id%>-Edit">
-         <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
- %           foreach my $cat (@category) {
- %               my ($depth, $name) = @$cat;
-         <option value="<% $name %>"><% '&nbsp;' x $depth |n %><% $name %></option>
- %           }
-       </select><br />
+ % my $selected = 0;
+ % my @category;
+ % my $id = $NamePrefix . $CustomField->Id;
 -% if ($CustomField->BasedOnObj->Id) {
 -% }
+ % my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
+ % if (@category and not $CustomField->BasedOnObj->id) {
+   <script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
+ %# XXX - Hide this select from w3m?
+   <select onchange="filter_cascade('<% $id %>-Values', this.value)" name="<% $id %>-Category" class="CF-<%$CustomField->id%>-Edit">
+     <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
+ %   foreach my $cat (@category) {
+ %     my ($depth, $name) = @$cat;
+       <option value="<% $name %>"><% '&nbsp;' x $depth |n %><% $name %></option>
+ %   }
+     </select><br />
+ % }
++% if (@category) {
 +%# this hidden select is to supply a full list of values,
 +%# see filter_cascade() in js/cascaded.js
 +      <select name="<%$id%>-Values-Complete" id="<%$id%>-Values-Complete" class="hidden" disabled="disabled">
 +        <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
 +%       $m->out($out);
 +      </select>
- %       }
-       <select name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
- %       if ( $Rows && ( $Multiple || !@category ) ) {
-         size="<% $Rows %>"
- %       }
-         <% $Multiple && qq[multiple="multiple"] |n %> >
-         <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
- %       $m->out($out);
-       </select>
++% }
+ % my @Derivatives = map {$_->id} $CustomField->DerivativeCFs;
+ % if (@Derivatives) {
+   <script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
+ <script type="text/javascript"><!--
+ doOnLoad(  function () {<% join(";", map {"filter_cascade('$NamePrefix$_-Values',document.getElementById('$id-Values').value, 1)"} @Derivatives) |n%>} );
+ --></script>
+ <select onchange="<% join(";", map {"filter_cascade('$NamePrefix$_-Values', this.value, 1)"} @Derivatives) |n%>"
+ % } else {
+ <select
+ % }
+   name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
+ % if ( $Rows && ( $Multiple || !@category ) ) {
+   size="<% $Rows %>"
+ % }
+ <% $Multiple && qq[multiple="multiple"] |n %> >
+ <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
+ % $m->out($out);
+ </select>
  <%ARGS>
  $Object => undef
  $CustomField => undef
diff --cc share/html/NoAuth/js/cascaded.js
index e3bdce7,ace4f38..e980b29
--- a/share/html/NoAuth/js/cascaded.js
+++ b/share/html/NoAuth/js/cascaded.js
@@@ -52,44 -50,16 +52,51 @@@ function filter_cascade (id, val) 
      if (!select) { return };
      var i;
      var children = select.childNodes;
 -    for (i in children) {
 -        if (!children[i].label) { continue };
 +
 +    if ( complete_select ) {
 +        while (select.hasChildNodes()){
 +            select.removeChild(select.firstChild);
 +        }
 +
 +        var complete_children = complete_select.childNodes;
 +
-         if ( val == '' ) {
+         if ( val == '' && arguments.length == 3 ) {
 -            hide(children[i]);
 -            continue;
++            // no category, and the category is from a hierchical cf;
++            // leave this set of options empty
++        } else if ( val == '' ) {
 +            // no category, let's clone all node
 +            for (i in complete_children) {
 +                if ( complete_children[i].cloneNode ) {
 +                    new_option = complete_children[i].cloneNode(true);
 +                    select.appendChild(new_option);
 +                }
 +            }
 +        }
 +        else {
 +            for (i in complete_children) {
 +                if (!complete_children[i].label ||
 +                        complete_children[i].label.substr(0, val.length) == val ) {
 +                    if ( complete_children[i].cloneNode ) {
 +                        new_option = complete_children[i].cloneNode(true);
 +                        select.appendChild(new_option);
 +                    }
 +                }
 +            }
          }
 -        if ( val == '' || children[i].label.substr(0, val.length) == val) {
 -            show(children[i]);
 -            continue;
 +    }
 +    else {
 +// for back compatibility
 +        for (i in children) {
 +            if (!children[i].label) { continue };
++            if ( val == '' && arguments.length == 3 ) {
++                hide(children[i]);
++                continue;
++            }
 +            if ( val == '' || children[i].label.substr(0, val.length) == val) {
 +                show(children[i]);
 +                continue;
 +            }
 +            hide(children[i]);
          }
 -        hide(children[i]);
      }
  }

-----------------------------------------------------------------------


More information about the Rt-commit mailing list