added bookbag CRUD+ interface which supports create/delete/rename/show/hide/add_rec...
authorberick <berick@esilibrary.com>
Fri, 4 Mar 2011 19:43:36 +0000 (14:43 -0500)
committerberick <berick@esilibrary.com>
Fri, 4 Mar 2011 19:43:36 +0000 (14:43 -0500)
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Container.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/web/templates/default/opac/myopac/lists.tt2

index 40d867b..bb1371b 100644 (file)
@@ -118,7 +118,8 @@ sub load {
     return $self->load_myopac_circs if $path =~ /opac\/myopac\/circs/;
     return $self->load_myopac_fines if $path =~ /opac\/myopac\/main/;
     return $self->load_myopac_update_email if $path =~ /opac\/myopac\/update_email/;
-    return $self->load_myopac_bookbags if $path =~ /opac\/myopac\/bookbags/;
+    return $self->load_myopac_bookbags if $path =~ /opac\/myopac\/lists/;
+    return $self->load_myopac_bookbag_update if $path =~ /opac\/myopac\/list\/update/;
     return $self->load_myopac if $path =~ /opac\/myopac/;
 
     return Apache2::Const::OK;
@@ -131,8 +132,7 @@ sub load {
 sub redirect_ssl {
     my $self = shift;
     my $new_page = sprintf('https://%s%s', $self->apache->hostname, $self->apache->unparsed_uri);
-    $self->apache->print($self->cgi->redirect(-url => $new_page));
-    return Apache2::Const::REDIRECT;
+    return $self->generic_redirect($new_page);
 }
 
 # -----------------------------------------------------------------------------
@@ -143,8 +143,7 @@ sub redirect_auth {
     my $self = shift;
     my $login_page = sprintf('https://%s%s/login', $self->apache->hostname, $self->ctx->{opac_root});
     my $redirect_to = uri_escape($self->apache->unparsed_uri);
-    $self->apache->print($self->cgi->redirect(-url => "$login_page?redirect_to=$redirect_to"));
-    return Apache2::Const::REDIRECT;
+    return $self->generic_redirect("$login_page?redirect_to=$redirect_to");
 }
 
 # -----------------------------------------------------------------------------
@@ -248,20 +247,16 @@ sub load_login {
     my $acct = $self->apache->unparsed_uri;
     $acct =~ s#/login#/myopac/main#;
 
-    $self->apache->print(
-        $cgi->redirect(
-            -url => $cgi->param('redirect_to') || $acct,
-            -cookie => $cgi->cookie(
-                -name => COOKIE_SES,
-                -path => '/',
-                -secure => 1,
-                -value => $response->{payload}->{authtoken},
-                -expires => ($persist) ? CORE::time + $response->{payload}->{authtime} : undef
-            )
+    return $self->generic_redirect(
+        $cgi->param('redirect_to') || $acct,
+        $cgi->cookie(
+            -name => COOKIE_SES,
+            -path => '/',
+            -secure => 1,
+            -value => $response->{payload}->{authtoken},
+            -expires => ($persist) ? CORE::time + $response->{payload}->{authtime} : undef
         )
     );
-
-    return Apache2::Const::REDIRECT;
 }
 
 # -----------------------------------------------------------------------------
@@ -274,19 +269,15 @@ sub load_logout {
     # while logged in, go ahead and clear it out.
     $self->clear_anon_cache;
 
-    $self->apache->print(
-        $self->cgi->redirect(
-            -url => $self->ctx->{home_page},
-            -cookie => $self->cgi->cookie(
-                -name => COOKIE_SES,
-                -path => '/',
-                -value => '',
-                -expires => '-1h'
-            )
+    return $self->generic_redirect(
+        $self->ctx->{home_page},
+        $self->cgi->cookie(
+            -name => COOKIE_SES,
+            -path => '/',
+            -value => '',
+            -expires => '-1h'
         )
     );
-
-    return Apache2::Const::REDIRECT;
 }
 
 1;
index 5042641..5adff47 100644 (file)
@@ -233,8 +233,7 @@ sub load_place_hold {
             if($stat and $stat > 0) {
                 # if successful, return the user to the requesting page
                 $self->apache->log->info("Redirecting back to " . $cgi->param('redirect_to'));
-                $self->apache->print($cgi->redirect(-url => $cgi->param('redirect_to')));
-                return Apache2::Const::REDIRECT;
+                return $self->generic_redirect;
 
             } else {
                 $ctx->{hold_failed} = 1;
@@ -482,9 +481,8 @@ sub load_myopac_update_email {
 
     my $url = $self->apache->unparsed_uri;
     $url =~ s/update_email/main/;
-    $self->apache->print($self->cgi->redirect(-url => $url));
 
-    return Apache2::Const::REDIRECT;
+    return $self->generic_redirect($url);
 }
 
 sub load_myopac_bookbags {
@@ -496,7 +494,9 @@ sub load_myopac_bookbags {
 
     my $args = {order_by => {cbreb => 'name'}};
     $args->{limit} = $limit if $limit;
-    $args->{offset} = $limit if $limit;
+    $args->{offset} = $offset if $offset;
+
+    (undef, $ctx->{mylist}) = $self->fetch_mylist;
 
     $ctx->{bookbags} = $e->search_container_biblio_record_entry_bucket([
         {owner => $self->editor->requestor->id, btype => 'bookbag'},
@@ -507,4 +507,79 @@ sub load_myopac_bookbags {
 }
 
 
+# actions are create, delete, show, hide, rename, add_rec, delete_item
+# CGI is action, list=list_id, add_rec=bre_id, del_item=bucket_item_id, name=new_bucket_name
+sub load_myopac_bookbag_update {
+    my $self = shift;
+    my $e = $self->editor;
+    my $cgi = $self->cgi;
+    my $action = $cgi->param('action');
+    my $list_id = $cgi->param('list');
+    my $add_rec = $cgi->param('add_rec');
+    my $del_item = $cgi->param('del_item');
+    my $name = $cgi->param('name');
+    my $success = 0;
+    my $list;
+
+    if($action eq 'create') {
+        $list = Fieldmapper::container::biblio_record_entry_bucket->new;
+        $list->name($name);
+        $list->owner($e->requestor->id);
+        $list->btype('bookbag');
+        $list->pub('f');
+        $success = $U->simplereq('open-ils.actor', 
+            'open-ils.actor.container.create', $e->authtoken, 'biblio', $list)
+
+    } else {
+
+        $list = $e->retrieve_container_biblio_record_entry_bucket($list_id);
+
+        return Apache2::Const::HTTP_BAD_REQUEST unless 
+            $list and $list->owner == $e->requestor->id;
+    }
+
+    if($action eq 'delete') {
+        $success = $U->simplereq('open-ils.actor', 
+            'open-ils.actor.container.full_delete', $e->authtoken, 'biblio', $list_id);
+
+    } elsif($action eq 'show') {
+        unless($U->is_true($list->pub)) {
+            $list->pub('t');
+            $success = $U->simplereq('open-ils.actor', 
+                'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
+        }
+
+    } elsif($action eq 'hide') {
+        if($U->is_true($list->pub)) {
+            $list->pub('f');
+            $success = $U->simplereq('open-ils.actor', 
+                'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
+        }
+
+    } elsif($action eq 'rename') {
+        if($name) {
+            $list->name($name);
+            $success = $U->simplereq('open-ils.actor', 
+                'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
+        }
+
+    } elsif($action eq 'add_rec') {
+        my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
+        $item->bucket($list_id);
+        $item->target_biblio_record_entry($add_rec);
+        $success = $U->simplereq('open-ils.actor', 
+            'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item);
+
+    } elsif($action eq 'del_item') {
+        $success = $U->simplereq('open-ils.actor', 
+            'open-ils.actor.container.item.delete', $e->authtoken, 'biblio', $del_item);
+    }
+
+    return $self->generic_redirect if $success;
+
+    $self->ctx->{bucket_action} = $action;
+    $self->ctx->{bucket_action_failed} = 1;
+    return Apache2::Const::OK;
+}
+
 1
index 934714a..49954e7 100644 (file)
@@ -97,19 +97,15 @@ sub mylist_action_redirect {
     my $self = shift;
     my $cache_key = shift;
 
-    $self->apache->print(
-        $self->cgi->redirect(
-            -url => $self->cgi->param('redirect_to') || $self->ctx->{referer} || $self->ctx->{home_page},
-            -cookie => $self->cgi->cookie(
-                -name => COOKIE_ANON_CACHE,
-                -path => '/',
-                -value => ($cache_key) ? $cache_key : '',
-                -expires => ($cache_key) ? undef : '-1h'
-            )
+    return $self->generic_redirect(
+        undef, 
+        $self->cgi->cookie(
+            -name => COOKIE_ANON_CACHE,
+            -path => '/',
+            -value => ($cache_key) ? $cache_key : '',
+            -expires => ($cache_key) ? undef : '-1h'
         )
     );
-
-    return Apache2::Const::REDIRECT;
 }
 
 1;
index 50495a8..63b5213 100644 (file)
@@ -119,4 +119,22 @@ sub init_ro_object_cache {
     };
 }
 
+sub generic_redirect {
+    my $self = shift;
+    my $url = shift;
+    my $cookie = shift; # can be an array of cgi.cookie's
+
+    $self->apache->print(
+        $self->cgi->redirect(
+            -url => $url || 
+                $self->cgi->param('redirect_to') || 
+                $self->ctx->{referer} || 
+                $self->ctx->{home_page},
+            -cookie => $cookie
+        )
+    );
+
+    return Apache2::Const::REDIRECT;
+}
+
 1;
index c93fac5..6d1a6db 100644 (file)
@@ -2,60 +2,49 @@
     WRAPPER "default/opac/parts/base.tt2" +
         "default/opac/parts/myopac/base.tt2";
     myopac_page = "lists"  %]
-<div
-    style="margin-top: 6px;margin-left:20px;width:250px;padding:5px;"
-    id="mylist_div">
+<div style="margin-top: 6px;margin-left:20px;width:250px;padding:5px;" id="mylist_div">
+
+    <!-- new list creation -->
     <div style="padding-bottom: 7px;">
-        <h2 style="font-weight:normal;">Create new list</h2>
-        Enter the name of the new list:<br />
+        <h2 style="font-weight:normal;">[% l('Create new list') %]</h2>
+        [% l('Enter the name of the new list:') %]<br/>
         <input type="text" id="mylist_new" />
     </div>
+
     <table cellpadding="0" cellspacing="10" border="0">
         <tr>
             <td>
-                Share this list?
-                <a href="#"><img
-                    alt="Sharing Help"
+                [% l('Share this list?') %]
+                <a href="#"><img alt="Sharing Help"     
                     src="[% ctx.media_prefix %]/images/question-mark.png" /></a>
             </td>
             <td>
-                <input type="radio" value="0" name="shareList"
-                    id="shareListNo" checked="checked" />
-                <label for="shareListNo">No</label>
-                <br />
-                <input type="radio" value="1" name="shareList"
-                    id="shareListYes" />
-                    <label for="shareListYes">Yes</label>
+                <input type="radio" value="0" name="shareList" checked="checked" />[% l('No') %]
+                <br/>
+                <input type="radio" value="1" name="shareList"/>[% l('Yes') %]
             </td>
         </tr>
     </table>
-    <a href="#"><img
-        alt="Submit" src="[% ctx.media_prefix %]/images/btnSubmit.png" /></a>
+    <a href="#"><img alt="[% l('Submit') %]" src="[% ctx.media_prefix %]/images/btnSubmit.png"/></a>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-    <a href="#"><img
-        alt="Cancel" src="[% ctx.media_prefix %]/images/btnCancel.png" /></a>
+    <a href="#"><img alt="[% l('Cancel') %]" src="[% ctx.media_prefix %]/images/btnCancel.png" /></a>
 </div>
 <div id='myopac_bookbag_div' style="padding:5px;">
     <div class="header_middle">
-        <span id="acct_holds_header" style="float:left;">My Lists</span>
-        <span style="float:right;">
-            <a class="hide_me" href="#">Export List</a>
-        </span>
+        <span id="acct_holds_header" style="float:left;">[% l('My Lists') %]</span>
+        <span style="float:right;"><a class="hide_me" href="#">[% l('Export List') %]</a></span>
     </div>
     <div style="float:right;width:85px;">
         <div style="position:absolute">
             <div style="position:relative;top:13px;">
-                <a href="#"
-                    style="position:relative;top:-3px;left:-5px;"><img
-                    alt="Saving Help"
+                <a href="#" style="position:relative;top:-3px;left:-5px;"><img alt="[% l('Saving Help') %]" 
                     src="[% ctx.media_prefix %]/images/question-mark.png" /></a>
-                <a id='acct_lists_save' href="#"><img alt="Save"
-                    src="[% ctx.media_prefix %]/images/save-btn.png" /></a>
+                <a href="#"><img alt="[% l('Save') %]" src="[% ctx.media_prefix %]/images/save-btn.png"/></a>
             </div>
         </div>
     </div>
     <div class="clear-both pad-top-ten">
-        <a href="#">+ Add new list</a>
+        <a href="#">[% l('+ Add new list') %]</a>
     </div>
     <div id="temp_wrapper">
         <div id='acct_list_template2' class="hide_me">
                 <table cellpadding="0" cellspacing="0" border="0">
                     <tr>
                         <td style="font-weight:bold;padding-right:10px;" id='anon_list_name'>
-                            Temporary List
+                            [% l('Temporary List') %]
                         </td>
                         <td>
                             <a href="#"><img
-                                alt="Anonymous List Help"
+                                alt="[% l('Anonymous List Help') %]"
                                 src="[% ctx.media_prefix %]/images/question-mark.png" /></a>
                         </td>
                     </tr>
     
             <table id="acct_list_header_anon" cellpadding='0' cellspacing='0' border='0'>
                 <tr>
-                    <td width="1%" style="padding-left:10px;">
-                        <input type="checkbox" id="check_all_list_anon" />
+                    <td width="1%" style="padding-left:10px;"><input type="checkbox"/>
                     </td>
                     <td width="98%" style="padding-left:5px;">Title</td>
                     <td width="1%">
                         <select style='width:175px;margin-right:11px;'
                             name="list_actions" id="sel_all_list_anon">
-                            <option value="0">-- Actions for this list --</option>
-                            <option value="hold">Place Hold</option>
-                            <option value="remove">Remove Items</option>
+                            <option value="0">[% l('-- Actions for this list --') %]</option>
+                            <option value="hold">[% l('Place Hold') %]</option>
+                            <option value="remove">[% l('Remove Items') %]</option>
                         </select>
                     </td>
                 </tr>
         <div id='acct_lists_prime'>
             <div id='acct_list_template'>
                 <div style="width:100%">
-                    <div style="float:left;font-weight:bold;padding-top:5px;"
-                        name='list_name'></div>
+                    <div style="float:left;font-weight:bold;padding-top:5px;" name='list_name'></div>
+
                     <div style="float:left;padding:5px 0px 0px 10px;">
-                        <a target='_blank' name='share_list_rss'
-                            class='hide_me'><img alt="RSS Feed" border="0"
-                            src="/opac[% ctx.media_prefix %]/images/small-rss.png"
-                            title="You are sharing this list"/></a>
+
+                        <a target='_blank' name='share_list_rss' class='hide_me'><img 
+                            alt="[% l('RSS Feed') %]" border="0" src="[% ctx.media_prefix %]/images/small-rss.png"
+                            title="[% l('You are sharing this list') %]"/></a>
                     </div>
                     <div style="float:left;padding:5px 0px 0px 10px;">
-                        <a href="#" name="share_list_link">Share</a>
+                        <a href="#" name="share_list_link">[% l('Share') %]</a>
                     </div>
                     <div style="float:left;padding:5px 0px 0px 10px;">
-                        <a href="#" name="remove_list">Remove</a>
+                        <a href="#" name="remove_list">[% l('Remove') %]</a>
                     </div>
                     <div class="clear-both pad-bottom-five"></div>
                 </div>
-                <table id="acct_list_header" cellpadding='0' cellspacing='0'
-                    border='0'>
+                <table id="acct_list_header" cellpadding='0' cellspacing='0' border='0'>
                     <tr>
                         <td width="1%" style="padding-left:10px;">
                             <input type="checkbox" id="check_all_list" />
                         <td width="98%" style="padding-left:5px;">Title</td>
                         <td width="1%">
                             <select style='width:175px;margin-right:11px;' name="list_actions">
-                                <option value="0">-- Actions for this list --</option>
-                                <option value="hold">Place Hold</option>
-                                <option value="remove">Remove Items</option>
+                                <option value="0">[% l('-- Actions for this list --') %]</option>
+                                <option value="hold">[% l('Place Hold') %]</option>
+                                <option value="remove">[% l('Remove Items') %]</option>
                             </select>
                         </td>
                     </tr>
             </tr>
         </thead>
         <tbody id='myopac_bookbag_tbody'>
-            <tr id='myopac_bookbag_tr'>
+            <tr>
                 <td>
-                    <a href='#' class='classic_link'
-                        name='myopac_expand_bookbag'> </a>
+                    <a href='#' class='classic_link' name='myopac_expand_bookbag'> </a>
                 </td>
                 <td>
                     <span name='myopac_bookbag_item_count'> </span>
-                    <span> [% l("Items") %]</span>
+                    <span>[% l("Items") %]</span>
                 </td>
                 <td>
-                    <span name='myopac_bb_published_no' class='hide_me'>
-                        [% l("No") %]
-                    </span>
-                    <span name='myopac_bb_published_yes' class='hide_me'>
-                        [% l("Yes") %]
-                    </span>
-                    <a name='myopac_bb_published_view'
-                        class='classic_link hide_me'>[% l("(View)") %]</a>
-                    <a name='myopac_bb_published_atom'
-                        class='unadorned_link hide_me'>
-                        <img alt="RSS Feed" border="0"
-                        src="/opac[% ctx.media_prefix %]/images/small-rss.png"
-                        title="[% l("ATOM Feed") %]" />
+                    <span name='myopac_bb_published_no' class='hide_me'>[% l("No") %]</span>
+                    <span name='myopac_bb_published_yes' class='hide_me'>[% l("Yes") %]</span>
+                    <a class='classic_link hide_me'>[% l("(View)") %]</a>
+
+                    <a class='unadorned_link hide_me'><img 
+                        alt="[% l('RSS Feed') %]" border="0"
+                        src="[% ctx.media_prefix %]/images/small-rss.png" title="[% l("ATOM Feed") %]" />
                     </a>
                 </td>
                 <td>
-                    <a name='myopac_bb_make_unpublished'
-                        class='classic_link hide_me'>[% l("Hide") %]</a>
-                    <a name='myopac_bb_make_published'
-                        class='classic_link hide_me'>[% l("Share this Bookbag") %]</a>
+                    <a class='classic_link hide_me'>[% l("Hide") %]</a>
+                    <a class='classic_link hide_me'>[% l("Share this Bookbag") %]</a>
                 </td>
                 <td>
-                    <a class='classic_link' href='#'
-                        name='myopac_container_delete'>[% l("Delete") %]</a>
+                    <a class='classic_link' href='#'>[% l("Delete") %]</a>
                 </td>
             </tr>
         </tbody>
             <tr>
                 <td>
                     <span style='padding: 5px;'>[% l("Share this Bookbag") %]</span>
-                    <a class='classic_link'
-                        href='#'><b>[% l("(Help)") %]</b></a>
+                    <a class='classic_link' href='#'><b>[% l("(Help)") %]</b></a>
                     <span>[% l("Yes") %]</span>
                     <input type='radio' name='bb_public' id='bb_public_yes'/>
                     <span>[% l("No") %]</span>
                     <input type='radio' name='bb_public' id='bb_public_no' checked='checked'/>
-                    <input style='padding-left: 10px;' type='submit'
-                        value='[% l("Submit") %]' />
+                    <input style='padding-left: 10px;' type='submit' value='[% l("Submit") %]' />
                 </td>
             </tr>
         </tbody>
         <tbody id='myopac_bookbag_items_tbody'>
             <tr id='myopac_bookbag_items_row'>
                 <td>
-                    <a name='myopac_bookbag_items_title'
-                        class='classic_link'> </a>
+                    <a name='myopac_bookbag_items_title' class='classic_link'> </a>
                 </td>
                 <td name='myopac_bookbag_items_author'></td>
                 <td>
-                    <a name='myopac_bookbag_items_remove'
-                        class='classic_link'>[% l("remove") %]</a>
+                    <a name='myopac_bookbag_items_remove' class='classic_link'>[% l("remove") %]</a>
                 </td>    
             </tr>
         </tbody>