Commit af4bb121 authored by Boris Kocherov's avatar Boris Kocherov Committed by Vincent Bechu

working but bad solution of "transaction close on onsuccess callback ended" problem.

parent f09ad102
...@@ -303,8 +303,7 @@ ...@@ -303,8 +303,7 @@
}; };
IndexedDBStorage.prototype.getAttachment = function (id, name, options) { IndexedDBStorage.prototype.getAttachment = function (id, name, options) {
var transaction, var type,
type,
start, start,
end; end;
if (options === undefined) { if (options === undefined) {
...@@ -312,19 +311,32 @@ ...@@ -312,19 +311,32 @@
} }
return openIndexedDB(this) return openIndexedDB(this)
.push(function (db) { .push(function (db) {
transaction = openTransaction(db, ["attachment", "blob"], "readonly"); return new RSVP.Promise(function (resolve, reject) {
var transaction = openTransaction(db, ["attachment", "blob"],
"readonly"),
// XXX Should raise if key is not good // XXX Should raise if key is not good
return handleGet(transaction.objectStore("attachment") request = transaction.objectStore("attachment")
.get(buildKeyPath([id, name]))); .get(buildKeyPath([id, name]));
}) request.onerror = function (error) {
.push(function (attachment) { transaction.abort();
var total_length = attachment.info.length, reject(error);
};
request.onsuccess = function () {
var attachment = request.result,
total_length,
i, i,
promise_list = [], promise_list = [],
store = transaction.objectStore("blob"), store = transaction.objectStore("blob"),
start_index, start_index,
end_index; end_index;
if (!attachment) {
return reject(
new jIO.util.jIOError("Cannot find attachment", 404)
);
}
total_length = attachment.info.length;
type = attachment.info.content_type; type = attachment.info.content_type;
start = options.start || 0; start = options.start || 0;
end = options.end || total_length; end = options.end || total_length;
...@@ -353,7 +365,9 @@ ...@@ -353,7 +365,9 @@
name, i]))) name, i])))
); );
} }
return RSVP.all(promise_list); resolve(RSVP.all(promise_list));
};
});
}) })
.push(function (result_list) { .push(function (result_list) {
var array_buffer_list = [], var array_buffer_list = [],
...@@ -413,10 +427,12 @@ ...@@ -413,10 +427,12 @@
} }
// Remove previous attachment // Remove previous attachment
transaction = openTransaction(db, ["attachment", "blob"], "readwrite"); transaction = openTransaction(db, ["attachment", "blob"],
"readwrite", false);
return removeAttachment(transaction, id, name); return removeAttachment(transaction, id, name);
}) })
.push(function () { .push(function () {
transaction = openTransaction(db, ["attachment", "blob"], "readwrite");
var promise_list = [ var promise_list = [
handleRequest(transaction.objectStore("attachment").put({ handleRequest(transaction.objectStore("attachment").put({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment