file i/o works

This commit is contained in:
Sanj 2011-05-25 01:34:48 +05:30
parent f65741fa97
commit 8b671f7f75
3 changed files with 105 additions and 5 deletions

View File

@ -7,6 +7,7 @@
<link rel="stylesheet" type="text/css" href="speedtag.css" />
</head>
<body>
<div id="wrapper">
<div id="buttons">
<button id="saveLocationBtn">Select Output Folder</button>
@ -14,8 +15,9 @@
<button id="saveFormData">Save Metadata</button>
</div>
<div style="clear:both;"></div>
<div id="leftForm">
<form id="metadataForm" action="" method="GET">
<div id="leftForm">
<table id="formTable">
<tr>
<td class="formLabel optional">
@ -25,14 +27,54 @@
<input type="text" name="witnessName" id="witnessName" />
</td>
</tr>
<tr>
<td class="formLabel optional">
Is Secret:
</td>
<td class="formInput">
<input type="checkbox" name="isSecret" id="isSecret" />
</td>
</tr>
<tr>
<td class="formLabel optional">
Gender:
</td>
<td class="formInput">
<select name="gender" id="gender">
<option selected="selected" value="M">M</option>
<option value="F">F</option>
</select>
</td>
</tr>
<tr>
<td class="formLabel optional">
Marital Status:
</td>
<td class="formInput">
<select name="maritalStatus" id="maritalStatus">
<option selected="selected" value="Single">Single</option>
<option value="Married">Married</option>
</select>
</td>
</tr>
<tr>
<td class="formLabel optional">
Profession:
</td>
<td class="formInput">
<input type="text" name="profession" id="profession" />
</td>
</tr>
</table>
</form>
</div>
<div id="rightForm">
<textarea id="notesArea"></textarea>
</div>
</form>
</div>
</body>
</html>

View File

@ -1,11 +1,30 @@
var startTime = new Date();
$(function() {
var savePath = '';
$('#saveLocationBtn').click(function() {
savePath = selectFile();
savePath = mozillaSelectFolder().file.path;
// alert(savePath.file.path);
});
$('#selectAudioFile').click(function() {
if (savePath === '') { alert("Please select a save location first."); return false; }
fil = selectFile();
data = mozillaLoadFile(fil);
mozillaSaveFile("/tmp/blah.mp3", data);
// alert(savePath);
var destName = getDateString(startTime) + ".mp3";
mozillaCopyFile(fil.file.path, savePath, destName);
});
$('#saveFormData').click(function() {
if (savePath === '') { alert("Please select a save location first."); return false; }
var arr = $('#metadataForm').serializeArray();
var s = JSON.stringify(arr);
// alert(s);
var destFilePath = savePath + "/" + getDateString(startTime) + ".json";
// alert(destFilePath);
mozillaSaveFile(destFilePath, s);
alert("saved " + destFilePath);
});
});
function getDateString(dateObj) {
return dateObj.toUTCString().replace(",", "").replace(":", ".");
}

View File

@ -126,6 +126,25 @@ function mozillaSaveFile(filePath,content)
return null;
}
function mozillaSelectFolder() {
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
fp.init(window, "Select Save Folder", Components.interfaces.nsIFilePicker.modeGetFolder);
var rv = fp.show();
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
// alert("hoo");
return fp;
/*
var file = fp.file;
var path = fp.file.path;
return path;
*/
} else {
// alert("ho");
}
return false;
}
function mozillaSaveAs() {
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
@ -186,6 +205,26 @@ function mozillaLoadFile(filePath)
return null;
}
function mozillaCopyFile(sourcePath, destPath, destName) {
if (window.Components) {
try {
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
// alert(sourcePath);
file.initWithPath(sourcePath);
// file.copyTo(destPath);
var dest = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
dest.initWithPath(destPath);
file.copyTo(dest, destName);
alert("copied to " + destPath + "/" + destName);
return true;
} catch(ex) {
alert(ex);
return false;
}
} else {
return null;
}
}
function checkFileExists(filePath) {
if(window.Components) {