HUGE REFACTOR / CLEANUP
if there is a issue it's probably something in here that was changed
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
<gz-report-selector ref="reportSelector"></gz-report-selector>
|
||||
<div v-if="formState.ready">
|
||||
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
|
||||
|
||||
<v-form ref="form">
|
||||
<template v-if="!composing">
|
||||
<v-row>
|
||||
@@ -158,28 +157,18 @@
|
||||
</v-overlay>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/* Xeslint-disable */
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
const FORM_KEY = "memo-edit";
|
||||
const API_BASE_URL = "memo/";
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "Memo"; //<-- Should always be CoreBizObject AyaType name here where possible
|
||||
|
||||
const FORM_CUSTOM_TEMPLATE_KEY = "Memo";
|
||||
export default {
|
||||
async created() {
|
||||
let vm = this;
|
||||
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
|
||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Memo);
|
||||
vm.formState.readOnly = false; //can always do things with your own memos
|
||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
||||
|
||||
//id 0 means create or duplicate to new
|
||||
if (vm.$route.params.recordid != 0) {
|
||||
vm.composing = false;
|
||||
@@ -192,7 +181,7 @@ export default {
|
||||
loading: false
|
||||
});
|
||||
} else {
|
||||
await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
|
||||
await vm.getDataFromApi(vm.$route.params.recordid);
|
||||
}
|
||||
} else {
|
||||
//NEW MEMO, set defaults
|
||||
@@ -233,25 +222,21 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
|
||||
obj:
|
||||
//IMPORTANT NOTE: Fields that are NON NULLABLE in the schema for the table but *are* hideable **MUST** have a default value set here or else there will be no way to save the record
|
||||
//I.E. Serial, usertype fields, ACTIVE
|
||||
//Also, if it's a non-nullable Enum backed field then it should have a valid selection i.e. not zero if there is no zero
|
||||
{
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
name: null,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
viewed: false,
|
||||
replied: false,
|
||||
fromId: 1,
|
||||
toId: 1,
|
||||
sent: null,
|
||||
fromName: null
|
||||
},
|
||||
obj: {
|
||||
id: 0,
|
||||
concurrency: 0,
|
||||
name: null,
|
||||
notes: null,
|
||||
wiki: null,
|
||||
customFields: "{}",
|
||||
tags: [],
|
||||
viewed: false,
|
||||
replied: false,
|
||||
fromId: 1,
|
||||
toId: 1,
|
||||
sent: null,
|
||||
fromName: null
|
||||
},
|
||||
formState: {
|
||||
ready: false,
|
||||
dirty: false,
|
||||
@@ -271,24 +256,19 @@ export default {
|
||||
toUsers: []
|
||||
};
|
||||
},
|
||||
//WATCHERS
|
||||
watch: {
|
||||
formState: {
|
||||
handler: function(val) {
|
||||
//,oldval is available here too if necessary
|
||||
if (this.formState.loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
let hasSelection = this.toUsers.length > 0;
|
||||
//enable / disable save button
|
||||
const 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");
|
||||
}
|
||||
|
||||
//enable / disable duplicate / new button
|
||||
if (!val.dirty && val.valid && !val.readOnly) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":new");
|
||||
} else {
|
||||
@@ -298,23 +278,20 @@ export default {
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
userSelected(e) {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
if (!e) {
|
||||
return;
|
||||
}
|
||||
let user = vm.$refs.userid.getFullSelectionValue();
|
||||
const user = vm.$refs.userid.getFullSelectionValue();
|
||||
if (vm.selectedUsers.find(z => z.id == user.id)) {
|
||||
return;
|
||||
}
|
||||
vm.selectedUsers.push(user);
|
||||
},
|
||||
updateSave: function() {
|
||||
let hasSelection = this.toUsers.length > 0;
|
||||
|
||||
//enable / disable save button
|
||||
const hasSelection = this.toUsers.length > 0;
|
||||
if (
|
||||
this.formState.dirty &&
|
||||
this.formState.valid &&
|
||||
@@ -326,16 +303,15 @@ export default {
|
||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
|
||||
}
|
||||
},
|
||||
|
||||
closeChip(item) {
|
||||
let i = this.toUsers.findIndex(z => z.id == item.id);
|
||||
const i = this.toUsers.findIndex(z => z.id == item.id);
|
||||
if (i != -1) {
|
||||
this.toUsers.splice(i, 1);
|
||||
}
|
||||
this.updateSave();
|
||||
},
|
||||
addSelected() {
|
||||
let selected = this.$refs.userPickList.getFullSelectionValue();
|
||||
const selected = this.$refs.userPickList.getFullSelectionValue();
|
||||
if (selected == null) {
|
||||
return;
|
||||
}
|
||||
@@ -343,7 +319,6 @@ export default {
|
||||
if (this.toUsers.find(z => z.id == selected.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.toUsers.push(selected);
|
||||
this.pickListSelectedUserId = null;
|
||||
this.updateSave();
|
||||
@@ -364,7 +339,7 @@ export default {
|
||||
}
|
||||
},
|
||||
async getDataFromApi(recordId) {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
@@ -372,14 +347,11 @@ export default {
|
||||
if (!recordId) {
|
||||
throw new Error(FORM_KEY + "::getDataFromApi -> Missing recordID!");
|
||||
}
|
||||
let url = API_BASE_URL + recordId;
|
||||
|
||||
try {
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
|
||||
let res = await window.$gz.api.get(url);
|
||||
|
||||
const res = await window.$gz.api.get(API_BASE_URL + recordId);
|
||||
if (res.error) {
|
||||
//Not found?
|
||||
if (res.error.code == "2010") {
|
||||
window.$gz.form.handleObjectNotFound(vm);
|
||||
}
|
||||
@@ -387,9 +359,7 @@ export default {
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
vm.obj = res.data;
|
||||
//modify the menu as necessary
|
||||
generateMenu(vm);
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
dirty: false,
|
||||
@@ -407,30 +377,26 @@ export default {
|
||||
}
|
||||
},
|
||||
async submit() {
|
||||
let vm = this;
|
||||
let userIdList = [];
|
||||
const vm = this;
|
||||
const userIdList = [];
|
||||
if (vm.toUsers.length > 0) {
|
||||
vm.toUsers.forEach(z => {
|
||||
userIdList.push(z.id);
|
||||
});
|
||||
} else {
|
||||
throw "No users selected";
|
||||
throw new Error("No users selected");
|
||||
}
|
||||
|
||||
try {
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
});
|
||||
let url = API_BASE_URL; // + vm.$route.params.recordid;
|
||||
//clear any errors vm might be around from previous submit
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
vm.obj.sent = window.$gz.locale.nowUTC8601String();
|
||||
let res = await window.$gz.api.post(url, {
|
||||
const res = await window.$gz.api.post(API_BASE_URL, {
|
||||
users: userIdList,
|
||||
memo: vm.obj
|
||||
});
|
||||
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
@@ -448,42 +414,33 @@ export default {
|
||||
}
|
||||
},
|
||||
async remove() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
try {
|
||||
let dialogResult = await window.$gz.dialog.confirmDelete();
|
||||
const dialogResult = await window.$gz.dialog.confirmDelete();
|
||||
if (dialogResult != true) {
|
||||
return;
|
||||
}
|
||||
|
||||
//do the delete
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: true
|
||||
});
|
||||
//No need to delete a new record, just abandon it...
|
||||
if (vm.$route.params.recordid == 0) {
|
||||
//this should not get offered for delete but to be safe and clear just in case:
|
||||
LEAVE_OK = true;
|
||||
// navigate backwards
|
||||
vm.$router.go(-1);
|
||||
} else {
|
||||
let url = API_BASE_URL + vm.$route.params.recordid;
|
||||
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
let res = await window.$gz.api.remove(url);
|
||||
const res = await window.$gz.api.remove(
|
||||
API_BASE_URL + vm.$route.params.recordid
|
||||
);
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
//workaround to prevent warning about leaving dirty record
|
||||
//For some reason I couldn't just reset isdirty in formstate
|
||||
LEAVE_OK = true;
|
||||
// navigate backwards
|
||||
vm.$router.go(-1);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false
|
||||
@@ -492,23 +449,21 @@ export default {
|
||||
}
|
||||
},
|
||||
replyForward(forward) {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
if (!forward) {
|
||||
//REPLY MODE
|
||||
vm.obj.toId = vm.obj.fromId;
|
||||
vm.replyMode = true;
|
||||
vm.toUsers.push({ id: vm.obj.fromId });
|
||||
}
|
||||
let header = `${vm.$ay.t("MemoSent")} ${vm.$ay.dt(
|
||||
const header = `${vm.$ay.t("MemoSent")} ${vm.$ay.dt(
|
||||
vm.obj.sent
|
||||
)}\n${vm.$ay.t("MemoFromID")} ${vm.obj.fromName}\n${vm.$ay.t(
|
||||
"MemoSubject"
|
||||
)} ${vm.obj.name}\n`;
|
||||
|
||||
vm.obj.name = `${vm.$ay.t("MemoRe")} ${vm.obj.name}`;
|
||||
vm.obj.notes = `\n\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n${header}\n\n${vm.obj.notes}`;
|
||||
vm.obj.id = 0;
|
||||
|
||||
vm.composing = true;
|
||||
generateMenu(vm);
|
||||
window.$gz.form.setFormState({
|
||||
@@ -517,16 +472,13 @@ export default {
|
||||
valid: true,
|
||||
loading: false
|
||||
});
|
||||
|
||||
vm.updateSave();
|
||||
this.$nextTick(() => {
|
||||
let el = document.getElementById("notes");
|
||||
const el = document.getElementById("notes");
|
||||
el.focus();
|
||||
el.setSelectionRange(0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
//end methods
|
||||
}
|
||||
};
|
||||
|
||||
@@ -537,7 +489,7 @@ async function clickHandler(menuItem) {
|
||||
if (!menuItem) {
|
||||
return;
|
||||
}
|
||||
let m = window.$gz.menu.parseMenuItem(menuItem);
|
||||
const m = window.$gz.menu.parseMenuItem(menuItem);
|
||||
if (m.owner == FORM_KEY && !m.disabled) {
|
||||
switch (m.key) {
|
||||
case "save":
|
||||
@@ -552,7 +504,7 @@ async function clickHandler(menuItem) {
|
||||
params: { recordid: 0 }
|
||||
});
|
||||
case "report":
|
||||
let res = await m.vm.$refs.reportSelector.open(
|
||||
const res = await m.vm.$refs.reportSelector.open(
|
||||
{
|
||||
AType: window.$gz.type.Memo,
|
||||
selectedRowIds: [m.vm.obj.id]
|
||||
@@ -585,7 +537,7 @@ async function clickHandler(menuItem) {
|
||||
//
|
||||
//
|
||||
function generateMenu(vm) {
|
||||
let menuOptions = {
|
||||
const menuOptions = {
|
||||
isMain: false,
|
||||
readOnly: vm.formState.readOnly,
|
||||
icon: "$ayiInbox",
|
||||
@@ -619,8 +571,6 @@ function generateMenu(vm) {
|
||||
});
|
||||
}
|
||||
|
||||
//REPORTS
|
||||
//Report not Print, print is a further option
|
||||
menuOptions.menuItems.push({
|
||||
title: "Report",
|
||||
icon: "$ayiFileAlt",
|
||||
@@ -628,8 +578,7 @@ function generateMenu(vm) {
|
||||
vm: vm
|
||||
});
|
||||
|
||||
//get last report selected
|
||||
let lastReport = window.$gz.form.getLastReport(FORM_KEY);
|
||||
const lastReport = window.$gz.form.getLastReport(FORM_KEY);
|
||||
if (lastReport != null) {
|
||||
menuOptions.menuItems.push({
|
||||
title: lastReport.name,
|
||||
@@ -715,21 +664,21 @@ async function fetchTranslatedText(vm) {
|
||||
]);
|
||||
} /*
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new memo as a Reply or Forward based on this fetched read only memo
|
||||
/// </summary>
|
||||
/// <param name="bForward">If true, this is a forward reply to don't set the toID just yet</param>
|
||||
/// <returns>A memo object with fields filled in ready for typing reply/forward text</returns>
|
||||
public Memo ReplyForward(bool bForward)
|
||||
{
|
||||
Memo m=Memo.NewItem();
|
||||
if(!bForward)
|
||||
m.ToID=this.FromID;
|
||||
|
||||
m.Subject=LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.Re")+ " " + this.Subject;
|
||||
m.Message="\r\n\r\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n" + this.Header + "\r\n\r\n" + this.Message;
|
||||
|
||||
return m;
|
||||
}
|
||||
/// <summary>
|
||||
/// Generate a new memo as a Reply or Forward based on this fetched read only memo
|
||||
/// </summary>
|
||||
/// <param name="bForward">If true, this is a forward reply to don't set the toID just yet</param>
|
||||
/// <returns>A memo object with fields filled in ready for typing reply/forward text</returns>
|
||||
public Memo ReplyForward(bool bForward)
|
||||
{
|
||||
Memo m=Memo.NewItem();
|
||||
if(!bForward)
|
||||
m.ToID=this.FromID;
|
||||
|
||||
m.Subject=LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.Re")+ " " + this.Subject;
|
||||
m.Message="\r\n\r\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n" + this.Header + "\r\n\r\n" + this.Message;
|
||||
|
||||
return m;
|
||||
}
|
||||
*/
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user