123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- //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("");
-
- 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);
-
- //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=getLink]',clone).attr('href','javascript:copy2Clipboard("' + fullfolder + '");');
- $('[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 deleteData(datalink) {
- if (confirm('Deleting ' + datalink)) {
- $.ajax({
- type: "DELETE",
- url: "../server/data/" + encodeURIComponent(datalink),
- success: function(res) {
- 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 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)
- }
- $(document).ready(function() {
- listFolders();
- //listExternalFolders();
- getAllFolders();
- });
|