This repository has been archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·107 lines (100 loc) · 2.89 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
panel.plugin("medienbaecker/link", {
fields: {
link: {
props: {
label: String,
value: Object,
options: Array,
endpoints: Object
},
data: function() {
if(this.value) {
return {
type: this.value.type,
link: this.value.link
}
}
else {
return {
type: "",
link: ""
}
}
},
watch: {
value(value) {
this.type = value.type,
this.link = value.link;
}
},
methods: {
input() {
this.$emit("input", {
link: this.link,
type: this.type
});
},
setType(option = false) {
var link = '';
if(typeof(option) === "object") {
if(option[0].filename) {
link = option[0].filename;
option = "file";
}
else {
link = option[0].id;
option = "page";
}
}
this.$emit("input", {
link: link,
type: option
});
this.$nextTick(() => {
this.$refs.input.focus();
});
},
select(option = false) {
if(option == "page") {
this.$refs['pagesDialog'].open({
endpoint: this.endpoints.field + '/get/pages',
multiple: false,
selected: []
});
}
else if(option == "file") {
this.$api.get(this.endpoints.field + '/get/files').then(files => {
this.$refs.filesDialog.open(files, {
multiple: false
});
});
}
else {
this.setType(option);
}
},
close() {
this.$emit("input", {
link: '',
type: false
});
}
},
template: `
<k-field v-bind="$props" class="k-link-field">
<k-button v-show="type" @click="select()" slot="options" icon="cancel">{{ $t('link-field.change') }}</k-button>
<k-input theme="field" :icon="type">
<k-button-group v-show="!type">
<k-button @click="select(option)" v-for="option in options" :icon="option">
{{ $t('link-field.' + option) }}
</k-button>
</k-button-group>
<k-input ref="input" v-show="type" :id="_uid" v-model="link" type="text" @input="input" @keyup.esc="close"/>
</k-input>
<k-pages-dialog ref="pagesDialog" @submit="select"/>
<k-files-dialog ref="filesDialog" @submit="select"/>
</k-field>
`
}
}
});