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