mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 09:52:34 +01:00
Added very simple file manager to manage local data
This commit is contained in:
parent
cbfdbae209
commit
d267ec658b
2 changed files with 84 additions and 0 deletions
56
web/app/filemanager.js
Normal file
56
web/app/filemanager.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
var showThesketches = 0
|
||||
function showsketches(cb) {
|
||||
showThesketches = cb.checked;
|
||||
updatelistbox();
|
||||
}
|
||||
|
||||
|
||||
function updatelistbox()
|
||||
{
|
||||
document.getElementById("filelist").options.length = 0;
|
||||
for(var i in localStorage)
|
||||
{
|
||||
console.log(localStorage[i]);
|
||||
}
|
||||
|
||||
//test for firefox 3.6 see if it works
|
||||
//with this way of iterating it
|
||||
for(var i=0, len=localStorage.length; i<len; i++) {
|
||||
var key = localStorage.key(i);
|
||||
var value = localStorage[key];
|
||||
console.log(key + " => " + value);
|
||||
|
||||
|
||||
|
||||
if (localStorage.key(i).search("sketch") <0 | showThesketches)
|
||||
{
|
||||
var x = document.getElementById("filelist");
|
||||
var option = document.createElement("option");
|
||||
option.text = localStorage.key(i);
|
||||
x.add(option);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function deleteItem()
|
||||
{
|
||||
var filetodelete = document.getElementById("filelist").options[document.getElementById("filelist").selectedIndex].text;
|
||||
var arr = []; // Array to hold the keys
|
||||
// Iterate over localStorage and insert the keys that meet the condition into arr
|
||||
for (var i = 0; i < localStorage.length; i++){
|
||||
if (localStorage.key(i).startsWith(filetodelete)) {
|
||||
arr.push(localStorage.key(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate over arr and remove the items by key
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
localStorage.removeItem(arr[i]);
|
||||
}
|
||||
updatelistbox();
|
||||
}
|
||||
28
web/filemanager.htm
Normal file
28
web/filemanager.htm
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>TCAD</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="css/toolkit.css?modeler">
|
||||
<link rel="stylesheet" href="lib/font-awesome/css/font-awesome.min.css?modeler">
|
||||
<script src="app/filemanager.js"></script>
|
||||
|
||||
<script src="lib/jquery-2.1.0.min.js"></script>
|
||||
|
||||
|
||||
</head>
|
||||
<body onload="updatelistbox();">
|
||||
<div>
|
||||
<button onclick="deleteItem()">Delete</button>
|
||||
Show Sketches<input type="checkbox" id="showsketches" onclick='showsketches(this);'><br>
|
||||
<select id = 'filelist' size="50"> </select>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in a new issue