mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-26 05:44:24 +00:00
android app progress + polls plugin
This commit is contained in:
63
src/server/backend/plugins/others/poll/js/settings.js
Normal file
63
src/server/backend/plugins/others/poll/js/settings.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const { createApp } = Vue;
|
||||
|
||||
createApp( {
|
||||
data() {
|
||||
return {
|
||||
polls: {},
|
||||
newPoll: {},
|
||||
operation: 'Add new',
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getData() {
|
||||
fetch( '/admin/plugins/polls/getData' ).then( response => {
|
||||
response.json().then( data => {
|
||||
this.polls = data;
|
||||
this.newPoll = {};
|
||||
} );
|
||||
} );
|
||||
},
|
||||
save() {
|
||||
if ( this.newPoll.comment && this.newPoll.display && this.newPoll.id ) {
|
||||
this.polls[ this.newPoll.id ] = this.newPoll;
|
||||
let fetchOptions = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( this.polls ),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'charset': 'utf-8'
|
||||
},
|
||||
};
|
||||
fetch( '/admin/plugins/polls/save', fetchOptions ).then( response => {
|
||||
if ( response.status !== 200 ) {
|
||||
alert( 'there was an error updating' );
|
||||
}
|
||||
} );
|
||||
this.closePopup();
|
||||
this.getData();
|
||||
} else {
|
||||
alert( 'Not all required fields are filled out!' );
|
||||
}
|
||||
},
|
||||
closePopup() {
|
||||
$( '#popup' ).fadeOut( 500 );
|
||||
$( 'body' ).removeClass( 'menuOpen' );
|
||||
this.getData();
|
||||
},
|
||||
addPoll () {
|
||||
this.newPoll = { 'allowAdding': true };
|
||||
this.operation = 'Add new';
|
||||
$( '#popup' ).fadeIn( 500 );
|
||||
$( 'body' ).addClass( 'menuOpen' );
|
||||
},
|
||||
editPoll ( pollID ) {
|
||||
this.operation = 'Edit';
|
||||
this.newPoll = this.polls[ pollID ];
|
||||
$( '#popup' ).fadeIn( 500 );
|
||||
$( 'body' ).addClass( 'menuOpen' );
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getData();
|
||||
}
|
||||
} ).mount( '#app' );
|
||||
91
src/server/backend/plugins/others/poll/js/voting.js
Normal file
91
src/server/backend/plugins/others/poll/js/voting.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const { createApp } = Vue;
|
||||
|
||||
createApp( {
|
||||
data() {
|
||||
return {
|
||||
entries: {},
|
||||
newSuggestion: {},
|
||||
votingDetails: {},
|
||||
votedOn: {},
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getData() {
|
||||
fetch( '/polls/get/' + location.pathname.substring( 7 ) ).then( response => {
|
||||
response.json().then( data => {
|
||||
this.entries = data;
|
||||
} );
|
||||
} );
|
||||
fetch( '/polls/getDetails/' + location.pathname.substring( 7 ) ).then( response => {
|
||||
response.json().then( data => {
|
||||
this.votingDetails = data;
|
||||
} );
|
||||
} );
|
||||
this.votedOn = JSON.parse( localStorage.getItem( 'itemsVotedOn' ) ?? '{}' );
|
||||
},
|
||||
save() {
|
||||
if ( this.newSuggestion.comment && this.newSuggestion.title ) {
|
||||
let fetchOptions = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( this.newSuggestion ),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'charset': 'utf-8'
|
||||
},
|
||||
};
|
||||
fetch( '/polls/add/' + location.pathname.substring( 7 ), fetchOptions ).then( response => {
|
||||
if ( response.status !== 200 ) {
|
||||
alert( 'there was an error updating' );
|
||||
}
|
||||
} );
|
||||
this.closePopup();
|
||||
this.getData();
|
||||
} else {
|
||||
alert( 'Not all required fields are filled out!' );
|
||||
}
|
||||
},
|
||||
vote( type, suggestionID ) {
|
||||
let voteType = type;
|
||||
let didDeactivate = false;
|
||||
if ( this.votedOn[ suggestionID ] === type ) {
|
||||
didDeactivate = true;
|
||||
if ( type === 'up' ) {
|
||||
voteType = 'down';
|
||||
} else {
|
||||
voteType = 'up';
|
||||
}
|
||||
} else if ( this.votedOn[ suggestionID ] ) {
|
||||
return;
|
||||
}
|
||||
let fetchOptions = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( { 'voteType': voteType, 'id': suggestionID } ),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'charset': 'utf-8'
|
||||
},
|
||||
};
|
||||
fetch( '/polls/vote/' + location.pathname.substring( 7 ), fetchOptions ).then( response => {
|
||||
if ( response.status !== 200 ) {
|
||||
alert( 'there was an error updating' );
|
||||
} else {
|
||||
this.votedOn[ suggestionID ] = didDeactivate ? undefined : voteType;
|
||||
localStorage.setItem( 'itemsVotedOn', JSON.stringify( this.votedOn ) );
|
||||
this.getData();
|
||||
}
|
||||
} );
|
||||
},
|
||||
closePopup() {
|
||||
$( '#popup' ).fadeOut( 500 );
|
||||
$( 'body' ).removeClass( 'menuOpen' );
|
||||
this.getData();
|
||||
},
|
||||
addSuggestion () {
|
||||
$( '#popup' ).fadeIn( 500 );
|
||||
$( 'body' ).addClass( 'menuOpen' );
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getData();
|
||||
}
|
||||
} ).mount( '#app' );
|
||||
Reference in New Issue
Block a user