data.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <html>
  2. <?php include("header.php") ?>
  3. <style type="text/css">
  4. #resume-upload {
  5. display: none;
  6. }
  7. .upload-info {
  8. margin-left: 10px;
  9. margin-right: 10px;
  10. padding: 5px;
  11. border-bottom: 1px solid gray;
  12. /*border-radius: 10%;*/
  13. /*box-shadow: 0px 3px 5px lightgray;*/
  14. }
  15. .upload-info p {
  16. margin: 0px;
  17. font-family: "Open Sans";
  18. font-size: 12px;
  19. }
  20. </style>
  21. <div class="sidebar">
  22. <!--<button class="add-bucket-modal button"><i class="fa fa-compass"></i> Add New Region</button>-->
  23. <button class="create-project-modal button"><i class="fa fa-plus"></i> Create New Project</button>
  24. <button class="upload-data-modal button"><i class="fa fa-cloud-upload"></i> Upload Data</button>
  25. <div id="active-uploads">
  26. <h1>Unfinished Uploads</h1>
  27. <?php if(empty($active_uploads)) { echo "No current uploads."; } ?>
  28. <?php foreach($active_uploads as $upload) :
  29. $startTimestamp = strtotime($upload['uploadtime']);
  30. ?>
  31. <div class='upload-info'>
  32. <p class="upload-project-name">Project: <?=$upload['project_name']?></p>
  33. <p class="upload-user"> Started by: <span title="<?=$upload['username']?>"><?=$upload['user_name']?></span></p>
  34. <p class="upload-file-count">Files remaining: <?=$upload["count"]?></p>
  35. <p class="upload-started-date">Start date: <?=date("Y-m-d", $startTimestamp)?></p>
  36. <p class="upload-started-time">Start time: <?=date("H:i:s T", $startTimestamp)?></p>
  37. <p class="upload-user"> User: <?=$upload['user_name']?> (<?=$upload['username']?>)</p>
  38. </div>
  39. <?php endforeach; ?>
  40. </div>
  41. </div>
  42. <div class="content">
  43. <div id="message-center"></div>
  44. <table>
  45. <tr>
  46. <th>Id</th>
  47. <th style="width: 160px;">Region</th>
  48. <th style="width: 160px;">Project Folder</th>
  49. <th style="width: 160px;">Display Name</th>
  50. <th style="width: 160px;">Account Access</th>
  51. <th style="width: 160px;">Actions</th>
  52. </tr>
  53. <?php foreach($projects as $project) : ?>
  54. <?php if (empty($project)) continue; ?>
  55. <tr class="display-row">
  56. <td><?=$project['project_id']?></td>
  57. <td><?=$project['bucket']?></td>
  58. <td><?=$project['folder']?></td>
  59. <td><?=$project['display_name']?></td>
  60. <td><?php if(empty($project['clients'])) { echo "no assigned clients"; } else { ?>
  61. <?php foreach($project['clients'] as $client) : ?>
  62. <div class="domain"><?=$client['subdomain']?></div>
  63. <?php endforeach; ?>
  64. <?php }?></td>
  65. <td>
  66. <button class="edit button" data-data="<?=$project['project_id']?>">Edit</button>
  67. </td>
  68. </tr>
  69. <tr class="edit-row">
  70. <td><?=$project['project_id']?></td>
  71. <td>
  72. <select name="bucket" autocomplete="off">
  73. <option>---Region---</option>
  74. <?php foreach($buckets as $bucketValue => $bucketName) : ?>
  75. <option value="<?=$bucketValue?>" <?=($project['bucket'] == $bucketValue) ? 'selected="selected"': ''?>><?=$bucketName?></option>
  76. <?php endforeach; ?>
  77. </select>
  78. </td>
  79. <td><input type="text" name="folder" value="<?=$project['folder']?>" /></td>
  80. <td><input type="text" name="display_name" value="<?=$project['display_name']?>" /></td>
  81. <td><?php if(empty($project['clients'])) { echo "no assigned clients"; } else { ?>
  82. <?php foreach($project['clients'] as $client) : ?>
  83. <div class="domain"><?=$client['subdomain']?><button class="remove-client" data-data="<?=$project['project_id']?>" data-client="<?=$client['client_id']?>">X</button></div>
  84. <?php endforeach; ?>
  85. <?php } ?>
  86. <input type="text" name="subdomain" /><button class="add-client" data-data="<?=$project['project_id']?>">+</button></td>
  87. <td>
  88. <button class="save button" data-data="<?=$project['project_id']?>">Save</button>
  89. <button class="cancel button">Cancel</button>
  90. </td>
  91. </tr>
  92. <?php endforeach; ?>
  93. </table>
  94. </div>
  95. <div class="modal-overlay"></div>
  96. <div class="modal-popup"><button class="modal-close">X</button>
  97. <!-- <form id="add-bucket-form" autocomplete="off" style="display:none;">
  98. <h1>Add Bucket</h1>
  99. <hr />
  100. <div class="modal-message"></div>
  101. <div class="input-row centered"><input name="bucket-name" type="text" placeholder="bucket name" autocomplete="off" /></div>
  102. <div class="input-row centered"><button class="add-bucket">Add Bucket</button></div>
  103. </form> -->
  104. <form id="create-project-form" autocomplete="off" style="display:none;">
  105. <h1>Create New Project</h1>
  106. <hr />
  107. <div class="modal-message"></div>
  108. <div class="input-row centered">
  109. <select name="bucket" autocomplete="off">
  110. <option>---Region---</option>
  111. <?php foreach($buckets as $bucketValue => $bucketName) : ?>
  112. <option value="<?=$bucketValue?>"><?=$bucketName?></option>
  113. <?php endforeach; ?>
  114. </select></div>
  115. <div class="input-row centered"><input name="project" type="text" placeholder="project name" autocomplete="off" /></div>
  116. <div class="input-row centered"><input name="display_name" type="text" placeholder="display name" autocomplete="off" /></div>
  117. <div class="input-row centered"><button class="create-project">Create Project</button></div>
  118. </form>
  119. <form id="upload-data-form" autocomplete="off" style="display:none;" enctype="multipart/form-data">
  120. <h1>Upload Data</h1>
  121. <hr />
  122. <div class="modal-message"></div>
  123. <div class="input-row centered">
  124. <select name="project_id" autocomplete="off"<?=($resume)? ' disabled="disabled"': ""?>>
  125. <option>---Project---</option>
  126. <?php foreach($projects as $project) : ?>
  127. <option value="<?=$project['project_id']?>"><?=$project['display_name']?></option>
  128. <?php endforeach; ?>
  129. </select></div>
  130. <div id="resume-upload" class="input-row centered alert-notification">To resume an upload, please select the previous folder used for this project.
  131. <input type="hidden" name="resume" value="false" />
  132. </div>
  133. <div class="input-row centered drop-zone">
  134. <!--<p>Drop files here</p>-->
  135. <input name="dir" id="dir-input" type="file" webkitdirectory directory multiple/><br/>
  136. <div id="loading-spinner" style="display:none;"><div class="sk-fading-circle"><div class="sk-circle1 sk-circle"></div><div class="sk-circle2 sk-circle"></div><div class="sk-circle3 sk-circle"></div><div class="sk-circle4 sk-circle"></div><div class="sk-circle5 sk-circle"></div><div class="sk-circle6 sk-circle"></div><div class="sk-circle7 sk-circle"></div><div class="sk-circle8 sk-circle"></div><div class="sk-circle9 sk-circle"></div><div class="sk-circle10 sk-circle"></div><div class="sk-circle11 sk-circle"></div><div class="sk-circle12 sk-circle"></div></div></div>
  137. <div class="input-row centered"><button class="upload-data" disabled="disabled">Upload Data</button></div>
  138. <div id="dir-info"></div>
  139. <div id="upload-messages">
  140. <p><span id="progress-number">0</span> files remaining</p>
  141. <div id="upload-console"></div>
  142. <div id="error-messages"></div>
  143. </div>
  144. </div>
  145. </form>
  146. </div>
  147. </body>
  148. <script type="text/javascript" src="/js/resumefilemanager.js"></script>
  149. <script type="text/javascript">
  150. document.addEventListener("DOMContentLoaded", function(event) {
  151. bindButtons();
  152. <?php foreach($abandoned_uploads as $upload): ?>
  153. showUnfinishedUploadDialog(<?=$upload['project_id']?>, "<?=$upload['project_name']?>", "<?=$upload['upload_timestamp']?>", <?=$upload['count']?>);
  154. <?php endforeach; ?>
  155. handleResume(<?=$resume?>);
  156. <?php if($superadmin): ?>
  157. superadminNotice();
  158. <?php endif; ?>
  159. });
  160. function handleResume(projectId) {
  161. if(typeof projectId != typeof undefined) {
  162. var uploadDataForm = document.getElementById("upload-data-form");
  163. var selectFields = uploadDataForm.getElementsByTagName("select");
  164. selectFields.project_id.value = parseInt(projectId);
  165. var inputFields = uploadDataForm.getElementsByTagName("input");
  166. inputFields.resume.value = true;
  167. document.getElementById("resume-upload").style.display = "block";
  168. uploadDataModalButton_click();
  169. //open modal
  170. //select project
  171. //display upload resume message
  172. }
  173. };
  174. function bindButtons() {
  175. // var addBucketModalButton = document.getElementsByClassName("add-bucket-modal")[0];
  176. // addBucketModalButton.addEventListener("click", addBucketModalButton_click);
  177. var createProjectModalButton = document.getElementsByClassName("create-project-modal")[0];
  178. createProjectModalButton.addEventListener("click", createProjectModalButton_click);
  179. var uploadDataModalButton = document.getElementsByClassName("upload-data-modal")[0];
  180. uploadDataModalButton.addEventListener("click", uploadDataModalButton_click);
  181. // var dropZone = document.getElementsByClassName('drop-zone')[0];
  182. // dropZone.addEventListener("dragover", dropZone_drag);
  183. // dropZone.addEventListener("drop", dropZone_drop);
  184. // dropZone.addEventListener("dragenter", dropZone_drag);
  185. // dropZone.addEventListener("dragend", dropZone_dragend);
  186. // dropZone.addEventListener("dragleave", dropZone_dragend);
  187. // dropZone.addEventListener("drop", dropZone_dragend);
  188. var createProjectButton = document.getElementsByClassName("create-project")[0];
  189. createProjectButton.addEventListener("click", createProjectButton_click);
  190. var uploadDataButton = document.getElementsByClassName("upload-data")[0];
  191. uploadDataButton.addEventListener("click", uploadDataButton_click);
  192. var editButtons = document.getElementsByClassName("edit");
  193. for(var i = 0; i < editButtons.length; i++) {
  194. editButtons[i].addEventListener("click", editButton_click);
  195. }
  196. var cancelButtons = document.getElementsByClassName("cancel");
  197. for(var i = 0; i < cancelButtons.length; i++) {
  198. cancelButtons[i].addEventListener("click", cancelButton_click);
  199. }
  200. var saveButtons = document.getElementsByClassName("save");
  201. for(var i = 0; i < saveButtons.length; i++) {
  202. saveButtons[i].addEventListener("click", saveButton_click);
  203. }
  204. var addClientButtons = document.getElementsByClassName("add-client");
  205. for(var i = 0; i < addClientButtons.length; i++) {
  206. addClientButtons[i].addEventListener("click", addClientButton_click);
  207. }
  208. var removeClientButtons = document.getElementsByClassName("remove-client");
  209. for(var i = 0; i < removeClientButtons.length; i++) {
  210. removeClientButtons[i].addEventListener("click", removeClientButton_click);
  211. }
  212. var overlay = document.getElementsByClassName("modal-overlay")[0];
  213. overlay.addEventListener("click", closeModal_click);
  214. var closeModal = document.getElementsByClassName("modal-close")[0];
  215. closeModal.addEventListener("click", closeModal_click);
  216. }
  217. function addBucketModalButton_click(event) {
  218. // document.getElementById("add-bucket-form").style.display = "block";
  219. document.getElementById("upload-data-form").style.display = "none";
  220. document.getElementById("create-project-form").style.display = "none";
  221. var overlay = document.getElementsByClassName("modal-overlay")[0];
  222. var popup = document.getElementsByClassName("modal-popup")[0];
  223. overlay.classList.add("make-visible");
  224. popup.classList.add("make-visible");
  225. }
  226. function createProjectModalButton_click(event) {
  227. // document.getElementById("add-bucket-form").style.display = "none";
  228. document.getElementById("upload-data-form").style.display = "none";
  229. document.getElementById("create-project-form").style.display = "block";
  230. var overlay = document.getElementsByClassName("modal-overlay")[0];
  231. var popup = document.getElementsByClassName("modal-popup")[0];
  232. overlay.classList.add("make-visible");
  233. popup.classList.add("make-visible");
  234. }
  235. function uploadDataModalButton_click(event) {
  236. // document.getElementById("add-bucket-form").style.display = "none";
  237. document.getElementById("upload-data-form").style.display = "block";
  238. document.getElementById("create-project-form").style.display = "none";
  239. var overlay = document.getElementsByClassName("modal-overlay")[0];
  240. var popup = document.getElementsByClassName("modal-popup")[0];
  241. overlay.classList.add("make-visible");
  242. popup.classList.add("make-visible");
  243. }
  244. function createProjectButton_click(event) {
  245. event.preventDefault();
  246. var form = this.parentNode.parentNode;
  247. var inputFields = form.getElementsByTagName("input");
  248. var selectFields = form.getElementsByTagName("select");
  249. var bucket = selectFields.bucket.value;
  250. var project = inputFields.project.value;
  251. var displayName = inputFields.display_name.value;
  252. var postData = {"bucket": bucket, "display_name": displayName, "project": project};
  253. var promise = ajaxPost("/api/addproject", postData);
  254. promise.success = function(response) {
  255. var message = document.getElementsByClassName("modal-message")[0];
  256. if(response.hasOwnProperty("error")) {
  257. message.innerHTML = response.error;
  258. if(response.hasOwnProperty("exception")) {
  259. console.warn(response.exception);
  260. }
  261. } else {
  262. location.reload();
  263. }
  264. };
  265. promise.failure = function(response) {
  266. console.warn("Communication failure", response);
  267. };
  268. }
  269. function uploadDataButton_click(event) {
  270. event.preventDefault();
  271. var form = this.parentNode.parentNode.parentNode;
  272. var inputFields = form.getElementsByTagName("input");
  273. var selectFields = form.getElementsByTagName("select");
  274. var projectId = selectFields.project_id.value;
  275. var isResume = inputFields.resume.value;
  276. var fileList = document.getElementById('dir-input').files;
  277. if(isResume != "true") {
  278. var logData = {};
  279. logData.project_id = projectId;
  280. logData.uploadtime = (new Date()).toISOString();
  281. window.requestAnimationFrame(function() {
  282. writeBatchedLogs(logData, fileList, 0);
  283. });
  284. } else {
  285. fileManager.resumeUpload(projectId);
  286. }
  287. }
  288. function writeBatchedLogs(logData, fileList, offset) {
  289. var batchsize = 500;
  290. uploadLog("Building upload list ("+ Math.min(offset + batchsize, fileList.length) + ")");
  291. var logFileList = [];
  292. for(var i = offset; i < Math.min(offset + batchsize, fileList.length); i++) {
  293. logFileList.push(fileList[i].webkitRelativePath);
  294. }
  295. logData.filelist = JSON.stringify(logFileList);
  296. var promise = ajaxPost("/api/logupload", logData);
  297. promise.success = function(event) {
  298. if(fileList.length > offset+batchsize) {
  299. window.requestAnimationFrame(function() {
  300. writeBatchedLogs(logData, fileList, offset + batchsize);
  301. });
  302. } else {
  303. fileManager.resumeUpload(logData.project_id);
  304. }
  305. };
  306. }
  307. // function uploadComplete() {
  308. // if(parseInt(document.getElementById('progress-number').innerHTML) >= persistentUploadData.restoreCount) {
  309. // var uploadOutput = document.getElementById("upload-messages");
  310. // var completeNode = document.createElement("p");
  311. // completeNode.innerHTML = "Upload complete!";
  312. // uploadOutput.appendChild(completeNode);
  313. // }
  314. // }
  315. // function delayedUploadAwsFile(index, isResume) {
  316. // var file = document.getElementById('dir-input').files[index];
  317. // var projectId = persistentUploadData.uploadProject;
  318. // var data = {};
  319. // data.filePath = file.webkitRelativePath;
  320. // data.fileType = file.type;
  321. // data.project_id = projectId;
  322. // data.resume = isResume;
  323. // var promise = ajaxPost("/api/putfileaccesstoken", data);
  324. // promise.success = function(authEvent) {
  325. // if(authEvent.status == 2) {
  326. // //subtract value from total files
  327. // persistentUploadData.restoreCount--;
  328. // document.getElementById('total-files').innerHTML = persistentUploadData.restoreCount;
  329. // if(index + 10 < persistentUploadData.uploadCount) {
  330. // window.requestAnimationFrame(function() {
  331. // delayedUploadAwsFile(index + 10, isResume);
  332. // });
  333. // } else {
  334. // uploadComplete();
  335. // }
  336. // return;
  337. // }
  338. // var fileList2 = document.getElementById('dir-input').files;
  339. // fileReader = new FileReader();
  340. // fileReader.onload = function(fileEvent) {
  341. // var fileData = fileEvent.target.result;
  342. // var contentType = file.type;
  343. // var headers = authEvent.headers;
  344. // headers['content-type'] = contentType;
  345. // var putPromise = ajaxPut(authEvent.url, fileData, headers);
  346. // putPromise.success = function(event) {
  347. // document.getElementById("progress-number").innerHTML = parseInt(document.getElementById("progress-number").innerHTML) + 1;
  348. // var data = {"project_id": projectId, "filepath": file.webkitRelativePath};
  349. // ajaxPost('/api/confirmupload', data);
  350. // };
  351. // putPromise.failure = function(event) {
  352. // var errorOutput = document.getElementById("upload-messages");
  353. // var errorNode = document.createElement("p");
  354. // errorNode.innerHTML = "Failed to upload " + authEvent.clean_file + ".";
  355. // errorOutput.appendChild(errorNode);
  356. // console.error("Failed to upload " + authEvent.clean_file + ".");
  357. // //save take url, fileData and headers
  358. // persistentUploadData.uploadError.push(index);
  359. // };
  360. // putPromise.finally = function(event) {
  361. // var errorIndex = persistentUploadData.uploadError.indexOf(index);
  362. // if(errorIndex > -1) {
  363. // persistentUploadData.uploadError.splice(errorIndex, 1);
  364. // window.requestAnimationFrame(function() {
  365. // delayedUploadAwsFile(index, isResume);
  366. // });
  367. // }
  368. // if(index + 10 < persistentUploadData.uploadCount) {
  369. // window.requestAnimationFrame(function() {
  370. // delayedUploadAwsFile(index + 10, isResume);
  371. // });
  372. // } else {
  373. // uploadComplete();
  374. // }
  375. // }
  376. // };
  377. // fileReader.readAsArrayBuffer(file);
  378. // };
  379. // promise.failure = function(event) {
  380. // var errorOutput = document.getElementById("upload-messages");
  381. // var errorNode = document.createElement("p");
  382. // errorNode.innerHTML = "Failed to get auth token for " + authEvent.clean_file + ".";
  383. // errorOutput.appendChild(errorNode);
  384. // console.error("Failed to get auth token for " + authEvent.clean_file + ".");
  385. // };
  386. // }
  387. // function resumeUploadAwsFile(index, filesToResume) {
  388. // var file = document.getElementById('dir-input').files[index];
  389. // var projectId = persistentUploadData.uploadProject;
  390. // var data = {};
  391. // data.filePath = file.webkitRelativePath;
  392. // data.fileType = file.type;
  393. // data.project_id = projectId;
  394. // data.resume = true;
  395. // if(filesToResume.indexOf(data.filePath) == -1) {
  396. // //file is duplicate
  397. // if(index + 10 < persistentUploadData.uploadCount) {
  398. // window.requestAnimationFrame(function() {
  399. // resumeUploadAwsFile(index + 10, filesToResume);
  400. // });
  401. // } else {
  402. // uploadComplete();
  403. // }
  404. // return;
  405. // }
  406. // filesToResume.splice(data.filePath, 1);
  407. // var promise = ajaxPost("/api/putfileaccesstoken", data);
  408. // promise.success = function(authEvent) {
  409. // if(authEvent.status == 2) {
  410. // //subtract value from total files
  411. // persistentUploadData.restoreCount--;
  412. // document.getElementById('total-files').innerHTML = persistentUploadData.restoreCount;
  413. // if(index + 10 < persistentUploadData.uploadCount) {
  414. // window.requestAnimationFrame(function() {
  415. // resumeUploadAwsFile(index + 10, filesToResume);
  416. // });
  417. // } else {
  418. // uploadComplete();
  419. // }
  420. // return;
  421. // }
  422. // var fileList2 = document.getElementById('dir-input').files;
  423. // fileReader = new FileReader();
  424. // fileReader.onload = function(fileEvent) {
  425. // var fileData = fileEvent.target.result;
  426. // var headers = authEvent.headers;
  427. // var putPromise = ajaxPut(authEvent.url, fileData, headers);
  428. // putPromise.success = function(event) {
  429. // document.getElementById("progress-number").innerHTML = parseInt(document.getElementById("progress-number").innerHTML) + 1;
  430. // var data = {"project_id": projectId, "filepath": file.webkitRelativePath};
  431. // ajaxPost('/api/confirmupload', data);
  432. // document.getElementById("loading-spinner").style.display="none";
  433. // };
  434. // putPromise.failure = function(event) {
  435. // var errorOutput = document.getElementById("upload-messages");
  436. // var errorNode = document.createElement("p");
  437. // errorNode.innerHTML = "Failed to upload " + authEvent.clean_file + ".";
  438. // errorOutput.appendChild(errorNode);
  439. // console.error("Failed to upload " + authEvent.clean_file + ".");
  440. // //save take url, fileData and headers
  441. // persistentUploadData.uploadError.push(index);
  442. // };
  443. // putPromise.finally = function(event) {
  444. // var errorIndex = persistentUploadData.uploadError.indexOf(index);
  445. // if(errorIndex > -1) {
  446. // persistentUploadData.uploadError.splice(errorIndex, 1);
  447. // window.requestAnimationFrame(function() {
  448. // resumeUploadAwsFile(index, filesToResume);
  449. // });
  450. // }
  451. // if(index + 10 < persistentUploadData.uploadCount) {
  452. // window.requestAnimationFrame(function() {
  453. // resumeUploadAwsFile(index + 10, filesToResume);
  454. // });
  455. // } else {
  456. // uploadComplete();
  457. // }
  458. // }
  459. // };
  460. // fileReader.readAsArrayBuffer(file);
  461. // };
  462. // promise.failure = function(event) {
  463. // var errorOutput = document.getElementById("upload-messages");
  464. // var errorNode = document.createElement("p");
  465. // errorNode.innerHTML = "Failed to get auth token for " + authEvent.clean_file + ".";
  466. // errorOutput.appendChild(errorNode);
  467. // console.error("Failed to get auth token for " + authEvent.clean_file + ".");
  468. // };
  469. // }
  470. function readableFileSize(rawsize) {
  471. var readable = "";
  472. if (rawsize > 1024 * 1024 * 1024) {
  473. readable = (Math.round(rawsize * 100 / (1024 * 1024 * 1024)) / 100).toString() + ' GB';
  474. } else if (rawsize > 1024 * 1024) {
  475. readable = (Math.round(rawsize * 100 / (1024 * 1024)) / 100).toString() + ' MB';
  476. } else if (rawsize > 1024) {
  477. readable = (Math.round(rawsize * 100 / 1024) / 100).toString() + ' KB';
  478. } else {
  479. readable = rawsize + ' bytes';
  480. }
  481. return readable;
  482. }
  483. // function printFiles(e) {
  484. // var fileList = document.getElementById('dir-input').files;
  485. // var total = 0;
  486. // for (var i = 0, file; file = fileList[i]; i++) {
  487. // total += file.size;
  488. // }
  489. // document.getElementById('dir-info').innerHTML = "Total size: " + readableFileSize(total);
  490. // document.getElementById('progress-number').innerHTML = 0;
  491. // document.getElementById('total-files').innerHTML = fileList.length;
  492. // }
  493. document.getElementById('dir-input').addEventListener("click", function() {
  494. document.getElementById("loading-spinner").style.display="block";
  495. });
  496. document.getElementById('dir-input').addEventListener("change", function() {
  497. fileManager.process();
  498. document.getElementById("loading-spinner").style.display="none";
  499. document.getElementsByClassName("upload-data")[0].disabled = false;
  500. });
  501. function addClientButton_click(event) {
  502. var projectId = this.getAttribute("data-data");
  503. var inputFields = this.parentNode.getElementsByTagName("input");
  504. var subdomain = inputFields.subdomain.value;
  505. var postData = {"project_id": projectId, "subdomain": subdomain};
  506. var promise = ajaxPost("/api/addprojecttoaccount", postData);
  507. promise.success = function(response) {
  508. location.reload();
  509. };
  510. promise.failure = function(response) {
  511. console.warn("Communication failure", response);
  512. };
  513. }
  514. function removeClientButton_click(event) {
  515. var projectId = this.getAttribute("data-data");
  516. var clientId = this.getAttribute("data-client");
  517. var postData = {"project_id": projectId, "client_id": clientId};
  518. var promise = ajaxPost("/api/removeprojectfromaccount", postData);
  519. promise.success = function(response) {
  520. location.reload();
  521. };
  522. promise.failure = function(response) {
  523. console.warn("Communication failure", response);
  524. };
  525. }
  526. function editButton_click(event) {
  527. this.parentNode.parentNode.style="display: none";
  528. this.parentNode.parentNode.nextElementSibling.style="display: table-row";
  529. }
  530. function cancelButton_click(event) {
  531. this.parentNode.parentNode.style="display: none";
  532. this.parentNode.parentNode.previousElementSibling.style="display: table-row";
  533. }
  534. function saveButton_click(event) {
  535. this.parentNode.parentNode.style.display="none";
  536. this.parentNode.parentNode.previousElementSibling.style.display="table-row";
  537. var projectId = this.getAttribute("data-data");
  538. var inputFields = this.parentNode.parentNode.getElementsByTagName("input");
  539. var selectFields = this.parentNode.parentNode.getElementsByTagName("select");
  540. var bucket = selectFields.bucket.value;
  541. var folder = inputFields.folder.value;
  542. var displayName = inputFields.display_name.value;
  543. var postData = {};
  544. postData.project_id = projectId;
  545. postData.bucket = bucket;
  546. postData.folder = folder;
  547. postData.display_name = displayName;
  548. var promise = ajaxPost("/api/editproject", postData);
  549. promise.success = function(response) {
  550. // //TODO: instead of reload, update display section
  551. location.reload();
  552. };
  553. promise.failure = function(response) {
  554. console.warn("Communication failure", response);
  555. };
  556. }
  557. function closeModal_click(event) {
  558. var overlay = document.getElementsByClassName("modal-overlay")[0];
  559. var popup = document.getElementsByClassName("modal-popup")[0];
  560. overlay.classList.remove("make-visible");
  561. popup.classList.remove("make-visible");
  562. }
  563. </script>
  564. </html>