app/javascript/packs/settings.js in fluentd-ui-1.0.0.alpha.3 vs app/javascript/packs/settings.js in fluentd-ui-1.0.0.beta.1
- old
+ new
@@ -1,38 +1,43 @@
+/* global _ */
+"use strict";
+
+import "lodash/lodash";
+
$(document).ready(() => {
const SettingSection = {
- template: '#vue-setting-section',
- props: ['id', 'content', 'type', 'name', 'arg'],
+ template: "#vue-setting-section",
+ props: ["id", "content", "type", "name", "arg"],
data: function() {
return {
- mode: 'default',
+ mode: "default",
processing: false
};
},
created: function() {
this.initialState();
},
computed: {
endpoint: function() {
- return '/api/settings/' + this.id;
+ return "/api/settings/" + this.id;
}
},
methods: {
- onCancel: function(event) {
+ onCancel: function(_event) {
this.initialState();
},
- onEdit: function(ev) {
+ onEdit: function(_event) {
this.mode = "edit";
},
- onDelete: function(ev) {
+ onDelete: function(_event) {
if (!confirm("really?")) {
return;
}
this.destroy();
},
- onSubmit: function(ev) {
- const token = document.getElementsByName("csrf-token")[0].getAttribute('content');
+ onSubmit: function(_event) {
+ const token = document.getElementsByName("csrf-token")[0].getAttribute("content");
this.processing = true;
this.content = $(`#${this.id} textarea.form-control`)[0].dataset.content;
$.ajax({
url: this.endpoint,
method: "POST",
@@ -40,11 +45,11 @@
_method: "PATCH",
id: this.id,
content: this.content
},
headers: {
- 'X-CSRF-Token': token
+ "X-CSRF-Token": token
}
}).then((data)=> {
_.each(data, function(v,k){
this[k] = v;
});
@@ -53,33 +58,36 @@
this.processing = false;
});
},
initialState: function(){
this.processing = false;
- this.mode = 'default';
+ this.mode = "default";
},
destroy: function(){
- const token = document.getElementsByName("csrf-token")[0].getAttribute('content');
+ const token = document.getElementsByName("csrf-token")[0].getAttribute("content");
$.ajax({
url: this.endpoint,
method: "POST",
data: {
_method: "DELETE",
id: this.id
},
headers: {
- 'X-CSRF-Token': token
+ "X-CSRF-Token": token
}
}).then(()=> {
this.$parent.update();
});
}
}
};
new Vue({
el: "#vue-setting",
+ components: {
+ "setting-section": SettingSection
+ },
data: function(){
return {
loaded: false,
loading: false,
sections: {
@@ -89,15 +97,12 @@
};
},
mounted: function() {
this.$nextTick(() => {
this.update();
- })
+ });
},
- components: {
- 'setting-section': SettingSection
- },
methods: {
update: function() {
this.loading = true;
$.getJSON("/api/settings", (data)=> {
var sources = [];
@@ -117,6 +122,6 @@
}, 500);
});
}
}
});
-})
+});