From: Mike Rylander Date: Fri, 18 Apr 2014 19:37:54 +0000 (-0400) Subject: LP#1309717: Pad out short 00[678] X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6de52e87049e7e6e4e76242a11958cddee2f8953;p=working%2FEvergreen.git LP#1309717: Pad out short 00[678] There are ways (many) where the 00X fields of a record may be saved without trailing spaces to pad out the correct length. This causes problems for the fixed field editor grid, which uses the substring() method to read and stitch together the data in the fixed fields. Specifically, if trailing space is truncated, both read and insertion can fail in annoying ways. To fix this, we should always pad out the 00X fields to their appropriate lengths before reading or modifying them. Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/web/js/dojo/MARC/FixedFields.js b/Open-ILS/web/js/dojo/MARC/FixedFields.js index b4df7046ea..ab23483f8f 100644 --- a/Open-ILS/web/js/dojo/MARC/FixedFields.js +++ b/Open-ILS/web/js/dojo/MARC/FixedFields.js @@ -34,7 +34,22 @@ if(!dojo._hasResource["MARC.FixedFields"]) { MFHD : { Type : /[uvxy]{1}/, BLvl : /.{1}/ } }; - MARC.Record._ff_pos = { + // See: http://jsperf.com/repeating-strings/11 -- stringFill4() + MARC.Record._padString = function (result, n, x) { + n = n - result.length; + if (!x) x = ' '; + + for (var pad = '';;) { + if (n & 1) pad += x; + if (n >>= 1) x += x; + else break; + } + + if (pad) result += pad; + return result; + } + + MARC.Record._ff_pos = { AccM : { _8 : { SCO : {start: 24, len : 6, def : ' ' }, @@ -1672,6 +1687,7 @@ if(!dojo._hasResource["MARC.FixedFields"]) { MARC.Record.prototype.videorecordingFormatName = function () { var _7 = this.field('007').data; + _7 = MARC.Record._padString(_7, 23); if (_7 && _7.match(/^v/)) { var _v_e = _7.substr( @@ -1687,6 +1703,7 @@ if(!dojo._hasResource["MARC.FixedFields"]) { MARC.Record.prototype.videorecordingFormatCode = function () { var _7 = this.field('007').data; + _7 = MARC.Record._padString(_7, 23); if (_7 && _7.match(/^v/)) { return _7.substr( @@ -1705,6 +1722,9 @@ if(!dojo._hasResource["MARC.FixedFields"]) { var _8 = this.field('008').data; var _6 = this.field('006').data; + _8 = MARC.Record._padString(_8, 40); + _6 = MARC.Record._padString(_6, 18); + var rtype = this.recordType(); var val; @@ -1771,6 +1791,9 @@ if(!dojo._hasResource["MARC.FixedFields"]) { var _l = this.leader; var _8 = this.field('008').data; var _6 = this.field('006').data; + + _8 = MARC.Record._padString(_8, 40); + _6 = MARC.Record._padString(_6, 18); var rtype = this.recordType();