fluentd-ui/app/javascript/packs/owned_plugin_form.js
Kenji Okimoto d80afa5e8a
Fix typos
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2018-06-12 17:23:27 +09:00

80 lines
1.7 KiB
JavaScript

'use strict'
const OwnedPluginForm = {
template: "#vue-owned-plugin-form",
props: [
"id",
"optionsJson",
"initialPluginName",
"pluginType",
"pluginLabel"
],
data: () => {
return {
pluginName: "",
options: [],
commonOptions: [],
advancedOptions: []
}
},
computed: {
token: function() {
return Rails.csrfToken()
}
},
mounted: function() {
this.options = JSON.parse(this.optionsJson)
this.pluginName = this.initialPluginName
this.$on("hook:updated", () => {
console.log("hook:updated")
$("[data-toggle=tooltip]").tooltip("dispose")
$("[data-toggle=tooltip]").tooltip("enable")
})
this.$once("data-loaded", () => {
this.updateSection()
})
this.$emit("data-loaded")
},
methods: {
onChange: function() {
this.updateSection()
},
updateSection: function() {
$.ajax({
method: "GET",
url: "/api/config_definitions",
headers: {
'X-CSRF-Token': this.token
},
data: {
type: this.pluginType,
name: this.pluginName
}
}).then((data) => {
this.commonOptions = data.commonOptions
})
},
selectId: function(pluginType) {
return `setting_${pluginType}_type`
},
selectClass: function(pluginType) {
return `${pluginType} form-control`
},
selectName: function(pluginType) {
return `setting[${pluginType}_type]`
},
inputId: function(pluginType, option) {
return `setting_${pluginType}_0__${option.name}`
},
inputName: function(pluginType, option) {
return `setting[${pluginType}[0]][${option.name}]`
}
}
}
export { OwnedPluginForm as default }