[dw-free] Inbox actions do not work well with single entry view
[commit: http://hg.dwscoalition.org/dw-free/rev/0e9424044833]
http://bugs.dwscoalition.org/show_bug.cgi?id=1979
When viewing inbox items for a single entry, fix some interactions: prev,
next, delete/mark all, etc.
Patch by
afuna.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1979
When viewing inbox items for a single entry, fix some interactions: prev,
next, delete/mark all, etc.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/LJ/NotificationInbox.pm
- cgi-bin/LJ/Widget/InboxFolder.pm
- htdocs/inbox/index.bml
- htdocs/js/esn_inbox.js
- htdocs/tools/endpoints/esn_inbox.bml
-------------------------------------------------------------------------------- diff -r ef785c00cbac -r 0e9424044833 cgi-bin/LJ/NotificationInbox.pm --- a/cgi-bin/LJ/NotificationInbox.pm Tue Nov 24 20:16:30 2009 +0000 +++ b/cgi-bin/LJ/NotificationInbox.pm Wed Nov 25 03:56:46 2009 +0000 @@ -526,7 +526,7 @@ sub can_add_bookmark { } sub delete_all { - my ( $self, $view ) = @_; + my ( $self, $view, %args ) = @_; my @items; # Unless in folder 'Bookmarks', don't fetch any bookmarks @@ -549,8 +549,10 @@ sub delete_all { @items = $self->bookmark_items; } elsif ( $view eq 'usermsg_sent' ) { @items = $self->usermsg_sent_items; - } elsif ( $view eq 'singleentry' ) { - @items = $self->singleentry_items; + } elsif ( $view eq 'singleentry' && $args{itemid} ) { + my $itemid = $args{itemid} + 0; + return unless $itemid; + @items = $self->singleentry_items( $itemid ); } @items = grep { !$self->is_bookmark($_->qid) } @items @@ -570,7 +572,7 @@ sub delete_all { } sub mark_all_read { - my ( $self, $view ) = @_; + my ( $self, $view, %args ) = @_; my @items; # Only get items in currently viewed folder and subfolders @@ -593,8 +595,10 @@ sub mark_all_read { @items = $self->bookmark_items; } elsif ( $view eq 'usermsg_sent' ) { @items = $self->usermsg_sent_items; - } elsif ( $view eq 'singleentry' ) { - @items = $self->singleentry_items; + } elsif ( $view eq 'singleentry' && $args{itemid} ) { + my $itemid = $args{itemid} + 0; + return unless $itemid; + @items = $self->singleentry_items( $itemid ); } # Mark read diff -r ef785c00cbac -r 0e9424044833 cgi-bin/LJ/Widget/InboxFolder.pm --- a/cgi-bin/LJ/Widget/InboxFolder.pm Tue Nov 24 20:16:30 2009 +0000 +++ b/cgi-bin/LJ/Widget/InboxFolder.pm Wed Nov 25 03:56:46 2009 +0000 @@ -44,6 +44,7 @@ sub render_body { my $nitems = $opts{items}; my $page = $opts{page} || 1; my $view = $opts{view} || "all"; + my $itemid = int( $opts{itemid} || 0 ); my $remote = LJ::get_remote(); my $unread_count = 1; #TODO get real number @@ -60,6 +61,11 @@ sub render_body { id => "inbox_view", }); + $msgs_body .= LJ::html_hidden({ + name => "itemid", + value => "$itemid", + id => "inbox_itemid", + }); # pagination my $page_limit = 15; $page = 1 if $page < 1; diff -r ef785c00cbac -r 0e9424044833 htdocs/inbox/index.bml --- a/htdocs/inbox/index.bml Tue Nov 24 20:16:30 2009 +0000 +++ b/htdocs/inbox/index.bml Wed Nov 25 03:56:46 2009 +0000 @@ -54,6 +54,8 @@ body<= $view = undef if $view eq 'archive' && ! LJ::is_enabled('esn_archive'); $view = undef if $view && !LJ::NotificationInbox->can("${view}_items"); + my $itemid = $view eq "singleentry" ? int( $POST{itemid} || $GET{itemid} || 0 ) : 0; + # Bolds the selected View/Folder my $selected_folder = $view || 'all'; $selected_folder = "entrycomment" if $selected_folder eq "singleentry"; @@ -85,9 +87,9 @@ body<= } if ($POST{markAllRead}) { - $inbox->mark_all_read( $view ); + $inbox->mark_all_read( $view, itemid => $itemid ); } elsif ($POST{deleteAll}) { - $inbox->delete_all( $view ); + $inbox->delete_all( $view, itemid => $itemid ); } else { # go through each item and see if it's checked foreach my $item (@$nitems) { @@ -125,9 +127,10 @@ body<= $body .= LJ::error_list(@errors) if (@errors); my $viewarg = $view ? "&view=$view" : ""; + my $itemidarg = $itemid ? "&itemid=$itemid" : ""; $body .= qq{ <div class="inbox_newitems pkg"> - <span class="esnlinks"><a href="$LJ::SITEROOT/inbox/?page=$page$viewarg" id="RefreshLink"><?_ml inbox.refresh _ml?></a> | + <span class="esnlinks"><a href="$LJ::SITEROOT/inbox/?page=$page$viewarg$itemidarg" id="RefreshLink"><?_ml inbox.refresh _ml?></a> | <a href="$LJ::SITEROOT/manage/subscriptions/"><?_ml inbox.manage_settings _ml?></a></span> </div> }; @@ -146,7 +149,6 @@ body<= my @all_items; if ($view) { if ( $view eq "singleentry" ) { - my $itemid = int( $POST{itemid} || $GET{itemid} ); @all_items = eval "\$inbox->${view}_items( $itemid )"; } else { @all_items = eval "\$inbox->${view}_items"; @@ -166,7 +168,9 @@ body<= page => $page, view => $view, mode => $GET{mode}, - items => \@all_items); + items => \@all_items, + itemid => $itemid, + ); $body .= qq{ </td></tr></table> @@ -195,6 +199,7 @@ LJ_cmtinfo['disableInlineDelete'] = 1; LJ_cmtinfo['disableInlineDelete'] = 1; var pageNum; var cur_folder = '<?_code return $POST{view} || $GET{view} || undef; _code?>'; +var itemid = <?_code return int( $POST{itemid} || $GET{itemid} || 0 ) _code?>; DOM.addEventListener(window, "load", setup, cur_folder); @@ -237,6 +242,7 @@ function xtra_args () { var args = ''; var view = $("inbox_view").value; if (view) args += "&view=" + view; + if (itemid) args += "&itemid="+itemid; return args; } diff -r ef785c00cbac -r 0e9424044833 htdocs/js/esn_inbox.js --- a/htdocs/js/esn_inbox.js Tue Nov 24 20:16:30 2009 +0000 +++ b/htdocs/js/esn_inbox.js Wed Nov 25 03:56:46 2009 +0000 @@ -9,7 +9,7 @@ DOM.addEventListener(window, "load", fun ESN_Inbox.initTableSelection(folder); ESN_Inbox.initContentExpandButtons(folder); - ESN_Inbox.initInboxBtns(folder, cur_folder); + ESN_Inbox.initInboxBtns(folder, cur_folder, itemid); ESN_Inbox.initActionLinks(folder); } }); @@ -156,7 +156,7 @@ ESN_Inbox.saveDefaultExpanded = function }; // set up inbox buttons -ESN_Inbox.initInboxBtns = function (folder, cur_folder) { +ESN_Inbox.initInboxBtns = function (folder, cur_folder, itemid) { // 2 instances of action buttons for (var i=1; i<=2; i++) { DOM.addEventListener($(folder + "_MarkRead_" + i), "click", function(e) { ESN_Inbox.markRead(e, folder) }); @@ -166,8 +166,8 @@ ESN_Inbox.initInboxBtns = function (fold // 2 instances of mark all and delete all buttons for (var i=1; i<=2; i++) { - DOM.addEventListener($(folder + "_MarkAllRead_" + i), "click", function(e) { ESN_Inbox.markAllRead(e, folder, cur_folder) }); - DOM.addEventListener($(folder + "_DeleteAll_" + i), "click", function(e) { ESN_Inbox.deleteAll(e, folder, cur_folder) }); + DOM.addEventListener($(folder + "_MarkAllRead_" + i), "click", function(e) { ESN_Inbox.markAllRead(e, folder, cur_folder, itemid) }); + DOM.addEventListener($(folder + "_DeleteAll_" + i), "click", function(e) { ESN_Inbox.deleteAll(e, folder, cur_folder, itemid) }); } }; @@ -223,17 +223,17 @@ ESN_Inbox.deleteItems = function (evt, f return false; }; -ESN_Inbox.markAllRead = function (evt, folder, cur_folder) { +ESN_Inbox.markAllRead = function (evt, folder, cur_folder, itemid) { Event.stop(evt); - ESN_Inbox.updateItems('mark_all_read', evt, folder, '', cur_folder); + ESN_Inbox.updateItems('mark_all_read', evt, folder, '', cur_folder, itemid); return false; }; -ESN_Inbox.deleteAll = function (evt, folder, cur_folder) { +ESN_Inbox.deleteAll = function (evt, folder, cur_folder, itemid) { Event.stop(evt); if (confirm("Delete all Inbox messages in the current folder except flagged?")) { - ESN_Inbox.updateItems('delete_all', evt, folder, '', cur_folder); + ESN_Inbox.updateItems('delete_all', evt, folder, '', cur_folder, itemid); } return false; }; @@ -245,7 +245,7 @@ ESN_Inbox.bookmark = function (evt, fold } // do an ajax action on the currently selected items -ESN_Inbox.updateItems = function (action, evt, folder, qid, cur_folder) { +ESN_Inbox.updateItems = function (action, evt, folder, qid, cur_folder, itemid) { if (!ESN_Inbox.hourglass) { var coords = DOM.getAbsoluteCursorPosition(evt); ESN_Inbox.hourglass = new Hourglass(); @@ -260,7 +260,8 @@ ESN_Inbox.updateItems = function (action "action": action, "qids": qids, "folder": folder, - "cur_folder": cur_folder + "cur_folder": cur_folder, + "itemid" : itemid }; var opts = { diff -r ef785c00cbac -r 0e9424044833 htdocs/tools/endpoints/esn_inbox.bml --- a/htdocs/tools/endpoints/esn_inbox.bml Tue Nov 24 20:16:30 2009 +0000 +++ b/htdocs/tools/endpoints/esn_inbox.bml Wed Nov 25 03:56:46 2009 +0000 @@ -49,6 +49,7 @@ $ret{items} = []; my $inbox = $u->notification_inbox; my $cur_folder = $POST{'cur_folder'} || 'all'; + my $itemid = $POST{itemid} ? $POST{itemid} + 0 : 0; # do actions if ($action eq 'mark_read') { @@ -65,7 +66,7 @@ $success = 1; } elsif ($action eq 'delete_all') { - @items = $inbox->delete_all( $cur_folder ); + @items = $inbox->delete_all( $cur_folder, itemid => $itemid ); foreach my $item (@items) { push @{$ret{items}}, { qid => $item->{qid}, deleted => 1 }; @@ -73,7 +74,7 @@ $success = 1; } elsif ($action eq 'mark_all_read') { - $inbox->mark_all_read( $cur_folder ); + $inbox->mark_all_read( $cur_folder, itemid => $itemid ); $success = 1; } elsif ($action eq 'set_default_expand_prop') { --------------------------------------------------------------------------------