Browse Source

json indent, change json format, implement load json file

master
Sanj 13 years ago
parent
commit
ecd4e695cd
  1. 2
      chrome/content/speedtag.css
  2. 3
      chrome/content/speedtag.html
  3. 29
      chrome/content/speedtag.js
  4. 18
      chrome/content/staticfuncs.js

2
chrome/content/speedtag.css

@ -22,7 +22,7 @@ body {
float: left;
}
#notesArea {
#notes {
width: 90%;
height: 600px;
}

3
chrome/content/speedtag.html

@ -13,6 +13,7 @@
<button id="saveLocationBtn">Select Output Folder</button>
<button id="selectAudioFile">Select Audio File</button>
<button id="saveFormData">Save Metadata</button>
<button id="loadData">Load Data</button>
</div>
<div style="clear:both;"></div>
<form id="metadataForm" action="" method="GET">
@ -70,7 +71,7 @@
</div>
<div id="rightForm">
<textarea id="notesArea"></textarea>
<textarea name="notes" id="notes"></textarea>
</div>
</form>
</div>

29
chrome/content/speedtag.js

@ -1,3 +1,5 @@
// vim: et:ts=2:sw=2:sts=2:ft=js
var startTime = new Date();
$(function() {
@ -10,21 +12,42 @@ $(function() {
if (savePath === '') { alert("Please select a save location first."); return false; }
fil = selectFile();
// alert(savePath);
var destName = getDateString(startTime) + ".mp3";
var destName = getDateString(startTime) + "." + getFileNameExt(fil.file.path);
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);
var arr = $('#metadataForm').serializeObject();
var s = JSON.stringify(arr, null, 2);
// alert(s);
var destFilePath = savePath + "/" + getDateString(startTime) + ".json";
// alert(destFilePath);
mozillaSaveFile(destFilePath, s);
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) {
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]);
}
}
}
}

18
chrome/content/staticfuncs.js

@ -260,3 +260,21 @@ function getFileNameSansExt(filename) {
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…
Cancel
Save