From: Jason Boyer Date: Thu, 4 Jan 2018 17:55:16 +0000 (-0500) Subject: LP1741072: Global String<->Num Directives for ngModel X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3a787aebee4b689a3fd4c5a54357da8db878ec5a;p=working%2FEvergreen.git 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 --- 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 d856ce626f..2efd97568a 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 76d5425115..47632ed696 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}}