mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-04-25 16:30:12 +00:00
[advancedcontentfilter] Add addon files
- Add hooks - Add mini-API module powered by Slim - Add addon settings page powered by VueJS - Add translation strings - Add help page
This commit is contained in:
parent
20862be7d0
commit
b02724f867
9 changed files with 1396 additions and 0 deletions
113
advancedcontentfilter/advancedcontentfilter.js
Normal file
113
advancedcontentfilter/advancedcontentfilter.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
Vue.http.headers.common['X-CSRF-Token'] = document.querySelector('#csrf').getAttribute('value');
|
||||
|
||||
new Vue({
|
||||
el: '#rules',
|
||||
|
||||
data: {
|
||||
showModal: false,
|
||||
errorMessage: '',
|
||||
editedIndex: null,
|
||||
rule: {id: '', name: '', expression: '', created: ''},
|
||||
rules: existingRules || [],
|
||||
itemUrl: '',
|
||||
itemJson: ''
|
||||
},
|
||||
|
||||
watch: {
|
||||
showModal: function () {
|
||||
if (this.showModal) {
|
||||
$(this.$refs.vuemodal).modal('show');
|
||||
} else {
|
||||
$(this.$refs.vuemodal).modal('hide');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
//created: function () {
|
||||
// this.fetchRules();
|
||||
//},
|
||||
|
||||
methods: {
|
||||
resetForm: function() {
|
||||
this.rule = {id: '', name: '', expression: '', created: ''};
|
||||
this.showModal = false;
|
||||
this.editedIndex = null;
|
||||
},
|
||||
|
||||
//fetchRules: function () {
|
||||
// this.$http.get('/advancedcontentfilter/api/rules')
|
||||
// .then(function (response) {
|
||||
// this.rules = response.body;
|
||||
// }, function (err) {
|
||||
// console.log(err);
|
||||
// });
|
||||
//},
|
||||
|
||||
addRule: function () {
|
||||
if (this.rule.name.trim()) {
|
||||
this.errorMessage = '';
|
||||
this.$http.post('/advancedcontentfilter/api/rules', this.rule)
|
||||
.then(function (res) {
|
||||
this.rules.push(res.body.rule);
|
||||
this.resetForm();
|
||||
}, function (err) {
|
||||
this.errorMessage = err.body.message;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
editRule: function (rule) {
|
||||
this.editedIndex = this.rules.indexOf(rule);
|
||||
this.rule = Object.assign({}, rule);
|
||||
this.showModal = true;
|
||||
},
|
||||
|
||||
saveRule: function (rule) {
|
||||
this.errorMessage = '';
|
||||
this.$http.put('/advancedcontentfilter/api/rules/' + rule.id, rule)
|
||||
.then(function (res) {
|
||||
this.rules[this.editedIndex] = rule;
|
||||
this.resetForm();
|
||||
}, function (err) {
|
||||
this.errorMessage = err.body.message;
|
||||
});
|
||||
},
|
||||
|
||||
toggleActive: function (rule) {
|
||||
this.$http.put('/advancedcontentfilter/api/rules/' + rule.id, {'active': Math.abs(parseInt(rule.active) - 1)})
|
||||
.then(function (res) {
|
||||
this.rules[this.rules.indexOf(rule)].active = Math.abs(parseInt(rule.active) - 1);
|
||||
}, function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
},
|
||||
|
||||
deleteRule: function (rule) {
|
||||
if (confirm('Are you sure you want to delete this rule?')) {
|
||||
this.$http.delete('/advancedcontentfilter/api/rules/' + rule.id)
|
||||
.then(function (res) {
|
||||
this.rules.splice(this.rules.indexOf(rule), 1);
|
||||
}, function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
showVariables: function () {
|
||||
var guid = '';
|
||||
|
||||
var urlParts = this.itemUrl.split('/');
|
||||
|
||||
guid = urlParts[urlParts.length - 1];
|
||||
|
||||
this.$http.get('/advancedcontentfilter/api/variables/' + guid)
|
||||
.then(function (response) {
|
||||
this.itemJson = response.bodyText;
|
||||
}, function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue