This commit is contained in:
2020-12-15 00:44:32 +00:00
parent 44c593f52f
commit a014d28123

View File

@@ -5,39 +5,6 @@
<v-row>
<!-- {{ toUsers }} -->
<gz-error :errorBoxMessage="formState.errorBoxMessage"></gz-error>
<!-- <v-row cols="12">
<v-col cols="9">
<gz-pick-list
:ayaType="ayaTypes().User"
:showEditIcon="false"
v-model="pickListSelectedUserId"
:label="$ay.t('UserList')"
ref="userPickList"
@input="checkSave()"
data-cy="pickListSelectedUserId"
></gz-pick-list> </v-col
><v-col cols="1">
<v-btn @click="addSelected()">
<v-icon>$ayiPlus</v-icon>
</v-btn>
</v-col>
</v-row>
<v-col cols="12">
<template v-for="item in toUsers">
<v-chip
color="primary"
outlined
:key="item.id"
class="ma-2"
close
@click:close="closeChip(item)"
>
{{ item.name }}
</v-chip>
</template>
</v-col> -->
<v-col cols="12">
<gz-pick-list
:allowNoSelection="false"
@@ -69,8 +36,9 @@
v-model="message"
:label="$ay.t('MemoMessage')"
ref="message"
:rules="[form().required(this, 'message')]"
auto-grow
@input="checkSave()"
@input="fieldValueChanged('message')"
></v-textarea>
</v-col>
</v-row>
@@ -156,8 +124,9 @@ export default {
}
//enable / disable save button
let canSave = val.dirty && val.valid && !val.readOnly;
if (canSave) {
let hasSelection = this.toUsers.length > 0;
if (val.dirty && val.valid && !val.readOnly && hasSelection) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
@@ -172,15 +141,15 @@ export default {
}
},
methods: {
checkSave() {
let hasSelection =
this.toUsers.length > 0 ||
(this.pickListSelectedUserId != null &&
this.pickListSelectedUserId != 0);
let hasText = this.message != null && this.message != "";
this.formState.dirty = hasSelection && hasText;
if (this.canSave) {
updateSave: function() {
let hasSelection = this.toUsers.length > 0;
//enable / disable save button
if (
this.formState.dirty &&
this.formState.valid &&
!this.formState.readOnly &&
hasSelection
) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
@@ -191,7 +160,7 @@ export default {
if (i != -1) {
this.toUsers.splice(i, 1);
}
this.checkSave();
this.updateSave();
},
addSelected() {
let selected = this.$refs.userPickList.getFullSelectionValue();
@@ -205,7 +174,7 @@ export default {
this.toUsers.push(selected);
this.pickListSelectedUserId = 0;
this.checkSave();
this.updateSave();
},
ayaTypes: function() {
return window.$gz.type;
@@ -214,52 +183,59 @@ export default {
form() {
return window.$gz.form;
},
fieldValueChanged(ref) {
if (
this.formState.ready &&
!this.formState.loading &&
!this.formState.readOnly
) {
window.$gz.form.fieldValueChanged(this, ref);
}
},
async submit() {
let vm = this;
if (vm.canSave) {
vm.formState.loading = true;
//always submit from this form for the current logged in user id
let url = "notify/direct-message";
vm.formState.loading = true;
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
try {
let userIdList = [];
if (vm.toUsers.length > 0) {
vm.toUsers.forEach(z => {
userIdList.push(z.id);
});
} else {
//just accept the single userid in the pickLkist
userIdList.push(vm.pickListSelectedUserId);
}
let res = await window.$gz.api.upsert(url, {
users: userIdList,
message: this.message
//always submit from this form for the current logged in user id
let url = "notify/direct-message";
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
try {
let userIdList = [];
if (vm.toUsers.length > 0) {
vm.toUsers.forEach(z => {
userIdList.push(z.id);
});
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
vm.pickListSelectedUserId = null;
vm.items = [];
vm.toUsers = [];
vm.message = null;
//Only a post, no data returned
window.$gz.form.setFormState({
vm: vm,
dirty: false
});
vm.checkSave();
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
} finally {
vm.loading = false;
} else {
//just accept the single userid in the pickLkist
userIdList.push(vm.pickListSelectedUserId);
}
let res = await window.$gz.api.upsert(url, {
users: userIdList,
message: this.message
});
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
vm.pickListSelectedUserId = null;
vm.items = [];
vm.toUsers = [];
vm.message = null;
//Only a post, no data returned
window.$gz.form.setFormState({
vm: vm,
dirty: false
});
vm.updateSave();
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
} finally {
vm.loading = false;
}
}
}