</select>
</div>
<div class="col-md-6" ng-class="{'bg-success': working.price !== undefined}">
- <input class="form-control" ng-disabled="!defaults.attributes.price" string-to-number ng-model="working.price" type="number" step="0.01"/>
+ <input class="form-control" ng-disabled="!defaults.attributes.price" str-to-float ng-model="working.price" type="number" step="0.01"/>
</div>
</div>
<div class="row">
<div class="col-md-6" ng-class="{'bg-success': working.loan_duration !== undefined}">
- <select class="form-control" ng-disabled="!defaults.attributes.loan_duration" ng-model="working.loan_duration">
+ <select class="form-control" int-to-str ng-disabled="!defaults.attributes.loan_duration" ng-model="working.loan_duration">
<option value="1">[% l('Short') %]</option>
<option value="2" selected>[% l('Normal') %]</option>
<option value="3">[% l('Extended') %]</option>
</select>
</div>
<div class="col-md-6" ng-class="{'bg-success': working.cost !== undefined}">
- <input class="form-control" ng-disabled="!defaults.attributes.cost" string-to-number ng-model="working.cost" type="number" step="0.01"/>
+ <input class="form-control" ng-disabled="!defaults.attributes.cost" str-to-float ng-model="working.cost" type="number" step="0.01"/>
</div>
</div>
<div class="row">
<div class="col-md-6" ng-class="{'bg-success': working.fine_level !== undefined}">
- <select class="form-control" ng-disabled="!defaults.attributes.fine_level" ng-model="working.fine_level">
+ <select class="form-control" int-to-str ng-disabled="!defaults.attributes.fine_level" ng-model="working.fine_level">
<option value="1">[% l('Low') %]</option>
<option value="2" selected>[% l('Normal') %]</option>
<option value="3">[% l('High') %]</option>
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"] = {};
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',
};
}])
+// <select int-to-str ><option value="1">Value</option></select>
+// 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;
+ });
+ }
+ };
+})
+
+// <input str-to-int value="10"/>
+.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);
+ });
+ }
+ };
+})
+
+// <input float-to-str
+.directive('floatToStr', function() {
+ return {
+ restrict: 'A',
+ require: 'ngModel',
+ link: function(scope, element, attrs, ngModel) {
+ ngModel.$parsers.push(function(value) {
+ return parseFloat(value);
+ });
+ ngModel.$formatters.push(function(value) {
+ return '' + value;
+ });
+ }
+ };
+})
+
+.directive('strToFloat', 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 parseFloat(value);
+ });
+ }
+ };
+})
// 'reverse' filter
// <div ng-repeat="item in items | reverse">{{item.name}}</div>