json indent, change json format, implement load json file
This commit is contained in:
parent
589694e376
commit
ecd4e695cd
|
@ -22,7 +22,7 @@ body {
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
#notesArea {
|
#notes {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
height: 600px;
|
height: 600px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
<button id="saveLocationBtn">Select Output Folder</button>
|
<button id="saveLocationBtn">Select Output Folder</button>
|
||||||
<button id="selectAudioFile">Select Audio File</button>
|
<button id="selectAudioFile">Select Audio File</button>
|
||||||
<button id="saveFormData">Save Metadata</button>
|
<button id="saveFormData">Save Metadata</button>
|
||||||
|
<button id="loadData">Load Data</button>
|
||||||
</div>
|
</div>
|
||||||
<div style="clear:both;"></div>
|
<div style="clear:both;"></div>
|
||||||
<form id="metadataForm" action="" method="GET">
|
<form id="metadataForm" action="" method="GET">
|
||||||
|
@ -70,7 +71,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="rightForm">
|
<div id="rightForm">
|
||||||
<textarea id="notesArea"></textarea>
|
<textarea name="notes" id="notes"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// vim: et:ts=2:sw=2:sts=2:ft=js
|
||||||
|
|
||||||
var startTime = new Date();
|
var startTime = new Date();
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
@ -10,21 +12,42 @@ $(function() {
|
||||||
if (savePath === '') { alert("Please select a save location first."); return false; }
|
if (savePath === '') { alert("Please select a save location first."); return false; }
|
||||||
fil = selectFile();
|
fil = selectFile();
|
||||||
// alert(savePath);
|
// alert(savePath);
|
||||||
var destName = getDateString(startTime) + ".mp3";
|
var destName = getDateString(startTime) + "." + getFileNameExt(fil.file.path);
|
||||||
mozillaCopyFile(fil.file.path, savePath, destName);
|
mozillaCopyFile(fil.file.path, savePath, destName);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#saveFormData').click(function() {
|
$('#saveFormData').click(function() {
|
||||||
if (savePath === '') { alert("Please select a save location first."); return false; }
|
if (savePath === '') { alert("Please select a save location first."); return false; }
|
||||||
var arr = $('#metadataForm').serializeArray();
|
var arr = $('#metadataForm').serializeObject();
|
||||||
var s = JSON.stringify(arr);
|
var s = JSON.stringify(arr, null, 2);
|
||||||
// alert(s);
|
// alert(s);
|
||||||
var destFilePath = savePath + "/" + getDateString(startTime) + ".json";
|
var destFilePath = savePath + "/" + getDateString(startTime) + ".json";
|
||||||
// alert(destFilePath);
|
// alert(destFilePath);
|
||||||
mozillaSaveFile(destFilePath, s);
|
mozillaSaveFile(destFilePath, s);
|
||||||
alert("saved " + destFilePath);
|
alert("saved " + destFilePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#loadData').click(function() {
|
||||||
|
var txtFile = selectFile().file.path;
|
||||||
|
var txt = mozillaLoadFile(txtFile);
|
||||||
|
var data = JSON.parse(txt);
|
||||||
|
loadFormData(data);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getDateString(dateObj) {
|
function getDateString(dateObj) {
|
||||||
return dateObj.toUTCString().replace(",", "").replace(":", ".");
|
return dateObj.toUTCString().replace(",", "").replace(":", ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadFormData(data) {
|
||||||
|
for (var key in data) {
|
||||||
|
if (data.hasOwnProperty(key)) {
|
||||||
|
var value = data[key];
|
||||||
|
if (value === "on") {
|
||||||
|
$('#' + key).attr("checked", "checked");
|
||||||
|
} else {
|
||||||
|
$('#' + key).val(data[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -260,3 +260,21 @@ function getFileNameSansExt(filename) {
|
||||||
return filenameSansExt;
|
return filenameSansExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$.fn.serializeObject = function()
|
||||||
|
{
|
||||||
|
var o = {};
|
||||||
|
var a = this.serializeArray();
|
||||||
|
$.each(a, function() {
|
||||||
|
if (o[this.name] !== undefined) {
|
||||||
|
if (!o[this.name].push) {
|
||||||
|
o[this.name] = [o[this.name]];
|
||||||
|
}
|
||||||
|
o[this.name].push(this.value || '');
|
||||||
|
} else {
|
||||||
|
o[this.name] = this.value || '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user