From da0712b6a55463650450b5883eb28963ac02d8a2 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 19 Aug 2016 20:51:07 +0000 Subject: [PATCH] Bug 8030 (QA Followup) - Use REST api and provide feedback Use REST API If cancelled return to previous selection If fail return to previous selection Use fa spinning icon while waiting Disable select while waiting --- koha-tmpl/intranet-tmpl/prog/js/holds.js | 45 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js index f2885a0..6a39013 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/holds.js +++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js @@ -101,11 +101,19 @@ $(document).ready(function() { { "mDataProp": function( oObj ) { if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){ - var branchSelect=''; for ( var i=0; i < oObj.branches.length; i++ ){ var selectedbranch; - if( oObj.branches[i].selected ){selectedbranch=" selected='selected' "}else{selectedbranch=''} - branchSelect += ''; + var setbranch; + if( oObj.branches[i].selected ){ + selectedbranch = " selected='selected' "; + setbranch = " (set) "; + } + else{ + selectedbranch = ''; + setbranch = ''; + } + branchSelect += ''; } branchSelect +=''; return branchSelect; @@ -189,17 +197,26 @@ $(document).ready(function() { $(".hold_location_select").change(function(){ if( confirm( _("Do you want to change the pickup location?") ) ){ - $.post('/cgi-bin/koha/svc/hold/update_location', { "reserve_id": $(this).attr('reserve_id'), "updated_branch": $(this).val() }, function( data ){ - if ( data.success ) { - holdsTable.api().ajax.reload(); - } - else { - if ( data.error == "HOLD_NOT_FOUND" ) { - alert ( RESUME_HOLD_ERROR_NOT_FOUND ); - holdsTable.api().ajax.reload(); - } - } - }); + $(this).prop("disabled",true); + var cur_select = $(this); + $(this).after(''); + var api_url = '/api/v1/holds/'+$(this).attr('reserve_id'); + var update_info = JSON.stringify({ branchcode: $(this).val(), priority: parseInt($(this).attr("priority"),10) }); + $.ajax({ + method: "PUT", + url: api_url, + data: update_info , + success: function( data ){ holdsTable.api().ajax.reload(); }, + error: function( jqXHR, textStatus, errorThrown) { + alert('There was an error:'+textStatus+" "+errorThrown); + cur_select.prop("disabled",false); + $("#holdwaiter").remove(); + cur_select.val( cur_select.children('option[selected="selected"]').val() ); + }, + }); + } + else{ + $(this).val( $(this).children('option[selected="selected"]').val() ); } }); -- 2.1.4