Skip to content

Commit

Permalink
[#1035] Convert profileexpandcollapse endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
afuna committed Nov 6, 2014
1 parent b171233 commit 92d4be1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 55 deletions.
37 changes: 37 additions & 0 deletions cgi-bin/DW/Controller/RPC/MiscLegacy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ DW::Routing->register_rpc( "esn_subs", \&esn_subs_handler, format => 'json' );
DW::Routing->register_rpc( "getsecurityoptions", \&get_security_options_handler, format => 'json' );
DW::Routing->register_rpc( "gettags", \&get_tags_handler, format => 'json' );
DW::Routing->register_rpc( "load_state_codes", \&load_state_codes_handler, format => 'json' );
DW::Routing->register_rpc( "profileexpandcollapse", \&profileexpandcollapse_handler, format => 'json' );
DW::Routing->register_rpc( "userpicselect", \&get_userpics_handler, format => 'json' );
DW::Routing->register_rpc( "widget", \&widget_handler, format => 'json' );

Expand Down Expand Up @@ -551,6 +552,42 @@ sub load_state_codes_handler {
);
}

sub profileexpandcollapse_handler {
my $r = DW::Request->get;
my $get = $r->get_args;

# if any opts aren't defined, they'll be passed in as empty strings
my $mode = $get->{mode} eq "save" ? "save" : "load";
my $header = $get->{header} eq "" ? undef : $get->{header};
my $expand = $get->{expand} eq "false" ? 0 : 1;

my $remote = LJ::get_remote();
return unless $remote;

if ( $mode eq "save" ) {
return unless $header && $header =~ /_header$/;
$header =~ s/_header$//;

my %is_collapsed = map { $_ => 1 } split( /,/, $remote->prop( "profile_collapsed_headers" ) );

# this header is already saved as expanded or collapsed, so we don't need to do anything
return if $is_collapsed{$header} && !$expand;
return if !$is_collapsed{$header} && $expand;

# remove header from list if expanding
# add header to list if collapsing
if ( $expand ) {
delete $is_collapsed{$header};
$remote->set_prop( profile_collapsed_headers => join( ",", keys %is_collapsed ) );
} else { # collapse
$is_collapsed{$header} = 1;
$remote->set_prop( profile_collapsed_headers => join( ",", keys %is_collapsed ) );
}
} else { # load
return DW::RPC->out( headers => [ split( /,/, $remote->prop( "profile_collapsed_headers" ) ) ] );
}
}

sub get_userpics_handler {
my $r = DW::Request->get;
my $get = $r->get_args;
Expand Down
1 change: 0 additions & 1 deletion cgi-bin/LJ/Global/Defaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ no strict "vars";
foreach my $src (keys %ajaxmapping) {
$LJ::AJAX_URI_MAP{$src} ||= $ajaxmapping{$src};
}
$LJ::AJAX_URI_MAP{profileexpandcollapse} = 'tools/endpoints/profileexpandcollapse.bml';

# List all countries that have states listed in 'codes' table in DB
# These countries will be displayed with drop-down menu on Profile edit page
Expand Down
54 changes: 0 additions & 54 deletions htdocs/tools/endpoints/profileexpandcollapse.bml

This file was deleted.

0 comments on commit 92d4be1

Please sign in to comment.