widgets: put input's deepCopyWithPrecision in widgets base class
This commit is contained in:
parent
f6fb539e83
commit
e6a6a38865
2 changed files with 7 additions and 22 deletions
|
|
@ -99,13 +99,13 @@ module.exports = class _widgets_base {
|
|||
|
||||
}
|
||||
|
||||
getValue() {
|
||||
getValue(withPrecision) {
|
||||
|
||||
return _widgets_base.deepCopy(this.value)
|
||||
return _widgets_base.deepCopy(this.value, withPrecision)
|
||||
|
||||
}
|
||||
|
||||
static deepCopy(obj){
|
||||
static deepCopy(obj, precision){
|
||||
|
||||
var copy = obj,
|
||||
key
|
||||
|
|
@ -119,6 +119,8 @@ module.exports = class _widgets_base {
|
|||
for (let key in obj) {
|
||||
copy[key] = _widgets_base.deepCopy(obj[key])
|
||||
}
|
||||
} else if (typeof obj == 'number') {
|
||||
return precision === undefined ? copy : parseFloat(copy.toFixed(precision))
|
||||
}
|
||||
|
||||
return copy
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
var {iconify} = require('../../utils'),
|
||||
_widgets_base = require('../common/_widgets_base'),
|
||||
_canvas_base = require('../common/_canvas_base'),
|
||||
widgetManager = require('../../managers/widgets')
|
||||
|
||||
|
|
@ -198,28 +199,10 @@ module.exports = class Input extends _canvas_base {
|
|||
|
||||
}
|
||||
|
||||
static deepCopyWithPrecision(obj, precision) {
|
||||
|
||||
var copy = obj,
|
||||
key
|
||||
|
||||
if (typeof obj === 'object') {
|
||||
copy = Array.isArray(obj) ? [] : {}
|
||||
for (key in obj) {
|
||||
copy[key] = Input.deepCopyWithPrecision(obj[key], precision)
|
||||
}
|
||||
} else if (typeof obj == 'number') {
|
||||
return parseFloat(copy.toFixed(precision))
|
||||
}
|
||||
|
||||
return copy
|
||||
|
||||
}
|
||||
|
||||
getStringValue() {
|
||||
if (this.value === undefined) return ''
|
||||
return typeof this.value != 'string' ?
|
||||
JSON.stringify(Input.deepCopyWithPrecision(this.value, this.precision)).replace(/,/g, ', ') :
|
||||
JSON.stringify(_widgets_base.deepCopy(this.value, this.precision)).replace(/,/g, ', ') :
|
||||
this.value
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue