Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[livejournal] r18893: LJSUP-8599: System message is not workin...

Committer: gariev
LJSUP-8599: System message is not working completely

U   trunk/cgi-bin/LJ/SiteMessages.pm
U   trunk/cgi-bin/LJ/Widget/AddSiteMessages.pm
Modified: trunk/cgi-bin/LJ/SiteMessages.pm
===================================================================
--- trunk/cgi-bin/LJ/SiteMessages.pm	2011-04-18 03:38:48 UTC (rev 18892)
+++ trunk/cgi-bin/LJ/SiteMessages.pm	2011-04-18 06:53:23 UTC (rev 18893)
@@ -6,7 +6,6 @@
     Permanent   => {    
                         value       => 1,
                         group       => 0,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
                                             
@@ -17,7 +16,6 @@
     Sponsored   => {    
                         value       => 2,
                         group       => 0,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
                                             
@@ -28,7 +26,6 @@
     Paid        => {    
                         value       => 4,
                         group       => 0,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
                                             
@@ -39,7 +36,6 @@
     Plus        => {    
                         value       => 8,
                         group       => 0,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
                                             
@@ -51,7 +47,6 @@
                         
                         value       => 16,
                         group       => 0,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
 
@@ -62,7 +57,6 @@
     SUP         => {    
                         value       => 32,
                         group       => 1,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
                                             
@@ -73,7 +67,6 @@
     NonSUP      => {    
                         value       => 64,
                         group       => 1,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
                                             
@@ -101,7 +94,6 @@
     TryNBuy     => {    
                         value       => 256,
                         group       => 3,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
 
@@ -112,7 +104,6 @@
     AlreadyTryNBuy => { 
                         value       => 512,
                         group       => 3,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
 
@@ -123,7 +114,6 @@
     NeverTryNBuy   => { 
                         value       => 1024,
                         group       => 3,
-                        selected    => 1,
                         validate    => sub {
                                             my ($u) = @_;
 
@@ -146,25 +136,13 @@
 #   Get all options names for form output
 #
 sub get_options_list {
-    return sort { 
-            AccountMask->{$b}->{value} <=> AccountMask->{$a}->{value}
+    return sort {
+            AccountMask->{$a}->{group} <=> AccountMask->{$b}->{group} ||
+            AccountMask->{$a}->{value} <=> AccountMask->{$b}->{value}
          } keys %{&AccountMask};
 }
 
 #
-#   Get default selected masks bits together
-#
-sub get_default_masks_value {
-    my $result = 0;
-     
-    for my $name (keys %{&AccountMask}) {
-        $result += AccountMask->{$name}->{value} if ( AccountMask->{$name}->{selected});    
-    }
-    
-    return $result;
-}
-
-#
 #   Get mask group number
 #
 sub get_group {
@@ -328,26 +306,36 @@
     
     return grep {
         my $last_group = -1;
-        my $group_match = 1;
+        my $group_is_not_empty = 0; ## group has at least 1 condition to test
+        my $group_matched = 0;      ## at least 1 condition from this group was met
         my $accept = 1;
 
         for my $key ($class->get_options_list) {
             # If entering a new group
             if ($last_group != AccountMask->{$key}->{group}) {
-                unless ($group_match) {
+                if ($group_is_not_empty && !$group_matched) {
                     $accept = 0;
                     last;
                 }
+                $last_group = AccountMask->{$key}->{group};
+                $group_is_not_empty = 0;
+                $group_matched = 0;
             }
 
             if (int($_->{accounts}) & AccountMask->{$key}->{value}) {
-                $group_match = AccountMask->{$key}->{validate}($u);
+                $group_is_not_empty = 1;
+                if (AccountMask->{$key}->{validate}($u)) {
+                    $group_matched = 1;
+                }
             }
-
-            $last_group = AccountMask->{$key}->{group};
         }
+        ## the last group:
+        if ($group_is_not_empty && !$group_matched) {
+            $accept = 0;
+        }
 
-        $accept;
+        return $accept;
+
     } @messages;
 }
 

Modified: trunk/cgi-bin/LJ/Widget/AddSiteMessages.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/AddSiteMessages.pm	2011-04-18 03:38:48 UTC (rev 18892)
+++ trunk/cgi-bin/LJ/Widget/AddSiteMessages.pm	2011-04-18 06:53:23 UTC (rev 18893)
@@ -38,7 +38,7 @@
         $end_hour = $end_date->hour;
         $end_min = $end_date->minute;
     } else { # default
-        $accounts = LJ::SiteMessages->get_default_masks_value();
+        $accounts = 0;
     }
 
     # default values for year/month/day = today's date
@@ -144,10 +144,13 @@
           value => $countries ) . "</td></tr>";
     $ret .= "<tr><td>&nbsp;</td><td>(if left blank, a user's country will be ignored)</td></tr>";
 
-    $ret .= "<tr><td valign='top'>Show this question to:</td><td>";
+    $ret .= "<tr><td valign='top'>Show this question to:</td><td><hr>";
     my $current_group = 0;
     foreach my $type (LJ::SiteMessages->get_options_list()) {
-        $ret .= '<br>' if($current_group != LJ::SiteMessages->get_group($type));
+        if ($current_group != LJ::SiteMessages->get_group($type)) {
+            $ret .= '<hr>'; 
+            $current_group = LJ::SiteMessages->get_group($type);
+        }
         
         my $ltype = lc $type;
         $ret .= $class->html_check
@@ -155,13 +158,14 @@
               id => 'show_' . $ltype,
               selected => LJ::SiteMessages->check_mask($type, $accounts)) . " <label for='show_$ltype'>$type Users</label><br />";
               
-        $current_group = LJ::SiteMessages->get_group($type);
     }
+    $ret .= $class->html_hidden( mid => $mid );
+    $ret .= "<hr><br>Note: a message will be visible to user if, in each options group, either <ol>" .
+            "<li> user satisfies (at least) one option in the group or</li>".
+            "<li> no options in the group are selected at all</li></ol></td></tr>";
+    $ret .= '</td></tr>'; 
 
-    $ret .= $class->html_hidden
-        ( mid => $mid );
-
-    $ret .= "<tr><td colspan='2' align='center'>";
+    $ret .= "<tr><td colspan='2' align='left'>";
     $ret .= $class->html_submit('Submit') . "</td></tr>";
     $ret .= "</table>";
     $ret .= $class->end_form;

Tags: gariev, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments