Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
editors.collection = editorsForm.formData.collection
editors.isbn = editorsForm.formData.isbn
editors.publicationDate = editorsForm.formData.publicationDate
this.editors.push(editors)
// reset the forms
this.dxLookUp.value = undefined
editorsForm.instance.resetValues()
editorForm.instance.resetValues()
// save in cache when user refresh or come back later
localStorage.setItem(CacheKey.EDITORS, JSON.stringify(this.editors))
// notify the user
notify({
message: `The edition has been saved locally`,
position: {
my: "center top",
at: "center top"
}
}, "success", 3000);
}
goNext(ev: Event) {
ev.preventDefault()
notify({
message: this.nextPageNotifyMsg,
position: {
my: "center top",
at: "center top"
}
}, "success", 3000);
// propagate to other component
this.bookService.updateBook(this.book)
// go next
this.routing.goNext(ev)
}
}
this.broadcastChannel.message.subscribe(message => {
switch(message.cmd) {
case 'book':
const book = this.books.find(book => book.id === message.book.id)
if (!book) {
notify(`no book found in store with id ${message.book.id}`, "warn", 5000)
return
}
for (let prop in message.book) {
book[prop] = message.book[prop]
}
// Take care, until you click on the parent window, data won't be refreshed in datagrid. don't know if it's because of browser behavior or DevXpress.datagrid
notify(`new Book received with id ${book.id}, focus the window to see the changes in datagrid.
Data is not saved until you edit it`, "info", 5000)
this.dataGrid.instance.clearSelection()
break
case 'hello':
case 'ping':
default:
}
for (const prop in message.book) {
book[prop] = message.book[prop]
}
// Take care, until you click on the parent window, data won't be refreshed in datagrid. don't know if it's because of browser behavior or DevXpress.datagrid
notify(`new Book received with id ${book.id}, focus the window to see the changes in datagrid.
Data is not saved until you edit it`, 'info', 5000);
this.dataGrid.instance.clearSelection()
break
case 'hello':
case 'ping':
default:
notify(`data received from second screen (cmd=${message.cmd})`, "info", 5000)
break
}
})
.subscribe((book: Book) => {
notify({
message: 'New book created with ID: ' + book.id,
position: {
my: "center top",
at: "center top"
}
}, "success", 3000)
const cacheKeys = Object.values(CacheKey)
// reset localStorage and service
// @todo should be in a Guar route when exit wizard/*
for (let cacheKey of cacheKeys) {
localStorage.removeItem(cacheKey)
}
this.bookService.reset()
this.routing.goEnd(ev)
addEditor(ev, editorsForm: DxFormComponent, editorForm: DxFormComponent) {
ev.preventDefault()
// we should never enter this coz the button is disabled until everything is ok
// but some user may force the form submit (yes they can) so we have to prevent that kind of hack
if (!editorsForm.instance.validate().isValid || !editorForm.instance.validate().isValid) {
notify({
message: `Your form still has errors, fix them before trying to add the edition`,
position: {
my: "center top",
at: "center top"
}
}, "warning", 3000);
return false
}
const editor = new Editor()
if (this.dxLookUp.value) {
// @todo improve this with maybe decomposition or anything else
editor.id = this.dxLookUp.value.id
editor.name = this.dxLookUp.value.name
} else {
const authors = new Authors()
authors.author = author
authors.role = job
this.authors.push(authors)
// reset the forms
this.dxAutocomplete.instance.reset()
this.dxSelectBox.instance.reset()
authorsForm.instance.resetValues()
// save in cache when user refresh or come back later
localStorage.setItem(CacheKey.AUTHORS, JSON.stringify(this.authors))
// notify the user
notify({
message: `The author has been saved locally`,
position: {
my: "center top",
at: "center top"
}
}, "success", 3000);
}
.catch(err => {
notify("Erro ao consultar Casas: " + err, "error", 2000);
this.setLoading(false);
console.log(err);
});
};
if (err.error.violations) {
for (let i = 0; i < err.error.violations.length; i++) {
console.warn(err.error.violations[i].propertyPath + ': ' + err.error.violations[i].message)
}
}
} else {
if (typeof err == 'string') {
msg += ': ' + err
} else {
if (err.statusText) {
msg += ': ' + err.statusText
}
}
}
notify({
message: msg,
position: {
my: "center top",
at: "center top"
}
}, "error", 3000)
})
}
changeFavoriteState = () => {
const currentHouse = this.state.currentHouse;
currentHouse.favorite = !currentHouse.favorite;
this.postFavorite(currentHouse.id, currentHouse.favorite);
this.setState({
currentHouse
});
notify({
message: `Este item foi ${currentHouse.favorite ? "adicionado a" : "removido da" } lista de Favoritos!`,
width: 450
},
currentHouse.favorite ? "success" : "error",
2000
);
};
}