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: "Spine Label", value: "spine-only" },
121 { label: "Pocket Label", 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);
220 $scope.record_details = {};
221 $scope.org_unit_settings = {};
224 $scope.org_unit_setting_list = [
225 'webstaff.cat.label.font.family'
226 , 'webstaff.cat.label.font.size'
227 , 'webstaff.cat.label.font.weight'
228 , 'webstaff.cat.label.inline_css'
229 , 'webstaff.cat.label.left_label.height'
230 , 'webstaff.cat.label.left_label.left_margin'
231 , 'webstaff.cat.label.left_label.width'
232 , 'webstaff.cat.label.right_label.height'
233 , 'webstaff.cat.label.right_label.left_margin'
234 , 'webstaff.cat.label.right_label.width'
235 , 'webstaff.cat.label.call_number_wrap_filter_height'
236 , 'webstaff.cat.label.call_number_wrap_filter_width'
240 egCore.pcrud.search('coust', { name: $scope.org_unit_setting_list }).then(
244 $scope.org_unit_settings[yaous.name()] = egCore.idl.toHash(yaous, true);
250 egCore.org.settings($scope.org_unit_setting_list).then(function (res) {
251 $scope.preview_scope.settings = res;
252 egCore.hatch.getItem('cat.printlabels.last_settings').then(function (last_settings) {
254 for (s in last_settings) {
255 $scope.preview_scope.settings[s] = last_settings[s];
262 angular.forEach(data.copies, function (copy) {
264 itemSvc.fetch(null, copy).then(function (res) {
265 var flat_copy = egCore.idl.toHash(res.copy, true);
266 $scope.preview_scope.copies.push(flat_copy);
267 $scope.record_details[flat_copy['call_number.record.id']] = 1;
272 $q.all(promises).then(function () {
275 angular.forEach($scope.record_details, function (el, k, obj) {
279 'open-ils.search.biblio.record.mods_slim.retrieve.authoritative',
281 ).then(function (data) {
282 obj[k] = egCore.idl.toHash(data, true);
287 $q.all(promises2).then(function () {
288 // today, staff, current_location, etc.
289 egCore.print.fleshPrintScope($scope.preview_scope);
290 $scope.template_changed(); // load the default
291 $scope.rebuild_cn_set();
292 if ($scope.preview_scope.toolbox_settings && $scope.template_name && $scope.print.template_content) {
294 if (re.test($scope.print.template_content)) {
295 $scope.applyTemplate($scope.template_name);
296 $scope.redraw_label_table();
303 ngToast.danger(egCore.strings.KEY_EXPIRED);
310 $scope.fetchTemplates = function (set_default) {
311 return egCore.hatch.getItem('cat.printlabels.templates').then(function (t) {
313 $scope.templates = t;
314 $scope.template_name_list = Object.keys(t);
316 egCore.hatch.getItem('cat.printlabels.default_template').then(function (d) {
317 if ($scope.template_name_list.indexOf(d, 0) > -1) {
318 $scope.template_name = d;
325 $scope.fetchTemplates(true);
327 $scope.applyTemplate = function (n) {
329 if ($scope.templates[n]) {
330 $scope.print.cn_template_content = $scope.templates[n].cn_content;
331 $scope.print.template_content = $scope.templates[n].content;
332 $scope.print.template_context = $scope.templates[n].context;
333 for (var s in $scope.templates[n].settings) {
334 $scope.preview_scope.settings[s] = $scope.templates[n].settings[s];
336 if ($scope.templates[n].toolbox_settings) {
337 $scope.preview_scope.toolbox_settings = $scope.templates[n].toolbox_settings;
338 $scope.create_print_label_table();
340 egCore.hatch.setItem('cat.printlabels.default_template', n);
341 $scope.save_locally();
346 $scope.deleteTemplate = function (n) {
348 delete $scope.templates[n]
349 $scope.template_name_list = Object.keys($scope.templates);
350 $scope.template_name = '';
351 egCore.hatch.setItem('cat.printlabels.templates', $scope.templates);
352 $scope.fetchTemplates();
353 ngToast.create(egCore.strings.PRINT_LABEL_TEMPLATE_SUCCESS_DELETE);
354 egCore.hatch.getItem('cat.printlabels.default_template').then(function (d) {
356 egCore.hatch.removeItem('cat.printlabels.default_template');
362 $scope.saveTemplate = function (n) {
364 $scope.templates[n] = {
365 content: $scope.print.template_content
366 , context: $scope.print.template_context
367 , cn_content: $scope.print.cn_template_content
368 , settings: JSON.parse(JSON.stringify($scope.preview_scope.settings))
369 , toolbox_settings: JSON.parse(JSON.stringify($scope.preview_scope.toolbox_settings))
371 $scope.template_name_list = Object.keys($scope.templates);
373 egCore.hatch.setItem('cat.printlabels.templates', $scope.templates);
374 $scope.fetchTemplates();
376 $scope.dirty = false;
378 // save all templates, as we might do after an import
379 egCore.hatch.setItem('cat.printlabels.templates', $scope.templates);
380 $scope.fetchTemplates();
382 ngToast.create(egCore.strings.PRINT_LABEL_TEMPLATE_SUCCESS_SAVE);
385 $scope.templates = {};
386 $scope.imported_templates = { data: '' };
387 $scope.template_name = '';
388 $scope.template_name_list = [];
390 $scope.print_labels = function () {
391 return egCore.print.print({
392 context: $scope.print.template_context,
393 template: $scope.print.template_name,
394 scope: $scope.preview_scope,
398 $scope.template_changed = function () {
399 $scope.print.load_failed = false;
400 egCore.print.getPrintTemplate('item_label')
403 $scope.print.template_content = html;
406 $scope.print.template_content = '';
407 $scope.print.load_failed = true;
410 egCore.print.getPrintTemplateContext('item_label')
411 .then(function (template_context) {
412 $scope.print.template_context = template_context;
414 egCore.print.getPrintTemplate('item_label_cn')
417 $scope.print.cn_template_content = html;
420 $scope.print.cn_template_content = '';
421 $scope.print.load_failed = true;
424 egCore.hatch.getItem('cat.printlabels.last_settings').then(function (s) {
426 $scope.preview_scope.settings = s;
431 $scope.reset_to_default = function () {
432 egCore.print.removePrintTemplate(
435 egCore.print.removePrintTemplateContext(
438 egCore.print.removePrintTemplate(
441 egCore.hatch.removeItem('cat.printlabels.last_settings');
442 for (s in $scope.preview_scope.settings) {
443 $scope.preview_scope.settings[s] = undefined;
445 $scope.preview_scope.settings = {};
446 egCore.org.settings($scope.org_unit_setting_list).then(function (res) {
447 $scope.preview_scope.settings = res;
450 $scope.template_changed();
453 $scope.save_locally = function () {
454 egCore.print.storePrintTemplate(
456 $scope.print.template_content
458 egCore.print.storePrintTemplateContext(
460 $scope.print.template_context
462 egCore.print.storePrintTemplate(
464 $scope.print.cn_template_content
466 egCore.hatch.setItem('cat.printlabels.last_settings', $scope.preview_scope.settings);
469 $scope.imported_print_templates = { data: '' };
470 $scope.$watch('imported_templates.data', function (newVal, oldVal) {
471 if (newVal && newVal != oldVal) {
473 var data = JSON.parse(newVal);
474 angular.forEach(data, function (el, k) {
475 $scope.templates[k] = {
477 , context: el.context
478 , cn_content: el.cn_content
479 , settings: el.settings
480 , toolbox_settings: el.toolbox_settings
483 $scope.saveTemplate();
484 $scope.template_changed(); // refresh
485 ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT);
487 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_IMPORT);
492 $scope.rendered_call_number_set = {};
493 $scope.rendered_cn_key_by_copy_id = {};
494 $scope.rebuild_cn_set = function () {
495 $timeout(function () {
496 $scope.rendered_call_number_set = {};
497 $scope.rendered_cn_key_by_copy_id = {};
498 for (var i = 0; i < $scope.preview_scope.copies.length; i++) {
499 var copy = $scope.preview_scope.copies[i];
500 var rendered_cn = document.getElementById('cn_for_copy_' + copy.id);
501 if (rendered_cn && rendered_cn.textContent) {
502 var key = rendered_cn.textContent;
503 if (typeof $scope.rendered_call_number_set[key] == 'undefined') {
504 $scope.rendered_call_number_set[key] = {
508 $scope.rendered_cn_key_by_copy_id[copy.id] = key;
511 $scope.preview_scope.tickle = Date() + ' ' + Math.random();
515 $scope.create_print_label_table = function () {
516 if ($scope.print_label_form.$valid && $scope.print.template_content && $scope.preview_scope) {
517 $scope.preview_scope.label_output_copies = labelOutputRowsFilter($scope.preview_scope.copies, $scope.preview_scope.toolbox_settings);
518 var html = $scope.print.template_content;
519 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.
520 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";
522 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";
523 table += "<pre class=\"{{col.cls}}\" style=\"border: none; margin-bottom: 0; margin-top: 0; overflow: hidden;\" ng-if=\"col.cls === 'spine'\">\n";
524 table += "{{col.c ? get_cn_for(col.c) : ''}}";
526 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";
527 table += "{{col.c ? col.c.barcode : ''}}\n";
528 table += "{{col.c ? col.c['call_number.label'] : ''}}\n";
529 table += "{{col.c ? get_bib_for(col.c).author : ''}}\n";
530 table += "{{col.c ? (get_bib_for(col.c).title | wrap:28:'once':' ') : ''}}\n";
535 var comments = html.match(/\<\!\-\-(?:(?!\-\-\>)(?:.|\s))*\-\-\>\s*/g);
536 html = html.replace(/\<\!\-\-(?:(?!\-\-\>)(?:.|\s))*\-\-\>\s*/g, "");
537 var style = html.match(/\<style[^\>]*\>(?:(?!\<\/style\>)(?:.|\s))*\<\/style\>\s*/gi);
538 var output = (style ? style.join("\n") : "") + (comments ? comments.join("\n") : "") + table;
539 output = output.replace(/\n+/, "\n");
540 $scope.print.template_content = output;
541 $scope.save_locally();
545 $scope.redraw_label_table = function () {
546 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.
547 var table = "<table id=\"eg_plt_" + d.getTime().toString() + "\"\></table>\n";
548 $scope.print.template_content += table;
549 $scope.create_print_label_table();
552 $scope.$watch('preview_scope.toolbox_settings.page.dimensions.columns',
553 function (newVal, oldVal) {
554 if (newVal && newVal != oldVal && $scope.preview_scope) {
555 $scope.redraw_label_table();
560 $scope.$watch('print.cn_template_content', function (newVal, oldVal) {
561 if (newVal && newVal != oldVal) {
562 $scope.rebuild_cn_set();
566 $scope.$watch("preview_scope.settings['webstaff.cat.label.call_number_wrap_filter_height']", function (newVal, oldVal) {
567 if (newVal && newVal != oldVal) {
568 $scope.rebuild_cn_set();
572 $scope.$watch("preview_scope.settings['webstaff.cat.label.call_number_wrap_filter_width']", function (newVal, oldVal) {
573 if (newVal && newVal != oldVal) {
574 $scope.rebuild_cn_set();
578 $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) {
579 if (newVal && newVal != oldVal && $scope.preview_scope.label_output_copies) {
580 $scope.redraw_label_table();
584 $scope.$watch("preview_scope.toolbox_settings.mode.selected", function (newVal, oldVal) {
585 if (newVal && newVal != oldVal) {
586 var ts_p = $scope.preview_scope.toolbox_settings.page;
587 if (ts_p.label.set.size === 1) {
588 if (newVal === "spine-pocket") {
589 ts_p.column_class = ["spine", "pocket"];
590 ts_p.label.set.size = 2;
592 ts_p.column_class = ["spine"];
595 if (newVal === "spine-only") {
596 for (var i = 0; i < ts_p.label.set.size; i++) {
597 ts_p.column_class[i] = "spine";
600 ts_p.label.set.size === 2 ? ts_p.column_class = ["spine", "pocket"] : false;
603 $scope.redraw_label_table();
607 $scope.$watch("preview_scope.toolbox_settings.page.label.set.size", function (newVal, oldVal) {
608 if (newVal && newVal != oldVal) {
609 var ts_p = $scope.preview_scope.toolbox_settings.page;
610 if (angular.isNumber(newVal)) {
611 while (ts_p.column_class.length > ts_p.label.set.size) {
612 ts_p.column_class.splice((ts_p.column_class.length - 1), 1);
614 while (ts_p.column_class.length < ts_p.label.set.size) {
615 ts_p.column_class.push("spine");
618 $scope.redraw_label_table();
622 $scope.current_tab = 'call_numbers';
623 $scope.set_tab = function (tab) {
624 $scope.current_tab = tab;
629 .directive("egPrintLabelColumnBounds", function () {
631 link: function (scope, element, attr, ctrl) {
632 function withinBounds(v) {
633 scope.$watch("preview_scope.toolbox_settings.page.dimensions.columns", function (newVal, oldVal) {
634 ctrl.$setValidity("egWithinPrintColumnBounds", scope.preview_scope.valid_print_label_start_column())
638 ctrl.$parsers.push(withinBounds);
639 ctrl.$formatters.push(withinBounds);
645 .directive("egPrintLabelRowBounds", function () {
647 link: function (scope, element, attr, ctrl) {
648 function withinBounds(v) {
649 scope.$watch("preview_scope.toolbox_settings.page.dimensions.rows", function (newVal, oldVal) {
650 ctrl.$setValidity("egWithinPrintRowBounds", scope.preview_scope.valid_print_label_start_row());
654 ctrl.$parsers.push(withinBounds);
655 ctrl.$formatters.push(withinBounds);
661 .directive("egPrintLabelValidCss", function () {
664 link: function (scope, element, attr, ctrl) {
665 function floatValidation(v) {
666 ctrl.$setValidity("isFloat", v.toString().match(/^\-*(?:^0$|(?:\d+)(?:\.\d{1,})*([a-z]{2}))$/) ? true : false);
669 ctrl.$parsers.push(floatValidation);
674 .directive("egPrintLabelValidInt", function () {
677 link: function (scope, element, attr, ctrl) {
678 function intValidation(v) {
679 ctrl.$setValidity("isInteger", v.toString().match(/^\d+$/));
682 ctrl.$parsers.push(intValidation);
687 .directive('egPrintTemplateOutput', ['$compile', function ($compile) {
688 return function (scope, element, attrs) {
691 return scope.$eval(attrs.content);
694 // create an isolate scope and copy the print context
695 // data into the new scope.
696 // TODO: see also print security concerns in egHatch
697 var result = element.html(value);
698 var context = scope.$eval(attrs.context);
699 var print_scope = scope.$new(true);
700 angular.forEach(context, function (val, key) {
701 print_scope[key] = val;
703 $compile(element.contents())(print_scope);
709 .filter('cn_wrap', function () {
710 return function (input, w, h, wrap_type) {
712 var prefix = input[0];
713 var callnum = input[1];
714 var suffix = input[2];
719 /* handle spine labels differently if using LC */
720 if (wrap_type == 'lc' || wrap_type == 3) {
721 /* Establish a pattern where every return value should be isolated on its own line
722 on the spine label: subclass letters, subclass numbers, cutter numbers, trailing stuff (date) */
723 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;
724 var result = callnum.match(patt1);
726 callnum = result.slice(1).join('\t');
728 callnum = callnum.split(/\s+/).join('\t');
731 /* If result is null, leave callnum alone. Can't parse this malformed call num */
733 callnum = callnum.split(/\s+/).join('\t');
737 callnum = prefix + '\t' + callnum;
740 callnum += '\t' + suffix;
743 /* At this point, the call number pieces are separated by tab characters. This allows
744 * some space-containing constructs like "v. 1" to appear on one line
746 callnum = callnum.replace(/\t\t/g, '\t'); /* Squeeze out empties */
747 names = callnum.split('\t');
748 var j = 0; var tb = [];
754 var name = names.shift();
758 /* if the name is greater than the label width... */
759 if (name.length > w) {
760 /* then try to split it on periods */
761 var sname = name.split(/\./);
762 if (sname.length > 1) {
763 /* if we can, then put the periods back in on each splitted element */
764 if (name.match(/^\./)) sname[0] = '.' + sname[0];
765 for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
766 /* and put all but the first one back into the names array */
767 names = sname.slice(1).concat(names);
768 /* if the name fragment is still greater than the label width... */
769 if (sname[0].length > w) {
770 /* then just truncate and throw the rest back into the names array */
771 tb[j] = sname[0].substr(0, w);
772 names = [sname[0].substr(w)].concat(names);
774 /* otherwise we're set */
778 /* if we can't split on periods, then just truncate and throw the rest back into the names array */
779 tb[j] = name.substr(0, w);
780 names = [name.substr(w)].concat(names);
783 /* otherwise we're set */
790 return tb.join('\n');
794 .filter("columnRowRange", function () {
795 return function (i) {
797 for (var j = 0; j < i; j++) {
804 //Accepts $scope.preview_scope.copies and $scope.preview_scope.toolbox_settings as its parameters.
805 .filter("labelOutputRows", function () {
806 return function (copies, settings) {
807 var cols = [], rows = [];
808 for (var j = 0; j < (settings.page.start_position.row - 1) ; j++) {
810 for (var k = 0; k < settings.page.dimensions.columns; k++) {
811 cols.push({ c: null, index: k, cls: getPrintLabelOutputClass(k, settings), styl: getPrintLabelStyle(k, settings) });
813 rows.push({ columns: cols });
816 for (var j = 0; j < (settings.page.start_position.column - 1) ; j++) {
817 cols.push({ c: null, index: j, cls: getPrintLabelOutputClass(j, settings), styl: getPrintLabelStyle(j, settings) });
820 for (var j = 0; j < copies.length; j++) {
821 for (var n = 0; n < settings.page.label.set.size; n++) {
822 if (m < settings.page.dimensions.columns) {
823 cols.push({ c: copies[j], index: cols.length, cls: getPrintLabelOutputClass(m, settings), styl: getPrintLabelStyle(m, settings) });
826 if (m === settings.page.dimensions.columns) {
828 rows.push({ columns: cols });
830 n = settings.page.label.set.size;
834 cols.length > 0 ? rows.push({ columns: cols }) : false;
835 if (rows.length > 0) {
836 while ((rows[(rows.length - 1)].columns.length) < settings.page.dimensions.columns) {
837 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) });
844 .filter('wrap', function () {
845 return function (input, w, wrap_type, indent) {
848 if (!w) return input;
849 if (!indent) indent = '';
851 function wrap_on_space(
855 if_cant_wrap_then_truncate,
859 console.log('possible infinite recursion, aborting');
862 if (String(text).length <= length) {
865 var truncated_text = String(text).substr(0, length);
866 var pivot_pos = truncated_text.lastIndexOf(' ');
867 var left_chunk = text.substr(0, pivot_pos).replace(/\s*$/, '');
868 var right_chunk = String(text).substr(pivot_pos + 1);
871 if (left_chunk.length == 0) {
872 if (if_cant_wrap_then_truncate) {
873 wrapped_line = truncated_text;
884 right_chunk.length > length
889 if_cant_wrap_then_truncate,
902 output = wrap_on_space(input, w, true, false, 0);
905 output = wrap_on_space(input, w, false, false, 0);
913 function getPrintLabelOutputClass(index, settings) {
914 return settings.page.column_class[index % settings.page.label.set.size];
917 function getPrintLabelStyle(index, settings) {
918 return index > 0 && (index % settings.page.label.set.size === 0) ? settings.page.label.gap.size : "";