This commit is contained in:
@@ -224,6 +224,12 @@ export default {
|
||||
return store.state.apiUrl + apiPath;
|
||||
},
|
||||
/////////////////////////////
|
||||
// REPLACE END OF URL
|
||||
// (used to change ID in url)
|
||||
replaceAfterLastSlash(theUrl, theReplacement) {
|
||||
return theUrl.substr(0, theUrl.lastIndexOf("\\") + 1) + theReplacement;
|
||||
},
|
||||
/////////////////////////////
|
||||
// ENCODE QUERY STRING
|
||||
//
|
||||
buildQuery(obj, sep, eq, name) {
|
||||
@@ -326,6 +332,26 @@ export default {
|
||||
handleError("DELETE", error, route, reject);
|
||||
});
|
||||
});
|
||||
},
|
||||
///////////////////////////////////
|
||||
// POST DUPLICATE TO API SERVER
|
||||
//
|
||||
duplicate(route) {
|
||||
var that = this;
|
||||
return new Promise(function duplicateRecordOnServer(resolve, reject) {
|
||||
fetch(that.APIUrl(route), that.fetchPostOptions(null))
|
||||
.then(that.status)
|
||||
.then(that.json)
|
||||
.then(response => {
|
||||
//Note: response.error indicates there is an error, however this is not an unusual condition
|
||||
//it could be validation errors or other general error so we need to treat it here like it's normal
|
||||
//and let the caller deal with it appropriately
|
||||
resolve(response);
|
||||
})
|
||||
.catch(function handleDuplicateError(error) {
|
||||
handleError("DUPLICATE", error, route, reject);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//new functions above here
|
||||
|
||||
@@ -157,7 +157,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* xeslint-disable */
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/* Xeslint-disable */
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////
|
||||
//
|
||||
@@ -395,6 +397,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
//enable / disable save button
|
||||
var canSave = val.dirty && val.valid && !val.readOnly;
|
||||
if (canSave) {
|
||||
this.$gzevent.$emit("menu-enable-item", "inventory-widget-edit:save");
|
||||
@@ -404,6 +407,20 @@ export default {
|
||||
"inventory-widget-edit:save"
|
||||
);
|
||||
}
|
||||
|
||||
//enable / disable duplicate button
|
||||
var canDuplicate = !val.dirty && val.valid && !val.readOnly;
|
||||
if (canDuplicate) {
|
||||
this.$gzevent.$emit(
|
||||
"menu-enable-item",
|
||||
"inventory-widget-edit:duplicate"
|
||||
);
|
||||
} else {
|
||||
this.$gzevent.$emit(
|
||||
"menu-disable-item",
|
||||
"inventory-widget-edit:duplicate"
|
||||
);
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
@@ -411,6 +428,9 @@ export default {
|
||||
computed: {
|
||||
canSave: function() {
|
||||
return this.formState.valid && this.formState.dirty;
|
||||
},
|
||||
canDuplicate: function() {
|
||||
return this.formState.valid && !this.formState.dirty;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -548,11 +568,34 @@ export default {
|
||||
});
|
||||
},
|
||||
duplicate() {
|
||||
//only if not dirty
|
||||
//check rights
|
||||
//duplicate
|
||||
//navigate to new record
|
||||
throw "T$EST";
|
||||
if (this.canDuplicate && this.$route.params.id != 0) {
|
||||
this.formState.loading = true;
|
||||
var vm = this;
|
||||
var url = "Widget/duplicate/" + this.$route.params.id;
|
||||
|
||||
//clear any errors vm might be around from previous submit
|
||||
this.$gzform.deleteAllErrorBoxErrors(this);
|
||||
this.$gzapi
|
||||
.duplicate(url)
|
||||
.then(res => {
|
||||
// debugger;
|
||||
vm.formState.loading = false;
|
||||
if (res.error != undefined) {
|
||||
vm.formState.serverError = res.error;
|
||||
vm.$gzform.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
//Navigate to new record
|
||||
bugbug: this is not navigating, only changing the url in the location bar??
|
||||
vm.$router.push(
|
||||
vm.$gzapi.replaceAfterLastSlash(vm.$route.fullPath, res.data.id)
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch(function handleDuplicateError(error) {
|
||||
vm.formState.loading = false;
|
||||
vm.$gzHandleFormError(error, vm);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user