waibu-bootstrap 1.2.9 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -17,7 +17,10 @@ function getInputAttr (group, formControl = true, ro) {
|
|
|
17
17
|
else if (isString(val)) attr.dataValue = escape(val)
|
|
18
18
|
else attr.dataValue = val
|
|
19
19
|
if (ro) {
|
|
20
|
-
if (attr.
|
|
20
|
+
if (attr.rel) {
|
|
21
|
+
const [rel, fieldName = 'id'] = attr.rel.split(':')
|
|
22
|
+
attr.value = get(this, `component.locals.form._rel.${rel}.${fieldName}`, val)
|
|
23
|
+
} else if (attr.dataType === 'boolean') attr.value = this.component.req.t(val ? 'Yes' : 'No')
|
|
21
24
|
else if (has(attr, 'name') === 'lat') attr.value = escape(this.component.req.format(val, attr.dataType, { latitude: true }))
|
|
22
25
|
else if (has(attr, 'name') === 'lng') attr.value = escape(this.component.req.format(val, attr.dataType, { longitude: true }))
|
|
23
26
|
else attr.value = escape(this.component.req.format(val, attr.dataType))
|
|
@@ -45,9 +45,12 @@ async function formSelectExt () {
|
|
|
45
45
|
|
|
46
46
|
build = async () => {
|
|
47
47
|
const { generateId } = this.plugin.app.bajo
|
|
48
|
-
const { omit, merge } = this.plugin.lib._
|
|
48
|
+
const { omit, merge, has } = this.plugin.lib._
|
|
49
49
|
const { routePath } = this.plugin.app.waibu
|
|
50
50
|
const { jsonStringify, base64JsonDecode, groupAttrs } = this.plugin.app.waibuMpa
|
|
51
|
+
const { req } = this.component
|
|
52
|
+
let apiKey = ''
|
|
53
|
+
if (req.user && this.plugin.app.sumba) apiKey = await this.plugin.app.sumba.getApiKeyFromUserId(req.user.id)
|
|
51
54
|
const xref = this.params.attr['x-ref'] ?? 'select'
|
|
52
55
|
this.params.attr.id = this.params.attr.id ?? generateId('alpha')
|
|
53
56
|
this.params.attr['x-ref'] = xref
|
|
@@ -68,7 +71,6 @@ async function formSelectExt () {
|
|
|
68
71
|
return { value: item, text: item }
|
|
69
72
|
})
|
|
70
73
|
}
|
|
71
|
-
this.params.attr.options = options
|
|
72
74
|
}
|
|
73
75
|
let opts = { plugins }
|
|
74
76
|
let cOpts = {}
|
|
@@ -80,23 +82,28 @@ async function formSelectExt () {
|
|
|
80
82
|
if (!cOpts.optsText) opts = jsonStringify(merge(opts, cOpts), true)
|
|
81
83
|
else opts = cOpts.optsText
|
|
82
84
|
const group = groupAttrs(this.params.attr, ['remote'])
|
|
85
|
+
const fetchOpts = { headers: {} }
|
|
83
86
|
if (group.remote) {
|
|
84
87
|
group.remote.url = routePath(group.remote.url)
|
|
85
88
|
group.remote.searchField = group.remote.searchField ?? 'id'
|
|
86
89
|
group.remote.labelField = group.remote.labelField ?? 'id'
|
|
87
90
|
group.remote.valueField = group.remote.valueField ?? 'id'
|
|
91
|
+
if (has(group.remote, 'apiKey')) {
|
|
92
|
+
if (group.remote.apiKey === true) fetchOpts.headers.Authorization = `Bearer ${apiKey}` // TODO: get it from wmpa
|
|
93
|
+
else fetchOpts.headers.Authorization = `Bearer ${group.remote.apiKey}`
|
|
94
|
+
}
|
|
88
95
|
opts = `{
|
|
89
96
|
searchField: '${group.remote.searchField}',
|
|
90
97
|
labelField: '${group.remote.labelField}',
|
|
91
98
|
valueField: '${group.remote.valueField}',
|
|
92
99
|
load: (query, callback) => {
|
|
93
|
-
fetch('${group.remote.url}?query=${group.remote.searchField}:~\\'' + query + '\\'')
|
|
100
|
+
fetch('${group.remote.url}?query=${group.remote.searchField}:~\\'' + query + '\\'', ${jsonStringify(fetchOpts, true)})
|
|
94
101
|
.then(resp => resp.json())
|
|
95
102
|
.then(json => {
|
|
96
103
|
callback(json.data)
|
|
97
104
|
})
|
|
98
105
|
.catch(() => {
|
|
99
|
-
callback
|
|
106
|
+
callback()
|
|
100
107
|
})
|
|
101
108
|
},
|
|
102
109
|
render: {
|
|
@@ -114,7 +121,19 @@ async function formSelectExt () {
|
|
|
114
121
|
this.params.attr['@load.window'] = `
|
|
115
122
|
const opts = ${opts}
|
|
116
123
|
instance = new TomSelect($refs.${xref}, opts)
|
|
124
|
+
const val = $refs.${xref}.dataset.value
|
|
125
|
+
if (!_.isEmpty(val)) {
|
|
126
|
+
fetch('${group.remote.url}?query=${group.remote.valueField}:' + val, ${jsonStringify(fetchOpts, true)})
|
|
127
|
+
.then(resp => resp.json())
|
|
128
|
+
.then(json => {
|
|
129
|
+
if (json.data.length === 0) return
|
|
130
|
+
const opt = _.pick(json.data[0], ['${group.remote.valueField}', '${group.remote.labelField}'])
|
|
131
|
+
instance.addOption(opt)
|
|
132
|
+
instance.setValue(opt.${group.remote.valueField})
|
|
133
|
+
})
|
|
134
|
+
}
|
|
117
135
|
`
|
|
136
|
+
this.params.attr.options = options
|
|
118
137
|
this.params.attr = omit(this.params.attr, ['noDropdownInput', 'removeBtn', 'clearBtn', 'c-opts', 'remoteUrl', 'remoteSearchField', 'remoteLabelField', 'remoteValueField'])
|
|
119
138
|
await build.call(this, buildFormSelect, this.params)
|
|
120
139
|
}
|