From 04ddb284da1a8c4663b60e18a8535de41f968edc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 5 Aug 2018 13:42:53 +0200 Subject: [PATCH] Revert "Merge pull request #682 from MrPetovan/bug/5341-advancedcontentfilter-honors-csp" This reverts commit e79d73843778f4df19b3e7e85a71b2d38d80e973, reversing changes made to 20e42c09b7a77b4da850c32e13717f081f50ea8a. --- .../advancedcontentfilter.js | 122 +++++++++ .../advancedcontentfilter.php | 2 +- advancedcontentfilter/templates/settings.tpl | 231 +++++++----------- advancedcontentfilter/templates/vue_dom.tpl | 96 -------- 4 files changed, 213 insertions(+), 238 deletions(-) create mode 100644 advancedcontentfilter/advancedcontentfilter.js delete mode 100644 advancedcontentfilter/templates/vue_dom.tpl diff --git a/advancedcontentfilter/advancedcontentfilter.js b/advancedcontentfilter/advancedcontentfilter.js new file mode 100644 index 00000000..67a2b8d2 --- /dev/null +++ b/advancedcontentfilter/advancedcontentfilter.js @@ -0,0 +1,122 @@ +$.ajaxSetup({headers: {'X-CSRF-Token': document.querySelector('#csrf').getAttribute('value')}}); + +$.extend({ + ajaxJSON: function(method, url, data) { + return $.ajax({ + type: method.toUpperCase(), + url: url, + data: JSON.stringify(data), + contentType: 'application/json; charset=utf-8', + dataType: 'json' + }); + } +}); + +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'); + } + } + }, + + methods: { + resetForm: function() { + this.rule = {id: '', name: '', expression: '', created: ''}; + this.showModal = false; + this.editedIndex = null; + }, + + addRule: function () { + if (this.rule.name.trim()) { + this.errorMessage = ''; + + var self = this; + $.ajaxJSON('post', '/advancedcontentfilter/api/rules', this.rule) + .then(function (responseJSON) { + self.rules.push(responseJSON.rule); + self.resetForm(); + }, function (response) { + self.errorMessage = response.responseJSON.message; + }); + } + }, + + editRule: function (rule) { + this.editedIndex = this.rules.indexOf(rule); + this.rule = Object.assign({}, rule); + this.showModal = true; + }, + + saveRule: function (rule) { + this.errorMessage = ''; + + var self = this; + $.ajaxJSON('put', '/advancedcontentfilter/api/rules/' + rule.id, rule) + .then(function () { + self.rules[self.editedIndex] = rule; + self.resetForm(); + }, function (response) { + self.errorMessage = response.responseJSON.message; + }); + }, + + toggleActive: function (rule) { + var previousValue = this.rules[this.rules.indexOf(rule)].active; + var newValue = Math.abs(parseInt(rule.active) - 1); + + this.rules[this.rules.indexOf(rule)].active = newValue; + + var self = this; + $.ajaxJSON('put', '/advancedcontentfilter/api/rules/' + rule.id, {'active': newValue}) + .fail(function (response) { + self.rules[self.rules.indexOf(rule)].active = previousValue; + console.log(response.responseJSON.message); + }); + }, + + deleteRule: function (rule) { + if (confirm('Are you sure you want to delete this rule?')) { + var self = this; + $.ajaxJSON('delete', '/advancedcontentfilter/api/rules/' + rule.id) + .then(function () { + self.rules.splice(self.rules.indexOf(rule), 1); + }, function (response) { + console.log(response.responseJSON.message); + }); + } + }, + + showVariables: function () { + var urlParts = this.itemUrl.split('/'); + var guid = urlParts[urlParts.length - 1]; + + this.itemJson = ''; + + var self = this; + $.ajaxJSON('get', '/advancedcontentfilter/api/variables/' + guid) + .then(function (responseJSON) { + self.itemJson = responseJSON.variables; + }, function (response) { + self.itemJson = response.responseJSON.message; + }); + + return false; + } + } +}); \ No newline at end of file diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index 2d1308e7..34d47425 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -213,7 +213,7 @@ function advancedcontentfilter_content(App $a) '$title' => L10n::t('Advanced Content Filter'), '$add_a_rule' => L10n::t('Add a Rule'), '$help' => L10n::t('Help'), - '$advanced_content_filter_intro' => addslashes(L10n::t('Add and manage your personal content filter rules in this screen. Rules have a name and an arbitrary expression that will be matched against post data. For a complete reference of the available operations and variables, check the help page.')), + '$advanced_content_filter_intro' => L10n::t('Add and manage your personal content filter rules in this screen. Rules have a name and an arbitrary expression that will be matched against post data. For a complete reference of the available operations and variables, check the help page.'), '$your_rules' => L10n::t('Your rules'), '$no_rules' => L10n::t('You have no rules yet! Start adding one by clicking on the button above next to the title.'), '$disabled' => L10n::t('Disabled'), diff --git a/advancedcontentfilter/templates/settings.tpl b/advancedcontentfilter/templates/settings.tpl index b12df73c..813dc919 100644 --- a/advancedcontentfilter/templates/settings.tpl +++ b/advancedcontentfilter/templates/settings.tpl @@ -1,149 +1,98 @@
-
+
+

🔙 {{$backtosettings}}

+

+ {{$title}} + + + + +

+
{{$advanced_content_filter_intro}}
+

+ {{$your_rules}} + +

+
+ {{$no_rules}} +
+ +
    +
  • +

    + + + + + +

    +

    + {{$rule}} #{{ rule.id }}: {{ rule.name }} +

    +
    {{ rule.expression }}
    +
  • +
+ + + +
+
+ Show post variables +
+ + +
+ +
+
+
+{{ itemJson }}
+		
+
- +
diff --git a/advancedcontentfilter/templates/vue_dom.tpl b/advancedcontentfilter/templates/vue_dom.tpl deleted file mode 100644 index 24538b86..00000000 --- a/advancedcontentfilter/templates/vue_dom.tpl +++ /dev/null @@ -1,96 +0,0 @@ - -
-

🔙 ##$backtosettings##

-

- ##$title## - - - - -

-
##$advanced_content_filter_intro##
-

- ##$your_rules## - -

-
- ##$no_rules## -
- - - - - -
-
- Show post variables -
- - -
- -
-
-
-{{ itemJson }}
-	
-