mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-25 09:56:15 -04:00
lint: Run eslint --fix
on src/
This commit is contained in:
parent
b8d07a42eb
commit
8e5fd19db2
109 changed files with 9061 additions and 10572 deletions
|
@ -1,271 +1,262 @@
|
|||
$(document).ready(function () {
|
||||
$(document).ready(() => {
|
||||
let socket;
|
||||
const loc = document.location;
|
||||
const port = loc.port == '' ? (loc.protocol == 'https:' ? 443 : 80) : loc.port;
|
||||
const url = `${loc.protocol}//${loc.hostname}:${port}/`;
|
||||
const pathComponents = location.pathname.split('/');
|
||||
// Strip admin/plugins
|
||||
const baseURL = `${pathComponents.slice(0, pathComponents.length - 2).join('/')}/`;
|
||||
const resource = `${baseURL.substring(1)}socket.io`;
|
||||
|
||||
var socket,
|
||||
loc = document.location,
|
||||
port = loc.port == "" ? (loc.protocol == "https:" ? 443 : 80) : loc.port,
|
||||
url = loc.protocol + "//" + loc.hostname + ":" + port + "/",
|
||||
pathComponents = location.pathname.split('/'),
|
||||
// Strip admin/plugins
|
||||
baseURL = pathComponents.slice(0,pathComponents.length-2).join('/') + '/',
|
||||
resource = baseURL.substring(1) + "socket.io";
|
||||
|
||||
//connect
|
||||
var room = url + "pluginfw/installer";
|
||||
socket = io.connect(room, {path: baseURL + "socket.io", resource : resource});
|
||||
// connect
|
||||
const room = `${url}pluginfw/installer`;
|
||||
socket = io.connect(room, {path: `${baseURL}socket.io`, resource});
|
||||
|
||||
function search(searchTerm, limit) {
|
||||
if(search.searchTerm != searchTerm) {
|
||||
search.offset = 0
|
||||
search.results = []
|
||||
search.end = false
|
||||
if (search.searchTerm != searchTerm) {
|
||||
search.offset = 0;
|
||||
search.results = [];
|
||||
search.end = false;
|
||||
}
|
||||
limit = limit? limit : search.limit
|
||||
limit = limit ? limit : search.limit;
|
||||
search.searchTerm = searchTerm;
|
||||
socket.emit("search", {searchTerm: searchTerm, offset:search.offset, limit: limit, sortBy: search.sortBy, sortDir: search.sortDir});
|
||||
socket.emit('search', {searchTerm, offset: search.offset, limit, sortBy: search.sortBy, sortDir: search.sortDir});
|
||||
search.offset += limit;
|
||||
|
||||
$('#search-progress').show()
|
||||
search.messages.show('fetching')
|
||||
search.searching = true
|
||||
$('#search-progress').show();
|
||||
search.messages.show('fetching');
|
||||
search.searching = true;
|
||||
}
|
||||
search.searching = false;
|
||||
search.offset = 0;
|
||||
search.limit = 999;
|
||||
search.results = [];
|
||||
search.sortBy = 'name';
|
||||
search.sortDir = /*DESC?*/true;
|
||||
search.sortDir = /* DESC?*/true;
|
||||
search.end = true;// have we received all results already?
|
||||
search.messages = {
|
||||
show: function(msg) {
|
||||
//$('.search-results .messages').show()
|
||||
$('.search-results .messages .'+msg+'').show()
|
||||
$('.search-results .messages .'+msg+' *').show()
|
||||
show(msg) {
|
||||
// $('.search-results .messages').show()
|
||||
$(`.search-results .messages .${msg}`).show();
|
||||
$(`.search-results .messages .${msg} *`).show();
|
||||
},
|
||||
hide: function(msg) {
|
||||
$('.search-results .messages').hide()
|
||||
$('.search-results .messages .'+msg+'').hide()
|
||||
$('.search-results .messages .'+msg+' *').hide()
|
||||
}
|
||||
}
|
||||
hide(msg) {
|
||||
$('.search-results .messages').hide();
|
||||
$(`.search-results .messages .${msg}`).hide();
|
||||
$(`.search-results .messages .${msg} *`).hide();
|
||||
},
|
||||
};
|
||||
|
||||
var installed = {
|
||||
const installed = {
|
||||
progress: {
|
||||
show: function(plugin, msg) {
|
||||
$('.installed-results .'+plugin+' .progress').show()
|
||||
$('.installed-results .'+plugin+' .progress .message').text(msg)
|
||||
if($(window).scrollTop() > $('.'+plugin).offset().top)$(window).scrollTop($('.'+plugin).offset().top-100)
|
||||
show(plugin, msg) {
|
||||
$(`.installed-results .${plugin} .progress`).show();
|
||||
$(`.installed-results .${plugin} .progress .message`).text(msg);
|
||||
if ($(window).scrollTop() > $(`.${plugin}`).offset().top)$(window).scrollTop($(`.${plugin}`).offset().top - 100);
|
||||
},
|
||||
hide(plugin) {
|
||||
$(`.installed-results .${plugin} .progress`).hide();
|
||||
$(`.installed-results .${plugin} .progress .message`).text('');
|
||||
},
|
||||
hide: function(plugin) {
|
||||
$('.installed-results .'+plugin+' .progress').hide()
|
||||
$('.installed-results .'+plugin+' .progress .message').text('')
|
||||
}
|
||||
},
|
||||
messages: {
|
||||
show: function(msg) {
|
||||
$('.installed-results .messages').show()
|
||||
$('.installed-results .messages .'+msg+'').show()
|
||||
show(msg) {
|
||||
$('.installed-results .messages').show();
|
||||
$(`.installed-results .messages .${msg}`).show();
|
||||
},
|
||||
hide(msg) {
|
||||
$('.installed-results .messages').hide();
|
||||
$(`.installed-results .messages .${msg}`).hide();
|
||||
},
|
||||
hide: function(msg) {
|
||||
$('.installed-results .messages').hide()
|
||||
$('.installed-results .messages .'+msg+'').hide()
|
||||
}
|
||||
},
|
||||
list: []
|
||||
}
|
||||
list: [],
|
||||
};
|
||||
|
||||
function displayPluginList(plugins, container, template) {
|
||||
plugins.forEach(function(plugin) {
|
||||
var row = template.clone();
|
||||
plugins.forEach((plugin) => {
|
||||
const row = template.clone();
|
||||
|
||||
for (attr in plugin) {
|
||||
if(attr == "name"){ // Hack to rewrite URLS into name
|
||||
var link = $('<a>');
|
||||
link.attr('href', 'https://npmjs.org/package/'+plugin['name']);
|
||||
if (attr == 'name') { // Hack to rewrite URLS into name
|
||||
const link = $('<a>');
|
||||
link.attr('href', `https://npmjs.org/package/${plugin.name}`);
|
||||
link.attr('plugin', 'Plugin details');
|
||||
link.attr('target', '_blank');
|
||||
link.text(plugin['name'].substr(3));
|
||||
link.text(plugin.name.substr(3));
|
||||
row.find('.name').append(link);
|
||||
} else {
|
||||
row.find("." + attr).text(plugin[attr]);
|
||||
row.find(`.${attr}`).text(plugin[attr]);
|
||||
}
|
||||
}
|
||||
row.find(".version").text(plugin.version);
|
||||
row.addClass(plugin.name)
|
||||
row.data('plugin', plugin.name)
|
||||
row.find('.version').text(plugin.version);
|
||||
row.addClass(plugin.name);
|
||||
row.data('plugin', plugin.name);
|
||||
container.append(row);
|
||||
})
|
||||
});
|
||||
updateHandlers();
|
||||
}
|
||||
|
||||
function sortPluginList(plugins, property, /*ASC?*/dir) {
|
||||
return plugins.sort(function(a, b) {
|
||||
if (a[property] < b[property])
|
||||
return dir? -1 : 1;
|
||||
if (a[property] > b[property])
|
||||
return dir? 1 : -1;
|
||||
function sortPluginList(plugins, property, /* ASC?*/dir) {
|
||||
return plugins.sort((a, b) => {
|
||||
if (a[property] < b[property]) return dir ? -1 : 1;
|
||||
if (a[property] > b[property]) return dir ? 1 : -1;
|
||||
// a must be equal to b
|
||||
return 0;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function updateHandlers() {
|
||||
// Search
|
||||
$("#search-query").unbind('keyup').keyup(function () {
|
||||
search($("#search-query").val());
|
||||
$('#search-query').unbind('keyup').keyup(() => {
|
||||
search($('#search-query').val());
|
||||
});
|
||||
|
||||
// Prevent form submit
|
||||
$('#search-query').parent().bind('submit', function() {
|
||||
return false;
|
||||
});
|
||||
$('#search-query').parent().bind('submit', () => false);
|
||||
|
||||
// update & install
|
||||
$(".do-install, .do-update").unbind('click').click(function (e) {
|
||||
var $row = $(e.target).closest("tr")
|
||||
, plugin = $row.data('plugin');
|
||||
if($(this).hasClass('do-install')) {
|
||||
$row.remove().appendTo('#installed-plugins')
|
||||
installed.progress.show(plugin, 'Installing')
|
||||
}else{
|
||||
installed.progress.show(plugin, 'Updating')
|
||||
$('.do-install, .do-update').unbind('click').click(function (e) {
|
||||
const $row = $(e.target).closest('tr');
|
||||
const plugin = $row.data('plugin');
|
||||
if ($(this).hasClass('do-install')) {
|
||||
$row.remove().appendTo('#installed-plugins');
|
||||
installed.progress.show(plugin, 'Installing');
|
||||
} else {
|
||||
installed.progress.show(plugin, 'Updating');
|
||||
}
|
||||
socket.emit("install", plugin);
|
||||
installed.messages.hide("nothing-installed")
|
||||
socket.emit('install', plugin);
|
||||
installed.messages.hide('nothing-installed');
|
||||
});
|
||||
|
||||
// uninstall
|
||||
$(".do-uninstall").unbind('click').click(function (e) {
|
||||
var $row = $(e.target).closest("tr")
|
||||
, pluginName = $row.data('plugin');
|
||||
socket.emit("uninstall", pluginName);
|
||||
installed.progress.show(pluginName, 'Uninstalling')
|
||||
installed.list = installed.list.filter(function(plugin) {
|
||||
return plugin.name != pluginName
|
||||
})
|
||||
$('.do-uninstall').unbind('click').click((e) => {
|
||||
const $row = $(e.target).closest('tr');
|
||||
const pluginName = $row.data('plugin');
|
||||
socket.emit('uninstall', pluginName);
|
||||
installed.progress.show(pluginName, 'Uninstalling');
|
||||
installed.list = installed.list.filter((plugin) => plugin.name != pluginName);
|
||||
});
|
||||
|
||||
// Sort
|
||||
$('.sort.up').unbind('click').click(function() {
|
||||
$('.sort.up').unbind('click').click(function () {
|
||||
search.sortBy = $(this).attr('data-label').toLowerCase();
|
||||
search.sortDir = false;
|
||||
search.offset = 0;
|
||||
search(search.searchTerm, search.results.length);
|
||||
search.results = [];
|
||||
})
|
||||
$('.sort.down, .sort.none').unbind('click').click(function() {
|
||||
});
|
||||
$('.sort.down, .sort.none').unbind('click').click(function () {
|
||||
search.sortBy = $(this).attr('data-label').toLowerCase();
|
||||
search.sortDir = true;
|
||||
search.offset = 0;
|
||||
search(search.searchTerm, search.results.length);
|
||||
search.results = [];
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('results:search', function (data) {
|
||||
if(!data.results.length) search.end = true;
|
||||
if(data.query.offset == 0) search.results = [];
|
||||
search.messages.hide('nothing-found')
|
||||
search.messages.hide('fetching')
|
||||
$("#search-query").removeAttr('disabled')
|
||||
socket.on('results:search', (data) => {
|
||||
if (!data.results.length) search.end = true;
|
||||
if (data.query.offset == 0) search.results = [];
|
||||
search.messages.hide('nothing-found');
|
||||
search.messages.hide('fetching');
|
||||
$('#search-query').removeAttr('disabled');
|
||||
|
||||
console.log('got search results', data)
|
||||
console.log('got search results', data);
|
||||
|
||||
// add to results
|
||||
search.results = search.results.concat(data.results);
|
||||
|
||||
// Update sorting head
|
||||
$('.sort')
|
||||
.removeClass('up down')
|
||||
.addClass('none');
|
||||
$('.search-results thead th[data-label='+data.query.sortBy+']')
|
||||
.removeClass('none')
|
||||
.addClass(data.query.sortDir? 'up' : 'down');
|
||||
.removeClass('up down')
|
||||
.addClass('none');
|
||||
$(`.search-results thead th[data-label=${data.query.sortBy}]`)
|
||||
.removeClass('none')
|
||||
.addClass(data.query.sortDir ? 'up' : 'down');
|
||||
|
||||
// re-render search results
|
||||
var searchWidget = $(".search-results");
|
||||
searchWidget.find(".results *").remove();
|
||||
if(search.results.length > 0) {
|
||||
displayPluginList(search.results, searchWidget.find(".results"), searchWidget.find(".template tr"))
|
||||
}else {
|
||||
search.messages.show('nothing-found')
|
||||
const searchWidget = $('.search-results');
|
||||
searchWidget.find('.results *').remove();
|
||||
if (search.results.length > 0) {
|
||||
displayPluginList(search.results, searchWidget.find('.results'), searchWidget.find('.template tr'));
|
||||
} else {
|
||||
search.messages.show('nothing-found');
|
||||
}
|
||||
search.messages.hide('fetching')
|
||||
$('#search-progress').hide()
|
||||
search.searching = false
|
||||
search.messages.hide('fetching');
|
||||
$('#search-progress').hide();
|
||||
search.searching = false;
|
||||
});
|
||||
|
||||
socket.on('results:installed', function (data) {
|
||||
installed.messages.hide("fetching")
|
||||
installed.messages.hide("nothing-installed")
|
||||
socket.on('results:installed', (data) => {
|
||||
installed.messages.hide('fetching');
|
||||
installed.messages.hide('nothing-installed');
|
||||
|
||||
installed.list = data.installed
|
||||
sortPluginList(installed.list, 'name', /*ASC?*/true);
|
||||
installed.list = data.installed;
|
||||
sortPluginList(installed.list, 'name', /* ASC?*/true);
|
||||
|
||||
// filter out epl
|
||||
installed.list = installed.list.filter(function(plugin) {
|
||||
return plugin.name != 'ep_etherpad-lite'
|
||||
})
|
||||
installed.list = installed.list.filter((plugin) => plugin.name != 'ep_etherpad-lite');
|
||||
|
||||
// remove all installed plugins (leave plugins that are still being installed)
|
||||
installed.list.forEach(function(plugin) {
|
||||
$('#installed-plugins .'+plugin.name).remove()
|
||||
})
|
||||
installed.list.forEach((plugin) => {
|
||||
$(`#installed-plugins .${plugin.name}`).remove();
|
||||
});
|
||||
|
||||
if(installed.list.length > 0) {
|
||||
displayPluginList(installed.list, $("#installed-plugins"), $("#installed-plugin-template"));
|
||||
if (installed.list.length > 0) {
|
||||
displayPluginList(installed.list, $('#installed-plugins'), $('#installed-plugin-template'));
|
||||
socket.emit('checkUpdates');
|
||||
}else {
|
||||
installed.messages.show("nothing-installed")
|
||||
} else {
|
||||
installed.messages.show('nothing-installed');
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('results:updatable', function(data) {
|
||||
data.updatable.forEach(function(pluginName) {
|
||||
var $row = $('#installed-plugins > tr.'+pluginName)
|
||||
, actions = $row.find('.actions')
|
||||
actions.append('<input class="do-update" type="button" value="Update" />')
|
||||
})
|
||||
socket.on('results:updatable', (data) => {
|
||||
data.updatable.forEach((pluginName) => {
|
||||
const $row = $(`#installed-plugins > tr.${pluginName}`);
|
||||
const actions = $row.find('.actions');
|
||||
actions.append('<input class="do-update" type="button" value="Update" />');
|
||||
});
|
||||
updateHandlers();
|
||||
})
|
||||
});
|
||||
|
||||
socket.on('finished:install', function(data) {
|
||||
if(data.error) {
|
||||
if(data.code === "EPEERINVALID"){
|
||||
socket.on('finished:install', (data) => {
|
||||
if (data.error) {
|
||||
if (data.code === 'EPEERINVALID') {
|
||||
alert("This plugin requires that you update Etherpad so it can operate in it's true glory");
|
||||
}
|
||||
alert('An error occurred while installing '+data.plugin+' \n'+data.error)
|
||||
$('#installed-plugins .'+data.plugin).remove()
|
||||
alert(`An error occurred while installing ${data.plugin} \n${data.error}`);
|
||||
$(`#installed-plugins .${data.plugin}`).remove();
|
||||
}
|
||||
|
||||
socket.emit("getInstalled");
|
||||
socket.emit('getInstalled');
|
||||
|
||||
// update search results
|
||||
search.offset = 0;
|
||||
search(search.searchTerm, search.results.length);
|
||||
search.results = [];
|
||||
})
|
||||
});
|
||||
|
||||
socket.on('finished:uninstall', function(data) {
|
||||
if(data.error) alert('An error occurred while uninstalling the '+data.plugin+' \n'+data.error)
|
||||
socket.on('finished:uninstall', (data) => {
|
||||
if (data.error) alert(`An error occurred while uninstalling the ${data.plugin} \n${data.error}`);
|
||||
|
||||
// remove plugin from installed list
|
||||
$('#installed-plugins .'+data.plugin).remove()
|
||||
$(`#installed-plugins .${data.plugin}`).remove();
|
||||
|
||||
socket.emit("getInstalled");
|
||||
socket.emit('getInstalled');
|
||||
|
||||
// update search results
|
||||
search.offset = 0;
|
||||
search(search.searchTerm, search.results.length);
|
||||
search.results = [];
|
||||
})
|
||||
});
|
||||
|
||||
// init
|
||||
updateHandlers();
|
||||
socket.emit("getInstalled");
|
||||
socket.emit('getInstalled');
|
||||
search('');
|
||||
|
||||
// check for updates every 5mins
|
||||
setInterval(function() {
|
||||
setInterval(() => {
|
||||
socket.emit('checkUpdates');
|
||||
}, 1000*60*5)
|
||||
}, 1000 * 60 * 5);
|
||||
});
|
||||
|
|
|
@ -1,81 +1,75 @@
|
|||
$(document).ready(function () {
|
||||
var socket,
|
||||
loc = document.location,
|
||||
port = loc.port == "" ? (loc.protocol == "https:" ? 443 : 80) : loc.port,
|
||||
url = loc.protocol + "//" + loc.hostname + ":" + port + "/",
|
||||
pathComponents = location.pathname.split('/'),
|
||||
// Strip admin/plugins
|
||||
baseURL = pathComponents.slice(0,pathComponents.length-2).join('/') + '/',
|
||||
resource = baseURL.substring(1) + "socket.io";
|
||||
$(document).ready(() => {
|
||||
let socket;
|
||||
const loc = document.location;
|
||||
const port = loc.port == '' ? (loc.protocol == 'https:' ? 443 : 80) : loc.port;
|
||||
const url = `${loc.protocol}//${loc.hostname}:${port}/`;
|
||||
const pathComponents = location.pathname.split('/');
|
||||
// Strip admin/plugins
|
||||
const baseURL = `${pathComponents.slice(0, pathComponents.length - 2).join('/')}/`;
|
||||
const resource = `${baseURL.substring(1)}socket.io`;
|
||||
|
||||
//connect
|
||||
var room = url + "settings";
|
||||
socket = io.connect(room, {path: baseURL + "socket.io", resource : resource});
|
||||
|
||||
socket.on('settings', function (settings) {
|
||||
// connect
|
||||
const room = `${url}settings`;
|
||||
socket = io.connect(room, {path: `${baseURL}socket.io`, resource});
|
||||
|
||||
socket.on('settings', (settings) => {
|
||||
/* Check whether the settings.json is authorized to be viewed */
|
||||
if(settings.results === 'NOT_ALLOWED') {
|
||||
if (settings.results === 'NOT_ALLOWED') {
|
||||
$('.innerwrapper').hide();
|
||||
$('.innerwrapper-err').show();
|
||||
$('.err-message').html("Settings json is not authorized to be viewed in Admin page!!");
|
||||
$('.err-message').html('Settings json is not authorized to be viewed in Admin page!!');
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check to make sure the JSON is clean before proceeding */
|
||||
if(isJSONClean(settings.results))
|
||||
{
|
||||
if (isJSONClean(settings.results)) {
|
||||
$('.settings').append(settings.results);
|
||||
$('.settings').focus();
|
||||
$('.settings').autosize();
|
||||
}
|
||||
else{
|
||||
alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD");
|
||||
} else {
|
||||
alert('YOUR JSON IS BAD AND YOU SHOULD FEEL BAD');
|
||||
}
|
||||
});
|
||||
|
||||
/* When the admin clicks save Settings check the JSON then send the JSON back to the server */
|
||||
$('#saveSettings').on('click', function(){
|
||||
var editedSettings = $('.settings').val();
|
||||
if(isJSONClean(editedSettings)){
|
||||
$('#saveSettings').on('click', () => {
|
||||
const editedSettings = $('.settings').val();
|
||||
if (isJSONClean(editedSettings)) {
|
||||
// JSON is clean so emit it to the server
|
||||
socket.emit("saveSettings", $('.settings').val());
|
||||
}else{
|
||||
alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD")
|
||||
socket.emit('saveSettings', $('.settings').val());
|
||||
} else {
|
||||
alert('YOUR JSON IS BAD AND YOU SHOULD FEEL BAD');
|
||||
$('.settings').focus();
|
||||
}
|
||||
});
|
||||
|
||||
/* Tell Etherpad Server to restart */
|
||||
$('#restartEtherpad').on('click', function(){
|
||||
socket.emit("restartServer");
|
||||
$('#restartEtherpad').on('click', () => {
|
||||
socket.emit('restartServer');
|
||||
});
|
||||
|
||||
socket.on('saveprogress', function(progress){
|
||||
socket.on('saveprogress', (progress) => {
|
||||
$('#response').show();
|
||||
$('#response').text(progress);
|
||||
$('#response').fadeOut('slow');
|
||||
});
|
||||
|
||||
socket.emit("load"); // Load the JSON from the server
|
||||
|
||||
socket.emit('load'); // Load the JSON from the server
|
||||
});
|
||||
|
||||
|
||||
function isJSONClean(data){
|
||||
var cleanSettings = JSON.minify(data);
|
||||
function isJSONClean(data) {
|
||||
let cleanSettings = JSON.minify(data);
|
||||
// this is a bit naive. In theory some key/value might contain the sequences ',]' or ',}'
|
||||
cleanSettings = cleanSettings.replace(",]","]").replace(",}","}");
|
||||
try{
|
||||
cleanSettings = cleanSettings.replace(',]', ']').replace(',}', '}');
|
||||
try {
|
||||
var response = jQuery.parseJSON(cleanSettings);
|
||||
}
|
||||
catch(e){
|
||||
} catch (e) {
|
||||
return false; // the JSON failed to be parsed
|
||||
}
|
||||
if(typeof response !== 'object'){
|
||||
if (typeof response !== 'object') {
|
||||
return false;
|
||||
}else{
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue