mirror of
https://github.com/Alamantus/Lexiconga.git
synced 2025-07-12 10:25:54 +02:00
Add Updater for saving new values. Add EditDictionaryForm and EditLinguisticsForm. Add helpful Array and Object functions to Helper.
58 lines
No EOL
1.6 KiB
JavaScript
58 lines
No EOL
1.6 KiB
JavaScript
import helper from './Helper';
|
|
|
|
export class Updater {
|
|
constructor (appWithDictionaryState, dictionary) {
|
|
this.app = appWithDictionaryState;
|
|
this.dictionary = dictionary;
|
|
}
|
|
|
|
setDictionaryName (newName) {
|
|
this.app.setState({
|
|
name: newName,
|
|
}, () => {
|
|
this.dictionary.name = newName;
|
|
});
|
|
}
|
|
|
|
setDictionarySpecification (newSpecification) {
|
|
this.app.setState({
|
|
specification: newSpecification,
|
|
}, () => {
|
|
this.dictionary.specification = newSpecification;
|
|
});
|
|
}
|
|
|
|
updateDictionaryDetails (dicitonaryDetails = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
const updatedDetails = {};
|
|
|
|
if (dicitonaryDetails.name) {
|
|
updatedDetails['name'] = dicitonaryDetails.name;
|
|
this.dictionary.name = dicitonaryDetails.name;
|
|
}
|
|
|
|
if (dicitonaryDetails.specification) {
|
|
updatedDetails['specification'] = dicitonaryDetails.specification;
|
|
this.dicitonary.specification = dicitonaryDetails.specification;
|
|
}
|
|
|
|
if (dicitonaryDetails.description) {
|
|
updatedDetails['description'] = dicitonaryDetails.description;
|
|
this.dictionary.description = dicitonaryDetails.description;
|
|
}
|
|
|
|
if (dicitonaryDetails.partsOfSpeech) {
|
|
updatedDetails['partsOfSpeech'] = dicitonaryDetails.partsOfSpeech;
|
|
this.dictionary.partsOfSpeech = dicitonaryDetails.partsOfSpeech;
|
|
}
|
|
|
|
if (helper.objectIsEmpty(updatedDetails)) {
|
|
reject('No dictionary details have changed.');
|
|
} else {
|
|
this.app.setState(updatedDetails, () => {
|
|
resolve();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
} |