From 2fc3252063450c10032e0e7e987874c2774d400c Mon Sep 17 00:00:00 2001 From: Jason Boyer Date: Thu, 4 Jan 2018 12:55:16 -0500 Subject: [PATCH] LP1741072: Global String<->Num Directives for ngModel To increase flexibility the stringToNumber directive has been separated into int and float versions and aditional directives are added to convert in the other direction. The existing use of stringToNumber in the volume/copy editor are also converted to strToFloat. Signed-off-by: Jason Boyer Signed-off-by: Bill Erickson --- .../templates/staff/cat/volcopy/t_attr_edit.tt2 | 8 +-- .../web/js/ui/default/staff/cat/volcopy/app.js | 20 ------- Open-ILS/web/js/ui/default/staff/services/ui.js | 63 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 b/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 index 775c77bf0e..8b61610f17 100644 --- a/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 +++ b/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 @@ -226,7 +226,7 @@
- +
@@ -243,14 +243,14 @@
-
- +
@@ -370,7 +370,7 @@
- diff --git a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js index a9218dad23..dbafc5abd9 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js @@ -333,11 +333,6 @@ function(egCore , $q) { if ( curr_field["type"] === "stat_cat" ) { stat_cats[field_name] = parseInt(curr_field["value"]); } else { - tmp_val = curr_field['value']; // so... some of the number fields are actually strings. Groovy. - if ( tmp_val.toString().match(/^[-0-9.]+$/) && !(field_name.match(/(?:loan_duration|fine_level)/))) { - tmp_val = parseFloat(tmp_val); - } - if (field_name.match(/^batch_.*_menulist$/)) { // special handling for volume fields if (!("callnumber" in curr_templ)) curr_templ["callnumber"] = {}; @@ -446,21 +441,6 @@ function(egCore , $q) { return service; }]) -.directive('stringToNumber', function() { - return { - require: 'ngModel', - link: function(scope, element, attrs, ngModel) { - ngModel.$parsers.push(function(value) { - return value; - }); - - ngModel.$formatters.push(function(value) { - return parseFloat(value); - }); - } - }; -}) - .directive("egVolCopyEdit", function () { return { restrict: 'E', diff --git a/Open-ILS/web/js/ui/default/staff/services/ui.js b/Open-ILS/web/js/ui/default/staff/services/ui.js index 38f775d03b..24c6d50b12 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -73,6 +73,69 @@ function($timeout , $parse) { }; }]) +// +// use integer models for string values +.directive('intToStr', function() { + return { + restrict: 'A', + require: 'ngModel', + link: function(scope, element, attrs, ngModel) { + ngModel.$parsers.push(function(value) { + return parseInt(value); + }); + ngModel.$formatters.push(function(value) { + return '' + value; + }); + } + }; +}) + +// +.directive('strToInt', function() { + return { + restrict: 'A', + require: 'ngModel', + link: function(scope, element, attrs, ngModel) { + ngModel.$parsers.push(function(value) { + return '' + value; + }); + ngModel.$formatters.push(function(value) { + return parseInt(value); + }); + } + }; +}) + +// {{item.name}}
-- 2.11.0