123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- //delete = delets from DB
- //remove = removes from HTML
- //save = save to DB
- //add = changes HTML
- //get = get from DB
- //new = changes HTML
- //CrossSiteReference needed for WAS
- var test = {};
- var ref = $(test);
- $(document).on('change', '#selectfolders', function(e) {
- //getFolders(this.options[e.target.selectedIndex].text);
- listFolders(this.options[e.target.selectedIndex].text);
- });
- function listFolders(folder = ""){
- $('#Folders').text("");
- $('#CurFolder').text("");
- toggleRemoveLinks(true);
- getAllFolders();
-
- if(folder != "" && folder != "." && folder != ".."){
- $("#selectfolders").val(folder);
- }
- else{
- $("#selectfolders").val(".");
- }
-
- $.ajax({
- type: "GET",
- url: "../server/folders/" + folder,
- dataType: "json",
- success: function(data) {
-
-
- if(folder != "" && folder != "." && folder != ".."){
- var clone = document.importNode(document.querySelector('#cpyFolder').content,true);
- $('[data-class=text]',clone).text("..");
- $('[data-class=link]',clone).attr('onclick','listFolders("' + folder.substr(0, folder.lastIndexOf("/")) + '")');
- // dont show remove link on .. folder
- $('[data-class=removefolder]',clone).remove()
- $('#Folders').append(clone);
- }
-
-
-
- $.each( data, function( key, value ) {
- var clone = document.importNode(document.querySelector('#cpyFolder').content,true);
-
- //remove /
- value = value.slice(0,-1)
- $('[data-class=text]',clone).text(value);
-
- if(folder == ""){
- $('[data-class=link]',clone).attr('onclick','listFolders("' + value + '")');
- $('[data-class=removefolder]',clone).attr('onclick','deleteFolder("' + value + '")');
- }
- else{
- $('[data-class=link]',clone).attr('onclick','listFolders("' + folder + "/" + value + '")');
- $('[data-class=removefolder]',clone).attr('onclick','deleteFolder("' + folder + "/" + value + '")');
- }
- $('#Folders').append(clone);
- });
-
- //new Folder
- var clone = document.importNode(document.querySelector('#cpyFolderNew').content,true);
- $('[data-class=text]',clone).text("+");
- $('[data-class=link]',clone).attr('onclick','createFolder("' + folder + '")');
- $('#Folders').append(clone);
- }
- });
-
- listData(folder)
- }
- function createFolder(folder = ""){
- var newFolder = window.prompt("Please enter a folder name.","");
- if (newFolder != null && newFolder != "") {
- $.ajax({
- type: "Post",
- url: "../server/folders/" + folder + "/" + newFolder,
- success: function(res) {
- listFolders(folder)
- }
- });
- }
- }
- function deleteFolder(datalink) {
- if (datalink != "" && datalink != "." && datalink != ".." && confirm('Deleting ' + datalink)) {
- $.ajax({
- type: "DELETE",
- url: "../server/folders/" + datalink,
- success: function(res) {
- listFolders(datalink.substr(0, datalink.lastIndexOf("/")))
- }
- });
- }
- }
- function listData(folder = ""){
- $('#Data').text("");
- const imageext = ["png", "jpg", "svg", "JPG", "PNG", "SVG"]
- const movieext = ["mp4"]
- $('#imgUpload').attr("action", "../server/data/" + folder);
-
- $.ajax({
- type: "GET",
- url: "../server/images/" + folder,
- dataType: "json",
- success: function(data) {
- $.each( data, function( key, value ) {
-
- var ext = value.substr(value.lastIndexOf('.') + 1);
- if(folder == ""){
- fullfolder = value
- }
- else{
- fullfolder = folder + "/" + value;
- }
-
- var clone = document.importNode(document.querySelector('#DataItem').content,true);
- $('[data-class=name]',clone).text(value);
- $('[data-class=name]',clone).attr('title', value);
-
- //Image
- if(imageext.includes(ext)){
- $('[data-class=image]',clone).append("<img src='./../storage/"+ fullfolder + "' alt=''>")
- }
- else if(movieext.includes(ext)){
- $('[data-class=image]',clone).append("<div class='imageAlternative' style='padding-top: 0.12em;'>▶</div>")
- }
- else{
- $('[data-class=image]',clone).append("<div class='imageAlternative'>🗎</div>")
- }
-
- $('[data-class=image]',clone).attr('onclick',"overlayOn('" + fullfolder + "')");
-
- $('[data-class=inspect]',clone).attr('href','../storage/' + fullfolder + '');
- $('[data-class=delete]',clone).attr('href','javascript:deleteData("' + fullfolder + '");');
- $('[data-class=multiRemovelink]',clone).attr('name', fullfolder );
-
- $('[data-class=getLink]',clone).attr('href','javascript:copy2Clipboard("' + fullfolder + '");');
-
- $('[data-class=rename]',clone).attr('href','javascript:rename("' + fullfolder + '", "' + value.slice(0, - (ext.length +1)) +'");');
-
- $('[data-class=createSymlink]',clone).attr('href','javascript:createSymlink("' + fullfolder + '", "' + value.slice(0, - (ext.length +1)) +'");');
-
-
-
- var queryString = window.location.search;
- var urlParams = new URLSearchParams(queryString);
-
- if(urlParams.has('iframe')){
- $('[data-class=eventTrigger]',clone).css("visibility", "visible")
- $('[data-class=eventTrigger]',clone).attr('href','javascript:triggerEvent("' + fullfolder + '");');
-
- console.log("I am an Iframe")
- }
-
- $('#Data').append(clone);
- });
- }
- });
-
- if(folder != "" && folder != "." && folder != ".."){
- $('#RemoveFolder').css("display", "block")
- $('#removeFolderLink').attr('href','javascript:deleteFolder("' + folder + '");');
- }
- else{
- $('#RemoveFolder').css("display", "none")
- }
- }
- function triggerEvent(data) {
- //get url
- var datalink = new URL("../storage/" + data, document.baseURI).href;
-
- ref = $(test);
- setTimeout(function(){
- ref.triggerHandler('getUrl', {"url": datalink});
- },500);
- }
- function overlayOn(data) {
- var url = new URL("../storage/" + data, document.baseURI).href
- document.getElementById("overlay").style.display = "block";
- const imageext = ["png", "jpg", "svg", "PNG", "JPG", "SVG"]
- const movieext = ["mp4"]
- var ext = url.substr(url.lastIndexOf('.') + 1);
-
- if(imageext.includes(ext)){
- $('#overlaycontentsize').append("<img id='overlaycontent' src=" + url + "></img>");
- }
- else if(movieext.includes(ext)){
- $('#overlaycontentsize').append("<video id='overlaycontent' controls> <source src=" + url + " type=\"video/mp4\">Your browser does not support the video tag.</video>");
- }
- else{
- $('#overlaycontentsize').append("<iframe id='overlaycontent' src=" + url + "></iframe>");
- }
- }
- function overlayOff() {
- document.getElementById("overlay").style.display = "none";
- $('#overlaycontentsize').text("");
- }
- function toggleRemoveLinks(setoff = false) {
- if(setoff || $(".showremoveitems").is(":visible")){
- $(".showremoveitems").css("display", "none")
- $(".showremoveitemsNot").css("display", "inline")
- }
- else{
- $(".showremoveitems").css("display", "inline")
- $(".showremoveitemsNot").css("display", "none")
- }
- }
- function selectRemoveItems() {
- toggleRemoveLinks()
- }
- function unselectAll(){
- $(':input','#Data')
- .not(':button, :submit, :reset, :hidden')
- .val('')
- .prop('checked', false)
- .prop('selected', false);
- toggleRemoveLinks()
- }
- function selectAll(){
- $(':input','#Data')
- .not(':button, :submit, :reset, :hidden')
- .val('')
- .prop('checked', true)
- .prop('selected', true);
- }
- function removeSelectedItems(){
- var removedItems = [];
- $("#Data input[type=checkbox]:checked").each(function(index, data){
- removedItems.push($(data).attr("name"));
- });
-
- if (confirm('Deleting: ' + removedItems)) {
- $("#Data input[type=checkbox]:checked").each(function(index, data){
- //only refresh item list when last item is removed
- deleteDataItem($(data).attr("name"), index === ($("#Data input[type=checkbox]:checked").length -1))
- });
- toggleRemoveLinks()
- }
- }
- function deleteData(datalink) {
- if (confirm('Deleting ' + datalink)) {
- deleteDataItem(datalink)
- }
- }
- function deleteDataItem(datalink, refresh = true) {
- $.ajax({
- type: "DELETE",
- url: "../server/data/" + encodeURIComponent(datalink),
- success: function(res) {
- if(refresh)
- listFolders(datalink.substr(0, datalink.lastIndexOf("/")))
- }
- });
- }
- function copy2Clipboard(datalink) {
- new URL("../storage/" + datalink, document.baseURI).href
- datalink = new URL("../storage/" + datalink, document.baseURI).href;
- const el = document.createElement('textarea');
- el.value = datalink;
- document.body.appendChild(el);
- el.select();
- document.execCommand('copy');
- document.body.removeChild(el);
- }
- function createSymlink(datalink, oldfilename) {
- var filename = prompt("Please enter symlink filename");
-
-
-
- if (filename != null && filename != "") {
- var sendfilename = {"filename": filename, "oldfilename": oldfilename}
- $.ajax({
- type: "POST",
- data: JSON.stringify(sendfilename),
- headers: {"content-id": "list"},
- contentType: "application/json",
- url: "../server/data/" + datalink,
- success: function(res) {
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
- }
-
-
- }
- function rename(datalink, oldfilename) {
- var filename = prompt("Please enter new filename, without file extension.", oldfilename);
-
- if (filename != null && filename != "") {
- var sendfilename = {"link": datalink, "oldfilename": oldfilename, "newfilename": filename}
- $.ajax({
- type: "PUT",
- data: JSON.stringify(sendfilename),
- headers: {"content-id": "list"},
- contentType: "application/json",
- url: "../server/data/" + datalink,
- success: function(res) {
- listFolders(datalink.substr(0, datalink.lastIndexOf("/")))
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
- }
-
-
- }
- function getAllFolders(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
- $('#selectfolders').find('option').remove()
- $('#selectfolders').append("<option>.</option>")
- $.ajax({
- type: "GET",
- url: "../server/allfolders/" + folder,
- async: false,
- dataType: "json",
- success: function(data) {
- $.each( data, function( key, value ) {
- $('#selectfolders').append("<option>" + value.slice(0,-1) +"</option>")
-
- });
- }
- });
- }
- function saveexternalfolder(folder = ""){
- var newFolder = window.prompt("Please enter URL","");
- if (newFolder != null && newFolder != "") {
- $.ajax({
- type: "Post",
- data: JSON.stringify({"folder": newFolder}),
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- async:true,
- url: "../server/externalFolder/",
- success: function(res) {
- }
- });
- }
- }
- function listExternalFolders(folder = ""){
- $('#ExternalFolders').text("");
- if(folder == ""){
- $.ajax({
- type: "GET",
- url: "../server/externalFolder",
- dataType: "json",
- success: function(data) {
- $.each( data, function( key, value ) {
- var clone = document.importNode(document.querySelector('#cpyFolder').content,true);
-
- //remove /
- value = value.slice(0,-1)
- $('[data-class=text]',clone).text(value);
- $('[data-class=link]',clone).attr('onclick','listExternalFolders("' + value + '")');
- $('#ExternalFolders').append(clone);
- });
- }
- });
- }
- else{
- $('#Folders').text("");
-
-
-
- //alert($.get(folder));
-
- /*
- $.ajax({
- type: "GET",
- url: folder,
- crossDomain: true,
- success: function(data) {
- alert(data);
- }
- });
- */
-
- }
-
- //listData(folder)
- }
- var getUrlParameter = function getUrlParameter(sParam) {
- var sPageURL = window.location.search.substring(1),
- sURLVariables = sPageURL.split('&'),
- sParameterName,
- i;
- for (i = 0; i < sURLVariables.length; i++) {
- sParameterName = sURLVariables[i].split('=');
- if (sParameterName[0] === sParam) {
- return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
- }
- }
- return false;
- };
- $(document).ready(function() {
- var path = getUrlParameter('path');
- if(!path){
- path = "";
- }
- listFolders(path);
- //listExternalFolders();
- getAllFolders(path);
- });
|