From 97aa353652257d0b4f4074c0f87bf6d08995d9c4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 4 Aug 2018 15:59:04 +0200 Subject: [PATCH 1/3] [advancedcontentfilter] Move Vue template from DOM to compiled render functions --- .../advancedcontentfilter.php | 2 +- advancedcontentfilter/templates/settings.tpl | 231 +++++++++++------- 2 files changed, 142 insertions(+), 91 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index 34d47425..2d1308e7 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' => 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' => 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.')), '$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 813dc919..b12df73c 100644 --- a/advancedcontentfilter/templates/settings.tpl +++ b/advancedcontentfilter/templates/settings.tpl @@ -1,98 +1,149 @@
-
-

🔙 {{$backtosettings}}

-

- {{$title}} - - - - -

-
{{$advanced_content_filter_intro}}
-

- {{$your_rules}} - -

-
- {{$no_rules}} -
- -
    -
  • -

    - - - - - -

    -

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

    -
    {{ rule.expression }}
    -
  • -
- - - -
-
- Show post variables -
- - -
- -
-
-
-{{ itemJson }}
-		
-
+
- +
From ee8f151a232ef287d90553d49455da740c2c7a6c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 4 Aug 2018 16:00:03 +0200 Subject: [PATCH 2/3] [advancedcontentfilter] Remove obsolete external JS resource --- .../advancedcontentfilter.js | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 advancedcontentfilter/advancedcontentfilter.js diff --git a/advancedcontentfilter/advancedcontentfilter.js b/advancedcontentfilter/advancedcontentfilter.js deleted file mode 100644 index 67a2b8d2..00000000 --- a/advancedcontentfilter/advancedcontentfilter.js +++ /dev/null @@ -1,122 +0,0 @@ -$.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 From 48d887dd21ea9cd9aaca5a843b564303680680d0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 4 Aug 2018 16:00:41 +0200 Subject: [PATCH 3/3] [advancedcontentfilter] Add new support DOM file --- advancedcontentfilter/templates/vue_dom.tpl | 96 +++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 advancedcontentfilter/templates/vue_dom.tpl diff --git a/advancedcontentfilter/templates/vue_dom.tpl b/advancedcontentfilter/templates/vue_dom.tpl new file mode 100644 index 00000000..24538b86 --- /dev/null +++ b/advancedcontentfilter/templates/vue_dom.tpl @@ -0,0 +1,96 @@ + +
+

🔙 ##$backtosettings##

+

+ ##$title## + + + + +

+
##$advanced_content_filter_intro##
+

+ ##$your_rules## + +

+
+ ##$no_rules## +
+ +
    +
  • +

    + + + + + +

    +

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

    +
    {{ rule.expression }}
    +
  • +
+ + + +
+
+ Show post variables +
+ + +
+ +
+
+
+{{ itemJson }}
+	
+