[Rt-commit] rt branch, 4.0/consistent-admin-ui-for-class, created. rt-4.0.2-68-gee45627

? sunnavy sunnavy at bestpractical.com
Tue Sep 13 03:11:30 EDT 2011


The branch, 4.0/consistent-admin-ui-for-class has been created
        at  ee4562784e2487523d67f9db978b7f3ba84aa722 (commit)

- Log -----------------------------------------------------------------
commit ee4562784e2487523d67f9db978b7f3ba84aa722
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 13 14:40:51 2011 +0800

    make admin class consistent with other admin elements.
    
    this includes 2 changes:
    
    1. consistent submit button and title.
    2. back to form instead of Abort() if creation fails.

diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index 892500e..c0d527a 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -80,6 +80,7 @@
 <ul>
 <li><input type="checkbox" name="Include-Name" value="1" <% $include{Name} %>> Include article name</li>
 <li><input type="checkbox" name="Include-Summary" value="1" <% $include{Summary} %>> Include article summary</li>
+% if ( $cfs ) {
 % while (my $cf = $cfs->Next) {
 <li>Include custom field '<% $cf->Name %>'
   <ul>
@@ -87,12 +88,16 @@
     <li><input type="checkbox" name="Include-CF-Value-<% $cf->Id %>" <% $include{"CF-Value-".$cf->Id} %> />Value</li>
   </ul>
 </li>
-% }
+% } }
 </ul>
 
 %$m->callback( CallbackName => 'BeforeSubmit', CustomFields => $cfs, ClassObj => $ClassObj );
 
-<& /Elements/Submit &>
+% if ( $Create ) {
+<& /Elements/Submit, Label => loc('Create') &>
+% } else {
+<& /Elements/Submit, Label => loc('Save Changes') &>
+% }
 </form>
 
 <%INIT>
@@ -103,17 +108,27 @@ my  ($title, @results, $Disabled);
 if ($Create) {
     $title = loc("Create a Class");
 } else {
+    my ( $val, $msg );
     if ($id eq 'new') {
-        my ($val, $msg) =  $ClassObj->Create(Name => $Name);
-        if ($val == 0 ) {
-            $m->comp("/Elements/Error", Why => "$msg");
-        } else {
+        ($val, $msg) = $ClassObj->Create(Name => $Name);
+        if ( $val ) {
             push @results, $msg;
-        }    
+        }
+        else {
+            push @results, loc('Class could not be created: [_1]', $msg);
+        }
     } else {
         $ClassObj->Load($id) || $ClassObj->Load($Name) || $m->comp("/Elements/Error", Why => "Couldn't load class '$Name'");
+        $val = $ClassObj->id;
+    }
+
+    if ( $val ) {
+        $title = loc('Modify the Class [_1]', $ClassObj->Name);
+    }
+    else {
+        $title = loc("Create a Class");
+        $Create = 1;
     }
-    $title = loc('Editing Configuration for Class [_1]', $ClassObj->Name);
 }
 
 if ($ClassObj->Id()) {
@@ -133,10 +148,14 @@ if ((defined $Enabled && $Enabled == 1) or (not defined $Enabled and $Create)) {
 }
 
 my %include = (Name => 1, Summary => 1);
-my $cfs = $ClassObj->ArticleCustomFields;
-$include{"CF-Title-".$_->Id} = $include{"CF-Value-".$_->Id} = 1 while $_ = $cfs->Next;
 
-if  ( $Submitted ) {
+my $cfs;
+if ( $ClassObj->id ) {
+    $cfs = $ClassObj->ArticleCustomFields;
+    $include{"CF-Title-".$_->Id} = $include{"CF-Value-".$_->Id} = 1 while $_ = $cfs->Next;
+}
+
+if  ( $ClassObj->id && $Submitted ) {
     if ( $Disabled != $ClassObj->Disabled) {
         my  ($code, $msg) = $ClassObj->SetDisabled($Disabled);
         push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
@@ -155,14 +174,17 @@ if  ( $Submitted ) {
 MaybeRedirectForResults(
     Actions     => \@results,
     Arguments   => { id => $ClassObj->Id },
-);
+) if $ClassObj->id;
+
 
+if ( $ClassObj->id ) {
+    $include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;
+}
 
-$include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;
 $include{$_} = $include{$_} ? " CHECKED" : "" for keys %include;
 
 my $EnabledChecked = ($Create ? $Disabled : $ClassObj->Disabled()) ? "" : "CHECKED";
-my $HotListChecked = $ClassObj->HotList ? "CHECKED" : "";
+my $HotListChecked = $ClassObj->id && $ClassObj->HotList ? "CHECKED" : "";
 </%INIT>
 
 
diff --git a/t/articles/class.t b/t/articles/class.t
index 784aeb3..84d6e23 100644
--- a/t/articles/class.t
+++ b/t/articles/class.t
@@ -66,7 +66,7 @@ $m->submit_form_ok({
     fields => { Name => 'Test Redirect' },
 });
 $m->content_contains('Object created', 'found results');
-$m->content_contains('Editing Configuration for Class Test Redirect', 'found title');
+$m->content_contains('Modify the Class Test Redirect', 'found title');
 $m->form_number(3);
 $m->untick( 'Include-Name', 1 );
 $m->field( 'Description', 'Test Description' );
diff --git a/t/articles/queue-specific-class.t b/t/articles/queue-specific-class.t
index 38159e7..a73d583 100644
--- a/t/articles/queue-specific-class.t
+++ b/t/articles/queue-specific-class.t
@@ -21,7 +21,7 @@ for my $name ( keys %class ) {
         fields      => { Name => $name, HotList => 1 },
     );
 
-    $m->content_contains( "Editing Configuration for Class $name",
+    $m->content_contains( "Modify the Class $name",
         'created class $name' );
     my ($id) = ( $m->content =~ /name="id" value="(\d+)"/ );
     ok( $id, "id of $name" );

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


More information about the Rt-commit mailing list