htdocs/inbox/index.bml
author mark
Wed Apr 15 04:44:57 2009 +0000
branchproduction
changeset 707 66c67e811173
parent 655 53dd152590d8
child 903 9744cbe5ad6a
permissions -rw-r--r--
http://bugs.dwscoalition.org/show_bug.cgi?id=295

Remove a heckuva lot of LJ blue still sitting around.

Patch by ursamajor.
     1 <?page
     2 body<=
     3 <?_code
     4 {
     5     use strict;
     6     use vars qw($title $body $head %GET %POST);
     7     use Class::Autouse qw (
     8                            LJ::NotificationInbox
     9                            LJ::Event
    10                            );
    11 
    12     $title = $ML{'.title'};
    13     $body = "";
    14 
    15     my $remote = LJ::get_remote()
    16         or return "<?needlogin?>";
    17 
    18     return $ML{'.error.not_ready'} unless $remote->can_use_esn;
    19 
    20     LJ::need_res(qw(
    21                   js/core.js
    22                   js/dom.js
    23                   js/view.js
    24                   js/controller.js
    25                   js/datasource.js
    26                   js/checkallbutton.js
    27                   js/selectable_table.js
    28                   js/httpreq.js
    29                   js/hourglass.js
    30                   js/esn_inbox.js
    31                   stc/esn.css
    32                   stc/lj_base.css
    33                   ));
    34 
    35     my $formauth = LJ::form_auth();
    36 
    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} }) );
    40 
    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});
    49         }
    50     }
    51 
    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"));
    56 
    57     # Bolds the selected View/Folder
    58     my $selected_folder = $view || 'all';
    59     $selected_folder = qq(
    60         <style>#esn_folder_$selected_folder {
    61         font-weight: bold;
    62         background-color: #ffd8d8;
    63         border: 1px solid #bbb;
    64         }</style>
    65         );
    66     $head = $selected_folder;
    67 
    68     # get events sitting in inbox
    69     my @notifications = $inbox->items;
    70 
    71     my @errors;
    72 
    73     if (LJ::did_post()) {
    74 
    75         # operate on notices by default but switch if view parameter specified
    76         my $nitems = \@notifications;
    77         my $name = "all";
    78         if ($view) {
    79             my @items = eval "\$inbox->${name}_items";
    80             push @items, $inbox->usermsg_sent_items;
    81             $nitems = \@items;
    82         }
    83 
    84         if ($POST{markAllRead}) {
    85             $inbox->mark_all_read( $view );
    86         } elsif ($POST{deleteAll}) {
    87             $inbox->delete_all( $view );
    88         } else {
    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"};
    93                 next unless $checked;
    94 
    95                 if ($POST{markRead}) {
    96                     $item->mark_read;
    97                 } elsif ($POST{markUnread}) {
    98                     $item->mark_unread;
    99                 } elsif ($POST{delete}) {
   100                     $item->delete;
   101                 }
   102             }
   103 
   104             # reload inbox after making changes
   105             @$nitems = eval "\$inbox->${name}_items";
   106         }
   107     }
   108 
   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});
   114     }
   115     if ($GET{bookmark_on} && $GET{bookmark_on} =~ /^\d+$/) {
   116         $inbox->remove_bookmark($GET{bookmark_on});
   117     }
   118 
   119     # Pagination
   120     my $page = int($POST{page} || $GET{page});
   121 
   122     $body .= LJ::error_list(@errors) if (@errors);
   123 
   124     $body .= qq{
   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>
   127     </div> };
   128 
   129     # Inbox Nav
   130     $body .= qq{
   131         <table style="width: 100%"><tr><td valign="top" style="padding-right: 12px">};
   132     $body .= LJ::Widget::InboxFolderNav->render( 'page' => 1 );
   133 
   134     $body .= qq{
   135         </td>
   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%;">
   138     };
   139 
   140     # Filter by view if specified
   141     my @all_items;
   142     if ($view) {
   143         @all_items = eval "\$inbox->${view}_items";
   144     } else {
   145         @all_items = $inbox->all_items;
   146     }
   147 
   148     # Pagination
   149     my $page = int($POST{page} || $GET{page});
   150     
   151     $body .= LJ::Widget::InboxFolder->render(
   152                      folder  => "all",
   153                      reply_btn => 1,
   154                      expand    => $GET{expand},
   155                      inbox     => $inbox,
   156                      page      => $page,
   157                      view      => $view,
   158                      mode      => $GET{mode},
   159                      items     => \@all_items);
   160 
   161     $body .= qq{
   162         </td></tr></table>
   163     };
   164 
   165     return $body;
   166 }
   167  _code?>
   168 <=body
   169 title=><?_code return $title; _code?>
   170 head<=
   171 
   172 <?_code return $head; _code?>
   173 
   174 <script>
   175 LJ_cmtinfo = {};
   176 LJ_cmtinfo['disableInlineDelete'] = 1;
   177 var pageNum;
   178 var cur_folder = '<?_code return $POST{view} || $GET{view} || undef; _code?>';
   179 
   180 DOM.addEventListener(window, "load", setup, cur_folder);
   181 
   182 var tableview;
   183 var checkallButton;
   184 /* Can have multiple tables or folders displayed on the same page */
   185 var folders = ['all'];
   186 
   187 function setup (e) {
   188     if (! Site.has_remote) return;
   189 
   190     for (var i=0; i<folders.length; i++) {
   191         var name = folders[i];
   192         tableview = new View();
   193 
   194         tableview.init({ "view": $(name + "_Table") });
   195 
   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()
   203             });
   204         }
   205     }
   206 
   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);
   211 }
   212 
   213 if ($("pageNum")) pageNum = parseInt($("pageNum").value);
   214 }
   215 
   216 function xtra_args () {
   217     var args = '';
   218     var view = $("inbox_view").value;
   219     if (view) args += "&view=" + view;
   220     return args;
   221 }
   222 
   223 function Page_Prev (e) {
   224     if (pageNum) {
   225         var args = xtra_args();
   226         window.location.href = "<?siteroot?>/inbox/?page=" + (pageNum - 1) + args;
   227     }
   228 }
   229 
   230 function Page_Next (e) {
   231     if (pageNum) {
   232         var args = xtra_args();
   233         window.location.href = "<?siteroot?>/inbox/?page=" + (pageNum + 1) + args;
   234     }
   235 }
   236 
   237 </script>
   238 
   239 <=head
   240 
   241 page?>