mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-13 18:00:05 +00:00
ui: create new feed
This commit is contained in:
25
template/static/javascripts/api.js
Normal file
25
template/static/javascripts/api.js
Normal file
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
var api = function(method, endpoint, data) {
|
||||
var promise = fetch(endpoint, {
|
||||
method: method,
|
||||
headers: {'content-type': 'application/json'},
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
return promise.then(function(res) {
|
||||
if (res.ok) return res.json()
|
||||
})
|
||||
}
|
||||
|
||||
window.api = {
|
||||
feeds: {
|
||||
list: function() {
|
||||
return api('get', '/api/feeds')
|
||||
},
|
||||
create: function(data) {
|
||||
return api('post', '/api/feeds', data)
|
||||
},
|
||||
}
|
||||
}
|
||||
})()
|
@@ -32,6 +32,7 @@ var vm = new Vue({
|
||||
'itemSelected': null,
|
||||
'settings': 'manage',
|
||||
'newFolderTitle': null,
|
||||
'loading': {newfeed: 0},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -95,5 +96,20 @@ var vm = new Vue({
|
||||
this.feeds = this.feeds.filter(function(f) { f.id != feed.id })
|
||||
}
|
||||
},
|
||||
createFeed: function(event) {
|
||||
var form = event.target
|
||||
var data = {
|
||||
url: form.querySelector('input[name=url]').value,
|
||||
folder_id: parseInt(form.querySelector('select[name=folder_id]').value) || null,
|
||||
}
|
||||
this.loading.newfeed = true
|
||||
var vm = this
|
||||
api.feeds.create(data).then(function(result) {
|
||||
if (result.status === 'success') {
|
||||
vm.$bvModal.hide('settings-modal')
|
||||
}
|
||||
vm.loading.newfeed = false
|
||||
})
|
||||
},
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user