From 6de52e87049e7e6e4e76242a11958cddee2f8953 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 18 Apr 2014 15:37:54 -0400 Subject: [PATCH] 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 --- Open-ILS/web/js/dojo/MARC/FixedFields.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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(); -- 2.11.0