@agendize/vue-settings
Version:
Vue agendize's settings component
236 lines (235 loc) • 7.81 kB
JavaScript
import { inject as A, ref as u, reactive as R, watch as U, onMounted as W, defineComponent as j, openBlock as T, createBlock as I, unref as l, withCtx as w, createElementVNode as z, normalizeStyle as q, toDisplayString as k, createVNode as G, withModifiers as H, createCommentVNode as J } from "vue";
import { _ as K } from "./View.vue_vue_type_style_index_0_lang.18cc377c.js";
import { ConfirmDialog as Q, Table as X, FieldToggle as Y, Mandatory as Z } from "@agendize/design-system";
import { i as x, S as N } from "./index.d2d0aba2.js";
import "./viewModel.ceed8ca9.js";
import "./index.b1f405e6.js";
import "@agendize/vue-tools";
import "./vendor.26bbd9f1.js";
import "@agendize/az-i18n";
import "@agendize/js-calendar-api";
import "vue-router";
import "@agendize/vue-acl";
function aa(h, C, s, i, D, o, v) {
const t = x(h), d = A("toaster"), b = A("createConfirmDialog"), y = u(!1), L = R({
columns: [
{
label: t.global.t("settings.staffs.columns.lastname"),
field: "lastName",
width: "flex-1",
sortable: !0
},
{
label: t.global.t("settings.staffs.columns.firstname"),
field: "firstName",
width: "flex-1",
sortable: !0
},
{
label: t.global.t("settings.staffs.columns.email"),
field: "email",
width: "flex-1",
sortable: !0
},
{
label: t.global.t("settings.staffs.columns.enabled"),
field: "enabled",
width: "80px",
sortable: !0,
columnClasses: "az-table-flex-cell-medium",
sortCompareFn: F
}
],
sortable: {
order: "name",
sort: "asc"
}
}), B = u(0), e = u([]), g = u({
label: t.global.t("settings.staffs.new"),
show: e.value.length === 0,
hasAcl: !1,
actionLoading: !1,
class: "az-btn-color-primary",
mobileIcon: "fa fa-plus",
mobileClass: "az-btn-color-transparent",
action: _
}), p = u({
label: t.global.t("settings.staffs.duplicate"),
show: e.value.length === 1,
hasAcl: !1,
actionLoading: !1,
class: "az-btn-color-primary",
mobileIcon: "fas fa-clone",
mobileClass: "az-btn-color-transparent",
action: V
}), n = u({
label: t.global.t("settings.staffs.delete"),
show: e.value.length > 0,
hasAcl: !1,
actionLoading: !1,
class: "az-btn-color-error ",
mobileIcon: "fas fa-trash",
mobileClass: "az-btn-color-error",
action: $
}), m = u([p, n, g]);
function f(a) {
return s.getAllStaffs(i, D.email).then((r) => {
const c = r.results ? r.results : [];
return B.value = c.length, c;
});
}
function S(a, r) {
return r && r.length > 0 ? a.filter((c) => (c.firstName + " " + c.lastName).toLowerCase().indexOf(r.toLowerCase()) > -1) : a;
}
function M(a) {
e.value = a;
}
async function V() {
e.value && e.value.length === 1 && (await (o == null ? void 0 : o.push({
name: N.StaffDetails,
params: { companyId: i, staffId: e.value[0].id },
query: { clone: "true" }
})), e.value = []);
}
async function _() {
await (o == null ? void 0 : o.push({
name: N.StaffDetails,
params: { companyId: i, staffId: "0" },
query: { new: "true" }
}));
}
async function $() {
if (e.value && e.value.length > 0 && b) {
const { reveal: a, onConfirm: r } = b(Q, {
locale: h,
closeOnBlurClick: !0,
confirmation: t.global.t("settings.staffs.confirm"),
description: t.global.t("settings.staffs.confirmDelete", e.value.length),
title: t.global.t("settings.staffs.delete")
});
r(async () => {
y.value = !0, await Promise.all(e.value.map(async (c) => {
if (c.id)
return s.deleteStaff(i, c.id);
})), await new Promise((c) => setTimeout(c, 200)), C.value.reload(), d == null || d.success(t.global.t("settings.staffs.deleted", e.value.length)), e.value = [], y.value = !1;
}), await a();
}
}
function F(a, r) {
return a.availableForWidget ? 0 : 1;
}
async function E(a) {
await (o == null ? void 0 : o.push({ name: N.StaffDetails, params: { companyId: i, staffId: a.id } }));
}
async function O(a) {
a && a.id && s.updateStaff(i, a.id, a).then(() => {
d == null || d.success(t.global.t("settings.staffs.updated"));
});
}
async function P() {
g.value.hasAcl = await v.can("createStaff", i), p.value.hasAcl = g.value.hasAcl, n.value.hasAcl = await v.can("deleteStaff", i);
}
return U(() => e.value, (a) => {
g.value.show = a.length === 0, n.value.show = a.length > 0, p.value.show = a.length === 1;
}), W(async () => {
try {
await P();
} catch {
}
}), {
actionButtons: m,
staffsTableInfo: L,
fetchStaffs: f,
filterStaffs: S,
selectStaffs: M,
selectedStaffs: e,
displayStaffDetails: E,
enableStaff: O
};
}
const ea = { class: "az-grid az-grid-flow-col az-justify-start az-gap-2 az-items-center" }, ta = { class: "az-text-ellipsis az-overflow-hidden" }, la = { class: "az-m-2 az-text-grey-700" }, pa = /* @__PURE__ */ j({
__name: "View",
props: {
acl: {},
api: {},
locale: {},
companyId: {},
router: {},
logger: {},
company: {},
organisation: {}
},
emits: ["companyLoading"],
setup(h, { emit: C }) {
const s = h, i = x(s.locale), D = C, o = u(null), v = i.global.t("settings.staffs.search.placeholder"), t = u(!1), {
actionButtons: d,
staffsTableInfo: b,
fetchStaffs: y,
filterStaffs: L,
selectStaffs: B,
selectedStaffs: e,
displayStaffDetails: g,
enableStaff: p
} = aa(s.locale, o, s.api, s.companyId, s.organisation, s.router, s.acl);
return (n, m) => (T(), I(K, {
acl: n.acl,
api: n.api,
router: n.router,
locale: n.locale,
logger: n.logger,
company: n.company,
onCompanyLoaded: m[1] || (m[1] = (f) => t.value = !0),
onCompanyLoading: m[2] || (m[2] = (f) => D("companyLoading", n.companyId)),
companyId: n.companyId,
tab: "staffs",
actionButtons: l(d)
}, {
staffs: w(() => [
t.value ? (T(), I(l(X), {
key: 0,
ref_key: "staffsTable",
ref: o,
selectable: !0,
searchable: !0,
searchLabel: l(v),
columns: l(b).columns,
sortable: l(b).sortable,
fetchMoreData: l(y),
filter: l(L),
onSelect: l(B),
onSelectRow: l(g)
}, {
"col(lastName)": w(({ row: f }) => [
z("div", ea, [
z("div", {
class: "az-rounded-full az-bg-red az-w-[24px] az-h-[24px] az-min-w-[24px] az-min-h-[24px]",
style: q("background-color:" + f.color)
}, null, 4),
z("span", ta, k(f.lastName), 1)
])
]),
"col(enabled)": w(({ row: f }) => [
G(l(Y), {
id: f.id,
label: "",
locale: s.locale,
mandatory: l(Z).ignore,
modelValue: f.availableForWidget,
"onUpdate:modelValue": [(S) => f.availableForWidget = S, (S) => l(p)(f)],
onClick: m[0] || (m[0] = H(() => {
}, ["stop"]))
}, null, 8, ["id", "locale", "mandatory", "modelValue", "onUpdate:modelValue"])
]),
noData: w(() => [
z("div", la, k(l(i).global.t("settings.staffs.no")), 1)
]),
_: 1
}, 8, ["searchLabel", "columns", "sortable", "fetchMoreData", "filter", "onSelect", "onSelectRow"])) : J("", !0)
]),
_: 1
}, 8, ["acl", "api", "router", "locale", "logger", "company", "companyId", "actionButtons"]));
}
});
export {
pa as default
};