From 5171ee499de09bf08772231e183191d77b66031a Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 4 Sep 2015 10:56:56 -0400 Subject: [PATCH] webstaff: Make next-barcode-on-enter happy Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- .../src/templates/staff/cat/volcopy/t_edit.tt2 | 2 +- .../web/js/ui/default/staff/cat/volcopy/app.js | 86 ++++++++++++++++++---- 2 files changed, 73 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 b/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 index b067b1943a..4897231c96 100644 --- a/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 @@ -54,7 +54,7 @@ - + diff --git a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js index 0a3bafaa49..b0f5dc7e5f 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js @@ -194,21 +194,21 @@ function(egCore , $q) { template: '
'+ '
'+ - ''+ '
'+ '
'+ '
'+ '
', - scope: { copy: "=", callNumber: "=", index: "@" }, + scope: { focusNext: "=", copy: "=", callNumber: "=", index: "@" }, controller : ['$scope','itemSvc','egCore', function ( $scope , itemSvc , egCore ) { $scope.new_part_id = 0; $scope.nextBarcode = function (i) { - $scope.$parent.focusNextBarcode($scope.copy.id()); + $scope.focusNext(i); } $scope.updateBarcode = function () { $scope.copy.barcode($scope.barcode); $scope.copy.ischanged(1); }; @@ -277,11 +277,11 @@ function(egCore , $q) { ''+ '
'+ '
'+ - ''+ + ''+ '
'+ '', - scope: {allcopies: "=", copies: "=" }, + scope: {focusNext: "=", allcopies: "=", copies: "=" }, controller : ['$scope','itemSvc','egCore', function ( $scope , itemSvc , egCore ) { $scope.callNumber = $scope.copies[0].call_number(); @@ -304,9 +304,11 @@ function(egCore , $q) { }); if (n) { - var next = '#' + $scope.callNumber.id() + '.' + n; - var el = $(next).get(0); + var next = '#' + $scope.callNumber.id() + '_' + n; + var el = $(next); if (el) el.focus() + } else { + $scope.focusNext($scope.callNumber.id()) } } @@ -431,16 +433,43 @@ function(egCore , $q) { '
'+ '
'+ '
'+ - ''+ + ''+ '
'+ '', - scope: { allcopies: "=", struct: "=", lib: "@", record: "@" }, + scope: { focusNext: "=", allcopies: "=", struct: "=", lib: "@", record: "@" }, controller : ['$scope','itemSvc','egCore', function ( $scope , itemSvc , egCore ) { $scope.first_cn = Object.keys($scope.struct)[0]; $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number(); + $scope.focusNextFirst = function(prev_cn) { + var n; + var yep = false; + angular.forEach(Object.keys($scope.struct).sort(), function (cn) { + console.log('checking '+cn); + if (n) return; + + if (cn == prev_cn) { + console.log('prev is '+cn); + yep = true; + return; + } + console.log('prev is not '+cn); + + if (yep) n = cn; + }); + + console.log('found '+n); + if (n) { + var next = '#' + n + '_' + $scope.struct[n][0].id(); + var el = $(next); + if (el) el.focus() + } else { + $scope.focusNext($scope.lib); + } + } + $scope.cn_count = Object.keys($scope.struct).length; $scope.orig_cn_count = $scope.cn_count; @@ -476,10 +505,11 @@ function(egCore , $q) { var how_many = o - n; var list = Object .keys($scope.struct) - .sort(function(a, b){return a-b}) - .reverse(); - for (var i = how_many; i > 0; i--) { + .sort(function(a, b){return parseInt(a)-parseInt(b)}) + .filter(function(x){ return parseInt(x) <= 0 }); + for (var i = 0; i < how_many; i++) { // Trimming the global list is a bit more tricky + console.log('trying to trim ' + i); angular.forEach($scope.struct[list[i]], function (d) { angular.forEach( $scope.allcopies, function (l, j) { if (l === d) $scope.allcopies.splice(j,1); @@ -867,6 +897,34 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore , $scope.workingGridDataProvider.refresh(); }); + $scope.focusNextFirst = function(prev_lib) { + var n; + var yep = false; + angular.forEach(Object.keys($scope.data.tree).sort(), function (lib) { + console.log('checking lib '+lib); + if (n) return; + + if (lib == prev_lib) { + console.log('prev is '+lib); + yep = true; + return; + } + console.log('prev is not '+lib); + + if (yep) n = lib; + }); + + console.log('found '+n); + if (n) { + var first_cn = Object.keys($scope.data.tree[n])[0]; + var next = '#' + first_cn + '_' + $scope.data.tree[n][first_cn][0].id(); + var el = $(next); + if (el) el.focus() + } else { + $scope.focusNext($scope.lib); + } + } + $scope.in_item_select = false; $scope.afterItemSelect = function() { $scope.in_item_select = false }; $scope.handleItemSelect = function (item_list) { @@ -955,7 +1013,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore , var final_orgs = all_orgs.filter(function(e,i,a){ return a.lastIndexOf(e) === i; - }).sort(function(a,b){return b-a}); + }).sort(function(a, b){return parseInt(a)-parseInt(b)}); if ($scope.location_orgs.toString() != final_orgs.toString()) { $scope.location_orgs = final_orgs; -- 2.11.0