enrecipes/app/components/modal/ActionDialog.vue

159 lines
4.2 KiB
Vue
Raw Normal View History

2020-10-21 17:54:45 +00:00
<template>
2021-03-10 15:59:50 +00:00
<Page @loaded="onPageLoad" backgroundColor="transparent">
2021-02-28 15:10:26 +00:00
<GridLayout
columns="*"
:rows="`auto, auto, ${stretch ? '*' : 'auto'}, auto`"
class="dialogContainer"
:class="appTheme"
>
2021-03-21 17:02:04 +00:00
<StackLayout row="0" class="dialogHeader" orientation="horizontal">
<Label class="er dialogIcon" :text="icon[helpIcon]" />
2021-03-23 06:16:25 +00:00
<Label class="dialogTitle" :text="`${title}` | L" />
2021-03-21 17:02:04 +00:00
</StackLayout>
<ListView
rowHeight="48"
row="2"
@loaded="listViewLoad"
for="item in newList"
:height="stretch ? '100%' : itemInView"
>
<v-template>
<StackLayout margin="0" padding="0">
<Label
class="actionItem mdr"
2021-03-23 06:16:25 +00:00
:class="{ tb: title === 'srt' && sortType === item }"
2021-03-21 17:02:04 +00:00
:color="title === 'srt' && sortType === item ? '#ff5200' : ''"
2021-03-23 09:59:00 +00:00
:text="`${localized(item)}`"
2021-03-21 17:02:04 +00:00
@tap="tapAction(item)"
@longPress="removeItem(item)"
/>
</StackLayout>
</v-template>
</ListView>
2021-02-28 15:10:26 +00:00
<GridLayout
row="3"
rows="auto"
columns="auto, *, auto"
class="actionsContainer"
>
<MDButton
variant="text"
v-if="action"
col="0"
2021-03-23 06:16:25 +00:00
class="action tb pull-left"
2021-02-28 15:10:26 +00:00
:text="`${action}` | L"
@tap="$modal.close(action)"
/>
<MDButton
variant="text"
col="2"
2021-03-23 06:16:25 +00:00
class="action tb pull-right"
2021-02-28 15:10:26 +00:00
:text="'cBtn' | L"
@tap="$modal.close(false)"
/>
</GridLayout>
</GridLayout>
2021-02-28 15:10:26 +00:00
</Page>
2020-10-21 17:54:45 +00:00
</template>
<script>
2021-03-21 17:02:04 +00:00
import { Application } from "@nativescript/core";
2021-02-28 15:10:26 +00:00
import * as Toast from "nativescript-toast";
import { localize } from "@nativescript/localize";
import { mapState, mapActions } from "vuex";
import ConfirmDialog from "./ConfirmDialog.vue";
2021-03-10 15:59:50 +00:00
2020-10-21 17:54:45 +00:00
export default {
2021-03-21 17:02:04 +00:00
props: ["title", "list", "stretch", "action", "helpIcon", "count"],
2020-12-29 10:35:19 +00:00
data() {
return {
newList: this.list,
2021-03-21 17:02:04 +00:00
rowHeight: null,
2021-02-28 15:10:26 +00:00
};
2020-12-29 10:35:19 +00:00
},
computed: {
2021-02-28 15:10:26 +00:00
...mapState(["sortType", "icon"]),
appTheme() {
2021-02-28 15:10:26 +00:00
return Application.systemAppearance();
},
2021-03-21 17:02:04 +00:00
itemInView() {
return this.rowHeight * this.count;
2020-11-10 18:28:48 +00:00
},
2020-10-22 18:36:50 +00:00
},
2020-10-21 17:54:45 +00:00
methods: {
2021-02-28 15:10:26 +00:00
...mapActions(["removeListItemAction"]),
2021-03-10 15:59:50 +00:00
onPageLoad(args) {
args.object._dialogFragment
.getDialog()
.getWindow()
.setBackgroundDrawable(
new android.graphics.drawable.ColorDrawable(
android.graphics.Color.TRANSPARENT
)
);
},
2021-03-21 17:02:04 +00:00
listViewLoad(args) {
this.rowHeight = args.object.rowHeight;
let e = args.object.android;
e.setSelector(new android.graphics.drawable.StateListDrawable());
e.setDivider(null);
e.setDividerHeight(0);
},
2021-02-28 15:10:26 +00:00
localized(item) {
if (this.title !== "lang") return localize(item);
else return item;
2020-12-29 10:35:19 +00:00
},
2021-02-28 15:10:26 +00:00
tapAction(item) {
this.$modal.close(item);
2020-10-21 17:54:45 +00:00
},
2021-03-21 17:02:04 +00:00
// centerLabel(args) {
// args.object.android.setGravity(16);
// },
2021-02-28 15:10:26 +00:00
deletionConfirmation(type, description) {
return this.$showModal(ConfirmDialog, {
2020-12-29 10:35:19 +00:00
props: {
2021-02-28 15:10:26 +00:00
title: "conf",
2020-12-29 10:35:19 +00:00
description,
2021-01-13 05:02:48 +00:00
cancelButtonText: "cBtn",
okButtonText: "rBtn",
2021-02-28 15:10:26 +00:00
helpIcon: "err",
2021-03-21 17:02:04 +00:00
iconColor: "#c92a2a",
2020-12-29 10:35:19 +00:00
},
2021-02-28 15:10:26 +00:00
});
2020-12-29 10:35:19 +00:00
},
2021-03-21 17:02:04 +00:00
removeItem(item) {
// let item = this.newList[index];
2021-02-28 15:10:26 +00:00
let vm = this;
2020-12-29 10:35:19 +00:00
2021-02-28 15:10:26 +00:00
function removeListItem(type, listName, desc) {
vm.deletionConfirmation(
type,
`${localize(desc)} "${localize(item)}"\n\n${localize("rmLIInfo")}`
).then((action) => {
if (action != null && action)
vm.removeListItemAction({
2020-12-29 10:35:19 +00:00
item,
2021-02-28 15:10:26 +00:00
listName,
});
});
2020-12-29 10:35:19 +00:00
}
2021-02-28 15:10:26 +00:00
switch (this.title) {
2021-01-13 05:02:48 +00:00
case "cui":
2021-02-28 15:10:26 +00:00
removeListItem("cuisine", "cuisines", "rmCuiInfo");
2020-12-29 10:35:19 +00:00
break;
2021-01-13 05:02:48 +00:00
case "cat":
2021-02-28 15:10:26 +00:00
removeListItem("category", "categories", "rmCatInfo");
2020-12-29 10:35:19 +00:00
break;
2021-01-13 05:02:48 +00:00
case "yieldU":
2021-02-28 15:10:26 +00:00
removeListItem("yield unit", "yieldUnits", "rmYUInfo");
2020-12-29 10:35:19 +00:00
break;
2021-01-13 05:02:48 +00:00
case "Unit":
2021-02-28 15:10:26 +00:00
removeListItem("unit", "units", "rmUInfo");
2020-12-29 10:35:19 +00:00
break;
default:
}
2021-02-28 15:10:26 +00:00
},
2020-10-21 17:54:45 +00:00
},
2021-02-28 15:10:26 +00:00
};
2020-10-21 17:54:45 +00:00
</script>