5 angular.module('egPrintLabels',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
8 .config(function ($routeProvider, $locationProvider, $compileProvider) {
9 $locationProvider.html5Mode(true);
10 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
13 delay: ['egStartup', function (egStartup) { return egStartup.go(); }]
16 $routeProvider.when('/cat/printlabels/:dataKey', {
17 templateUrl: './cat/printlabels/t_view',
18 controller: 'LabelCtrl',
29 copies: [], // copy barcode search results
30 index: 0 // search grid index
36 acp: ['call_number', 'location', 'status', 'location', 'floating', 'circ_modifier', 'age_protect'],
37 acn: ['record', 'prefix', 'suffix'],
38 bre: ['simple_record', 'creator', 'editor']
41 // avoid fleshing MARC on the bre
42 // note: don't add simple_record.. not sure why
43 bre: ['id', 'tcn_value', 'creator', 'editor'],
47 // resolved with the last received copy
48 service.fetch = function (barcode, id, noListDupes) {
52 promise = egCore.pcrud.search('acp',
53 { barcode: barcode, deleted: 'f' }, service.flesh);
55 promise = egCore.pcrud.retrieve('acp', id, service.flesh);
60 function () { return lastRes },
63 // notify reads the stream of copies, one at a time.
68 // use the existing copy if possible
69 flatCopy = service.copies.filter(
70 function (c) { return c.id == copy.id() })[0];
74 flatCopy = egCore.idl.toHash(copy, true);
75 flatCopy.index = service.index++;
76 service.copies.unshift(flatCopy);
93 .controller('LabelCtrl',
94 ['$scope', '$q', '$window', '$routeParams', '$location', '$timeout', 'egCore', 'egNet', 'ngToast', 'itemSvc', 'labelOutputRowsFilter',
95 function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet, ngToast, itemSvc, labelOutputRowsFilter) {
97 var dataKey = $routeParams.dataKey;
98 console.debug('dataKey: ' + dataKey);
101 template_name: 'item_label',
103 template_context: 'default'
106 var toolbox_settings = {
109 { label: "Continuous", value: "continuous" },
110 { label: "Sheet", value: "sheet" },
112 selected: "continuous"
120 { label: "Label 1 Only", value: "spine-only" },
121 { label: "Labels 1 & 2", value: "spine-pocket" }
123 selected: "spine-pocket"
126 column_class: ["spine"],
140 top: { size: 0, label: "Top" },
141 left: { size: 0, label: "Left" },
143 space_between_labels: {
144 horizontal: { size: 0, label: "Horizontal" },
145 vertical: { size: 0, label: "Vertical" }
154 if (dataKey && dataKey.length > 0) {
158 'open-ils.actor.anon_cache.get_value',
159 dataKey, 'print-labels-these-copies'
160 ).then(function (data) {
164 $scope.preview_scope = {
167 , 'toolbox_settings': toolbox_settings
168 , 'get_cn_for': function (copy) {
169 var key = $scope.rendered_cn_key_by_copy_id[copy.id];
171 var manual_cn = $scope.rendered_call_number_set[key];
172 if (manual_cn && manual_cn.value) {
173 return manual_cn.value;
181 , 'get_bib_for': function (copy) {
182 return $scope.record_details[copy['call_number.record.id']];
184 , 'get_cn_prefix': function (copy) {
185 return copy['call_number.prefix.label'];
187 , 'get_cn_suffix': function (copy) {
188 return copy['call_number.suffix.label'];
190 , 'get_location_prefix': function (copy) {
191 return copy['location.label_prefix'];
193 , 'get_location_suffix': function (copy) {
194 return copy['location.label_suffix'];
196 , 'get_cn_and_location_prefix': function (copy, separator) {
197 var acpl_prefix = copy['location.label_prefix'] || '';
198 var cn_prefix = copy['call_number.prefix.label'] || '';
199 var prefix = acpl_prefix + ' ' + cn_prefix;
200 prefix = prefix.trim();
201 if (separator && prefix != '') { prefix += separator; }
204 , 'get_cn_and_location_suffix': function (copy, separator) {
205 var acpl_suffix = copy['location.label_suffix'] || '';
206 var cn_suffix = copy['call_number.suffix.label'] || '';
207 var suffix = cn_suffix + ' ' + acpl_suffix;
208 suffix = suffix.trim();
209 if (separator && suffix != '') { suffix = separator + suffix; }
212 , 'valid_print_label_start_column': function () {
213 return !angular.isNumber(toolbox_settings.page.dimensions.columns) || !angular.isNumber(toolbox_settings.page.start_position.column) ? false : (toolbox_settings.page.start_position.column <= toolbox_settings.page.dimensions.columns);
215 , 'valid_print_label_start_row': function () {
216 return !angular.isNumber(toolbox_settings.page.dimensions.rows) || !angular.isNumber(toolbox_settings.page.start_position.row) ? false : (toolbox_settings.page.start_position.row <= toolbox_settings.page.dimensions.rows);
219 $scope.record_details = {};
220 $scope.org_unit_settings = {};
223 $scope.org_unit_setting_list = [
224 'webstaff.cat.label.font.family'
225 , 'webstaff.cat.label.font.size'
226 , 'webstaff.cat.label.font.weight'
227 , 'webstaff.cat.label.inline_css'
228 , 'webstaff.cat.label.left_label.height'
229 , 'webstaff.cat.label.left_label.left_margin'
230 , 'webstaff.cat.label.left_label.width'
231 , 'webstaff.cat.label.right_label.height'
232 , 'webstaff.cat.label.right_label.left_margin'
233 , 'webstaff.cat.label.right_label.width'
234 , 'webstaff.cat.label.call_number_wrap_filter_height'
235 , 'webstaff.cat.label.call_number_wrap_filter_width'
239 egCore.pcrud.search('coust', { name: $scope.org_unit_setting_list }).then(
243 $scope.org_unit_settings[yaous.name()] = egCore.idl.toHash(yaous, true);
249 egCore.org.settings($scope.org_unit_setting_list).then(function (res) {
250 $scope.preview_scope.settings = res;
251 egCore.hatch.getItem('cat.printlabels.last_settings').then(function (last_settings) {
253 for (s in last_settings) {
254 $scope.preview_scope.settings[s] = last_settings[s];
261 angular.forEach(data.copies, function (copy) {
263 itemSvc.fetch(null, copy).then(function (res) {
264 var flat_copy = egCore.idl.toHash(res.copy, true);
265 $scope.preview_scope.copies.push(flat_copy);
266 $scope.record_details[flat_copy['call_number.record.id']] = 1;
271 $q.all(promises).then(function () {
274 angular.forEach($scope.record_details, function (el, k, obj) {
278 'open-ils.search.biblio.record.mods_slim.retrieve.authoritative',
280 ).then(function (data) {
281 obj[k] = egCore.idl.toHash(data, true);
286 $q.all(promises2).then(function () {
287 // today, staff, current_location, etc.
288 egCore.print.fleshPrintScope($scope.preview_scope);
289 $scope.template_changed(); // load the default
290 $scope.rebuild_cn_set();
295 ngToast.danger(egCore.strings.KEY_EXPIRED);
302 $scope.fetchTemplates = function (set_default) {
303 return egCore.hatch.getItem('cat.printlabels.templates').then(function (t) {
305 $scope.templates = t;
306 $scope.template_name_list = Object.keys(t);
308 egCore.hatch.getItem('cat.printlabels.default_template').then(function (d) {
309 if ($scope.template_name_list.indexOf(d, 0) > -1) {
310 $scope.template_name = d;
317 $scope.fetchTemplates(true);
319 $scope.applyTemplate = function (n) {
320 $scope.print.cn_template_content = $scope.templates[n].cn_content;
321 $scope.print.template_content = $scope.templates[n].content;
322 $scope.print.template_context = $scope.templates[n].context;
323 for (var s in $scope.templates[n].settings) {
324 $scope.preview_scope.settings[s] = $scope.templates[n].settings[s];
326 if ($scope.templates[n].toolbox_settings) {
327 $scope.preview_scope.toolbox_settings = $scope.templates[n].toolbox_settings;
328 $scope.create_print_label_table();
330 egCore.hatch.setItem('cat.printlabels.default_template', n);
331 $scope.save_locally();
334 $scope.deleteTemplate = function (n) {
336 delete $scope.templates[n]
337 $scope.template_name_list = Object.keys($scope.templates);
338 $scope.template_name = '';
339 egCore.hatch.setItem('cat.printlabels.templates', $scope.templates);
340 $scope.fetchTemplates();
341 ngToast.create(egCore.strings.PRINT_LABEL_TEMPLATE_SUCCESS_DELETE);
342 egCore.hatch.getItem('cat.printlabels.default_template').then(function (d) {
344 egCore.hatch.removeItem('cat.printlabels.default_template');
350 $scope.saveTemplate = function (n) {
353 $scope.templates[n] = {
354 content: $scope.print.template_content
355 , context: $scope.print.template_context
356 , cn_content: $scope.print.cn_template_content
357 , settings: $scope.preview_scope.settings
358 , toolbox_settings: $scope.preview_scope.toolbox_settings
360 $scope.template_name_list = Object.keys($scope.templates);
362 egCore.hatch.setItem('cat.printlabels.templates', $scope.templates);
363 $scope.fetchTemplates();
365 $scope.dirty = false;
367 // save all templates, as we might do after an import
368 egCore.hatch.setItem('cat.printlabels.templates', $scope.templates);
369 $scope.fetchTemplates();
371 ngToast.create(egCore.strings.PRINT_LABEL_TEMPLATE_SUCCESS_SAVE);
374 $scope.templates = {};
375 $scope.imported_templates = { data: '' };
376 $scope.template_name = '';
377 $scope.template_name_list = [];
379 $scope.print_labels = function () {
380 return egCore.print.print({
381 context: $scope.print.template_context,
382 template: $scope.print.template_name,
383 scope: $scope.preview_scope,
387 $scope.template_changed = function () {
388 $scope.print.load_failed = false;
389 egCore.print.getPrintTemplate('item_label')
392 $scope.print.template_content = html;
395 $scope.print.template_content = '';
396 $scope.print.load_failed = true;
399 egCore.print.getPrintTemplateContext('item_label')
400 .then(function (template_context) {
401 $scope.print.template_context = template_context;
403 egCore.print.getPrintTemplate('item_label_cn')
406 $scope.print.cn_template_content = html;
409 $scope.print.cn_template_content = '';
410 $scope.print.load_failed = true;
413 egCore.hatch.getItem('cat.printlabels.last_settings').then(function (s) {
415 $scope.preview_scope.settings = s;
420 $scope.reset_to_default = function () {
421 egCore.print.removePrintTemplate(
424 egCore.print.removePrintTemplateContext(
427 egCore.print.removePrintTemplate(
430 egCore.hatch.removeItem('cat.printlabels.last_settings');
431 for (s in $scope.preview_scope.settings) {
432 $scope.preview_scope.settings[s] = undefined;
434 $scope.preview_scope.settings = {};
435 egCore.org.settings($scope.org_unit_setting_list).then(function (res) {
436 $scope.preview_scope.settings = res;
439 $scope.template_changed();
442 $scope.save_locally = function () {
443 egCore.print.storePrintTemplate(
445 $scope.print.template_content
447 egCore.print.storePrintTemplateContext(
449 $scope.print.template_context
451 egCore.print.storePrintTemplate(
453 $scope.print.cn_template_content
455 egCore.hatch.setItem('cat.printlabels.last_settings', $scope.preview_scope.settings);
458 $scope.imported_print_templates = { data: '' };
459 $scope.$watch('imported_templates.data', function (newVal, oldVal) {
460 if (newVal && newVal != oldVal) {
462 var data = JSON.parse(newVal);
463 angular.forEach(data, function (el, k) {
464 $scope.templates[k] = {
466 , context: el.context
467 , cn_content: el.cn_content
468 , settings: el.settings
469 , toolbox_settings: el.toolbox_settings
472 $scope.saveTemplate();
473 $scope.template_changed(); // refresh
474 ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT);
476 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_IMPORT);
481 $scope.rendered_call_number_set = {};
482 $scope.rendered_cn_key_by_copy_id = {};
483 $scope.rebuild_cn_set = function () {
484 $timeout(function () {
485 $scope.rendered_call_number_set = {};
486 $scope.rendered_cn_key_by_copy_id = {};
487 for (var i = 0; i < $scope.preview_scope.copies.length; i++) {
488 var copy = $scope.preview_scope.copies[i];
489 var rendered_cn = document.getElementById('cn_for_copy_' + copy.id);
490 if (rendered_cn && rendered_cn.textContent) {
491 var key = rendered_cn.textContent;
492 if (typeof $scope.rendered_call_number_set[key] == 'undefined') {
493 $scope.rendered_call_number_set[key] = {
497 $scope.rendered_cn_key_by_copy_id[copy.id] = key;
500 $scope.preview_scope.tickle = Date() + ' ' + Math.random();
504 $scope.create_print_label_table = function () {
505 if ($scope.print_label_form.$valid && $scope.print.template_content && $scope.preview_scope) {
506 $scope.preview_scope.label_output_copies = labelOutputRowsFilter($scope.preview_scope.copies, $scope.preview_scope.toolbox_settings);
507 var html = $scope.print.template_content;
508 var d = new Date(); //Added to table ID with 'eg_plt_' to cause $complie on $scope.print.template_content to fire due to template content change.
509 var table = "<table id=\"eg_plt_" + d.getTime().toString() + "_{{$index}}\" eg-print-label-table style=\"border-collapse: collapse; border: 0 solid transparent; border-spacing: 0; margin: {{$index === 0 ?toolbox_settings.page.margins.top.size : 0}} 0 0 0;\" class=\"custom-label-table{{$index % toolbox_settings.page.dimensions.rows === 0 && $index > 0 && toolbox_settings.feed_option.selected === 'sheet' ? ' page-break' : ''}}\" ng-init=\"parentIndex = $index\" ng-repeat=\"row in label_output_copies\">\n";
511 table += "<td style=\"border: 0 solid transparent; padding: {{parentIndex % toolbox_settings.page.dimensions.rows === 0 && toolbox_settings.feed_option.selected === 'sheet' && parentIndex > 0 ? toolbox_settings.page.space_between_labels.vertical.size : parentIndex > 0 ? toolbox_settings.page.space_between_labels.vertical.size : 0}} 0 0 {{$index === 0 ? toolbox_settings.page.margins.left.size : col.styl ? col.styl : toolbox_settings.page.space_between_labels.horizontal.size}};\" ng-repeat=\"col in row.columns\">\n";
512 table += "<pre class=\"{{col.cls}}\" style=\"border: none; margin-bottom: 0; margin-top: 0; overflow: hidden;\" ng-if=\"col.cls === 'spine'\">\n";
513 table += "{{col.c ? get_cn_for(col.c) : ''}}";
515 table += "<pre class=\"{{col.cls}}{{parentIndex % toolbox_settings.page.dimensions.rows === 0 && parentIndex > 0 && toolbox_settings.feed_option.selected === 'sheet' ? ' page-break' : ''}}\" style=\"border: none; margin-bottom: 0; margin-top: 0; overflow: hidden;\" ng-if=\"col.cls === 'pocket'\">\n";
516 table += "{{col.c ? col.c.barcode : ''}}\n";
517 table += "{{col.c ? col.c['call_number.label'] : ''}}\n";
518 table += "{{col.c ? get_bib_for(col.c).author : ''}}\n";
519 table += "{{col.c ? (get_bib_for(col.c).title | wrap:28:'once':' ') : ''}}\n";
524 var comments = html.match(/\<\!\-\-(?:(?!\-\-\>)(?:.|\s))*\-\-\>\s*/g);
525 html = html.replace(/\<\!\-\-(?:(?!\-\-\>)(?:.|\s))*\-\-\>\s*/g, "");
526 var style = html.match(/\<style[^\>]*\>(?:(?!\<\/style\>)(?:.|\s))*\<\/style\>\s*/gi);
527 var output = (style ? style.join("\n") : "") + (comments ? comments.join("\n") : "") + table;
528 output = output.replace(/\n+/, "\n");
529 $scope.print.template_content = output;
533 $scope.redraw_label_table = function () {
534 var d = new Date(); //Added to table ID with 'eg_plt_' to cause $complie on $scope.print.template_content to fire due to template content change.
535 var table = "<table id=\"eg_plt_" + d.getTime().toString() + "\"\></table>\n";
536 $scope.print.template_content += table;
537 $scope.create_print_label_table();
540 $scope.$watch('preview_scope.toolbox_settings.page.dimensions.columns',
541 function (newVal, oldVal) {
542 if (newVal && newVal != oldVal && $scope.preview_scope) {
543 $scope.redraw_label_table();
548 $scope.$watch('print.cn_template_content', function (newVal, oldVal) {
549 if (newVal && newVal != oldVal) {
550 $scope.rebuild_cn_set();
554 $scope.$watch("preview_scope.settings['webstaff.cat.label.call_number_wrap_filter_height']", function (newVal, oldVal) {
555 if (newVal && newVal != oldVal) {
556 $scope.rebuild_cn_set();
560 $scope.$watch("preview_scope.settings['webstaff.cat.label.call_number_wrap_filter_width']", function (newVal, oldVal) {
561 if (newVal && newVal != oldVal) {
562 $scope.rebuild_cn_set();
566 $scope.$watchGroup(['preview_scope.toolbox_settings.page.margins.top.size', 'preview_scope.toolbox_settings.page.margins.left.size', 'preview_scope.toolbox_settings.page.dimensions.rows', 'preview_scope.toolbox_settings.page.space_between_labels.horizontal.size', 'preview_scope.toolbox_settings.page.space_between_labels.vertical.size', 'preview_scope.toolbox_settings.page.start_position.row', 'preview_scope.toolbox_settings.page.start_position.column', 'preview_scope.toolbox_settings.page.label.gap.size'], function (newVal, oldVal) {
567 if (newVal && newVal != oldVal && $scope.preview_scope.label_output_copies) {
568 $scope.redraw_label_table();
572 $scope.$watch("preview_scope.toolbox_settings.mode.selected", function (newVal, oldVal) {
573 if (newVal && newVal != oldVal) {
574 var ts_p = $scope.preview_scope.toolbox_settings.page;
575 if (ts_p.label.set.size === 1) {
576 if (newVal === "spine-pocket") {
577 ts_p.column_class = ["spine", "pocket"];
578 ts_p.label.set.size = 2;
580 ts_p.column_class = ["spine"];
583 if (newVal === "spine-only") {
584 for (var i = 0; i < ts_p.label.set.size; i++) {
585 ts_p.column_class[i] = "spine";
588 ts_p.label.set.size === 2 ? ts_p.column_class = ["spine", "pocket"] : false;
591 $scope.redraw_label_table();
595 $scope.$watch("preview_scope.toolbox_settings.page.label.set.size", function (newVal, oldVal) {
596 if (newVal && newVal != oldVal) {
597 var ts_p = $scope.preview_scope.toolbox_settings.page;
598 if (angular.isNumber(newVal)) {
599 while (ts_p.column_class.length > ts_p.label.set.size) {
600 ts_p.column_class.splice((ts_p.column_class.length - 1), 1);
602 while (ts_p.column_class.length < ts_p.label.set.size) {
603 ts_p.column_class.push("spine");
606 $scope.redraw_label_table();
610 $scope.current_tab = 'call_numbers';
611 $scope.set_tab = function (tab) {
612 $scope.current_tab = tab;
617 .directive("egPrintLabelColumnBounds", function () {
619 link: function (scope, element, attr, ctrl) {
620 function withinBounds(v) {
621 scope.$watch("preview_scope.toolbox_settings.page.dimensions.columns", function (newVal, oldVal) {
622 ctrl.$setValidity("egWithinPrintColumnBounds", scope.preview_scope.valid_print_label_start_column())
626 ctrl.$parsers.push(withinBounds);
627 ctrl.$formatters.push(withinBounds);
633 .directive("egPrintLabelRowBounds", function () {
635 link: function (scope, element, attr, ctrl) {
636 function withinBounds(v) {
637 scope.$watch("preview_scope.toolbox_settings.page.dimensions.rows", function (newVal, oldVal) {
638 ctrl.$setValidity("egWithinPrintRowBounds", scope.preview_scope.valid_print_label_start_row());
642 ctrl.$parsers.push(withinBounds);
643 ctrl.$formatters.push(withinBounds);
649 .directive("egPrintLabelValidCss", function () {
652 link: function (scope, element, attr, ctrl) {
653 function floatValidation(v) {
654 ctrl.$setValidity("isFloat", v.toString().match(/^\-*(?:^0$|(?:\d+)(?:\.\d{1,})*([a-z]{2}))$/) ? true : false);
657 ctrl.$parsers.push(floatValidation);
662 .directive("egPrintLabelValidInt", function () {
665 link: function (scope, element, attr, ctrl) {
666 function intValidation(v) {
667 ctrl.$setValidity("isInteger", v.toString().match(/^\d+$/));
670 ctrl.$parsers.push(intValidation);
675 .directive('egPrintTemplateOutput', ['$compile', function ($compile) {
676 return function (scope, element, attrs) {
679 return scope.$eval(attrs.content);
682 // create an isolate scope and copy the print context
683 // data into the new scope.
684 // TODO: see also print security concerns in egHatch
685 var result = element.html(value);
686 var context = scope.$eval(attrs.context);
687 var print_scope = scope.$new(true);
688 angular.forEach(context, function (val, key) {
689 print_scope[key] = val;
691 $compile(element.contents())(print_scope);
697 .filter('cn_wrap', function () {
698 return function (input, w, h, wrap_type) {
700 var prefix = input[0];
701 var callnum = input[1];
702 var suffix = input[2];
707 /* handle spine labels differently if using LC */
708 if (wrap_type == 'lc' || wrap_type == 3) {
709 /* Establish a pattern where every return value should be isolated on its own line
710 on the spine label: subclass letters, subclass numbers, cutter numbers, trailing stuff (date) */
711 var patt1 = /^([A-Z]{1,3})\s*(\d+(?:\.\d+)?)\s*(\.[A-Z]\d*)\s*([A-Z]\d*)?\s*(\d\d\d\d(?:-\d\d\d\d)?)?\s*(.*)$/i;
712 var result = callnum.match(patt1);
714 callnum = result.slice(1).join('\t');
716 callnum = callnum.split(/\s+/).join('\t');
719 /* If result is null, leave callnum alone. Can't parse this malformed call num */
721 callnum = callnum.split(/\s+/).join('\t');
725 callnum = prefix + '\t' + callnum;
728 callnum += '\t' + suffix;
731 /* At this point, the call number pieces are separated by tab characters. This allows
732 * some space-containing constructs like "v. 1" to appear on one line
734 callnum = callnum.replace(/\t\t/g, '\t'); /* Squeeze out empties */
735 names = callnum.split('\t');
736 var j = 0; var tb = [];
742 var name = names.shift();
746 /* if the name is greater than the label width... */
747 if (name.length > w) {
748 /* then try to split it on periods */
749 var sname = name.split(/\./);
750 if (sname.length > 1) {
751 /* if we can, then put the periods back in on each splitted element */
752 if (name.match(/^\./)) sname[0] = '.' + sname[0];
753 for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
754 /* and put all but the first one back into the names array */
755 names = sname.slice(1).concat(names);
756 /* if the name fragment is still greater than the label width... */
757 if (sname[0].length > w) {
758 /* then just truncate and throw the rest back into the names array */
759 tb[j] = sname[0].substr(0, w);
760 names = [sname[0].substr(w)].concat(names);
762 /* otherwise we're set */
766 /* if we can't split on periods, then just truncate and throw the rest back into the names array */
767 tb[j] = name.substr(0, w);
768 names = [name.substr(w)].concat(names);
771 /* otherwise we're set */
778 return tb.join('\n');
782 .filter("columnRowRange", function () {
783 return function (i) {
785 for (var j = 0; j < i; j++) {
792 //Accepts $scope.preview_scope.copies and $scope.preview_scope.toolbox_settings as its parameters.
793 .filter("labelOutputRows", function () {
794 return function (copies, settings) {
795 var cols = [], rows = [];
796 for (var j = 0; j < (settings.page.start_position.row - 1) ; j++) {
798 for (var k = 0; k < settings.page.dimensions.columns; k++) {
799 cols.push({ c: null, index: k, cls: getPrintLabelOutputClass(k, settings), styl: getPrintLabelStyle(k, settings) });
801 rows.push({ columns: cols });
804 for (var j = 0; j < (settings.page.start_position.column - 1) ; j++) {
805 cols.push({ c: null, index: j, cls: getPrintLabelOutputClass(j, settings), styl: getPrintLabelStyle(j, settings) });
808 for (var j = 0; j < copies.length; j++) {
809 for (var n = 0; n < settings.page.label.set.size; n++) {
810 if (m < settings.page.dimensions.columns) {
811 cols.push({ c: copies[j], index: cols.length, cls: getPrintLabelOutputClass(m, settings), styl: getPrintLabelStyle(m, settings) });
814 if (m === settings.page.dimensions.columns) {
816 rows.push({ columns: cols });
818 n = settings.page.label.set.size;
822 cols.length > 0 ? rows.push({ columns: cols }) : false;
823 if (rows.length > 0) {
824 while ((rows[(rows.length - 1)].columns.length) < settings.page.dimensions.columns) {
825 rows[(rows.length - 1)].columns.push({ c: null, index: rows[(rows.length - 1)].columns.length, cls: getPrintLabelOutputClass(rows[(rows.length - 1)].columns.length, settings), styl: getPrintLabelStyle(rows[(rows.length - 1)].columns.length, settings) });
832 .filter('wrap', function () {
833 return function (input, w, wrap_type, indent) {
836 if (!w) return input;
837 if (!indent) indent = '';
839 function wrap_on_space(
843 if_cant_wrap_then_truncate,
847 console.log('possible infinite recursion, aborting');
850 if (String(text).length <= length) {
853 var truncated_text = String(text).substr(0, length);
854 var pivot_pos = truncated_text.lastIndexOf(' ');
855 var left_chunk = text.substr(0, pivot_pos).replace(/\s*$/, '');
856 var right_chunk = String(text).substr(pivot_pos + 1);
859 if (left_chunk.length == 0) {
860 if (if_cant_wrap_then_truncate) {
861 wrapped_line = truncated_text;
872 right_chunk.length > length
877 if_cant_wrap_then_truncate,
890 output = wrap_on_space(input, w, true, false, 0);
893 output = wrap_on_space(input, w, false, false, 0);
901 function getPrintLabelOutputClass(index, settings) {
902 return settings.page.column_class[index % settings.page.label.set.size];
905 function getPrintLabelStyle(index, settings) {
906 return index > 0 && (index % settings.page.label.set.size === 0) ? settings.page.label.gap.size : "";