From 4e1fad10c52c524b265c5d9f2d6f52fac020a792 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 8 Oct 2015 16:16:01 +0000 Subject: [PATCH] webstaff: automatically advance focus in MARC editor Upon completing a tag, indicator, or subfield code input, focus will now automatically advance to the next input, allowing users to enter records with less need to use the tab button. Signed-off-by: Galen Charlton --- .../js/ui/default/staff/cat/services/marcedit.js | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js index 64a185aa2e..c295207794 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js @@ -65,7 +65,8 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) contextItemGenerator: '=', max: '@', itype: '@', - selectOnFocus: '=' + selectOnFocus: '=', + advanceFocusAfterInput: '=' }, controller : ['$scope', function ( $scope ) { @@ -148,6 +149,35 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) element.bind('focus', function () { element.select() }); } + function findCaretTarget(id, itype) { + var tgt = null; + if (itype == 'tag') { + tgt = id.replace(/tag$/, 'i1'); + } else if (itype == 'ind') { + if (id.match(/i1$/)) { + tgt = id.replace(/i1$/, 'i2'); + } else if (id.match(/i2$/)) { + tgt = id.replace(/i2$/, 's0code'); + } + } else if (itype == 'sfc') { + tgt = id.replace(/code$/, 'value'); + } + return tgt; + } + if (Boolean(scope.advanceFocusAfterInput)) { + element.bind('input', function (e) { + if (scope.content.length == scope.max) { + var tgt = findCaretTarget(e.currentTarget.id, scope.itype); + if (tgt) { + var element = $('#' + tgt).get(0); + if (element) { + element.focus(); + } + } + } + }); + } + element.bind('change', function (e) { element.size = scope.max || parseInt(scope.content.length * 1.1) }); element.bind('contextmenu', {scope : scope}, scope.showContext); @@ -300,6 +330,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) '>‡