HTML and CSS Reference
In-Depth Information
});
};
reader.onerror = function(evt) {
errorLogger('cannot_read_file', 'The file specified cannot be read');
};
reader.readAsText(event.target.files[0]);
}
After we read each line from the CSV, we send it to another function called loadTask which
tokenizes it using the CSV library, and constructs a task.
Notice also that we skip the first line in the file (since it is the header line), along with any
empty lines by using the following code:
if (indx >= 1 && val) {
We now have an array of tasks that we wish to save. At this point it may be worth adding
another method to our storage engines that performs a saveAll operation. This would mean
we can leverage transaction support in the underlying storage API (if available) to make
sure either all the tasks are persisted or none are. The saveAll method will return all the
objects saved in the transaction.
The following is the saveAll implementation in tasks-webstorage.js (it does not provide
transaction support):
saveAll : function(type, objs, successCallback, errorCallback) {
if (!initialized) {
errorCallback('storage_api_not_initialized', 'The storage engine has not been initialized');
} else if (!initializedTables[type]) {
errorCallback('table_not_initialized', 'The table '+type+' has not been initialized');
}
var storageItem = getStorageObject(type);
$.each(objs, function(indx, obj) {
if (!obj.id) {
obj.id = $.now();
}
storageItem[obj.id] = obj;
localStorage.setItem(type, JSON.stringify(storageItem));
});
Search WWH ::




Custom Search