Commit 515f6023 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Change ReplicateStorage reaction.

ReplicateStorage will now return the first returned result. (but not for
checkNameAvailability). So OfficeJS changed a little too.
parent 0e0a5cb0
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<label class="control-label" for="fileName">File Name</label> <label class="control-label" for="fileName">File Name</label>
<div class="controls docs-input-sizes"> <div class="controls docs-input-sizes">
<input type="text" name="fileName" id="input_fileName" <input type="text" name="fileName" id="input_fileName"
value="" placeholder="file name" /> value="{{CurrentFileName}}" placeholder="file name" />
</div> </div>
<!-- <label class="control-label" for="fileContent">File Content</label> --> <!-- <label class="control-label" for="fileContent">File Content</label> -->
<!-- <div class="controls docs-input-sizes"> --> <!-- <div class="controls docs-input-sizes"> -->
......
...@@ -24,7 +24,7 @@ require(['OfficeJS'],function (OJS) { ...@@ -24,7 +24,7 @@ require(['OfficeJS'],function (OJS) {
// some vars // some vars
text_editor_loaded_once = false, text_editor_loaded_once = false,
current_hash = 'default', current_hash = 'default',
ich_object = {DocumentList:[]}, ich_object = {DocumentList:[],CurrentFileName:''},
current_editor = null, current_editor = null,
// conf vars // conf vars
routes = { routes = {
...@@ -45,6 +45,7 @@ require(['OfficeJS'],function (OJS) { ...@@ -45,6 +45,7 @@ require(['OfficeJS'],function (OJS) {
}, },
onunload:function(){ onunload:function(){
document.querySelector('#text_editor').style.display = 'none'; document.querySelector('#text_editor').style.display = 'none';
ich_object.CurrentFileName = $('#input_fileName').attr('value');
current_editor = null; current_editor = null;
}, },
} }
...@@ -141,7 +142,6 @@ require(['OfficeJS'],function (OJS) { ...@@ -141,7 +142,6 @@ require(['OfficeJS'],function (OJS) {
priv.jio.saveDocument({ priv.jio.saveDocument({
'fileName':filename, 'fileName':filename,
'fileContent':filecontent, 'fileContent':filecontent,
'maxtries':3,
'callback':function (result){ 'callback':function (result){
alert (result.isSaved ? 'Document Saved.' : alert (result.isSaved ? 'Document Saved.' :
'Error: ' + result.message); 'Error: ' + result.message);
...@@ -158,7 +158,6 @@ require(['OfficeJS'],function (OJS) { ...@@ -158,7 +158,6 @@ require(['OfficeJS'],function (OJS) {
filename = $('#input_fileName').attr('value'); filename = $('#input_fileName').attr('value');
priv.jio.loadDocument({ priv.jio.loadDocument({
'fileName':filename, 'fileName':filename,
'maxtries':3,
'callback':function (result){ 'callback':function (result){
if (result.document.fileName) { if (result.document.fileName) {
getCurrentEditor().setHTML( getCurrentEditor().setHTML(
...@@ -179,7 +178,6 @@ require(['OfficeJS'],function (OJS) { ...@@ -179,7 +178,6 @@ require(['OfficeJS'],function (OJS) {
filename = $('#input_fileName').attr('value'); filename = $('#input_fileName').attr('value');
priv.jio.removeDocument({ priv.jio.removeDocument({
'fileName':filename, 'fileName':filename,
'maxtries':3,
'callback':function (result) { 'callback':function (result) {
alert (result.isRemoved?'Document Removed.': alert (result.isRemoved?'Document Removed.':
'Error: '+result.message); 'Error: '+result.message);
......
...@@ -502,6 +502,17 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -502,6 +502,17 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.setMaxTries (1); that.setMaxTries (1);
priv.execJobsFromStorageArray = function (callback) {
var newjob = {}, i;
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
};
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// Checks the availability of the [job.userName]. // Checks the availability of the [job.userName].
// if the name already exists in a storage, it is not available. // if the name already exists in a storage, it is not available.
...@@ -521,14 +532,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -521,14 +532,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done(isavailable); that.done(isavailable);
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.saveDocument = function () { that.saveDocument = function () {
// Save a single document in several storages. // Save a single document in several storages.
...@@ -541,29 +545,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -541,29 +545,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.fileContent: the document content. // this.job.fileContent: the document content.
// TODO // TODO
var newjob = {}, res = {'status':'done'}, i = 'id', var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (result.status === 'fail') { if (!done) {
res.status = 'fail'; if (result.status !== 'fail') {
} that.done ();
if (priv.returnsValuesArray.length === priv.length) { done = true;
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable to save all files.',0);
} else { } else {
that.done(); if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to save any file.',0);
}
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.loadDocument = function () { that.loadDocument = function () {
...@@ -583,60 +580,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -583,60 +580,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// TODO // TODO
var newjob = {}, aredifferent = false, doc = {}, i = 'id', var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false,
res = {'status':'done'}, callback = function (result) { res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (result.status === 'fail') { if (!done) {
res.status = 'fail'; if (result.status !== 'fail') {
} else { that.done (result.document);
// check if the file are different done = true;
if (!doc.fileContent && !doc.creationDate &&
!doc.lastModified) {
// if it is the first document loaded
doc = $.extend({},result.document);
} else {
if (doc.fileContent !==
result.document.fileContent) {
// if the document is different from the
// previous one
aredifferent = true;
}
if (doc.creationDate >
result.document.creationDate) {
// get older creation date
doc.creationDate = result.document.creationDate;
}
if (doc.lastModified <
result.document.lastModified) {
// get newer last modified
doc.fileContent = result.document.fileContent;
doc.lastModified = result.document.lastModified;
}
}
}
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable to load all files.',0);
} else { } else {
if (!aredifferent) { if (priv.returnsValuesArray.length ===
that.done(doc); priv.length) {
} else { that.fail ('Unable to load any file.',0);
// TODO the files are different! Give options
// to know what do we do now!
// console.warn ('The files are different.');
that.done(doc);
} }
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.getDocumentList = function () { that.getDocumentList = function () {
...@@ -667,14 +626,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -667,14 +626,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.removeDocument = function () { that.removeDocument = function () {
...@@ -690,26 +642,19 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -690,26 +642,19 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
var newjob = {}, res = {'status':'done'}, i = 'key', var newjob = {}, res = {'status':'done'}, i = 'key',
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (result.status === 'fail') { if (!done) {
res.status = 'fail'; if (result.status !== 'fail') {
} that.done ();
if (priv.returnsValuesArray.length === priv.length) { done = true;
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable remove all files.',0);
} else { } else {
that.done(); if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to remove any file.',0);
}
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
return that; return that;
}; };
......
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