enrecipes/app/components/modals/Action.vue

153 lines
3.7 KiB
Vue
Raw Normal View History

2020-10-21 23:24:45 +05:30
<template>
2021-04-12 23:39:48 +05:30
<Page
@loaded="transparentPage"
backgroundColor="transparent"
:class="appTheme"
>
2021-02-28 20:40:26 +05:30
<GridLayout
columns="*"
:rows="`auto, auto, ${stretch ? '*' : 'auto'}, auto`"
2021-04-01 16:25:35 +05:30
class="modal"
2021-02-28 20:40:26 +05:30
>
2021-04-01 16:25:35 +05:30
<Label class="title" :text="title | L" />
2021-03-21 22:32:04 +05:30
<ListView
rowHeight="48"
row="2"
for="item in newList"
2021-04-01 16:25:35 +05:30
:height="stretch ? '100%' : listHeight"
2021-03-21 22:32:04 +05:30
>
<v-template>
2021-04-01 16:25:35 +05:30
<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 22:32:04 +05:30
</v-template>
</ListView>
2021-04-01 16:25:35 +05:30
<GridLayout row="3" columns="auto, *, auto" class="actions">
<Button
2021-02-28 20:40:26 +05:30
v-if="action"
2021-04-01 16:25:35 +05:30
class="text sm"
:text="action | L"
2021-02-28 20:40:26 +05:30
@tap="$modal.close(action)"
/>
2021-04-01 16:25:35 +05:30
<Button
2021-02-28 20:40:26 +05:30
col="2"
2021-04-01 16:25:35 +05:30
class="text sm"
2021-02-28 20:40:26 +05:30
:text="'cBtn' | L"
@tap="$modal.close(false)"
/>
</GridLayout>
</GridLayout>
2021-02-28 20:40:26 +05:30
</Page>
2020-10-21 23:24:45 +05:30
</template>
2021-04-14 19:08:22 +05:30
<script lang="ts">
2021-04-01 16:25:35 +05:30
import { Screen } from "@nativescript/core";
2021-02-28 20:40:26 +05:30
import { localize } from "@nativescript/localize";
import { mapState, mapActions } from "vuex";
2021-05-25 20:02:53 +05:30
import Confirm from "./Confirm.vue";
2021-03-10 21:29:50 +05:30
2021-04-14 19:08:22 +05:30
interface IData {
newList: unknown[];
stretch: boolean;
listHeight: number;
}
2020-10-21 23:24:45 +05:30
export default {
2021-04-14 19:08:22 +05:30
props: {
title: {
type: String,
required: true,
},
list: {
type: Array,
required: true,
},
action: {
type: String,
required: false,
},
},
data(): IData {
2020-12-29 16:05:19 +05:30
return {
newList: this.list,
2021-04-01 16:25:35 +05:30
stretch: false,
listHeight: 0,
2021-02-28 20:40:26 +05:30
};
2020-12-29 16:05:19 +05:30
},
computed: {
2021-04-01 16:25:35 +05:30
...mapState(["sortType", "icon", "appTheme"]),
2020-10-23 00:06:50 +05:30
},
2020-10-21 23:24:45 +05:30
methods: {
2021-02-28 20:40:26 +05:30
...mapActions(["removeListItemAction"]),
2021-04-14 19:08:22 +05:30
localized(item: string): string {
return this.title !== "lang" ? localize(item) : item;
2020-12-29 16:05:19 +05:30
},
2021-04-14 19:08:22 +05:30
tapAction(item: string): void {
2021-02-28 20:40:26 +05:30
this.$modal.close(item);
2020-10-21 23:24:45 +05:30
},
2021-04-14 19:08:22 +05:30
deletionConfirmation(description: string): void {
2021-05-25 20:02:53 +05:30
return this.$showModal(Confirm, {
2020-12-29 16:05:19 +05:30
props: {
2021-02-28 20:40:26 +05:30
title: "conf",
2020-12-29 16:05:19 +05:30
description,
2021-01-13 10:32:48 +05:30
cancelButtonText: "cBtn",
okButtonText: "rBtn",
2020-12-29 16:05:19 +05:30
},
2021-02-28 20:40:26 +05:30
});
2020-12-29 16:05:19 +05:30
},
2021-04-14 19:08:22 +05:30
removeItem(item: string): void {
2021-02-28 20:40:26 +05:30
let vm = this;
2021-04-15 22:54:14 +05:30
let localizedItem = `"${localize(item)}"`;
2021-04-14 19:08:22 +05:30
function removeListItem(listName: string, desc: string): void {
2021-04-15 22:54:14 +05:30
vm.deletionConfirmation(`${localize(desc, localizedItem)}`).then(
(action: boolean) => {
if (action != null && action)
vm.removeListItemAction({
item,
listName,
});
}
);
2020-12-29 16:05:19 +05:30
}
2021-02-28 20:40:26 +05:30
switch (this.title) {
2021-01-13 10:32:48 +05:30
case "cui":
2021-04-14 19:08:22 +05:30
removeListItem("cuisines", "rmCuiInfo");
2020-12-29 16:05:19 +05:30
break;
2021-01-13 10:32:48 +05:30
case "cat":
2021-04-14 19:08:22 +05:30
removeListItem("categories", "rmCatInfo");
2020-12-29 16:05:19 +05:30
break;
2021-01-13 10:32:48 +05:30
case "yieldU":
2021-04-14 19:08:22 +05:30
removeListItem("yieldUnits", "rmYUInfo");
2020-12-29 16:05:19 +05:30
break;
2021-01-13 10:32:48 +05:30
case "Unit":
2021-04-14 19:08:22 +05:30
removeListItem("units", "rmUInfo");
2020-12-29 16:05:19 +05:30
break;
}
2021-02-28 20:40:26 +05:30
},
2021-04-14 19:08:22 +05:30
touch({ object, action }): void {
2021-04-01 16:25:35 +05:30
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 23:24:45 +05:30
},
2021-02-28 20:40:26 +05:30
};
2020-10-21 23:24:45 +05:30
</script>