[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm

raeburn raeburn at source.lon-capa.org
Tue Aug 6 23:13:32 EDT 2013


raeburn		Wed Aug  7 03:13:32 2013 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Only save colors to domain's configuration.db if different to defaults.
  - New routine: &role_defaults() for default text and background colors
    for coordinator, author, admin, student, and log-in page, to faclitate
    re-use.
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.199 loncom/interface/domainprefs.pm:1.200
--- loncom/interface/domainprefs.pm:1.199	Mon Jul 15 17:42:11 2013
+++ loncom/interface/domainprefs.pm	Wed Aug  7 03:13:31 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.199 2013/07/15 17:42:11 raeburn Exp $
+# $Id: domainprefs.pm,v 1.200 2013/08/07 03:13:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1142,17 +1142,7 @@
     my %designhash = &Apache::loncommon::get_domainconf($dom);
     my %defaultdesign = %Apache::loncommon::defaultdesign;
     my (%is_custom,%designs);
-    my %defaults = (
-                   img => $defaultdesign{$role.'.img'},
-                   font => $defaultdesign{$role.'.font'},
-		   fontmenu => $defaultdesign{$role.'.fontmenu'},
-                   );
-    foreach my $item (@bgs) {
-        $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
-    }
-    foreach my $item (@links) {
-        $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
-    }
+    my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
     if (ref($settings) eq 'HASH') {
         if (ref($settings->{$role}) eq 'HASH') {
             if ($settings->{$role}->{'img'} ne '') {
@@ -1213,6 +1203,44 @@
     return $datatable;
 }
 
+sub role_defaults {
+    my ($role,$bgs,$links,$images,$logintext) = @_;
+    my %defaults; 
+    unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) { 
+        return %defaults;
+    }
+    my %defaultdesign = %Apache::loncommon::defaultdesign;
+    if ($role eq 'login') {
+        %defaults = (
+                       font => $defaultdesign{$role.'.font'},
+                    );
+        if (ref($logintext) eq 'ARRAY') {
+            foreach my $item (@{$logintext}) {
+                $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
+            }
+        }
+        foreach my $item (@{$images}) {
+            $defaults{'showlogo'}{$item} = 1;
+        }
+    } else {
+        %defaults = (
+                       img => $defaultdesign{$role.'.img'},
+                       font => $defaultdesign{$role.'.font'},
+                       fontmenu => $defaultdesign{$role.'.fontmenu'},
+                    );
+    }
+    foreach my $item (@{$bgs}) {
+        $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
+    }
+    foreach my $item (@{$links}) {
+        $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
+    }
+    foreach my $item (@{$images}) {
+        $defaults{$item} = $defaultdesign{$role.'.'.$item};
+    }
+    return %defaults;
+}
+
 sub display_color_options {
     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
@@ -5109,24 +5137,45 @@
     my @images;
     my $servadm = $r->dir_config('lonAdmEMail');
     my $errors;
+    my %defaults;
     foreach my $role (@{$roles}) {
         if ($role eq 'login') {
             %choices = &login_choices();
             @logintext = ('textcol','bgcol');
         } else {
             %choices = &color_font_choices();
-            $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
         }
         if ($role eq 'login') {
             @images = ('img','logo','domlogo','login');
             @bgs = ('pgbg','mainbg','sidebg');
         } else {
             @images = ('img');
-            @bgs = ('pgbg','tabbg','sidebg'); 
+            @bgs = ('pgbg','tabbg','sidebg');
+        }
+        my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
+        unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
+            $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
+        }
+        if ($role eq 'login') {
+            foreach my $item (@logintext) {
+                unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
+                    $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+                }
+            }
+        } else {
+            unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
+                $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
+            }
         }
-        $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
-        foreach my $item (@bgs, at links, at logintext) {
-            $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+        foreach my $item (@bgs) {
+            unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
+                $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+            }
+        }
+        foreach my $item (@links) {
+            unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
+                $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
+            }
         }
         my ($configuserok,$author_ok,$switchserver) = 
             &config_check($dom,$confname,$servadm);




More information about the LON-CAPA-cvs mailing list