6 use vars qw($title $body $head %GET %POST);
7 use Class::Autouse qw (
12 $title = $ML{'.title'};
15 my $remote = LJ::get_remote()
16 or return "<?needlogin?>";
18 return $ML{'.error.not_ready'} unless $remote->can_use_esn;
27 js/selectable_table.js
35 my $formauth = LJ::form_auth();
37 # get the user's inbox
38 my $inbox = $remote->notification_inbox
39 or return LJ::error_list( BML::ml('.error.couldnt_retrieve_inbox', { 'user' => $remote->{user} }) );
41 # 2 instances of action buttons
42 # map each to one variable
43 my @buttons = qw{markRead markUnread delete markAllRead deleteAll};
44 foreach my $button (@buttons) {
45 for (my $i=1; $i<=2; $i++) {
46 my $sfx_button = $button . "_" . $i;
47 $GET{$button} = $GET{$sfx_button} if($GET{$sfx_button} && !$GET{$button});
48 $POST{$button} = $POST{$sfx_button} if($POST{$sfx_button} && !$POST{$button});
52 # Take a supplied filter but default it to undef unless it is valid
53 my $view = $POST{view} || $GET{view} || undef;
54 $view = undef if ($view eq 'archive' && $LJ::DISABLED{esn_archive});
55 $view = undef if ($view && !LJ::NotificationInbox->can("${view}_items"));
57 # Bolds the selected View/Folder
58 my $selected_folder = $view || 'all';
59 $selected_folder = qq(
60 <style>#esn_folder_$selected_folder {
62 background-color: #ffd8d8;
63 border: 1px solid #bbb;
66 $head = $selected_folder;
68 # get events sitting in inbox
69 my @notifications = $inbox->items;
75 # operate on notices by default but switch if view parameter specified
76 my $nitems = \@notifications;
79 my @items = eval "\$inbox->${name}_items";
80 push @items, $inbox->usermsg_sent_items;
84 if ($POST{markAllRead}) {
85 $inbox->mark_all_read( $view );
86 } elsif ($POST{deleteAll}) {
87 $inbox->delete_all( $view );
89 # go through each item and see if it's checked
90 foreach my $item (@$nitems) {
91 my $qid = eval { $item->qid } or next;
92 my $checked = $POST{"${name}_Check-$qid"};
95 if ($POST{markRead}) {
97 } elsif ($POST{markUnread}) {
99 } elsif ($POST{delete}) {
104 # reload inbox after making changes
105 @$nitems = eval "\$inbox->${name}_items";
109 # Allow bookmarking to work without Javascript
110 # or before JS events are bound
111 if ($GET{bookmark_off} && $GET{bookmark_off} =~ /^\d+$/) {
112 push @errors, $ML{'.error.max_bookmarks'}
113 unless $inbox->add_bookmark($GET{bookmark_off});
115 if ($GET{bookmark_on} && $GET{bookmark_on} =~ /^\d+$/) {
116 $inbox->remove_bookmark($GET{bookmark_on});
120 my $page = int($POST{page} || $GET{page});
122 $body .= LJ::error_list(@errors) if (@errors);
125 <div class="inbox_newitems pkg">
126 <span class="esnlinks"><a href="$LJ::SITEROOT/inbox/?page=$page" id="RefreshLink"><?_ml inbox.refresh _ml?></a> | <a href="$LJ::SITEROOT/manage/subscriptions/"><?_ml inbox.manage_settings _ml?></a></span>
131 <table style="width: 100%"><tr><td valign="top" style="padding-right: 12px">};
132 $body .= LJ::Widget::InboxFolderNav->render( 'page' => 1 );
136 <td width="1" height="100%" style="border-left: 1px solid #ccc"><img src="$LJ::IMGPREFIX/spacer.gif"></td>
137 <td valign="top" style="padding-left: 10px; width: 100%;">
140 # Filter by view if specified
143 @all_items = eval "\$inbox->${view}_items";
145 @all_items = $inbox->all_items;
149 my $page = int($POST{page} || $GET{page});
151 $body .= LJ::Widget::InboxFolder->render(
154 expand => $GET{expand},
159 items => \@all_items);
169 title=><?_code return $title; _code?>
172 <?_code return $head; _code?>
176 LJ_cmtinfo['disableInlineDelete'] = 1;
178 var cur_folder = '<?_code return $POST{view} || $GET{view} || undef; _code?>';
180 DOM.addEventListener(window, "load", setup, cur_folder);
184 /* Can have multiple tables or folders displayed on the same page */
185 var folders = ['all'];
188 if (! Site.has_remote) return;
190 for (var i=0; i<folders.length; i++) {
191 var name = folders[i];
192 tableview = new View();
194 tableview.init({ "view": $(name + "_Table") });
196 // 2 instances of action buttons
197 for (var i=1; i<=2; i++) {
198 checkallButton = new CheckallButton();
199 checkallButton.init({
200 "class": "InboxItem_Check",
201 "button": $(name + "_CheckAll_" + i),
202 "parent": tableview.getView()
207 // 2 instances of action buttons
208 for (var i=1; i<=2; i++) {
209 DOM.addEventListener($("Page_Prev_"+i), "click", Page_Prev);
210 DOM.addEventListener($("Page_Next_"+i), "click", Page_Next);
213 if ($("pageNum")) pageNum = parseInt($("pageNum").value);
216 function xtra_args () {
218 var view = $("inbox_view").value;
219 if (view) args += "&view=" + view;
223 function Page_Prev (e) {
225 var args = xtra_args();
226 window.location.href = "<?siteroot?>/inbox/?page=" + (pageNum - 1) + args;
230 function Page_Next (e) {
232 var args = xtra_args();
233 window.location.href = "<?siteroot?>/inbox/?page=" + (pageNum + 1) + args;