1 $.ajaxSetup({headers: {'X-CSRF-Token': document.querySelector('#csrf').getAttribute('value')}});
4 ajaxJSON: function(method, url, data) {
6 type: method.toUpperCase(),
8 data: JSON.stringify(data),
9 contentType: 'application/json; charset=utf-8',
22 rule: {id: '', name: '', expression: '', created: ''},
23 rules: existingRules || [],
29 showModal: function () {
31 $(this.$refs.vuemodal).modal('show');
33 $(this.$refs.vuemodal).modal('hide');
39 resetForm: function() {
40 this.rule = {id: '', name: '', expression: '', created: ''};
41 this.showModal = false;
42 this.editedIndex = null;
45 addRule: function () {
46 if (this.rule.name.trim()) {
47 this.errorMessage = '';
50 $.ajaxJSON('post', '/advancedcontentfilter/api/rules', this.rule)
51 .then(function (responseJSON) {
52 self.rules.push(responseJSON.rule);
54 }, function (response) {
55 self.errorMessage = response.responseJSON.message;
60 editRule: function (rule) {
61 this.editedIndex = this.rules.indexOf(rule);
62 this.rule = Object.assign({}, rule);
63 this.showModal = true;
66 saveRule: function (rule) {
67 this.errorMessage = '';
70 $.ajaxJSON('put', '/advancedcontentfilter/api/rules/' + rule.id, rule)
72 self.rules[self.editedIndex] = rule;
74 }, function (response) {
75 self.errorMessage = response.responseJSON.message;
79 toggleActive: function (rule) {
80 var previousValue = this.rules[this.rules.indexOf(rule)].active;
81 var newValue = Math.abs(parseInt(rule.active) - 1);
83 this.rules[this.rules.indexOf(rule)].active = newValue;
86 $.ajaxJSON('put', '/advancedcontentfilter/api/rules/' + rule.id, {'active': newValue})
87 .fail(function (response) {
88 self.rules[self.rules.indexOf(rule)].active = previousValue;
89 console.log(response.responseJSON.message);
93 deleteRule: function (rule) {
94 if (confirm('Are you sure you want to delete this rule?')) {
96 $.ajaxJSON('delete', '/advancedcontentfilter/api/rules/' + rule.id)
98 self.rules.splice(self.rules.indexOf(rule), 1);
99 }, function (response) {
100 console.log(response.responseJSON.message);
105 showVariables: function () {
106 var urlParts = this.itemUrl.split('/');
107 var guid = urlParts[urlParts.length - 1];
112 $.ajaxJSON('get', '/advancedcontentfilter/api/variables/' + guid)
113 .then(function (responseJSON) {
114 self.itemJson = responseJSON.variables;
115 }, function (response) {
116 self.itemJson = response.responseJSON.message;