fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-10-03 10:02 am

[dw-free] mood themes: inheritance does not work in the editor

[commit: http://hg.dwscoalition.org/dw-free/rev/296aacab97c2]

http://bugs.dwscoalition.org/show_bug.cgi?id=1032

Fix various issues with edits to moodthemes not being saved: fix inheritance
checkbox, allow children to rely on nearest parent's width/height. Don't
show success message for moods that weren't changed; add a success message
when a mood is deleted from a cleared field.

Patch by [personal profile] kareila.

Files modified:
  • htdocs/manage/moodthemes.bml
  • htdocs/manage/moodthemes.bml.text
--------------------------------------------------------------------------------
diff -r 1f9318482d9d -r 296aacab97c2 htdocs/manage/moodthemes.bml
--- a/htdocs/manage/moodthemes.bml	Sun Oct 03 00:39:27 2010 +0800
+++ b/htdocs/manage/moodthemes.bml	Sun Oct 03 18:01:08 2010 +0800
@@ -184,9 +184,8 @@ body<=
     #### Closure Definitions ####
     my $make_tree;
     $make_tree = sub {
-        my ( $num, $tid ) = @_;
+        my ( $num, $theme ) = @_;
         return unless $lists{$num};
-        my $theme = DW::Mood->new( $tid );
 
         $ret .= "<ul>\n";
 
@@ -226,15 +225,17 @@ body<=
                                                   value => $pic{h}, size => 4 });
             $ret .= "<br /><br /></td></tr>\n";
             $ret .= LJ::html_hidden({ name => "$mood->{id}parent", id => "$mood->{id}parent", value => $mood->{parent} });
+            $ret .= LJ::html_hidden({ name => "$mood->{id}oldinh", id => "$mood->{id}oldinh", value => $inherited });
             $ret .= "</table>\n";
 
-            $make_tree->( $mood->{id}, $tid );
+            $make_tree->( $mood->{id}, $theme );
         }
         $ret .= "</ul>\n";
     };
 
     my $editform = sub {
         my ( $id ) = @_;
+        my $theme = DW::Mood->new( $id );
 
         # Get a list of all possible moods
         my $moods = DW::Mood->get_moods;
@@ -244,7 +245,7 @@ body<=
             push @{ $lists{ $m->{parent} } }, $m;
         }
 
-        $make_tree->( 0, $id );
+        $make_tree->( 0, $theme );
     };
 
 
@@ -351,16 +352,31 @@ body<=
                     my $picurl = $POST{$key};
                     my $mname = DW::Mood->mood_name( $mid );
 
-                    # inherited, don't represent in db
-                    if ( $POST{$mid.'check'} eq 'checked' ) {
-                        push @picdata, [ $mid, {} ];
-                        $ret .= BML::ml( '.mood.deleted', { mood => "$mname($mid)"} ) . "<br />\n";
-                        next;
+                    # don't update if nothing changed
+                    my %picdata;
+                    $theme->get_picture( $mid, \%picdata );
+                    my $same = $picurl eq $picdata{pic} &&
+                               $width  == $picdata{w}   &&
+                               $height == $picdata{h};
+                    next if $same;
+
+                    # allow width & height to default to that of parent
+                    if ( my $pid = $POST{$mid . 'parent'} ) {
+                        $width  ||= $POST{$pid . 'w'};
+                        $height ||= $POST{$pid . 'h'};
+                        unless ( $width && $height ) {
+                            # check the database
+                            my %parent;
+                            $theme->get_picture( $pid, \%parent );
+                            $width  ||= $parent{w};
+                            $height ||= $parent{h};
+                        }
                     }
 
                     # one of these is blank, so delete the mood
                     unless ( $picurl && $width && $height ) {
                         push @picdata, [ $mid, {} ];
+                        $ret .= BML::ml( '.mood.reset', { mood => "$mname($mid)"} ) . "<br />\n";
                         next;
                     }
 
@@ -368,6 +384,22 @@ body<=
                     if ( $picurl =~ m!^https?://[^\'\"\0\s]+$! ) {
                         push @picdata, [ $mid, { picurl => $picurl, width => $width, height => $height } ];
                         $ret .= BML::ml( '.mood.setpic', { mood => "$mname($mid)", url => $picurl } ) . "<br />\n";
+                    }
+                }
+            }
+
+            # look again for inheritance
+            # (id key for url was disabled, so no match above)
+            foreach my $key ( keys %POST ) {
+                if ( $key =~ /^(\d+)inherit$/ ) {
+                    my $mid = $1;
+                    next if $POST{$mid};  # already processed above
+                    next if $POST{$mid . 'oldinh'};  # no change in status
+                    # inherited, don't represent in db
+                    my $mname = DW::Mood->mood_name( $mid );
+                    if ( $POST{$key} eq 'on' ) {
+                        push @picdata, [ $mid, {} ];
+                        $ret .= BML::ml( '.mood.deleted', { mood => "$mname($mid)"} ) . "<br />\n";
                     }
                 }
             }
diff -r 1f9318482d9d -r 296aacab97c2 htdocs/manage/moodthemes.bml.text
--- a/htdocs/manage/moodthemes.bml.text	Sun Oct 03 00:39:27 2010 +0800
+++ b/htdocs/manage/moodthemes.bml.text	Sun Oct 03 18:01:08 2010 +0800
@@ -45,6 +45,8 @@
 
 .mood.label.width=Width:
 
+.mood.reset=[[mood]] has been reset and will inherit if it has a parent.
+
 .mood.setpic=[[mood]] is set to [[url]].
 
 .saved=Changes have been successfully saved.
--------------------------------------------------------------------------------