diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index a8b99ed2..fa738d88 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -70,8 +70,15 @@ todo: TESTING After customer form is made OUTSTANDING WITH CUSTOMER contacts + make list of users in grid, shows all contact info + can open to cust-user edit form + Change cust-user edit form (and other user edit form) and add tabs and user options section so that it can all be set there as well + Add button to email the user their creds and login and invite them to change the password once they login Customer User (contacts) UI for this client (generate, view) case for this and notes, sb very simple way to create and send creds for user + Customer User / User(s) + Label as Contact / Contacts + Show customer / head office in generic contacts grid view Copy address to clipboard? Show all workorders diff --git a/ayanova/src/api/initialize.js b/ayanova/src/api/initialize.js index cf9ca424..85212ac3 100644 --- a/ayanova/src/api/initialize.js +++ b/ayanova/src/api/initialize.js @@ -277,7 +277,7 @@ function initNavPanel() { //Customer / Headoffice Users subitem sub.push({ - title: "UserList", + title: "Contacts", icon: "$ayiUsers", route: "/cust-users", key: key++ diff --git a/ayanova/src/api/translation.js b/ayanova/src/api/translation.js index 77d5fa13..dd580576 100644 --- a/ayanova/src/api/translation.js +++ b/ayanova/src/api/translation.js @@ -123,6 +123,7 @@ export default { "Service", "CustomerList", "HeadOfficeList", + "Contacts", "WorkOrderList", "WorkOrderServiceTemplate", "QuoteList", diff --git a/ayanova/src/views/cust-customer.vue b/ayanova/src/views/cust-customer.vue index dcb3f701..8bdbf418 100644 --- a/ayanova/src/views/cust-customer.vue +++ b/ayanova/src/views/cust-customer.vue @@ -6,7 +6,7 @@ - + {{ $ay.t("Customer") }} {{ $ay.t("Address") }} {{ $ay.t("Contacts") }} @@ -631,15 +631,15 @@ - + + + @@ -795,7 +813,15 @@ export default { serverError: {} }, rights: window.$gz.role.defaultRightsObject(), - ayaType: window.$gz.type.Customer + ayaType: window.$gz.type.Customer, + contactsObj: [], + hasFetchedContacts: false, + headers: [], + selected: [], + availableRoles: [], + timeZoneName: window.$gz.locale.getBrowserTimeZoneName(), + languageName: window.$gz.locale.getBrowserLanguages(), + hour12: window.$gz.locale.getHour12() }; }, //WATCHERS @@ -1032,7 +1058,113 @@ export default { loading: false }); } + }, + tabChanged: async function(tab) { + if (tab == 2) { + //contacts tab, load contacts if not done already + if (!this.hasFetchedContacts) { + await this.contactsGetDataFromApi(); + } + } + // let vm = this; + // if (vm[tabIndexToRoute(vm.tab)].isnew) { + // vm.getDataFromApi(); + // } + }, + addContact() { + if (this.obj.id == 0) { + return; + } + this.$router.push({ + name: "cust-user", + params: { recordid: 0, customerid: this.obj.id } + }); + }, + contactsRowClick(item) { + window.$gz.eventBus.$emit("openobject", { + type: window.$gz.type.User, + id: item.id, + inside: false + }); + }, + rolesDisplayFromRoles(roles) { + let roleNames = []; + if (roles != null && roles != 0) { + for (let i = 0; i < this.availableRoles.length; i++) { + let role = this.availableRoles[i]; + if (!!(roles & role.id)) { + roleNames.push(role.name); + } + } + } + return roleNames.join(", "); + }, + async contactsGetDataFromApi() { + let vm = this; + vm.formState.loading = true; + + window.$gz.form.deleteAllErrorBoxErrors(vm); + try { + let res = await window.$gz.api.get( + `user/customer-contacts/${vm.obj.id}` + ); + vm.hasFetchedContacts = true; + + if (res.error) { + if (res.error.code == "2010") { + window.$gz.form.handleObjectNotFound(vm); + } + vm.formState.serverError = res.error; + window.$gz.form.setErrorBoxErrors(vm); + } else { + if (res.data) { + /* Id = z.Id, + Active = z.Active, + Name = z.Name, + UserType = z.UserType, + LastLogin = z.LastLogin */ + let ret = []; + for (let i = 0; i < res.data.length; i++) { + let o = res.data[i]; + ret.push({ + id: o.id, + name: o.name, + active: o.active, + userType: window.$gz.enums.get("outsideusertype", o.userType), + lastLogin: window.$gz.locale.utcDateToShortDateAndTimeLocalized( + o.lastLogin, + this.timeZoneName, + this.languageName, + this.hour12 + ), + roles: this.rolesDisplayFromRoles(o.roles) + }); + } + + vm.contactsObj = ret; + } else { + vm.rawObj = []; + vm.contactsObj = []; + } + + window.$gz.form.setFormState({ + vm: vm, + dirty: false, + valid: true, + loading: false + }); + generateMenu(vm); + } + } catch (error) { + window.$gz.form.setFormState({ + vm: vm, + loading: false + }); + window.$gz.errorHandler.handleFormError(error, vm); + } } + + //end methods } }; @@ -1228,6 +1360,8 @@ async function initForm(vm) { await fetchTranslatedText(vm); await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY); await populateSelectionLists(vm); + await cacheEnums(vm); + await createTableHeaders(vm); } ////////////////////////////////////////////////////////// @@ -1236,8 +1370,7 @@ async function initForm(vm) { // async function fetchTranslatedText(vm) { await window.$gz.translation.cacheTranslations([ - "Customer", - "Contacts", + "Customer", "CustomerName", "CustomerNotes", "WebAddress", @@ -1295,6 +1428,26 @@ async function populateSelectionLists(vm) { await window.$gz.enums.fetchEnumList("usertype"); vm.selectLists.usertypes = window.$gz.enums.getSelectionList("usertype"); } - - +////////////////////// +// +// +async function cacheEnums(vm) { + //ensure the enum values required are pre-fetched + await window.$gz.enums.fetchEnumList("outsideusertype"); + await window.$gz.enums.fetchEnumList("AuthorizationRoles"); + vm.availableRoles = window.$gz.enums.getSelectionList("AuthorizationRoles"); +} + +////////////////////// +// +// +async function createTableHeaders(vm) { + vm.headers = [ + { text: vm.$ay.t("User"), value: "name" }, + { text: vm.$ay.t("Active"), value: "active" }, + { text: vm.$ay.t("UserType"), value: "userType" }, + { text: vm.$ay.t("LastLogin"), value: "lastLogin" } + ]; +} + diff --git a/ayanova/src/views/cust-user.vue b/ayanova/src/views/cust-user.vue index 2e177184..fc5250c2 100644 --- a/ayanova/src/views/cust-user.vue +++ b/ayanova/src/views/cust-user.vue @@ -1,11 +1,7 @@