enrecipes/app/components/modals/Action.vue

174 lines
4.3 KiB
Vue
Raw Normal View History

2020-10-21 17:54:45 +00:00
<template>
2021-06-18 12:52:03 +00:00
<Page @loaded="mLoad" backgroundColor="transparent" :class="theme">
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-06-15 11:04:42 +00:00
<RLabel 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-06-15 11:04:42 +00:00
<RLabel
2021-04-01 10:55:35 +00:00
class="listItem"
2021-06-15 11:04:42 +00:00
:class="{ select: item == selected || $index == selected }"
2021-04-01 10:55:35 +00:00
:text="`${localized(item)}`"
@touch="touch"
@tap="tapAction(item)"
@longPress="removeItem(item)"
/>
2021-03-21 17:02:04 +00:00
</v-template>
</ListView>
2021-06-15 11:04:42 +00:00
<RGridLayout :rtl="RTL" row="3" columns="auto, *, auto" class="actions">
2021-04-01 10:55:35 +00:00
<Button
2021-06-15 11:04:42 +00:00
:hidden="!action"
2021-06-18 12:52:03 +00:00
class="text tb st fb"
2021-04-01 10:55:35 +00:00
: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-06-18 12:52:03 +00:00
class="text tb st fb"
2021-02-28 15:10:26 +00:00
:text="'cBtn' | L"
2021-06-15 11:04:42 +00:00
@tap="$modal.close(0)"
2021-02-28 15:10:26 +00:00
/>
2021-06-15 11:04:42 +00:00
</RGridLayout>
</GridLayout>
2021-02-28 15:10:26 +00:00
</Page>
2020-10-21 17:54:45 +00:00
</template>
2021-04-14 13:38:22 +00:00
<script lang="ts">
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";
2021-05-25 14:32:53 +00:00
import Confirm from "./Confirm.vue";
2021-03-10 15:59:50 +00:00
2021-04-14 13:38:22 +00:00
interface IData {
newList: unknown[];
2021-06-15 11:04:42 +00:00
stretch: number;
2021-04-14 13:38:22 +00:00
listHeight: number;
}
2020-10-21 17:54:45 +00:00
export default {
2021-04-14 13:38:22 +00:00
props: {
title: {
type: String,
required: true,
},
list: {
type: Array,
required: true,
},
action: {
type: String,
required: false,
},
2021-06-15 11:04:42 +00:00
selected: {
type: String,
required: false,
},
2021-04-14 13:38:22 +00:00
},
data(): IData {
2020-12-29 10:35:19 +00:00
return {
newList: this.list,
2021-06-15 11:04:42 +00:00
stretch: 0,
2021-04-01 10:55:35 +00:00
listHeight: 0,
2021-02-28 15:10:26 +00:00
};
2020-12-29 10:35:19 +00:00
},
computed: {
2021-06-18 18:37:01 +00:00
...mapState(["icon", "theme", "RTL"]),
2020-10-22 18:36:50 +00:00
},
2020-10-21 17:54:45 +00:00
methods: {
2021-06-18 18:37:01 +00:00
...mapActions(["removeLI", "deleteTP"]),
2021-04-14 13:38:22 +00:00
localized(item: string): string {
return this.title !== "lang" ? localize(item) : item;
2020-12-29 10:35:19 +00:00
},
2021-04-14 13:38:22 +00:00
tapAction(item: string): void {
2021-02-28 15:10:26 +00:00
this.$modal.close(item);
2020-10-21 17:54:45 +00:00
},
2021-06-15 11:04:42 +00:00
removeConfirmation(description: string): void {
2021-05-25 14:32:53 +00:00
return this.$showModal(Confirm, {
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-06-15 11:04:42 +00:00
deletionConfirmation(description: string): void {
return this.$showModal(Confirm, {
props: {
title: "conf",
description,
cancelButtonText: "cBtn",
okButtonText: "dBtn",
},
});
},
2021-04-14 13:38:22 +00:00
removeItem(item: string): void {
2021-02-28 15:10:26 +00:00
let vm = this;
2021-06-15 11:04:42 +00:00
let index = this.newList.findIndex((e) => e === item);
2021-04-15 17:24:14 +00:00
let localizedItem = `"${localize(item)}"`;
2021-06-18 18:37:01 +00:00
function removeLI(listName: string, desc: string): void {
2021-06-15 11:04:42 +00:00
vm.removeConfirmation(`${localize(desc, localizedItem)}`).then(
2021-04-15 17:24:14 +00:00
(action: boolean) => {
2021-06-15 11:04:42 +00:00
if (action)
2021-06-18 18:37:01 +00:00
vm.removeLI({
2021-04-15 17:24:14 +00:00
item,
listName,
});
}
);
2020-12-29 10:35:19 +00:00
}
2021-06-18 18:37:01 +00:00
function deleteTP(): void {
2021-06-15 11:04:42 +00:00
vm.deletionConfirmation(`${localize("delPrst", `"${item}"`)}`).then(
(action: boolean) => {
if (action) {
2021-06-18 18:37:01 +00:00
vm.deleteTP(index);
2021-06-15 11:04:42 +00:00
vm.newList.splice(index, 1);
}
}
);
}
2021-02-28 15:10:26 +00:00
switch (this.title) {
2021-01-13 05:02:48 +00:00
case "cui":
2021-06-18 18:37:01 +00:00
removeLI("cuisines", "rmCuiInfo");
2020-12-29 10:35:19 +00:00
break;
2021-01-13 05:02:48 +00:00
case "cat":
2021-06-18 18:37:01 +00:00
removeLI("categories", "rmCatInfo");
2020-12-29 10:35:19 +00:00
break;
2021-01-13 05:02:48 +00:00
case "yieldU":
2021-06-18 18:37:01 +00:00
removeLI("yieldUnits", "rmYUInfo");
2020-12-29 10:35:19 +00:00
break;
2021-01-13 05:02:48 +00:00
case "Unit":
2021-06-18 18:37:01 +00:00
removeLI("units", "rmUInfo");
2020-12-29 10:35:19 +00:00
break;
2021-06-15 11:04:42 +00:00
case "prsts":
2021-06-18 18:37:01 +00:00
deleteTP();
2021-06-15 11:04:42 +00:00
break;
2020-12-29 10:35:19 +00:00
}
2021-02-28 15:10:26 +00:00
},
2021-04-14 13:38:22 +00:00
touch({ object, action }): void {
2021-06-18 12:52:03 +00:00
this.touchFade(object, action);
2021-04-01 10:55:35 +00:00
},
},
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 {
2021-06-15 11:04:42 +00:00
this.stretch = 1;
2021-04-01 10:55:35 +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>