[Rt-commit] rt branch, 5.0/select-class-in-article-create-form, created. rt-5.0.1-42-gfd44bbb48b

? sunnavy sunnavy at bestpractical.com
Fri Mar 12 17:43:41 EST 2021


The branch, 5.0/select-class-in-article-create-form has been created
        at  fd44bbb48b9b10f99811cc658ccb0fded7ea9299 (commit)

- Log -----------------------------------------------------------------
commit e4de5add8a426e43a7541014d7055a6b3ccd993d
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Tue Dec 29 11:38:44 2020 -0500

    Remove modal class selection for creating articles
    
    Instead, the article Class is chosen similarly to how Queue is chosen
    for Tickets or Catalog is chosen for Assets: There is a pulldown
    selection element in the create/edit page.  Updating this refreshes
    the page so the appropriate custom fields are presented for editing.

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index e40e26aa3d..700a8774bb 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -233,7 +233,7 @@ sub BuildMainNav {
         my $articles = $top->child( articles => title => loc('Articles'), path => "/Articles/index.html");
         $articles->child( articles => title => loc('Overview'), path => "/Articles/index.html" );
         $articles->child( topics   => title => loc('Topics'),   path => "/Articles/Topics.html" );
-        $articles->child( create   => title => loc('Create'),   path => "/Articles/Article/PreCreate.html" );
+        $articles->child( create   => title => loc('Create'),   path => "/Articles/Article/Edit.html" );
         $articles->child( search   => title => loc('Search'),   path => "/Articles/Article/Search.html" );
     }
 
diff --git a/share/html/Articles/Article/Edit.html b/share/html/Articles/Article/Edit.html
index 697f1d287a..22a9cde577 100644
--- a/share/html/Articles/Article/Edit.html
+++ b/share/html/Articles/Article/Edit.html
@@ -52,13 +52,16 @@
 <form method="post" action="Edit.html" name="EditArticle" id="EditArticle" enctype="multipart/form-data">
 <input type="hidden" name="next" value="<%$ARGS{next}||''%>" />
 <input type="hidden" name="id" value="<%$id%>" />
+<input type="hidden" name="ClassChanged" value="0" />
 
 <&| /Widgets/TitleBox, title => $title, class => 'article-basics', &>
 <& Elements/EditBasics, ArticleObj => $ArticleObj,
-                        EditClass =>$EditClass,
+                        EditClass => 1,
+                        DefaultClass => $DefaultClass,
                         ClassObj => $ClassObj,
                         %ARGS ,
-                        id => $id
+                        id => $id,
+                        $id eq 'new' ? ( OnClassChange => "jQuery(this).closest('form').find('input[name=ClassChanged]').val(1);jQuery(this).closest('form').submit();" ) : (),
                         &>
 </&>
 
@@ -66,6 +69,7 @@
 <& Elements/EditCustomFields, ArticleObj => $ArticleObj,
                               CFContent => \%CFContent,
                               ClassObj => $ClassObj,
+                              ClassChanged => $ARGS{ClassChanged},
                               %ARGS,
                               id => $id,
                               ForCreation => ($id eq 'new'),
@@ -108,15 +112,28 @@ my $title;
 my $Entries    = {};
 my $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
 my $ClassObj   = RT::Class->new( $session{'CurrentUser'} );
+my $DefaultClass;
 
 if ($Class) {
     $ClassObj->Load($Class);
     Abort(loc("'[_1]' isn't a valid class", $Class)) unless $ClassObj->Id;
+    $DefaultClass = $ClassObj->Id;
+}
+
+# If we don't have a class, default to the first class that user can
+# see and in which user can create articles
+if (!$DefaultClass) {
+    my $Classes = RT::Classes->new($session{'CurrentUser'});
+    $Classes->LimitToEnabled();
+    while (my $class = $Classes->Next) {
+        next unless ($class->Name);
+        $DefaultClass = $class->Id;
+        last;
+    }
 }
 
 my %create_args;
 my %CFContent;
-my $EditClass = 1;
 
 if ( $ARGS{SetEnabled} ) {
     $ARGS{Disabled} = $ARGS{Enabled} ? 0 : 1;
@@ -140,8 +157,6 @@ if ( !$id ) {
             $CFContent{ $ARGS{$arg} } .= $trans->Content;
         }
     }
-
-    $EditClass = 0;
     $id        = 'new';
 }
 elsif ( $id eq 'new' ) {
@@ -157,24 +172,28 @@ elsif ( $id eq 'new' ) {
     }
 
     my %cfs;
-    if ($sortorder_ok) {
-        %cfs = ProcessObjectCustomFieldUpdatesForCreate(
-            ARGSRef         => \%ARGS,
-            ContextObject   => $ClassObj,
-            );
-
-        my $msg;
-        ( $id, $msg ) = $ArticleObj->Create(
-            Summary => $ARGS{'Summary'},
-            Name    => $ARGS{'Name'},
-            SortOrder => $ARGS{'SortOrder'},
-            Class   => $ARGS{'Class'},
-            Topics  => $ARGS{'Topics'},
-            Disabled => $ARGS{'Disabled'},
-            %create_args,
-            %cfs
-            );
-        push( @results, $msg );
+    if (!$ARGS{ClassChanged}) {
+        if ($sortorder_ok) {
+            %cfs = ProcessObjectCustomFieldUpdatesForCreate(
+                ARGSRef         => \%ARGS,
+                ContextObject   => $ClassObj,
+                );
+
+            my $msg;
+            ( $id, $msg ) = $ArticleObj->Create(
+                Summary => $ARGS{'Summary'},
+                Name    => $ARGS{'Name'},
+                SortOrder => $ARGS{'SortOrder'},
+                Class   => $ARGS{'Class'},
+                Topics  => $ARGS{'Topics'},
+                Disabled => $ARGS{'Disabled'},
+                %create_args,
+                %cfs
+                );
+            push( @results, $msg );
+        } else {
+            $id = 0;
+        }
     } else {
         $id = 0;
     }
@@ -198,7 +217,6 @@ elsif ( $id eq 'new' ) {
     else {
         $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
         $id        = 'new';
-        $EditClass = 0;
         $title     = loc('Create a new article');
     }
 }
@@ -207,82 +225,86 @@ else {
     $ArticleObj->Load($id);
     unless ( $ArticleObj->id ) {
         $m->comp( "/Elements/Error",
-            Why => loc("Unable to load article") );
+                  Why => loc("Unable to load article") );
     }
 
-    my @attribs = qw(Name Summary Class Disabled SortOrder);
-
-    if ($sortorder_ok) {
-        @results = UpdateRecordObject(
-            AttributesRef => \@attribs,
-            Object        => $ArticleObj,
-            ARGSRef       => \%ARGS
-            );
-    }
+    # If it was a real submit, make changes.
+    # If it was just a reload to change the Class, don't make changes.
+    if (!$ARGS{ClassChanged}) {
+        my @attribs = qw(Name Summary Class Disabled SortOrder);
+
+        if ($sortorder_ok) {
+            @results = UpdateRecordObject(
+                AttributesRef => \@attribs,
+                Object        => $ArticleObj,
+                ARGSRef       => \%ARGS
+                );
+        }
 
-    my @cf_results = ProcessObjectCustomFieldUpdates(
-        Object  => $ArticleObj,
-        ARGSRef => \%ARGS
-    );
-    @results = ( @results, @cf_results );
-
-    # Delete links that are gone gone gone.
-    foreach my $arg ( keys %ARGS ) {
-        if ( $arg =~ /DeleteLink-(.*?)-(RefersTo|MemberOf|RefersTo)-(.*)$/ ) {
-            my $base   = $1;
-            my $type   = $2;
-            my $target = $3;
-
-            my ( $val, $msg ) = $ArticleObj->DeleteLink(
-                Base   => $base,
-                Type   => $type,
-                Target => $target
+        my @cf_results = ProcessObjectCustomFieldUpdates(
+            Object  => $ArticleObj,
+            ARGSRef => \%ARGS
             );
+        @results = ( @results, @cf_results );
 
-            push @results, $msg;
+        # Delete links that are gone gone gone.
+        foreach my $arg ( keys %ARGS ) {
+            if ( $arg =~ /DeleteLink-(.*?)-(RefersTo|MemberOf|RefersTo)-(.*)$/ ) {
+                my $base   = $1;
+                my $type   = $2;
+                my $target = $3;
 
-        }
+                my ( $val, $msg ) = $ArticleObj->DeleteLink(
+                    Base   => $base,
+                    Type   => $type,
+                    Target => $target
+                    );
 
-    }
-
-    my @linktypes = qw(DependsOn MemberOf RefersTo );
+                push @results, $msg;
 
-    foreach my $linktype (@linktypes) {
+            }
 
-    for my $luri ( split( / /, ( $ARGS{ $ArticleObj->Id . "-$linktype" } || '' )) ) {
-            $luri =~ s/\s*$//;    # Strip trailing whitespace
-            my ( $val, $msg ) =
-              $ArticleObj->AddLink( Target => $luri, Type => $linktype );
-            push @results, $msg;
-            delete $ARGS{ $ArticleObj->Id . "-$linktype" } if $val;
         }
 
-        for my $luri ( split( / /, ( $ARGS{ "$linktype-" . $ArticleObj->Id } || '' )) ) {
-            my ( $val, $msg ) =
-              $ArticleObj->AddLink( Base => $luri, Type => $linktype );
-            push @results, $msg;
-            delete $ARGS{ "$linktype-" . $ArticleObj->Id } if $val;
-        }
+        my @linktypes = qw(DependsOn MemberOf RefersTo );
 
-    }
+        foreach my $linktype (@linktypes) {
 
-    my %topics;
-    if ( $ARGS{'EditTopics'} ) {
-        $topics{$_}++ for @{ $ARGS{'Topics'} };
-        my $objTopics =
-          RT::ObjectTopics->new( $session{'CurrentUser'} );
-        $objTopics->LimitToObject($ArticleObj);
-        while ( my $t = $objTopics->Next ) {
-            $topics{ $t->Topic }--;
-        }
-        for my $id ( keys %topics ) {
-            if ( $topics{$id} > 0 ) {
-                my ( $val, $msg ) = $ArticleObj->AddTopic( Topic => $id );
+            for my $luri ( split( / /, ( $ARGS{ $ArticleObj->Id . "-$linktype" } || '' )) ) {
+                $luri =~ s/\s*$//;    # Strip trailing whitespace
+                my ( $val, $msg ) =
+                    $ArticleObj->AddLink( Target => $luri, Type => $linktype );
                 push @results, $msg;
+                delete $ARGS{ $ArticleObj->Id . "-$linktype" } if $val;
             }
-            elsif ( $topics{$id} < 0 ) {
-                my ( $val, $msg ) = $ArticleObj->DeleteTopic( Topic => $id );
+
+            for my $luri ( split( / /, ( $ARGS{ "$linktype-" . $ArticleObj->Id } || '' )) ) {
+                my ( $val, $msg ) =
+                    $ArticleObj->AddLink( Base => $luri, Type => $linktype );
                 push @results, $msg;
+                delete $ARGS{ "$linktype-" . $ArticleObj->Id } if $val;
+            }
+
+        }
+
+        my %topics;
+        if ( $ARGS{'EditTopics'} ) {
+            $topics{$_}++ for @{ $ARGS{'Topics'} };
+            my $objTopics =
+                RT::ObjectTopics->new( $session{'CurrentUser'} );
+            $objTopics->LimitToObject($ArticleObj);
+            while ( my $t = $objTopics->Next ) {
+                $topics{ $t->Topic }--;
+            }
+            for my $id ( keys %topics ) {
+                if ( $topics{$id} > 0 ) {
+                    my ( $val, $msg ) = $ArticleObj->AddTopic( Topic => $id );
+                    push @results, $msg;
+                }
+                elsif ( $topics{$id} < 0 ) {
+                    my ( $val, $msg ) = $ArticleObj->DeleteTopic( Topic => $id );
+                    push @results, $msg;
+                }
             }
         }
     }
diff --git a/share/html/Articles/Article/Elements/EditBasics b/share/html/Articles/Article/Elements/EditBasics
index c8d7b45e55..339fc35646 100644
--- a/share/html/Articles/Article/Elements/EditBasics
+++ b/share/html/Articles/Article/Elements/EditBasics
@@ -75,7 +75,7 @@
   </div>
   <div class="value col-9">
 % if ($EditClass) {
-<& /Articles/Elements/SelectClass, Name => 'Class', Default =>$ArticleObj->ClassObj->Id&>
+<& /Articles/Elements/SelectClass, Name => 'Class', Default => $DefaultClass || $ArticleObj->ClassObj->Id, ShowAllClasses => 0, ShowNullOption => 0, OnChange => $OnClassChange &>
 % } else {
 <span class="current-value form-control"><%$ClassObj->Name%></span>
 <input type="hidden" name="Class" value="<%$ClassObj->Id%>" />
@@ -124,6 +124,8 @@
 </%INIT>
 <%ARGS>
 $EditClass => 1
+$DefaultClass => undef
 $ClassObj => undef
 $ArticleObj => undef
+$OnClassChange => undef
 </%ARGS>
diff --git a/share/html/Articles/Article/PreCreate.html b/share/html/Articles/Article/PreCreate.html
deleted file mode 100644
index 0311c53bb6..0000000000
--- a/share/html/Articles/Article/PreCreate.html
+++ /dev/null
@@ -1,83 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2021 Best Practical Solutions, LLC
-%#                                          <sales at bestpractical.com>
-%#
-%# (Except where explicitly superseded by other copyright notices)
-%#
-%#
-%# LICENSE:
-%#
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org.
-%#
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%#
-%# You should have received a copy of the GNU General Public License
-%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-%# 02110-1301 or visit their web page on the internet at
-%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-%#
-%#
-%# CONTRIBUTION SUBMISSION POLICY:
-%#
-%# (The following paragraph is not intended to limit the rights granted
-%# to you to modify and distribute this software under the terms of
-%# the GNU General Public License and is only of importance to you if
-%# you choose to contribute your changes and enhancements to the
-%# community by submitting them to Best Practical Solutions, LLC.)
-%#
-%# By intentionally submitting any modifications, corrections or
-%# derivatives to this work, or any other work intended for use with
-%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-%# you are the copyright holder for those contributions and you grant
-%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
-%# royalty-free, perpetual, license to use, copy, create derivative
-%# works based on those contributions, and sublicense and distribute
-%# those contributions and any derivatives thereof.
-%#
-%# END BPS TAGGED BLOCK }}}
-<& /Elements/Header, Title => loc('Create an article in class...') &>
-<& /Elements/Tabs &>
-
-% if (not $classes_configured) {
-<& /Articles/Elements/NeedsSetup &>
-% } elsif (not @classes) {
-<i><&|/l&>You don't have permission to create Articles in any Class</&></i>
-% } else {
-<ul>
-% for my $Class (@classes) {
-% my $qs = $m->comp("/Elements/QueryString", %ARGS, Class=> $Class->Id);
-<li><a href="Edit.html?<% $qs|n %>"><&|/l, $Class->Name &>in class [_1]</&></a></li>
-% }
-</ul>
-% }
-<%init>
-my $Classes = RT::Classes->new($session{'CurrentUser'});
-$Classes->LimitToEnabled();
-
-# This is a COUNT(), which doesn't apply ACLs; as such, we don't display
-# the warning if there are classes, but the user can't see them.
-my $classes_configured = $Classes->Count;
-
-# ->Next applies SeeClass, but we also want to check CreateArticle
-my @classes;
-while (my $class = $Classes->Next) {
-    push @classes, $class if $class->CurrentUserHasRight("CreateArticle");
-}
-
-# If there is only one, redirect to it
-MaybeRedirectForResults(
-    Path  => "/Articles/Article/Edit.html",
-    Force => 1,
-    Arguments => { Class => $classes[0]->id },
-) if @classes == 1;
-</%init>
diff --git a/share/html/Articles/Elements/CreateArticleButton b/share/html/Articles/Elements/CreateArticleButton
index 83412f1b1a..d5f8e9e6f9 100644
--- a/share/html/Articles/Elements/CreateArticleButton
+++ b/share/html/Articles/Elements/CreateArticleButton
@@ -45,8 +45,8 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<form action="<% RT->Config->Get('WebPath') %>/Articles/Article/PreCreate.html">
+<form action="<% RT->Config->Get('WebPath') %>/Articles/Article/Edit.html">
   <div class="create-article-button">
-    <input type="submit" class="btn btn-primary article-create-modal" value="<&|/l&>Create new article</&>" />
+    <input type="submit" class="btn btn-primary" value="<&|/l&>Create new article</&>" />
   </div>
 </form>
diff --git a/share/html/Articles/Elements/SelectClass b/share/html/Articles/Elements/SelectClass
index 2040f791cd..fb392ef544 100644
--- a/share/html/Articles/Elements/SelectClass
+++ b/share/html/Articles/Elements/SelectClass
@@ -52,6 +52,9 @@
 % if ($Multiple) {
 MULTIPLE
 % }
+% if ($OnChange) {
+onchange="<%$OnChange%>"
+% }
 % if ($Size) {
 SIZE=<%$Size%>
 % }
@@ -80,6 +83,7 @@ $Name => undef
 $Verbose => undef
 $Default => undef
 $Lite => 0
+$OnChange => undef
 </%ARGS>
 
 <%INIT>
diff --git a/share/html/Articles/Helpers/CreateInClass b/share/html/Articles/Helpers/CreateInClass
deleted file mode 100644
index 19744bb2ca..0000000000
--- a/share/html/Articles/Helpers/CreateInClass
+++ /dev/null
@@ -1,61 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2021 Best Practical Solutions, LLC
-%#                                          <sales at bestpractical.com>
-%#
-%# (Except where explicitly superseded by other copyright notices)
-%#
-%#
-%# LICENSE:
-%#
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org.
-%#
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%#
-%# You should have received a copy of the GNU General Public License
-%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-%# 02110-1301 or visit their web page on the internet at
-%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-%#
-%#
-%# CONTRIBUTION SUBMISSION POLICY:
-%#
-%# (The following paragraph is not intended to limit the rights granted
-%# to you to modify and distribute this software under the terms of
-%# the GNU General Public License and is only of importance to you if
-%# you choose to contribute your changes and enhancements to the
-%# community by submitting them to Best Practical Solutions, LLC.)
-%#
-%# By intentionally submitting any modifications, corrections or
-%# derivatives to this work, or any other work intended for use with
-%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-%# you are the copyright holder for those contributions and you grant
-%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
-%# royalty-free, perpetual, license to use, copy, create derivative
-%# works based on those contributions, and sublicense and distribute
-%# those contributions and any derivatives thereof.
-%#
-%# END BPS TAGGED BLOCK }}}
-<div class="modal-dialog modal-dialog-centered" role="document">
-  <div class="modal-content">
-    <div class="modal-header">
-      <h5 class="modal-title"><&|/l&>Create Article</&></h5>
-      <a href="javascript:void(0)" class="close" data-dismiss="modal" aria-label="Close">
-        <span aria-hidden="true">×</span>
-      </a>
-    </div>
-    <div class="modal-body">
-        <& /Articles/Elements/CreateInClass &>
-    </div>
-  </div>
-</div>
-% $m->abort;
diff --git a/share/static/js/util.js b/share/static/js/util.js
index e6195c0459..650be6fd98 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -641,14 +641,6 @@ jQuery(function() {
         return false;
     });
 
-    jQuery("#articles-create, .article-create-modal").click(function(ev){
-        ev.preventDefault();
-        jQuery.get(
-            RT.Config.WebHomePath + "/Articles/Helpers/CreateInClass",
-            showModal
-        );
-    });
-
     jQuery(".card .card-header .toggle").each(function() {
         var e = jQuery(jQuery(this).attr('data-target'));
         e.on('hide.bs.collapse', function () {

commit fd44bbb48b9b10f99811cc658ccb0fded7ea9299
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Mar 13 06:30:25 2021 +0800

    Update tests for the deletion of article PreCreate page

diff --git a/t/articles/interface.t b/t/articles/interface.t
index 5822fc75e5..b2bce3a3ee 100644
--- a/t/articles/interface.t
+++ b/t/articles/interface.t
@@ -210,7 +210,7 @@ diag("Test creating a ticket in Class2 and make sure we don't see Class1 Topics"
 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
     'UI -> Articles' );
 $m->follow_link_ok( {text => 'Create' }, 'Articles -> New Article' );
-$m->follow_link_ok( {text => 'in class '.$class2->Name }, 'New Article -> in class '.$class2->Name );
+$m->submit_form_ok( { form_id => 'EditArticle', fields => { Class => $class2->Id, ClassChanged => 1 } } );
 $m->content_lacks( $topic1->Name, "Topic1 from Class1 isn't shown" );
 $m->content_lacks( $topic11->Name, "Topic11 from Class1 isn't shown" );
 $m->content_lacks( $topic12->Name, "Topic12 from Class1 isn't shown" );

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


More information about the rt-commit mailing list