Commit de1eecfee2bb1d4874b0e0c71995ab692f112ae2
1 parent
864dcd40
Exists in
master
{Redmine tarefa-4677}
Showing
2 changed files
with
52 additions
and
22 deletions
Show diff stats
cit-portal-web/src/main/webapp/assets/js/angular/custom/directive/LabelInputDecimalDirective.js
@@ -13,7 +13,7 @@ citApp.directive("labelInputDecimal", ["$translate", function($translate) { | @@ -13,7 +13,7 @@ citApp.directive("labelInputDecimal", ["$translate", function($translate) { | ||
13 | model : "=ngModel", | 13 | model : "=ngModel", |
14 | form : "=form", | 14 | form : "=form", |
15 | eventoChange : "&ngEventoChange", | 15 | eventoChange : "&ngEventoChange", |
16 | - precisao : "=ngPrecisao", | 16 | + precisao : "@ngPrecisao", |
17 | labelAlertTooltip: '@', | 17 | labelAlertTooltip: '@', |
18 | labelInfoTooltip: '@', | 18 | labelInfoTooltip: '@', |
19 | labelQuestionTooltip: '@', | 19 | labelQuestionTooltip: '@', |
@@ -23,8 +23,9 @@ citApp.directive("labelInputDecimal", ["$translate", function($translate) { | @@ -23,8 +23,9 @@ citApp.directive("labelInputDecimal", ["$translate", function($translate) { | ||
23 | restrict : 'E', | 23 | restrict : 'E', |
24 | template : "<div class='form-group' ng-class=\"{'has-error': form[id].$error.required && (!form[id].$pristine || form.$submitted)}\">" + | 24 | template : "<div class='form-group' ng-class=\"{'has-error': form[id].$error.required && (!form[id].$pristine || form.$submitted)}\">" + |
25 | " <label for='{{id}}' class='control-label' ng-if='labelRender'><translate>{{label}}</translate> <span class='red' ng-show='obrigatorio'>*</span> <i ng-if='obrigatorio' ng-show='form[id].$error.required && (!form[id].$pristine || form.$submitted)' class='fa fa-warning red' tooltip='{{labelAlertTooltipCopy}}' tooltip-placement='top'></i> <i ng-if='labelInfoTooltipRender' class='fa fa-info-circle blue' tooltip='{{labelInfoTooltip}}' tooltip-placement='top'></i> <i ng-if='labelQuestionTooltipRender' class='fa fa-question-circle green' tooltip='{{labelQuestionTooltip}}' tooltip-placement='top'></i></label>"+ | 25 | " <label for='{{id}}' class='control-label' ng-if='labelRender'><translate>{{label}}</translate> <span class='red' ng-show='obrigatorio'>*</span> <i ng-if='obrigatorio' ng-show='form[id].$error.required && (!form[id].$pristine || form.$submitted)' class='fa fa-warning red' tooltip='{{labelAlertTooltipCopy}}' tooltip-placement='top'></i> <i ng-if='labelInfoTooltipRender' class='fa fa-info-circle blue' tooltip='{{labelInfoTooltip}}' tooltip-placement='top'></i> <i ng-if='labelQuestionTooltipRender' class='fa fa-question-circle green' tooltip='{{labelQuestionTooltip}}' tooltip-placement='top'></i></label>"+ |
26 | - " <input type='text' class='form-control' ng-change='eventoChange()' ng-keydown='removeModel($event)' id='{{id}}' name='{{id}}' ng-model='model' ng-disabled='disabled' maxlength='{{maxlength ? maxlength : 23}}' ng-required='obrigatorio' ui-number-mask='precisao'/>" + | 26 | + " <input type='text' class='form-control' ng-change='eventoChange()' ng-keydown='removeModel($event)' id='{{id}}' name='{{id}}' ng-model='model' ng-disabled='disabled' maxlength='{{maxlength ? maxlength : 23}}' ng-required='obrigatorio' ui-number-mask='{{precisao}}'/>" + |
27 | "</div>", | 27 | "</div>", |
28 | + | ||
28 | controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) { | 29 | controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) { |
29 | if($scope.id === undefined){ | 30 | if($scope.id === undefined){ |
30 | $scope.id = $attrs['ngModel']; | 31 | $scope.id = $attrs['ngModel']; |
cit-portal-web/src/main/webapp/assets/js/angular/custom/directive/MasksDirective.js
@@ -13,7 +13,7 @@ var StringMask = (function() { | @@ -13,7 +13,7 @@ var StringMask = (function() { | ||
13 | '9': {pattern: /\d/, optional: true}, | 13 | '9': {pattern: /\d/, optional: true}, |
14 | '#': {pattern: /\d/, optional: true, recursive: true}, | 14 | '#': {pattern: /\d/, optional: true, recursive: true}, |
15 | 'S': {pattern: /[a-zA-Z]/}, | 15 | 'S': {pattern: /[a-zA-Z]/}, |
16 | - '$': {escape: true} | 16 | + '$': {escape: true} |
17 | }; | 17 | }; |
18 | var isEscaped = function(pattern, pos) { | 18 | var isEscaped = function(pattern, pos) { |
19 | var count = 0; | 19 | var count = 0; |
@@ -24,7 +24,7 @@ var StringMask = (function() { | @@ -24,7 +24,7 @@ var StringMask = (function() { | ||
24 | count += token && token.escape ? 1 : 0; | 24 | count += token && token.escape ? 1 : 0; |
25 | i--; | 25 | i--; |
26 | } | 26 | } |
27 | - return count > 0 && count%2 === 1; | 27 | + return count > 0 && count%2 === 1; |
28 | }; | 28 | }; |
29 | var calcOptionalNumbersToUse = function(pattern, value) { | 29 | var calcOptionalNumbersToUse = function(pattern, value) { |
30 | var numbersInP = pattern.replace(/[^0]/g,'').length; | 30 | var numbersInP = pattern.replace(/[^0]/g,'').length; |
@@ -189,7 +189,7 @@ var objectTypes = { | @@ -189,7 +189,7 @@ var objectTypes = { | ||
189 | }; | 189 | }; |
190 | 190 | ||
191 | if (objectTypes[typeof module]) { | 191 | if (objectTypes[typeof module]) { |
192 | - module.exports = StringMask; | 192 | + module.exports = StringMask; |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
@@ -827,7 +827,7 @@ var objectTypes = { | @@ -827,7 +827,7 @@ var objectTypes = { | ||
827 | 'object': true | 827 | 'object': true |
828 | }; | 828 | }; |
829 | if (objectTypes[typeof module]) { | 829 | if (objectTypes[typeof module]) { |
830 | - module.exports = BrV; | 830 | + module.exports = BrV; |
831 | } else { | 831 | } else { |
832 | root.BrV = BrV; | 832 | root.BrV = BrV; |
833 | } | 833 | } |
@@ -1562,32 +1562,61 @@ angular.module('ui.utils.masks.number', []) | @@ -1562,32 +1562,61 @@ angular.module('ui.utils.masks.number', []) | ||
1562 | modelMask = NumberMasks.modelMask(decimals); | 1562 | modelMask = NumberMasks.modelMask(decimals); |
1563 | 1563 | ||
1564 | function parse(value) { | 1564 | function parse(value) { |
1565 | + | ||
1565 | if(!value) { | 1566 | if(!value) { |
1566 | return value; | 1567 | return value; |
1567 | } | 1568 | } |
1568 | 1569 | ||
1569 | - var valueToFormat = PreFormatters.clearDelimitersAndLeadingZeros(value) || '0'; | ||
1570 | - var formatedValue = viewMask.apply(valueToFormat); | ||
1571 | - var actualNumber = parseFloat(modelMask.apply(valueToFormat)); | 1570 | + if(attrs.uiNumberMask == 'decimal'){ |
1571 | + | ||
1572 | + var pos = value.indexOf(","); | ||
1573 | + var result; | ||
1574 | + if (pos !== -1) { | ||
1575 | + var part1 = value.substr(0, pos > 6 ? 6 : pos); | ||
1576 | + var part2 = value.substr(pos > 6 ? 6 : pos + 1); | ||
1577 | + //2 casas decimais...... | ||
1578 | + part2 = part2.substr(0,2); | ||
1579 | + result = cleanForDecimal(part1) + "," + cleanForDecimal(part2); | ||
1580 | + } else { | ||
1581 | + result = cleanForDecimal(value).substr(0,6); | ||
1582 | + } | ||
1572 | 1583 | ||
1573 | - if(angular.isDefined(attrs.uiNegativeNumber)){ | ||
1574 | - var isNegative = (value[0] === '-'), | ||
1575 | - needsToInvertSign = (value.slice(-1) === '-'); | 1584 | + result = result ==',' ? '' : result; |
1576 | 1585 | ||
1577 | - //only apply the minus sign if it is negative or(exclusive) | ||
1578 | - //needs to be negative and the number is different from zero | ||
1579 | - if(needsToInvertSign ^ isNegative && !!actualNumber) { | ||
1580 | - actualNumber *= -1; | ||
1581 | - formatedValue = '-' + formatedValue; | 1586 | + if (ctrl.$viewValue !== result) { |
1587 | + ctrl.$setViewValue(result); | ||
1588 | + ctrl.$render(); | ||
1582 | } | 1589 | } |
1583 | - } | ||
1584 | 1590 | ||
1585 | - if (ctrl.$viewValue !== formatedValue) { | ||
1586 | - ctrl.$setViewValue(formatedValue); | ||
1587 | - ctrl.$render(); | 1591 | + return result.length > 0 ? parseFloat(result.replace(',','.')) : 0; |
1592 | + }else{ | ||
1593 | + var valueToFormat = PreFormatters.clearDelimitersAndLeadingZeros(value) || '0'; | ||
1594 | + var formatedValue = viewMask.apply(valueToFormat); | ||
1595 | + var actualNumber = parseFloat(modelMask.apply(valueToFormat)); | ||
1596 | + | ||
1597 | + if(angular.isDefined(attrs.uiNegativeNumber)){ | ||
1598 | + var isNegative = (value[0] === '-'), | ||
1599 | + needsToInvertSign = (value.slice(-1) === '-'); | ||
1600 | + | ||
1601 | + //only apply the minus sign if it is negative or(exclusive) | ||
1602 | + //needs to be negative and the number is different from zero | ||
1603 | + if(needsToInvertSign ^ isNegative && !!actualNumber) { | ||
1604 | + actualNumber *= -1; | ||
1605 | + formatedValue = '-' + formatedValue; | ||
1606 | + } | ||
1607 | + } | ||
1608 | + | ||
1609 | + if (ctrl.$viewValue !== formatedValue) { | ||
1610 | + ctrl.$setViewValue(formatedValue); | ||
1611 | + ctrl.$render(); | ||
1612 | + } | ||
1613 | + | ||
1614 | + return actualNumber; | ||
1588 | } | 1615 | } |
1616 | + } | ||
1589 | 1617 | ||
1590 | - return actualNumber; | 1618 | + function cleanForDecimal(string) { |
1619 | + return string.replace(/[^0-9]/g, ""); | ||
1591 | } | 1620 | } |
1592 | 1621 | ||
1593 | ctrl.$formatters.push(function(value) { | 1622 | ctrl.$formatters.push(function(value) { |