deleted unused modules
This commit is contained in:
@@ -1,120 +0,0 @@
|
|||||||
import helper from './helper'
|
|
||||||
import $ from 'jquery'
|
|
||||||
import Http from './http'
|
|
||||||
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
|
|
||||||
import inputBox from './inputBox'
|
|
||||||
import nctable from './ncTable'
|
|
||||||
|
|
||||||
const basePath = "/apps/ncdownloader";
|
|
||||||
|
|
||||||
const createInputBox = (event, type) => {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
//let id = event.target.closest("div").getAttribute('id');
|
|
||||||
let inputID = event.target.closest("div").dataset.inputbox;
|
|
||||||
let inputElement = inputID ? document.getElementById(inputID) : null;
|
|
||||||
if (inputElement) {
|
|
||||||
inputElement.remove();
|
|
||||||
}
|
|
||||||
let height = $(window).scrollTop();
|
|
||||||
if (height > 50)
|
|
||||||
$("html, body").animate({ scrollTop: 0 }, "fast");
|
|
||||||
let name = t("ncdownloader", 'Download'), path;
|
|
||||||
switch (type) {
|
|
||||||
case "ytdl":
|
|
||||||
path = basePath + "/youtube/new";
|
|
||||||
break;
|
|
||||||
case "search":
|
|
||||||
name = t("ncdownloader", 'Search');
|
|
||||||
path = basePath + "/search";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
path = basePath + "/new";
|
|
||||||
}
|
|
||||||
let container;
|
|
||||||
if (type === 'search') {
|
|
||||||
let selectOptions = [];
|
|
||||||
selectOptions.push({ name: 'bitSearch', label: 'BITSEARCH', selected: 0 });
|
|
||||||
selectOptions.push({ name: 'TPB', label: 'THEPIRATEBAY', selected: 1 });
|
|
||||||
container = inputBox.getInstance(name, type, path).createOptions(selectOptions).create().addSpinner();
|
|
||||||
//container.appendChild(inputBox.createLoading());
|
|
||||||
} else if (type === 'ytdl') {
|
|
||||||
let checkbox = [{id:'audio-only',label:'Audio Only'}];
|
|
||||||
container = inputBox.getInstance(name, type, path).createCheckbox(checkbox).create().getContainer();
|
|
||||||
} else {
|
|
||||||
container = inputBox.getInstance(name, type, path).create().getContainer();
|
|
||||||
}
|
|
||||||
$("#ncdownloader-form-wrapper").append(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleSpinner = element => {
|
|
||||||
let spinner = element.previousSibling || element.nextSibling
|
|
||||||
|
|
||||||
if (!spinner) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (element.style.display === 'none') {
|
|
||||||
element.style.display = 'block'
|
|
||||||
spinner.style.display = 'none';
|
|
||||||
} else {
|
|
||||||
element.style.display = 'none'
|
|
||||||
spinner.style.display = 'block';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const inputHandler = (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
let element = event.target;
|
|
||||||
toggleSpinner(element);
|
|
||||||
let formWrapper = element.closest('form');
|
|
||||||
|
|
||||||
let inputData = helper.getData('form-input-wrapper');
|
|
||||||
let inputValue = inputData.form_input_text;
|
|
||||||
if (inputData.type !== 'search' && !helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) {
|
|
||||||
helper.message(t("ncdownloader", "Invalid url"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (inputData.type === 'ytdl') {
|
|
||||||
inputData.audioOnly = document.getElementById('audio-only').checked;
|
|
||||||
helper.message(t("ncdownloader", "Your download has started!"), 5000);
|
|
||||||
}
|
|
||||||
if (inputData.type === 'search') {
|
|
||||||
//a scheduled 60s-interval update is running in the background, this is to prevent it from interfering when searching
|
|
||||||
helper.enabledPolling = 0;
|
|
||||||
nctable.getInstance().loading();
|
|
||||||
}
|
|
||||||
const successCallback = (data, element) => {
|
|
||||||
if (!data) {
|
|
||||||
helper.message(t("ncdownloader", "Something must have gone wrong!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (data.hasOwnProperty("error")) {
|
|
||||||
helper.message(t("ncdownloader", data.error));
|
|
||||||
} else if (data.hasOwnProperty("message")) {
|
|
||||||
helper.message(t("ncdownloader", data.message));
|
|
||||||
} else if (data.hasOwnProperty("file")) {
|
|
||||||
helper.message(t("ncdownloader", "Downloading" + " " + data.file));
|
|
||||||
}
|
|
||||||
if (data && data.title) {
|
|
||||||
toggleSpinner(element);
|
|
||||||
const tableInst = nctable.getInstance(data.title, data.row);
|
|
||||||
tableInst.actionLink = false;
|
|
||||||
tableInst.rowClass = "table-row-search";
|
|
||||||
tableInst.create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const path = formWrapper.dataset.path || basePath + "/new";
|
|
||||||
let url = helper.generateUrl(path);
|
|
||||||
Http.getInstance(url).setData(inputData).setHandler(function (data) {
|
|
||||||
successCallback(data, element);
|
|
||||||
}).send();
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
run: function () {
|
|
||||||
$("#app-navigation").on("click", "#new-download-ytdl", (event) => createInputBox(event, 'ytdl'));
|
|
||||||
$("#app-navigation").on("click", "#new-download", (event) => createInputBox(event, ''));
|
|
||||||
$("#app-navigation").on("click", "#torrent-search-button", (event) => createInputBox(event, 'search'));
|
|
||||||
$("#ncdownloader-form-wrapper").on("click", "#form-input-button", (event) => inputHandler(event));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
160
src/inputBox.js
160
src/inputBox.js
@@ -1,160 +0,0 @@
|
|||||||
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
|
|
||||||
import helper from './helper'
|
|
||||||
|
|
||||||
|
|
||||||
class inputBox {
|
|
||||||
path;
|
|
||||||
selectOptions = [];
|
|
||||||
checkbox = [];
|
|
||||||
constructor(btnName, id, path = null) {
|
|
||||||
this.btnName = btnName;
|
|
||||||
this.id = id;
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
static getInstance(btnName, id, path = null) {
|
|
||||||
return new inputBox(btnName, id, path);
|
|
||||||
}
|
|
||||||
create() {
|
|
||||||
this.formContainer = this._createForm();
|
|
||||||
this.textInput = this._createTextInput(this.id);
|
|
||||||
this.buttonContainer = this._createButtonContainer();
|
|
||||||
this.formContainer.appendChild(this.textInput);
|
|
||||||
if (this.checkbox.length !== 0) {
|
|
||||||
this.formContainer.appendChild(this._createCheckbox());
|
|
||||||
}
|
|
||||||
if (this.selectOptions.length !== 0) {
|
|
||||||
this.formContainer.appendChild(this._createSelect());
|
|
||||||
}
|
|
||||||
this.buttonContainer.appendChild(this._createButton());
|
|
||||||
this.formContainer.appendChild(this.buttonContainer);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
getContainer() {
|
|
||||||
return this.formContainer;
|
|
||||||
}
|
|
||||||
setPath(path) {
|
|
||||||
this.path = path;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
_createButtonContainer() {
|
|
||||||
let div = document.createElement("div");
|
|
||||||
|
|
||||||
div.classList.add("button-container");
|
|
||||||
return div;
|
|
||||||
}
|
|
||||||
_createForm() {
|
|
||||||
let container = document.createElement("form");
|
|
||||||
container.classList.add("form-input-wrapper");
|
|
||||||
container.setAttribute('id', 'form-input-wrapper');
|
|
||||||
if (this.path) {
|
|
||||||
container.setAttribute('data-path', this.path);
|
|
||||||
}
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
_createSelect(id) {
|
|
||||||
id = id || this.id;
|
|
||||||
let select = document.createElement('select');
|
|
||||||
select.setAttribute('id', "select-value-" + id);
|
|
||||||
select.setAttribute('value', '');
|
|
||||||
select.classList.add('form-select');
|
|
||||||
this.selectOptions.forEach(element => {
|
|
||||||
select.appendChild(element);
|
|
||||||
});
|
|
||||||
return select;
|
|
||||||
}
|
|
||||||
|
|
||||||
_createCheckbox() {
|
|
||||||
let div = document.createElement("div");
|
|
||||||
div.classList.add("checkboxes");
|
|
||||||
this.checkbox.forEach(element => {
|
|
||||||
div.appendChild(element);
|
|
||||||
})
|
|
||||||
return div;
|
|
||||||
}
|
|
||||||
|
|
||||||
createCheckbox(data) {
|
|
||||||
if (!data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
data.forEach(element => {
|
|
||||||
let div = document.createElement('div');
|
|
||||||
let label = document.createElement('label');
|
|
||||||
let text = document.createTextNode(element.label);
|
|
||||||
let span = document.createElement('span');
|
|
||||||
span.appendChild(text);
|
|
||||||
|
|
||||||
let input = document.createElement('input');
|
|
||||||
input.setAttribute('type', 'checkbox');
|
|
||||||
input.setAttribute('id', element.id);
|
|
||||||
input.setAttribute('value', 'off');
|
|
||||||
input.setAttribute('name', element.name || element.id);
|
|
||||||
|
|
||||||
label.setAttribute('for', element.id);
|
|
||||||
label.classList.add("checkbox-label");
|
|
||||||
label.appendChild(input);
|
|
||||||
label.appendChild(span);
|
|
||||||
div.appendChild(label);
|
|
||||||
this.checkbox.push(div);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
createOptions(data) {
|
|
||||||
if (!data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
data.forEach(element => {
|
|
||||||
let option = document.createElement('option');
|
|
||||||
option.setAttribute('value', element.name);
|
|
||||||
let text = document.createTextNode(element.label);
|
|
||||||
option.appendChild(text);
|
|
||||||
if (element.selected) {
|
|
||||||
option.setAttribute("selected", "selected");
|
|
||||||
}
|
|
||||||
this.selectOptions.push(option);
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
_createTextInput(id) {
|
|
||||||
id = id || 'general';
|
|
||||||
let textInput = document.createElement('input');
|
|
||||||
textInput.setAttribute('type', 'text');
|
|
||||||
textInput.setAttribute('id', "form_input_text");
|
|
||||||
textInput.setAttribute('data-type', id);
|
|
||||||
textInput.setAttribute('value', '');
|
|
||||||
textInput.classList.add('form-input-text');
|
|
||||||
switch (id) {
|
|
||||||
case 'general':
|
|
||||||
textInput.setAttribute('placeholder', t("ncdownloader",'Paste your magnet/http link here'));
|
|
||||||
break;
|
|
||||||
case 'ytdl':
|
|
||||||
textInput.setAttribute('placeholder', t("ncdownloader",'Paste your video link here'));
|
|
||||||
break;
|
|
||||||
case 'search':
|
|
||||||
textInput.setAttribute('placeholder', t("ncdownloader",'Enter your keyword to search'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return textInput;
|
|
||||||
}
|
|
||||||
_createButton() {
|
|
||||||
let button = document.createElement('button');
|
|
||||||
button.setAttribute('type', 'submit');
|
|
||||||
button.setAttribute('id', 'form-input-button');
|
|
||||||
//buttonInput.setAttribute('value', t('ncdownloader', helper.ucfirst(btnName)));
|
|
||||||
let text = document.createTextNode(t('ncdownloader', helper.ucfirst(this.btnName)));
|
|
||||||
button.appendChild(text);
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
addSpinner() {
|
|
||||||
const parser = new window.DOMParser();
|
|
||||||
let htmlString = '<button class="bs-spinner"><span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" disabled></span><span class="visually-hidden">Loading...</span></button>'
|
|
||||||
let doc = parser.parseFromString(htmlString, "text/html")
|
|
||||||
let element = doc.querySelector(".bs-spinner");
|
|
||||||
element.style.display = 'none';
|
|
||||||
this.buttonContainer.appendChild(element);
|
|
||||||
return this.formContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
export default inputBox;
|
|
||||||
Reference in New Issue
Block a user