]> git.mxchange.org Git - friendica-addons.git/blob - advancedcontentfilter/templates/settings.tpl
b12df73c2569106d81cc4fc8d71e2a5edc04fc52
[friendica-addons.git] / advancedcontentfilter / templates / settings.tpl
1 <div id="adminpage">
2         <style>[v-cloak] { display: none; }</style>
3         <div id="rules"></div>
4
5         <script> var existingRules = {{$rules}};</script>
6
7         <!-- JS -->
8         <script src="{{$baseurl}}/view/asset/vue/dist/vue.min.js"></script>
9         <script>
10 $.extend({
11         ajaxJSON: function(method, url, data) {
12                 return $.ajax({
13                         type: method.toUpperCase(),
14                         url: url,
15                         data: JSON.stringify(data),
16                         contentType: 'application/json; charset=utf-8',
17                         dataType: 'json'
18                 });
19         }
20 });
21
22 new Vue({
23         el: '#rules',
24
25         data: {
26                 showModal: false,
27                 errorMessage: '',
28                 editedIndex: null,
29                 rule: {id: '', name: '', expression: '', created: ''},
30                 rules: existingRules || [],
31                 itemUrl: '',
32                 itemJson: ''
33         },
34
35         watch: {
36                 showModal: function () {
37                         if (this.showModal) {
38                                 $(this.$refs.vuemodal).modal('show');
39                         } else {
40                                 $(this.$refs.vuemodal).modal('hide');
41                         }
42                 }
43         },
44
45         mounted: function() {
46                 $.ajaxSetup({headers: {'X-CSRF-Token': document.querySelector('#csrf').getAttribute('value')}});
47         },
48
49         methods: {
50                 resetForm: function() {
51                         this.rule = {id: '', name: '', expression: '', created: ''};
52                         this.showModal = false;
53                         this.editedIndex = null;
54                 },
55
56                 addRule: function () {
57                         if (this.rule.name.trim()) {
58                                 this.errorMessage = '';
59
60                                 var self = this;
61                                 $.ajaxJSON('post', '/advancedcontentfilter/api/rules', this.rule)
62                                 .then(function (responseJSON) {
63                                         self.rules.push(responseJSON.rule);
64                                         self.resetForm();
65                                 }, function (response) {
66                                         self.errorMessage = response.responseJSON.message;
67                                 });
68                         }
69                 },
70
71                 editRule: function (rule) {
72                         this.editedIndex = this.rules.indexOf(rule);
73                         this.rule = Object.assign({}, rule);
74                         this.showModal = true;
75                 },
76
77                 saveRule: function (rule) {
78                         this.errorMessage = '';
79
80                         var self = this;
81                         $.ajaxJSON('put', '/advancedcontentfilter/api/rules/' + rule.id, rule)
82                         .then(function () {
83                                 self.rules[self.editedIndex] = rule;
84                                 self.resetForm();
85                         }, function (response) {
86                                 self.errorMessage = response.responseJSON.message;
87                         });
88                 },
89
90                 toggleActive: function (rule) {
91                         var previousValue = this.rules[this.rules.indexOf(rule)].active;
92                         var newValue = Math.abs(parseInt(rule.active) - 1);
93
94                         this.rules[this.rules.indexOf(rule)].active = newValue;
95
96                         var self = this;
97                         $.ajaxJSON('put', '/advancedcontentfilter/api/rules/' + rule.id, {'active': newValue})
98                         .fail(function (response) {
99                                 self.rules[self.rules.indexOf(rule)].active = previousValue;
100                                 console.log(response.responseJSON.message);
101                         });
102                 },
103
104                 deleteRule: function (rule) {
105                         if (confirm('Are you sure you want to delete this rule?')) {
106                                 var self = this;
107                                 $.ajaxJSON('delete', '/advancedcontentfilter/api/rules/' + rule.id)
108                                 .then(function () {
109                                         self.rules.splice(self.rules.indexOf(rule), 1);
110                                 }, function (response) {
111                                         console.log(response.responseJSON.message);
112                                 });
113                         }
114                 },
115
116                 showVariables: function () {
117                         var urlParts = this.itemUrl.split('/');
118                         var guid = urlParts[urlParts.length - 1];
119
120                         this.itemJson = '';
121
122                         var self = this;
123                         $.ajaxJSON('get', '/advancedcontentfilter/api/variables/' + guid)
124                         .then(function (responseJSON) {
125                                 self.itemJson = responseJSON.variables;
126                         }, function (response) {
127                                 self.itemJson = response.responseJSON.message;
128                         });
129
130                         return false;
131                 }
132         },
133
134         // These render function have been compiled from templates/vue_dom.tpl, check this file out for instructions
135         render: function () {
136                 with(this){return _c('div',{attrs:{"id":"rules"}},[_m(0),_m(1),_c('div',[_v("{{$advanced_content_filter_intro}}")]),_c('h2',[_v("{{$your_rules}}"),_c('button',{staticClass:"btn btn-primary btn-sm",attrs:{"title":"{{$add_a_rule}}"},on:{"click":function($event){showModal = true}}},[_c('i',{staticClass:"fa fa-plus fa-2x",attrs:{"aria-hidden":"true"}})])]),(rules.length === 0)?_c('div',{},[_v("{{$no_rules}}")]):_e(),_c('ul',{staticClass:"list-group"},_l((rules),function(rule){return _c('li',{staticClass:"list-group-item"},[_c('p',{staticClass:"pull-right"},[(parseInt(rule.active))?_c('button',{staticClass:"btn btn-xs btn-primary",attrs:{"type":"button","aria-label":"{{$disable_this_rule}}","title":"{{$disable_this_rule}}"},on:{"click":function($event){toggleActive(rule)}}},[_c('i',{staticClass:"fa fa-toggle-on",attrs:{"aria-hidden":"true"}}),_v(" {{$enabled}}")]):_c('button',{staticClass:"btn btn-xs btn-default",attrs:{"type":"button","aria-label":"{{$enable_this_rule}}","title":"{{$enable_this_rule}}"},on:{"click":function($event){toggleActive(rule)}}},[_c('i',{staticClass:"fa fa-toggle-off",attrs:{"aria-hidden":"true"}}),_v(" {{$disabled}}")]),_c('button',{staticClass:"btn btn-xs btn-primary",attrs:{"type":"button","aria-label":"{{$edit_this_rule}}","title":"{{$edit_this_rule}}"},on:{"click":function($event){editRule(rule)}}},[_c('i',{staticClass:"fa fa-pencil",attrs:{"aria-hidden":"true"}})]),_c('button',{staticClass:"btn btn-xs btn-default",attrs:{"type":"button","aria-label":"{{$delete_this_rule}}","title":"{{$delete_this_rule}}"},on:{"click":function($event){deleteRule(rule)}}},[_c('i',{staticClass:"fa fa-trash-o",attrs:{"aria-hidden":"true"}})])]),_c('h3',{staticClass:"list-group-item-heading"},[_v("{{$rule}} #"+_s(rule.id)+": "+_s(rule.name))]),(rule.expression)?_c('pre',{staticClass:"list-group-item-text"},[_v(_s(rule.expression))]):_e()])})),_c('div',{ref:"vuemodal",staticClass:"modal fade",attrs:{"tabindex":"-1","role":"dialog"}},[_c('div',{staticClass:"modal-dialog",attrs:{"role":"document"}},[_c('div',{staticClass:"modal-content"},[_c('div',{staticClass:"modal-header"},[_c('button',{staticClass:"close",attrs:{"type":"button","data-dismiss":"modal","aria-label":"{{$close}}"},on:{"click":function($event){showModal = false}}},[_c('span',{attrs:{"aria-hidden":"true"}},[_v("×")])]),(rule.id)?_c('h3',[_v("{{$edit_the_rule}} \""+_s(rule.name)+"\"")]):_e(),(!rule.id)?_c('h3',[_v("{{$add_a_rule}}")]):_e()]),_c('div',{staticClass:"modal-body"},[_c('form',[_c('input',{attrs:{"type":"hidden","name":"form_security_token","id":"csrf","value":"{{$form_security_token}}"}}),(errorMessage)?_c('div',{staticClass:"alert alert-danger",attrs:{"role":"alert"}},[_v(_s(errorMessage))]):_e(),_c('div',{staticClass:"form-group"},[_c('input',{directives:[{name:"model",rawName:"v-model",value:(rule.name),expression:"rule.name"}],staticClass:"form-control",attrs:{"placeholder":"{{$rule_name}}"},domProps:{"value":(rule.name)},on:{"input":function($event){if($event.target.composing)return;$set(rule, "name", $event.target.value)}}})]),_c('div',{staticClass:"form-group"},[_c('input',{directives:[{name:"model",rawName:"v-model",value:(rule.expression),expression:"rule.expression"}],staticClass:"form-control",attrs:{"placeholder":"{{$rule_expression}}"},domProps:{"value":(rule.expression)},on:{"input":function($event){if($event.target.composing)return;$set(rule, "expression", $event.target.value)}}})])])]),_c('div',{staticClass:"modal-footer"},[_c('button',{staticClass:"btn btn-default",attrs:{"type":"button","data-dismiss":"modal","aria-label":"Close"},on:{"click":function($event){resetForm()}}},[_v("{{$cancel}}")]),(rule.id)?_c('button',{staticClass:"btn btn-primary",attrs:{"slot":"button","type":"button"},on:{"click":function($event){saveRule(rule)}},slot:"button"},[_v("{{$save_this_rule}}")]):_e(),(!rule.id)?_c('button',{staticClass:"btn btn-primary",attrs:{"slot":"button","type":"button"},on:{"click":function($event){addRule()}},slot:"button"},[_v("{{$add_a_rule}}")]):_e()])])])]),_c('form',{staticClass:"form-inline",on:{"submit":function($event){$event.preventDefault();showVariables()}}},[_c('fieldset',[_c('legend',[_v("Show post variables")]),_c('div',{staticClass:"form-group",staticStyle:{"width":"50%"}},[_c('label',{staticClass:"sr-only",attrs:{"for":"itemUrl"}},[_v("Post URL or item guid")]),_c('input',{directives:[{name:"model",rawName:"v-model",value:(itemUrl),expression:"itemUrl"}],staticClass:"form-control",staticStyle:{"width":"100%"},attrs:{"id":"itemUrl","placeholder":"Post URL or item guid"},domProps:{"value":(itemUrl)},on:{"input":function($event){if($event.target.composing)return;itemUrl=$event.target.value}}})]),_c('button',{staticClass:"btn btn-primary",attrs:{"type":"submit"}},[_v("Show Variables")])])]),_c('pre',{},[_v(_s(itemJson))])])}
137         },
138
139         staticRenderFns: [
140                 function () {
141                         with(this){return _c('p',[_c('a',{attrs:{"href":"settings/addon"}},[_v("🔙 {{$backtosettings}}")])])}
142                 },
143                 function () {
144                         with(this){return _c('h1',[_v("{{$title}}"),_c('a',{staticClass:"btn btn-default btn-sm",attrs:{"href":"{{$baseurl}}/advancedcontentfilter/help","title":"{{$help}}"}},[_c('i',{staticClass:"fa fa-question fa-2x",attrs:{"aria-hidden":"true"}})])])}
145                 }
146         ]
147 });
148         </script>
149 </div>