more bookbag fun
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 11 Jan 2006 22:13:45 +0000 (22:13 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 11 Jan 2006 22:13:45 +0000 (22:13 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2692 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm
Open-ILS/web/opac/common/js/config.js
Open-ILS/web/opac/skin/default/js/container.js [new file with mode: 0644]
Open-ILS/web/opac/skin/default/js/myopac.js
Open-ILS/web/opac/skin/default/js/rdetail.js
Open-ILS/web/opac/skin/default/xml/myopac/myopac_bookbags.xml
Open-ILS/web/opac/skin/default/xml/page_myopac.xml
Open-ILS/web/opac/skin/default/xml/page_rdetail.xml

index 77ceb26..259ec73 100644 (file)
@@ -21,6 +21,12 @@ $types{'copy'} = "$meth.copy_bucket";
 $types{'user'} = "$meth.user_bucket";
 my $event;
 
+sub _sort_buckets {
+       my $buckets = shift;
+       return $buckets unless ($buckets && $buckets->[0]);
+       return [ sort { $a->name cmp $b->name } @$buckets ];
+}
+
 __PACKAGE__->register_method(
        method  => "bucket_retrieve_all",
        api_name        => "open-ils.actor.container.all.retrieve_by_user",
@@ -107,11 +113,8 @@ __PACKAGE__->register_method(
 sub bucket_retrieve_class {
        my( $self, $client, $authtoken, $userid, $class, $type ) = @_;
 
-       my( $staff, $user, $evt );
-       ($staff, $evt) = $apputils->checkses($authtoken);
-       return $evt if $evt;
-
-       ($user, $evt) = $apputils->checkrequestor($staff, $userid, 'VIEW_CONTAINER');
+       my( $staff, $user, $evt ) = 
+               $apputils->checkses_requestor( $authtoken, $userid, 'VIEW_CONTAINER' );
        return $evt if $evt;
 
        $logger->debug("User " . $staff->id . 
@@ -128,7 +131,7 @@ sub bucket_retrieve_class {
                $buckets = $apputils->simplereq( $svc, $meth, { owner => $userid } );
        }
 
-       return $buckets;
+       return _sort_buckets($buckets);
 }
 
 __PACKAGE__->register_method(
@@ -152,6 +155,7 @@ sub bucket_create {
        $logger->activity( "User " . $staff->id . 
                " creating a new continer for user " . $bucket->owner );
 
+       $bucket->clear_id;
        $logger->debug("Creating new container object: " . Dumper($bucket));
 
        my $method = $types{$class} . ".create";
@@ -243,6 +247,7 @@ sub item_delete {
        
        ( $item, $evt ) = $apputils->fetch_container_item( $itemid, $class );
        return $evt if $evt;
+
        ( $bucket, $evt ) = $apputils->fetch_container($item->bucket, $class);
        return $evt if $evt;
 
@@ -260,6 +265,34 @@ sub item_delete {
        return $resp;
 }
 
+__PACKAGE__->register_method(
+       method  => 'full_delete',
+       api_name        => 'open-ils.actor.container.full_delete',
+       notes           => "Complety removes a container including all attached items",
+);     
+
+sub full_delete {
+       my( $self, $client, $authtoken, $class, $containerId ) = @_;
+       my( $staff, $target, $container, $evt);
+
+       ( $container, $evt ) = $apputils->fetch_container($containerId, $class);
+       return $evt if $evt;
+
+       ( $staff, $target, $evt ) = $apputils->checkses_requestor( 
+               $authtoken, $container->owner, 'DELETE_CONTAINER' );
+       return $evt if $evt;
+
+       $logger->activity("User " . $staff->id . " deleting full container $containerId");
+
+       my $meth = $types{$class};
+       my $items = $apputils->simplereq( $svc, "$meth"."_item.search.bucket.atomic", $containerId );
+
+       $self->item_delete( $client, $authtoken, $class, $_->id ) for @$items;
+
+       $meth = $types{$class} . ".delete";
+       return $apputils->simplereq( $svc, $meth, $containerId );
+}
+
 
 
 1;
index 8af0612..5a3d24f 100644 (file)
@@ -235,7 +235,7 @@ var FETCH_CNBROWSE_PREV                     = 'open-ils.search:open-ils.search.callnumber.browse.p
 var FETCH_CNBROWSE_NEXT                        = 'open-ils.search:open-ils.search.callnumber.browse.page_down';
 var FETCH_CONTAINERS                           = 'open-ils.actor:open-ils.actor.container.retrieve_by_class';
 var CREATE_CONTAINER                           = 'open-ils.actor:open-ils.actor.container.create';
-var DELETE_CONTAINER                           = 'open-ils.actor:open-ils.actor.container.delete';
+var DELETE_CONTAINER                           = 'open-ils.actor:open-ils.actor.container.full_delete';
 var CREATE_CONTAINER_ITEM              = 'open-ils.actor:open-ils.actor.container.item.create';
 var DELETE_CONTAINER_ITEM              = 'open-ils.actor:open-ils.actor.container.item.delete';
 var FLESH_CONTAINER                            = 'open-ils.actor:open-ils.actor.container.flesh';
diff --git a/Open-ILS/web/opac/skin/default/js/container.js b/Open-ILS/web/opac/skin/default/js/container.js
new file mode 100644 (file)
index 0000000..9f24129
--- /dev/null
@@ -0,0 +1,60 @@
+
+function containerDoRequest( req, callback, args ) {
+
+       if( callback ) {
+               req.callback( callback );
+               req.request.args = args;
+               req.send();
+               return null;
+       }
+
+       req.send(true); 
+       return req.result();
+}
+
+
+function containerFetchAll( callback, args ) {
+       var req = new Request( 
+               FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
+       return containerDoRequest( req, callback, args );
+}
+
+function containerFlesh( id, callback, args ) {
+       var req = new Request( FLESH_CONTAINER, G.user.session, 'biblio', id );                                                                                               
+       return containerDoRequest( req, callback, args );
+}
+
+function containerDelete( id, callback, args ) {
+       var req = new Request( DELETE_CONTAINER, G.user.session, 'biblio', id );
+       return containerDoRequest(req, callback, args );
+}
+
+
+function containerCreate( name, callback, args ) {
+
+       var container = new cbreb();
+       container.btype('bookbag');
+       container.owner( G.user.id() );
+       container.name( name );
+
+       var req = new Request( 
+               CREATE_CONTAINER, G.user.session, 'biblio', container );
+       return containerDoRequest( req, callback, args );
+}
+
+function containerCreateItem( containerId, target, callback, args ) {
+
+       var item = new cbrebi();
+       item.target_biblio_record_entry(target);
+       item.bucket(containerId);
+
+       var req = new Request( CREATE_CONTAINER_ITEM, 
+               G.user.session, 'biblio', item );
+
+       return containerDoRequest( req, callback, args );
+}
+
+function containerRemoveItem( id, callback, args ) {
+       var req = new Request( DELETE_CONTAINER_ITEM, G.user.session, 'biblio', id );
+       return containerDoRequest( req, callback, args );
+}
index b61474b..e5518e7 100644 (file)
@@ -530,11 +530,7 @@ function myOPACShowBookbags(force) {
 
        removeChildren(tbody);
 
-       var req = new Request( 
-               FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
-       
-       req.send(true);
-       var containers = req.result();
+       var containers = containerFetchAll();
 
        var found = false;
        for( var i in containers ) {
@@ -543,10 +539,12 @@ function myOPACShowBookbags(force) {
                var row = containerTemplate.cloneNode(true);
                row.id = 'myopac_bookbag_row_' + cont.id();
                var link = $n(row, 'myopac_expand_bookbag');
+               var dlink = $n(row, 'myopac_container_delete');
                link.appendChild( text(cont.name()) );
                link.setAttribute('href', 
                        'javascript:myOPACExpandBookbag("' + cont.id() + '","' + cont.name() + '");');
                myOPACFetchBBItems( cont.id(), row );
+               dlink.setAttribute('href', 'javascript:myOPACDeleteBookbag("'+cont.id()+'");');
                tbody.appendChild(row); 
        }
 
@@ -554,23 +552,32 @@ function myOPACShowBookbags(force) {
        else unHideMe($('myopac_bookbag_table'));       
 }
 
-function myOPACFetchBBItems( id, row, block ) {
-       var req = new Request( FLESH_CONTAINER, G.user.session, 'biblio', id );
-       req.request.row = row;
+function myOPACDeleteBookbag(id) {
+       if( confirm( $('myopac_delete_bookbag_warn').innerHTML ) ) {
+               var result = containerDelete(id);
+               var code = checkILSEvent(result);
+               if(code) { alertILSEvent(code); return; }
+               hideMe($('myopac_bookbag_items_table'));
+               hideMe($('myopac_bookbag_items_name'));
+               hideMe($('myopac_bookbag_no_items'));
+               myOPACShowBookbags(true);
+       }
+}
 
+function myOPACFetchBBItems( id, row, block ) {
        if(!block) {
-               req.callback( myOPACSetBBItems );
-               req.send();
+               containerFlesh( id, _myOPACSetBBItems, { row: row }  );
        } else {
-               req.send(true);
-               myOPACSetBBItems( req.request );
+               var cont = containerFlesh(id);
+               myOPACSetBBItems( cont, row );
        }
 }
 
-function myOPACSetBBItems( r ) {
-       var container = r.getResultObject();
+function _myOPACSetBBItems(r) { myOPACSetBBItems( r.getResultObject(), r.args.row ); }
+
+function myOPACSetBBItems( container, row ) {
        fleshedContainers[container.id()] = container;
-       var node = $n(r.row, 'myopac_bookbag_item_count');
+       var node = $n(row, 'myopac_bookbag_item_count');
        removeChildren(node);
        node.appendChild( text(container.items().length) );
 }
@@ -620,9 +627,7 @@ function myOPACExpandBookbag( id, name ) {
 }
 
 function myOPACRemoveBBItem( id, containerid, container_name ) {
-       var req = new Request( DELETE_CONTAINER_ITEM, G.user.session, 'biblio', id );
-       req.send(true);
-       req.result();
+       containerRemoveItem( id );
        myOPACFetchBBItems( containerid, $('myopac_bookbag_row_' + containerid), true);
        myOPACExpandBookbag( containerid, container_name );
 }
@@ -636,21 +641,9 @@ function myOPACShowBBItem(r) {
 function myOPACCreateBookbag() {
        var name = $('myopac_bookbag_new_name').value;  
        if(!name) return;
-
-       var container = new cbreb();
-       container.btype('bookbag');
-       container.owner( G.user.id() );
-       container.name( name );
-
-       var req = new Request( 
-               CREATE_CONTAINER, G.user.session, 'biblio', container );
-
-       req.send(true);
-
-       var result = req.result();
+       var result = containerCreate( name );
        var code = checkILSEvent(result);
        if(code) { alertILSEvent(code); return; }
-
        myOPACShowBookbags(true);
 }
 
index 1a76b02..b833638 100644 (file)
@@ -16,6 +16,8 @@ var defaultCN;
 var callnumberCache = {};
 var rdetailLocalOnly = true;
 
+var nextContainerIndex;
+
 function rdetailDraw() {
 
 
@@ -112,9 +114,6 @@ function rdetailSetExtrasSelector() {
        if(!grabUser()) return;
        unHideMe($('rdetail_more_actions'));
 
-
-       var selector = $('rdetail_more_actions_selector');
-
        var req = new Request( 
                FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
        req.callback(rdetailAddBookbags);
@@ -135,14 +134,33 @@ function rdetailAddBookbags(r) {
                        "container_" + container.id(), rdetailAddToBookbag, 1 );
        }
 
+       nextContainerIndex = index;
        if(!found) insertSelectorVal( selector, 3, "name", "value", 1 );
 }
 
+function rdetailNewBookbag() {
+       var name = prompt($('rdetail_bb_new').innerHTML,"");
+       if(!name) return;
+
+       var id;
+       if( id = containerCreate( name ) ) {
+               alert($('rdetail_bb_success').innerHTML);
+               var selector = $('rdetail_more_actions_selector');
+               setSelector( selector, 'start' );
+               insertSelectorVal( selector, nextContainerIndex++, name, 
+                       "container_" + id, rdetailAddToBookbag, 1 );
+       }
+}
+
+
 function rdetailAddToBookbag() {
        var selector = $('rdetail_more_actions_selector');
        var id = selector.options[selector.selectedIndex].value;
-       alert(id);
        setSelector( selector, 'start' );
+
+       if( containerCreateItem( id.substring(10), record.doc_id() )) {
+               alert($('rdetail_bb_item_success').innerHTML);
+       }
 }
 
 
index 82cdb74..61b9aa8 100644 (file)
@@ -1,13 +1,21 @@
 
 <div id='myopac_bookbag_div' class='hide_me' xmlns:xi="http://www.w3.org/2001/XInclude" >
 
+       <script language='javascript' src='../js/container.js'> </script>
+
+       <div id='myopac_delete_bookbag_warn' class='hide_me'>
+               This will remove the selected bookbag and all items contained within the bookbag.  
+               Are you sure you wish to continue?
+       </div>
+
        <br/>
 
        <div style='text-align: center; font-weight: bold;' class='hide_me' id='myopac_bookbags_none'>You have not created any bookbags</div>
 
+       <div style='width: 99%; text-align: center'> <b>My Bookbags</b></div>
        <table width='100%' class='data_grid data_grid_center hide_me' id='myopac_bookbag_table'>
                <thead>
-                       <tr><td colspan='2'>My Bookbags</td></tr>
+                       <tr><td>Name</td><td># Items</td><td>Delete this bookbag?</td></tr>
                </thead>
                <tbody id='myopac_bookbag_tbody'>
                        <tr id='myopac_bookbag_tr'>
@@ -15,6 +23,7 @@
                                        <a href='javascript:void(0);' class='classic_link' name='myopac_expand_bookbag'> </a>
                                </td>
                                <td><span name='myopac_bookbag_item_count'> </span> <span>Items</span></td>
+                               <td><a class='class_link' href='javascript:void(0);' name='myopac_container_delete'>Delete</a></td>
                        </tr>
                </tbody>
        </table>
@@ -27,7 +36,7 @@
                </thead>
                <tbody>
                        <tr><td> 
-                               <span>Enter the name of the new Bookbag: </span>
+                               <span style='padding-right: 5px;'>Enter the name of the new Bookbag: </span>
                                <input id='myopac_bookbag_new_name' type='text'> </input> 
                                <input onclick='myOPACCreateBookbag();' type='submit' value='&common.submit;'> </input>
                        </td>
index 4222a81..107f3b9 100644 (file)
                                </td>
 
                                <td class='myopac_link' id='myopac_bookbag_td' >
+                                       <span><img src='../../../../images/bookbag.gif' style='width: 25px; height: 25px;'> </img></span>
                                        <a href='javascript:void(0);' 
-                                               onclick='myOPACChangePage("bookbag");'>Bookbags </a>
+                                               onclick='myOPACChangePage("bookbag");'> Bookbags </a>
+
                                </td>
 
                                <td width='5%' style='border-left: 1px solid #808080;'></td>
index 8c8e4c8..7e66c7c 100644 (file)
@@ -4,6 +4,7 @@
        <script language='javascript' src='../js/rdetail.js'> </script>
        <script language='javascript' src='../js/holds.js'> </script>
        <script language='javascript' src='../js/cn_browse.js'> </script>
+       <script language='javascript' src='../js/container.js'> </script>
 
        <script language='javascript'>
                config.ids.rdetail = {};
@@ -27,7 +28,7 @@
                                                        <option disabled='disabled'>--------------</option>
                                                        <option disabled='disabled'>Add to Bookbag</option>
                                                        <option disabled='disabled'>--------------</option>
-                                                       <option value='new_bookbag'>Create a new bookbag</option>
+                                                       <option value='new_bookbag' onclick='rdetailNewBookbag();'>Create a new bookbag</option>
                                                </select>
                                        </span>
 
@@ -40,4 +41,8 @@
        <!--#include virtual="rdetail/rdetail_extras.xml"-->
 
        <div class='hide_me' id='rdetail_bb_none'>(none)</div>
+       <div class='hide_me' id='rdetail_bb_item_success'>Item successfully added to Bookbag</div>
+       <div class='hide_me' id='rdetail_bb_new'>Enter the name of the new bookbag</div>
+       <div class='hide_me' id='rdetail_bb_success'>Bookbag successfully created</div>
+
 </div>