Small FileWriter fix

This commit is contained in:
macdonst 2010-10-28 04:09:13 +08:00
parent 577284b960
commit b7024ad1f5
3 changed files with 837 additions and 219 deletions

View File

@ -350,18 +350,43 @@ FileReader.prototype.readAsBinaryString = function(file) {
*/ */
function FileWriter() { function FileWriter() {
this.fileName = ""; this.fileName = "";
this.result = null;
this.readyState = 0; // EMPTY this.readyState = 0; // EMPTY
this.result = null; this.result = null;
this.onerror = null;
this.oncomplete = null; // Error
this.error = null;
// Event handlers
this.onwritestart = null; // When writing starts
this.onprogress = null; // While writing the file, and reporting partial file data
this.onwrite = null; // When the write has successfully completed.
this.onwriteend = null; // When the request has completed (either in success or failure).
this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
this.onerror = null; // When the write has failed (see errors).
}; };
// States // States
FileWriter.EMPTY = 0; FileWriter.INIT = 0;
FileWriter.LOADING = 1; FileWriter.WRITING = 1;
FileWriter.DONE = 2; FileWriter.DONE = 2;
/**
* Abort writing file.
*/
FileWriter.prototype.abort = function() {
this.readyState = FileWriter.DONE;
// If abort callback
if (typeof this.onabort == "function") {
var evt = File._createEvent("abort", this);
this.onabort(evt);
}
// TODO: Anything else to do? Maybe sent to native?
};
FileWriter.prototype.writeAsText = function(file, text, bAppend) { FileWriter.prototype.writeAsText = function(file, text, bAppend) {
if (bAppend != true) { if (bAppend != true) {
bAppend = false; // for null values bAppend = false; // for null values
@ -369,12 +394,12 @@ FileWriter.prototype.writeAsText = function(file, text, bAppend) {
this.fileName = file; this.fileName = file;
// LOADING state // WRITING state
this.readyState = FileWriter.LOADING; this.readyState = FileWriter.WRITING;
var me = this; var me = this;
// Read file // Write file
navigator.fileMgr.writeAsText(file, text, bAppend, navigator.fileMgr.writeAsText(file, text, bAppend,
// Success callback // Success callback
@ -391,10 +416,16 @@ FileWriter.prototype.writeAsText = function(file, text, bAppend) {
// DONE state // DONE state
me.readyState = FileWriter.DONE; me.readyState = FileWriter.DONE;
// If oncomplete callback // If onwrite callback
if (typeof me.oncomplete == "function") { if (typeof me.onwrite == "function") {
var evt = File._createEvent("complete", me); var evt = File._createEvent("write", me);
me.oncomplete(evt); me.onwrite(evt);
}
// If onwriteend callback
if (typeof me.onwriteend == "function") {
var evt = File._createEvent("writeend", me);
me.onwriteend(evt);
} }
}, },
@ -417,6 +448,12 @@ FileWriter.prototype.writeAsText = function(file, text, bAppend) {
var evt = File._createEvent("error", me); var evt = File._createEvent("error", me);
me.onerror(evt); me.onerror(evt);
} }
// If onwriteend callback
if (typeof me.onwriteend == "function") {
var evt = File._createEvent("writeend", me);
me.onwriteend(evt);
}
} }
); );

View File

@ -19,7 +19,7 @@
*/ */
function Position(coords, timestamp) { function Position(coords, timestamp) {
this.coords = coords; this.coords = coords;
this.timestamp = new Date().getTime(); this.timestamp = (timestamp != 'undefined') ? timestamp : new Date().getTime();
} }
function Coordinates(lat, lng, alt, acc, head, vel, altacc) { function Coordinates(lat, lng, alt, acc, head, vel, altacc) {

File diff suppressed because it is too large Load Diff