Update Vue front-end according to the new API definition and paths

This commit is contained in:
Bubka
2021-10-09 19:23:24 +02:00
parent 83f7370b57
commit 184237697b
51 changed files with 472 additions and 358 deletions

View File

@ -1,8 +1,6 @@
import Vue from 'vue'
import Errors from './FormErrors'
// import { deepCopy } from './util'
class Form {
/**
* Create a new form instance.
@ -14,7 +12,7 @@ class Form {
this.isDisabled = false
// this.successful = false
this.errors = new Errors()
// this.originalData = deepCopy(data)
this.originalData = this.deepCopy(data)
Object.assign(this, data)
}
@ -30,6 +28,31 @@ class Form {
})
}
/**
* Update original form data.
*/
setOriginal () {
Object.keys(this)
.filter(key => !Form.ignore.includes(key))
.forEach(key => {
this.originalData[key] = this.deepCopy(this[key])
})
}
/**
* Fill form data.
*
* @param {Object} data
*/
fillWithKeyValueObject (data) {
this.keys().forEach(key => {
const keyValueObject = data.find(s => s.key === key.toString())
if(keyValueObject != undefined) {
this[key] = keyValueObject.value
}
})
}
/**
* Get the form data.
*
@ -83,7 +106,7 @@ class Form {
Object.keys(this)
.filter(key => !Form.ignore.includes(key))
.forEach(key => {
this[key] = deepCopy(this.originalData[key])
this[key] = this.deepCopy(this.originalData[key])
})
}
@ -265,6 +288,26 @@ class Form {
this.errors.clear(event.target.name)
}
}
/**
* Deep copy the given object.
*
* @param {Object} obj
* @return {Object}
*/
deepCopy (obj) {
if (obj === null || typeof obj !== 'object') {
return obj
}
const copy = Array.isArray(obj) ? [] : {}
Object.keys(obj).forEach(key => {
copy[key] = this.deepCopy(obj[key])
})
return copy
}
}
Form.routes = {}