ustore.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. //delete = delets from DB
  2. //remove = removes from HTML
  3. //save = save to DB
  4. //add = changes HTML
  5. //get = get from DB
  6. //new = changes HTML
  7. //CrossSiteReference needed for WAS
  8. var test = {};
  9. var ref = $(test);
  10. $(document).on('change', '#selectfolders', function(e) {
  11. //getFolders(this.options[e.target.selectedIndex].text);
  12. listFolders(this.options[e.target.selectedIndex].text);
  13. });
  14. function listFolders(folder = ""){
  15. $('#Folders').text("");
  16. $('#CurFolder').text("");
  17. getAllFolders();
  18. if(folder != "" && folder != "." && folder != ".."){
  19. $("#selectfolders").val(folder);
  20. }
  21. else{
  22. $("#selectfolders").val(".");
  23. }
  24. $.ajax({
  25. type: "GET",
  26. url: "../server/folders/" + folder,
  27. dataType: "json",
  28. success: function(data) {
  29. if(folder != "" && folder != "." && folder != ".."){
  30. var clone = document.importNode(document.querySelector('#cpyFolder').content,true);
  31. $('[data-class=text]',clone).text("..");
  32. $('[data-class=link]',clone).attr('onclick','listFolders("' + folder.substr(0, folder.lastIndexOf("/")) + '")');
  33. // dont show remove link on .. folder
  34. $('[data-class=removefolder]',clone).remove()
  35. $('#Folders').append(clone);
  36. }
  37. $.each( data, function( key, value ) {
  38. var clone = document.importNode(document.querySelector('#cpyFolder').content,true);
  39. //remove /
  40. value = value.slice(0,-1)
  41. $('[data-class=text]',clone).text(value);
  42. if(folder == ""){
  43. $('[data-class=link]',clone).attr('onclick','listFolders("' + value + '")');
  44. $('[data-class=removefolder]',clone).attr('onclick','deleteFolder("' + value + '")');
  45. }
  46. else{
  47. $('[data-class=link]',clone).attr('onclick','listFolders("' + folder + "/" + value + '")');
  48. $('[data-class=removefolder]',clone).attr('onclick','deleteFolder("' + folder + "/" + value + '")');
  49. }
  50. $('#Folders').append(clone);
  51. });
  52. //new Folder
  53. var clone = document.importNode(document.querySelector('#cpyFolderNew').content,true);
  54. $('[data-class=text]',clone).text("+");
  55. $('[data-class=link]',clone).attr('onclick','createFolder("' + folder + '")');
  56. $('#Folders').append(clone);
  57. }
  58. });
  59. listData(folder)
  60. }
  61. function createFolder(folder = ""){
  62. var newFolder = window.prompt("Please enter a folder name.","");
  63. if (newFolder != null && newFolder != "") {
  64. $.ajax({
  65. type: "Post",
  66. url: "../server/folders/" + folder + "/" + newFolder,
  67. success: function(res) {
  68. listFolders(folder)
  69. }
  70. });
  71. }
  72. }
  73. function deleteFolder(datalink) {
  74. if (datalink != "" && datalink != "." && datalink != ".." && confirm('Deleting ' + datalink)) {
  75. $.ajax({
  76. type: "DELETE",
  77. url: "../server/folders/" + datalink,
  78. success: function(res) {
  79. listFolders(datalink.substr(0, datalink.lastIndexOf("/")))
  80. }
  81. });
  82. }
  83. }
  84. function listData(folder = ""){
  85. $('#Data').text("");
  86. const imageext = ["png", "jpg", "svg", "JPG", "PNG", "SVG"]
  87. const movieext = ["mp4"]
  88. $('#imgUpload').attr("action", "../server/data/" + folder);
  89. $.ajax({
  90. type: "GET",
  91. url: "../server/images/" + folder,
  92. dataType: "json",
  93. success: function(data) {
  94. $.each( data, function( key, value ) {
  95. var ext = value.substr(value.lastIndexOf('.') + 1);
  96. if(folder == ""){
  97. fullfolder = value
  98. }
  99. else{
  100. fullfolder = folder + "/" + value;
  101. }
  102. var clone = document.importNode(document.querySelector('#DataItem').content,true);
  103. $('[data-class=name]',clone).text(value);
  104. //Image
  105. if(imageext.includes(ext)){
  106. $('[data-class=image]',clone).append("<img src='./../storage/"+ fullfolder + "' alt=''>")
  107. }
  108. else if(movieext.includes(ext)){
  109. $('[data-class=image]',clone).append("<div class='imageAlternative' style='padding-top: 0.12em;'>▶</div>")
  110. }
  111. else{
  112. $('[data-class=image]',clone).append("<div class='imageAlternative'>🗎</div>")
  113. }
  114. $('[data-class=image]',clone).attr('onclick',"overlayOn('" + fullfolder + "')");
  115. $('[data-class=inspect]',clone).attr('href','../storage/' + fullfolder + '');
  116. $('[data-class=delete]',clone).attr('href','javascript:deleteData("' + fullfolder + '");');
  117. $('[data-class=getLink]',clone).attr('href','javascript:copy2Clipboard("' + fullfolder + '");');
  118. $('[data-class=createSymlink]',clone).attr('href','javascript:createSymlink("' + fullfolder + '", "' + value.slice(0, - (ext.length +1)) +'");');
  119. var queryString = window.location.search;
  120. var urlParams = new URLSearchParams(queryString);
  121. if(urlParams.has('iframe')){
  122. $('[data-class=eventTrigger]',clone).css("visibility", "visible")
  123. $('[data-class=eventTrigger]',clone).attr('href','javascript:triggerEvent("' + fullfolder + '");');
  124. console.log("I am an Iframe")
  125. }
  126. $('#Data').append(clone);
  127. });
  128. }
  129. });
  130. if(folder != "" && folder != "." && folder != ".."){
  131. $('#RemoveFolder').css("display", "block")
  132. $('#removeFolderLink').attr('href','javascript:deleteFolder("' + folder + '");');
  133. }
  134. else{
  135. $('#RemoveFolder').css("display", "none")
  136. }
  137. }
  138. function triggerEvent(data) {
  139. //get url
  140. var datalink = new URL("../storage/" + data, document.baseURI).href;
  141. ref = $(test);
  142. setTimeout(function(){
  143. ref.triggerHandler('getUrl', {"url": datalink});
  144. },500);
  145. }
  146. function overlayOn(data) {
  147. var url = new URL("../storage/" + data, document.baseURI).href
  148. document.getElementById("overlay").style.display = "block";
  149. const imageext = ["png", "jpg", "svg", "PNG", "JPG", "SVG"]
  150. const movieext = ["mp4"]
  151. var ext = url.substr(url.lastIndexOf('.') + 1);
  152. if(imageext.includes(ext)){
  153. $('#overlaycontentsize').append("<img id='overlaycontent' src=" + url + "></img>");
  154. }
  155. else if(movieext.includes(ext)){
  156. $('#overlaycontentsize').append("<video id='overlaycontent' controls> <source src=" + url + " type=\"video/mp4\">Your browser does not support the video tag.</video>");
  157. }
  158. else{
  159. $('#overlaycontentsize').append("<iframe id='overlaycontent' src=" + url + "></iframe>");
  160. }
  161. }
  162. function overlayOff() {
  163. document.getElementById("overlay").style.display = "none";
  164. $('#overlaycontentsize').text("");
  165. }
  166. function deleteData(datalink) {
  167. if (confirm('Deleting ' + datalink)) {
  168. $.ajax({
  169. type: "DELETE",
  170. url: "../server/data/" + encodeURIComponent(datalink),
  171. success: function(res) {
  172. listFolders(datalink.substr(0, datalink.lastIndexOf("/")))
  173. }
  174. });
  175. }
  176. }
  177. function copy2Clipboard(datalink) {
  178. new URL("../storage/" + datalink, document.baseURI).href
  179. datalink = new URL("../storage/" + datalink, document.baseURI).href;
  180. const el = document.createElement('textarea');
  181. el.value = datalink;
  182. document.body.appendChild(el);
  183. el.select();
  184. document.execCommand('copy');
  185. document.body.removeChild(el);
  186. }
  187. function createSymlink(datalink, oldfilename) {
  188. var filename = prompt("Please enter symlink filename");
  189. if (filename != null && filename != "") {
  190. var sendfilename = {"filename": filename, "oldfilename": oldfilename}
  191. $.ajax({
  192. type: "POST",
  193. data: JSON.stringify(sendfilename),
  194. headers: {"content-id": "list"},
  195. contentType: "application/json",
  196. url: "../server/data/" + datalink,
  197. success: function(res) {
  198. },
  199. error: function (request, status, error) {
  200. alert(request.responseText + status + error);
  201. }
  202. });
  203. }
  204. }
  205. function getAllFolders(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
  206. $('#selectfolders').find('option').remove()
  207. $('#selectfolders').append("<option>.</option>")
  208. $.ajax({
  209. type: "GET",
  210. url: "../server/allfolders/" + folder,
  211. async: false,
  212. dataType: "json",
  213. success: function(data) {
  214. $.each( data, function( key, value ) {
  215. $('#selectfolders').append("<option>" + value.slice(0,-1) +"</option>")
  216. });
  217. }
  218. });
  219. }
  220. function saveexternalfolder(folder = ""){
  221. var newFolder = window.prompt("Please enter URL","");
  222. if (newFolder != null && newFolder != "") {
  223. $.ajax({
  224. type: "Post",
  225. data: JSON.stringify({"folder": newFolder}),
  226. contentType: "application/json; charset=utf-8",
  227. dataType: "json",
  228. async:true,
  229. url: "../server/externalFolder/",
  230. success: function(res) {
  231. }
  232. });
  233. }
  234. }
  235. function listExternalFolders(folder = ""){
  236. $('#ExternalFolders').text("");
  237. if(folder == ""){
  238. $.ajax({
  239. type: "GET",
  240. url: "../server/externalFolder",
  241. dataType: "json",
  242. success: function(data) {
  243. $.each( data, function( key, value ) {
  244. var clone = document.importNode(document.querySelector('#cpyFolder').content,true);
  245. //remove /
  246. value = value.slice(0,-1)
  247. $('[data-class=text]',clone).text(value);
  248. $('[data-class=link]',clone).attr('onclick','listExternalFolders("' + value + '")');
  249. $('#ExternalFolders').append(clone);
  250. });
  251. }
  252. });
  253. }
  254. else{
  255. $('#Folders').text("");
  256. //alert($.get(folder));
  257. /*
  258. $.ajax({
  259. type: "GET",
  260. url: folder,
  261. crossDomain: true,
  262. success: function(data) {
  263. alert(data);
  264. }
  265. });
  266. */
  267. }
  268. //listData(folder)
  269. }
  270. $(document).ready(function() {
  271. listFolders();
  272. //listExternalFolders();
  273. getAllFolders();
  274. });