mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
added basic ingredient editor
This commit is contained in:
@@ -26,11 +26,11 @@
|
||||
<script>
|
||||
import Vue from "vue"
|
||||
import Multiselect from "vue-multiselect"
|
||||
import { ApiMixin } from "@/utils/utils"
|
||||
import {ApiMixin} from "@/utils/utils"
|
||||
|
||||
export default {
|
||||
name: "GenericMultiselect",
|
||||
components: { Multiselect },
|
||||
components: {Multiselect},
|
||||
mixins: [ApiMixin],
|
||||
data() {
|
||||
return {
|
||||
@@ -42,16 +42,16 @@ export default {
|
||||
}
|
||||
},
|
||||
props: {
|
||||
placeholder: { type: String, default: undefined },
|
||||
placeholder: {type: String, default: undefined},
|
||||
model: {
|
||||
type: Object,
|
||||
default() {
|
||||
return {}
|
||||
},
|
||||
},
|
||||
label: { type: String, default: "name" },
|
||||
parent_variable: { type: String, default: undefined },
|
||||
limit: { type: Number, default: 25 },
|
||||
label: {type: String, default: "name"},
|
||||
parent_variable: {type: String, default: undefined},
|
||||
limit: {type: Number, default: 25},
|
||||
sticky_options: {
|
||||
type: Array,
|
||||
default() {
|
||||
@@ -68,10 +68,11 @@ export default {
|
||||
type: Object,
|
||||
default: undefined,
|
||||
},
|
||||
multiple: { type: Boolean, default: true },
|
||||
allow_create: { type: Boolean, default: false },
|
||||
create_placeholder: { type: String, default: "You Forgot to Add a Tag Placeholder" },
|
||||
clear: { type: Number },
|
||||
search_on_load: {type: Boolean, default: true},
|
||||
multiple: {type: Boolean, default: true},
|
||||
allow_create: {type: Boolean, default: false},
|
||||
create_placeholder: {type: String, default: "You Forgot to Add a Tag Placeholder"},
|
||||
clear: {type: Number},
|
||||
},
|
||||
watch: {
|
||||
initial_selection: function (newVal, oldVal) {
|
||||
@@ -82,12 +83,12 @@ export default {
|
||||
empty[this.label] = `..${this.$t("loading")}..`
|
||||
this.selected_objects.forEach((x) => {
|
||||
if (typeof x !== "object") {
|
||||
this.selected_objects[this.selected_objects.indexOf(x)] = { ...empty, id: x }
|
||||
this.selected_objects[this.selected_objects.indexOf(x)] = {...empty, id: x}
|
||||
get_details.push(x)
|
||||
}
|
||||
})
|
||||
get_details.forEach((x) => {
|
||||
this.genericAPI(this.model, this.Actions.FETCH, { id: x })
|
||||
this.genericAPI(this.model, this.Actions.FETCH, {id: x})
|
||||
.then((result) => {
|
||||
// this.selected_objects[this.selected_objects.map((y) => y.id).indexOf(x)] = result.data
|
||||
Vue.set(this.selected_objects, this.selected_objects.map((y) => y.id).indexOf(x), result.data)
|
||||
@@ -103,8 +104,8 @@ export default {
|
||||
if (typeof this.selected_objects !== "object") {
|
||||
let empty = {}
|
||||
empty[this.label] = `..${this.$t("loading")}..`
|
||||
this.selected_objects = { ...empty, id: this.selected_objects }
|
||||
this.genericAPI(this.model, this.Actions.FETCH, { id: this.selected_objects })
|
||||
this.selected_objects = {...empty, id: this.selected_objects}
|
||||
this.genericAPI(this.model, this.Actions.FETCH, {id: this.selected_objects})
|
||||
.then((result) => {
|
||||
this.selected_objects = result.data
|
||||
})
|
||||
@@ -123,7 +124,9 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
this.id = Math.random()
|
||||
this.search("")
|
||||
if (this.search_on_load) {
|
||||
this.search("")
|
||||
}
|
||||
if (this.multiple || !this.initial_single_selection) {
|
||||
this.selected_objects = this.initial_selection
|
||||
} else {
|
||||
@@ -171,7 +174,7 @@ export default {
|
||||
})
|
||||
},
|
||||
selectionChanged: function () {
|
||||
this.$emit("change", { var: this.parent_variable, val: this.selected_objects })
|
||||
this.$emit("change", {var: this.parent_variable, val: this.selected_objects})
|
||||
},
|
||||
addNew(e) {
|
||||
this.$emit("new", e)
|
||||
|
||||
Reference in New Issue
Block a user