reorganizing file structures;
This commit is contained in:
42
src/actions/buttonActions.js
Normal file
42
src/actions/buttonActions.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import Http from '../lib/http'
|
||||
import helper from '../utils/helper'
|
||||
import eventHandler from '../lib/eventHandler'
|
||||
const buttonHandler = (event, type) => {
|
||||
let element = event.target;
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
let url = element.getAttribute("path");
|
||||
let row, data = {};
|
||||
let removeRow = true;
|
||||
if (row = element.closest('.table-row-search')) {
|
||||
data['text-input-value'] = row.dataset.link;
|
||||
} else {
|
||||
row = element.closest('.table-row')
|
||||
data = row.dataset;
|
||||
if (!data.gid) {
|
||||
console.log("gid is not set!");
|
||||
}
|
||||
}
|
||||
Http.getInstance(url).setErrorHandler(function (xhr, textStatus, error) {
|
||||
console.log(error);
|
||||
}).setHandler(function (data) {
|
||||
if (data.hasOwnProperty('error')) {
|
||||
helper.message(data['error']);
|
||||
return;
|
||||
}
|
||||
if (data.hasOwnProperty('result')) {
|
||||
helper.message("Success " + data['result']);
|
||||
}
|
||||
if (data.hasOwnProperty('message')) {
|
||||
helper.message(data.message);
|
||||
}
|
||||
if (row && removeRow)
|
||||
row.remove();
|
||||
}).setData(data).send();
|
||||
|
||||
}
|
||||
export default {
|
||||
run: function () {
|
||||
eventHandler.add("click", "#ncdownloader-table-wrapper", ".table-cell-action-item .button-container button", e => buttonHandler(e, ''));
|
||||
}
|
||||
}
|
||||
50
src/actions/updatePage.js
Normal file
50
src/actions/updatePage.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import helper from '../utils/helper'
|
||||
import eventHandler from '../lib/eventHandler';
|
||||
import Http from '../lib/http'
|
||||
|
||||
const basePath = "/apps/ncdownloader/status/";
|
||||
const tableContainer = ".table";
|
||||
export default {
|
||||
run: function () {
|
||||
|
||||
const clickHandler = (event, type) => {
|
||||
event.preventDefault();
|
||||
helper.hideDownload();
|
||||
let container = document.querySelector(tableContainer);
|
||||
let currentType = container.getAttribute("type");
|
||||
let path = basePath + type;
|
||||
if (type === "youtube-dl") {
|
||||
path = "/apps/ncdownloader/youtube/get";
|
||||
}
|
||||
let name = type + "-downloads";
|
||||
//avoid repeated click
|
||||
if (currentType === name && helper.enabledPolling) {
|
||||
return;
|
||||
}
|
||||
helper.enabledPolling = 1;
|
||||
//$(tableContainer).removeClass().addClass("table " + name);
|
||||
container.setAttribute("type", name);
|
||||
container.className = "table " + name;
|
||||
let delay = 15000;
|
||||
if (['active', 'youtube-dl'].includes(type)) {
|
||||
delay = 1500;
|
||||
}
|
||||
helper.loop(helper.refresh, delay, ...[path])
|
||||
};
|
||||
eventHandler.add("click",".waiting-downloads a",event => clickHandler(event, 'waiting'));
|
||||
eventHandler.add("click",".complete-downloads a",event => clickHandler(event, 'complete'));
|
||||
eventHandler.add("click",".active-downloads a",event => clickHandler(event, 'active'));
|
||||
eventHandler.add("click",".fail-downloads a",event => clickHandler(event, 'fail'));
|
||||
eventHandler.add("click",".youtube-dl-downloads a",event => clickHandler(event, 'youtube-dl'));
|
||||
eventHandler.add("click", "#ncdownloader-table-wrapper",".download-file-folder", function (event) {
|
||||
event.stopPropagation();
|
||||
const path = "/apps/ncdownloader/update";
|
||||
let url = helper.generateUrl(path);
|
||||
Http.getInstance(url).setMethod('GET').send();
|
||||
});
|
||||
helper.polling(function (url) {
|
||||
url = helper.generateUrl(url);
|
||||
Http.getInstance(url).setMethod('GET').send();
|
||||
}, 60000, "/apps/ncdownloader/update");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user