This commit is contained in:
2019-05-01 23:28:57 +00:00
parent b87d43b70d
commit 7ad284cf77
8 changed files with 192 additions and 91 deletions

View File

@@ -180,6 +180,14 @@ export default {
headers: this.postAuthorizedHeaders()
};
},
fetchRemoveOptions() {
/* REMOVE WITH AUTH */
return {
method: "delete",
mode: "cors",
headers: this.postAuthorizedHeaders()
};
},
APIUrl(apiPath) {
if ("" == store.state.apiUrl) {
//construct the api url and store it
@@ -292,6 +300,24 @@ export default {
handleError("UPSERT", error, route, reject);
});
});
},
///////////////////////////////////
// DELETE DATA FROM API SERVER
//
remove(route) {
var that = this;
return new Promise(function removeDataFromServer(resolve, reject) {
fetch(that.APIUrl(route), that.fetchRemoveOptions())
.then(that.status)
//.then(that.json)
.then(response => {
resolve(response);
})
.catch(function handleRemoveError(error) {
//fundamental error, can't proceed with this call
handleError("DELETE", error, route, reject);
});
});
}
//new functions above here

View File

@@ -502,5 +502,12 @@ export default {
newState.vm.formState.readOnly = newState.readOnly;
}
});
},
async confirm(vm) {
const res = await vm.$dialog.confirm({
text: "Do you really want to exit?",
title: "Warning"
});
return res;
}
};

View File

@@ -12,6 +12,8 @@ import NProgress from "nprogress";
import "nprogress/nprogress.css";
import dayjs from "dayjs";
import lodash from "./libs/lodash.min.js";
import VuetifyDialog from "vuetify-dialog";
//my libs
import gzeventbus from "./api/eventbus";
import gzmenu from "./api/gzmenu";
@@ -22,7 +24,6 @@ import gzform from "./api/gzform";
import roles from "./api/authorizationroles";
import gztype from "./api/ayatype";
import "@/assets/css/main.css";
import gzdateandtimepicker from "./components/gzdateandtimepicker.vue";
/////////////////////////////////////////////////////////////////
@@ -46,11 +47,6 @@ Object.defineProperty(Vue.prototype, "$gzdevmode", {
value: errorHandler.devMode
});
/////////////////////////////////////////////////////////////////
// FORM VALIDATION
//
//TODO: CODE THIS
/////////////////////////////////////////////////////////////////
// ERROR HANDLING
//
@@ -147,6 +143,11 @@ Vue.filter("boolastext", function vueFilterBoolAsText(value) {
//
Vue.component("gz-date-time-picker", gzdateandtimepicker);
////////////////////////////////////////////////////////
//3rd party ui components
//
Vue.use(VuetifyDialog);
/////////////////////////////////////////////////////////////////
// INSTANTIATE
//

View File

@@ -157,7 +157,7 @@
</template>
<script>
/* xeslint-disable */
/* eslint-disable */
/////////////////////////////
//
@@ -401,16 +401,69 @@ export default {
}
},
remove() {
//check rights
//Prompt:
//do the delete
alert("STUB: DELETE");
this.formState.loading = true;
var url = "Widget/" + this.$route.params.id;
//TODO: check if it's a new record (no ID) or one from server (has id)
var vm = this;
this.$gzform.deleteAllErrorBoxErrors(this);
this.$gzapi
.remove(url)
.then(res => {
if (res.error) {
vm.formState.serverError = res.error;
vm.$gzform.setErrorBoxErrors(vm);
} else {
//success, navigate backwards
vm.$router.go(-1);
}
})
.catch(function handleGetDataFromAPIError(error) {
//Update the form status
vm.$gzform.setFormState({
vm: vm,
loading: false
});
vm.$gzHandleFormError(error, vm);
});
},
duplicate() {
//this.$gzrole.getRights(this, this.$gztype.Widget, this.obj.ownerId);
this.$gzevent.$emit(
"popup-message",
"This is a test popup message\r\nDUPLICATE ALL THE THINGS!"
);
console.log("About to dialog");
this.$dialog.confirm({
text: "Do you really want to exit?",
title: "Warning"
}).then(res => {
console.log("The dialog result is:");
console.log(res);
});
//console.log(this.$gzform.confirm(this));
// this.$dialog.error({
// text: "Cannot delete this item",
// title: "Error"
// });
console.log("Done dialog");
// this.$dialog.notify.info("Test notification", {
// position: "top-right",
// timeout: 5000
// });
// this.$dialog.message.info("Test", {
// position: "top-left"
// });
// this.$gzevent.$emit(
// "popup-message",
// "This is a test popup message\r\nDUPLICATE ALL THE THINGS!"
// );
//only if not dirty
//check rights
//duplicate