enrecipes/app/components/modal/ActionDialog.vue

136 lines
3.5 KiB
Vue
Raw Normal View History

2020-10-21 17:54:45 +00:00
<template>
2021-04-12 18:09:48 +00:00
<Page
@loaded="transparentPage"
backgroundColor="transparent"
:class="appTheme"
>
2021-02-28 15:10:26 +00:00
<GridLayout
columns="*"
:rows="`auto, auto, ${stretch ? '*' : 'auto'}, auto`"
2021-04-01 10:55:35 +00:00
class="modal"
2021-02-28 15:10:26 +00:00
>
2021-04-01 10:55:35 +00:00
<Label class="title" :text="title | L" />
2021-03-21 17:02:04 +00:00
<ListView
rowHeight="48"
row="2"
for="item in newList"
2021-04-01 10:55:35 +00:00
:height="stretch ? '100%' : listHeight"
2021-03-21 17:02:04 +00:00
>
<v-template>
2021-04-01 10:55:35 +00:00
<Label
class="listItem"
:class="{ tb: title === 'srt' && sortType === item }"
:color="title === 'srt' && sortType === item ? '#ff5200' : ''"
:text="`${localized(item)}`"
@touch="touch"
@tap="tapAction(item)"
@longPress="removeItem(item)"
/>
2021-03-21 17:02:04 +00:00
</v-template>
</ListView>
2021-04-01 10:55:35 +00:00
<GridLayout row="3" columns="auto, *, auto" class="actions">
<Button
2021-02-28 15:10:26 +00:00
v-if="action"
2021-04-01 10:55:35 +00:00
class="text sm"
:text="action | L"
2021-02-28 15:10:26 +00:00
@tap="$modal.close(action)"
/>
2021-04-01 10:55:35 +00:00
<Button
2021-02-28 15:10:26 +00:00
col="2"
2021-04-01 10:55:35 +00:00
class="text sm"
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-04-01 10:55:35 +00:00
import { Screen } from "@nativescript/core";
2021-02-28 15:10:26 +00:00
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-04-01 10:55:35 +00:00
props: ["title", "list", "action"],
2020-12-29 10:35:19 +00:00
data() {
return {
newList: this.list,
2021-04-01 10:55:35 +00:00
stretch: false,
listHeight: 0,
2021-02-28 15:10:26 +00:00
};
2020-12-29 10:35:19 +00:00
},
computed: {
2021-04-01 10:55:35 +00:00
...mapState(["sortType", "icon", "appTheme"]),
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"]),
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-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",
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) {
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;
}
2021-02-28 15:10:26 +00:00
},
2021-04-01 10:55:35 +00:00
touch({ object, action }) {
object.className = action.match(/down|move/)
? "listItem fade"
: "listItem";
},
},
created() {
let screenHeight = Screen.mainScreen.heightDIPs;
let usableHeight = screenHeight - 144 - 24; // margin and statusbar
let count = this.newList.length;
let listHeight = 48 * count;
let modalHeight = 104 + listHeight; // header + actions height = 104
if (modalHeight < usableHeight) {
this.listHeight = listHeight;
} else {
this.stretch = true;
}
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>