diff --git a/public/js/components/DashboardWidget/Url.js b/public/js/components/DashboardWidget/Url.js
index 8dabf7b4c..c3ad0c810 100644
--- a/public/js/components/DashboardWidget/Url.js
+++ b/public/js/components/DashboardWidget/Url.js
@@ -5,7 +5,10 @@ export default {
data: () => ({
title_input: "",
url_input: "",
- invalidURL: false,
+ validation:{
+ invalidURL: false,
+ invalidTitel:false,
+ }
}),
mixins: [AbstractWidget],
computed: {
@@ -23,28 +26,37 @@ export default {
},
},
methods: {
+ isValidationSuccessfull(){
+ // validate the input fields
+ if (this.title_input.length === 0) {
+ this.$fhcAlert.alertError(this.$p.t("bookmark", "invalidTitel"));
+ this.validation.invalidTitel = true;
+ }
+ if (!URL.canParse(this.url_input)) {
+ this.$fhcAlert.alertError(this.$p.t("bookmark", "invalidUrl"));
+ this.validation.invalidURL = true;
+ }
+
+ return !Object.values(this.validation).some(value => value === true);
+ },
async fetchBookmarks() {
await this.$fhcApi.factory.bookmark
.getBookmarks()
.then((res) => res.data)
.then((result) => {
- this.shared = result;
- })
+ this.shared = result;
+ })
.catch(this.$fhcAlert.handleSystemError);
},
- async confirmDelete() {
- if ((await this.$fhcAlert.confirmDelete()) === false) return;
- },
addLink() {
// reset is-invalid css on url input field
- this.invalidURL = false;
-
- if(!URL.canParse(this.url_input))
- {
- this.$fhcAlert.alertError(this.$p.t("bookmark", "invalidUrl"));
- this.invalidURL = true;
- return;
+ for(let key of Object.keys(this.validation)){
+ this.validation[key] = false;
}
+
+ // early return if validation failed
+ if (!this.isValidationSuccessfull()) return;
+
this.$fhcApi.factory.bookmark
.insert({
tag: this.config.tag,
@@ -54,28 +66,30 @@ export default {
.then((res) => res.data)
.then((result) => {
this.$fhcAlert.alertInfo(this.$p.t("bookmark", "bookmarkAdded"));
+ // refetch the bookmarks to see the updates
+ this.fetchBookmarks();
})
.catch(this.$fhcAlert.handleSystemError);
// reset the values for the title and url inputs
this.title_input = "";
this.url_input = "";
-
- // refetch the bookmarks to see the updates
- this.fetchBookmarks();
},
async removeLink(bookmark_id) {
- await this.confirmDelete();
- this.$fhcApi.factory.bookmark
+ let isConfirmed = await this.$fhcAlert.confirmDelete();
+
+ // early return if the confirm dialog was not confirmed
+ if(!isConfirmed) return;
+
+ this.$fhcApi.factory.bookmark
.delete(bookmark_id)
.then((res) => res.data)
.then((result) => {
this.$fhcAlert.alertInfo(this.$p.t("bookmark", "bookmarkDeleted"));
+ // refetch the bookmarks to see the updates
+ this.fetchBookmarks();
})
.catch(this.$fhcAlert.handleSystemError);
-
- // refetch the bookmarks to see the updates
- this.fetchBookmarks();
},
},
async mounted() {
@@ -92,11 +106,22 @@ export default {