From: Jason Etheridge Date: Mon, 6 Mar 2017 22:03:10 +0000 (-0500) Subject: webstaff: better stock template for labels, and a | wrap filter X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fcollab%2Fphasefx%2Fwebstaff_print_labels;p=working%2FEvergreen.git webstaff: better stock template for labels, and a | wrap filter Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/templates/staff/share/print_templates/t_item_label.tt2 b/Open-ILS/src/templates/staff/share/print_templates/t_item_label.tt2 index d59ba3dc6e..2b46ff17d3 100644 --- a/Open-ILS/src/templates/staff/share/print_templates/t_item_label.tt2 +++ b/Open-ILS/src/templates/staff/share/print_templates/t_item_label.tt2 @@ -10,11 +10,48 @@ with a variety of keys, including call_number.label location.name +Line-wrapping may be done with the | wrap filter. The first +parameter is the number of characters to target for the string +width. The second parameter is the wrapping algorithm to use. +The third parameter is the prefix to use for the second and +subsequent wrapped lines. One use for this is indentation +with spaces. + +Available wrapping algorithms: + +once = Wraps a line just once +default = Keeps wrapping a line until no more wraps are possible + +--> + + + + + + + + -
-
{{copy['call_number.label']}}
-
-{{copy['call_number.record.simple_record.title']}}
+
+ +
+ +
{{copy['call_number.label']}}
+ +
+{{copy.barcode}}
+{{copy['call_number.label']}}
 {{copy['call_number.record.simple_record.author']}}
-
- +{{copy['call_number.record.simple_record.title'] | wrap:28:'once':' '}} +
diff --git a/Open-ILS/web/js/ui/default/staff/cat/printlabels/app.js b/Open-ILS/web/js/ui/default/staff/cat/printlabels/app.js index bc650c05cb..7429efb215 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/printlabels/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/printlabels/app.js @@ -256,4 +256,74 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore , }; }]) +.filter('wrap', function() { + return function(input, w, wrap_type, indent) { + var output; + + if (!w) return input; + if (!indent) indent = ''; + + function wrap_on_space( + text, + length, + wrap_just_once, + if_cant_wrap_then_truncate, + idx + ) { + if (idx>10) { + console.log('possible infinite recursion, aborting'); + return ''; + } + if (String(text).length <= length) { + return text; + } else { + var truncated_text = String(text).substr(0,length); + var pivot_pos = truncated_text.lastIndexOf(' '); + var left_chunk = text.substr(0,pivot_pos).replace(/\s*$/,''); + var right_chunk = String(text).substr(pivot_pos+1); + + var wrapped_line; + if (left_chunk.length == 0) { + if (if_cant_wrap_then_truncate) { + wrapped_line = truncated_text; + } else { + wrapped_line = text; + } + } else { + wrapped_line = + left_chunk + '\n' + + indent + ( + wrap_just_once + ? right_chunk + : ( + right_chunk.length > length + ? wrap_on_space( + right_chunk, + length, + false, + if_cant_wrap_then_truncate, + idx+1) + : right_chunk + ) + ) + ; + } + return wrapped_line; + } + } + + switch(wrap_type) { + case 'once': + console.log('wrap: once'); + output = wrap_on_space(input,w,true,false,0); + break; + default: + console.log('wrap: default'); + output = wrap_on_space(input,w,false,false,0); + break; + } + + return output; + } +})