Commit 89c6789c authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Change return value var name from jobs + grunt tests.

parent fe1379fb
......@@ -225,9 +225,9 @@ require(['OfficeJS'],function (OJS) {
priv.jio.loadDocument({
'fileName':filename,
'callback':function (result){
if (result.document.fileName) {
if (result.return_value.fileName) {
getCurrentEditor().setHTML(
result.document.fileContent);
result.return_value.fileContent);
} else {
console.error ('Error: ' + result.message);
}
......@@ -264,17 +264,17 @@ require(['OfficeJS'],function (OJS) {
'maxtries':3,
'callback':function (result) {
var htmlString = '', i, document_array = [];
for (i = 0; i < result.list.length; i += 1) {
for (i = 0; i < result.return_value.length; i += 1) {
htmlString += '<li><a href="#/texteditor:fileName='+
result.list[i].fileName + '">\n' +
result.list[i].fileName;
result.list[i].creationDate =
(new Date(result.list[i].creationDate)).
result.return_value[i].fileName + '">\n' +
result.return_value[i].fileName;
result.return_value[i].creationDate =
(new Date(result.return_value[i].creationDate)).
toLocaleString();
result.list[i].lastModified =
(new Date(result.list[i].lastModified)).
result.return_value[i].lastModified =
(new Date(result.return_value[i].lastModified)).
toLocaleString();
document_array.push (result.list[i]);
document_array.push (result.return_value[i]);
htmlString += '</a></li>\n';
}
if (htmlString === '') {
......
/*! JIO - v0.1.0 - 2012-05-22
/*! JIO - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
......@@ -713,52 +713,50 @@ var JIO =
//// Private Methods
priv.fail_checkNameAvailability = function () {
priv.res.isAvailable = false;
priv.res.message = 'Unable to check name availability.';
};
priv.done_checkNameAvailability = function ( isavailable ) {
priv.res.message = priv.job.userName + ' is ' +
(isavailable?'':'not ') + 'available.';
priv.res.isAvailable = isavailable;
priv.res.return_value = isavailable;
};
priv.fail_loadDocument = function () {
priv.res.document = {};
priv.res.message = 'Unable to load document.';
};
priv.done_loadDocument = function ( returneddocument ) {
priv.res.message = 'Document loaded.';
priv.res.document = returneddocument;
priv.res.return_value = returneddocument;
// transform date into ms
priv.res.document.lastModified =
new Date(priv.res.document.lastModified).getTime();
priv.res.document.creationDate =
new Date(priv.res.document.creationDate).getTime();
priv.res.return_value.lastModified =
new Date(priv.res.return_value.lastModified).getTime();
priv.res.return_value.creationDate =
new Date(priv.res.return_value.creationDate).getTime();
};
priv.fail_saveDocument = function () {
priv.res.isSaved = false;
priv.res.message = 'Unable to save document.';
};
priv.done_saveDocument = function () {
priv.res.message = 'Document saved.';
priv.res.isSaved = true;
};
priv.fail_getDocumentList = function () {
priv.res.list = [];
priv.res.message = 'Unable to retrieve document list.';
};
priv.done_getDocumentList = function ( documentlist ) {
var i;
priv.res.message = 'Document list received.';
priv.res.list = documentlist;
for (i = 0; i < priv.res.list.length; i += 1) {
priv.res.list[i].lastModified =
new Date(priv.res.list[i].lastModified).getTime();
priv.res.list[i].creationDate =
new Date(priv.res.list[i].creationDate).getTime();
priv.res.return_value = documentlist;
for (i = 0; i < priv.res.return_value.length; i += 1) {
priv.res.return_value[i].lastModified =
new Date(priv.res.return_value[i].lastModified).getTime();
priv.res.return_value[i].creationDate =
new Date(priv.res.return_value[i].creationDate).getTime();
}
};
priv.fail_removeDocument = function () {
priv.res.isRemoved = false;
priv.res.message = 'Unable to removed document.';
};
priv.done_removeDocument = function () {
priv.res.message = 'Document removed.';
priv.res.isRemoved = true;
};
priv.retryLater = function () {
......@@ -1004,9 +1002,13 @@ var JIO =
// - true if the job was added or replaced
// example :
// jio.checkNameAvailability({'userName':'myName','callback':
// function (result) { alert('is available? ' +
// result.isAvailable); }});
// jio.checkNameAvailability({'userName':'myName','callback':
// function (result) {
// if (result.status === 'done') {
// if (result.return_value === true) { // available
// } else { } // not available
// } else { } // Error
// }});
var settings = $.extend ({
'userName': priv.storage.userName,
......@@ -1036,8 +1038,10 @@ var JIO =
// - true if the job was added or replaced
// jio.saveDocument({'fileName':'file','fileContent':'content',
// 'callback': function (result) { alert('saved?' +
// result.isSaved); }});
// 'callback': function (result) {
// if (result.status === 'done') { // Saved
// } else { } // Error
// }});
var settings = $.extend({
'storage': priv.storage,
......@@ -1067,9 +1071,14 @@ var JIO =
// - true if the job was added or replaced
// jio.loadDocument({'fileName':'file','callback':
// function (result) { alert('content: '+
// result.doc.fileContent + ' creation date: ' +
// result.doc.creationDate); }});
// function (result) {
// if (result.status === 'done') { // Loaded
// } else { } // Error
// }});
// result.return_value is a document object that looks like {
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
var settings = $.extend ({
'storage': priv.storage,
......@@ -1097,7 +1106,13 @@ var JIO =
// - true if the job was added or replaced
// jio.getDocumentList({'callback':
// function (result) { alert('list: '+result.list); }});
// function (result) {
// if (result.status === 'done') { // OK
// console.log(result.return_value);
// } else { } // Error
// }});
// result.return_value is an Array that contains documents objects.
var settings = $.extend ({
'storage': priv.storage,
......@@ -1124,7 +1139,10 @@ var JIO =
// - true if the job was added or replaced
// jio.removeDocument({'fileName':'file','callback':
// function (result) { alert('removed? '+result.isRemoved); }});
// function (result) {
// if(result.status === 'done') { // Removed
// } else { } // Not Removed
// }});
var settings = $.extend ({
'storage': priv.storage,
......
This diff is collapsed.
/*! JIO Storage - v0.1.0 - 2012-05-22
/*! JIO Storage - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
......@@ -521,18 +521,30 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// if the name already exists in a storage, it is not available.
// this.job.userName: the name we want to check.
// this.job.storage.storageArray: An Array of storages.
// TODO
var newjob = {}, isavailable = true, i = 'id',
var newjob = {}, i = 'id', done = false,
res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result);
if (result.status === 'fail') {
res.status = 'fail';
}
if (!result.isAvailable) { isavailable = false; }
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
that.done(isavailable);
if (!done) {
if (result.status === 'fail') {
res.status = 'fail';
} else {
if (result.return_value === false) {
that.done (false);
done = true;
return;
}
}
if (priv.returnsValuesArray.length ===
priv.length) {
if (res.status === 'fail') {
that.fail ('Unable to check name availability.',0);
} else {
that.done (true);
}
done = true;
return;
}
}
};
priv.execJobsFromStorageArray(callback);
......@@ -546,7 +558,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.applicant.ID: the applicant ID.
// this.job.fileName: the document name.
// this.job.fileContent: the document content.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
......@@ -580,7 +591,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date}
// TODO
var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false,
......@@ -588,7 +598,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.document);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -610,16 +620,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// the list is [object,object] -> object = {'fileName':string,
// the list is [object,object,...] -> object = {'fileName':string,
// 'lastModified':date,'creationDate':date}
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.list);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -640,7 +649,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.userName: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'key', done = false,
callback = function (result) {
......
This diff is collapsed.
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-22
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage =
......
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-22
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-23
* Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage=function(){var a=function(){var a=function(){};a.prototype={getItem:function(a){return JSON.parse(localStorage.getItem(a))},setItem:function(a,b){if(a)return localStorage.setItem(a,JSON.stringify(b))},getAll:function(){return localStorage},deleteItem:function(a){a&&delete localStorage[a]}};var b=function(){};b.prototype={getItem:function(a){var b=document.cookie.split(";"),c;for(c=0;c<b.length;c+=1){var d=b[c].substr(0,b[c].indexOf("=")),e=b[c].substr(b[c].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,"");if(d===a)return unescape(e)}return null},setItem:function(a,b){return b!==undefined?(document.cookie=a+"="+JSON.stringify(b)+";domain="+window.location.hostname+";path="+window.location.pathname,!0):!1},getAll:function(){var a={},b,c=document.cookie.split(":");for(b=0;b<c.length;b+=1){var d=c[b].substr(0,c[b].indexOf("=")),e=c[b].substr(c[b].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,""),a[d]=unescape(e)}return a},deleteItem:function(a){document.cookie=a+"=null;domain="+window.location.hostname+";path="+window.location.pathname+";expires=Thu, 01-Jan-1970 00:00:01 GMT"}};try{return localStorage.getItem?new a:new b}catch(c){return new b}};return window.requirejs?(define("LocalOrCookieStorage",[],a),undefined):a()}();
\ No newline at end of file
......@@ -710,52 +710,50 @@ var JIO =
//// Private Methods
priv.fail_checkNameAvailability = function () {
priv.res.isAvailable = false;
priv.res.message = 'Unable to check name availability.';
};
priv.done_checkNameAvailability = function ( isavailable ) {
priv.res.message = priv.job.userName + ' is ' +
(isavailable?'':'not ') + 'available.';
priv.res.isAvailable = isavailable;
priv.res.return_value = isavailable;
};
priv.fail_loadDocument = function () {
priv.res.document = {};
priv.res.message = 'Unable to load document.';
};
priv.done_loadDocument = function ( returneddocument ) {
priv.res.message = 'Document loaded.';
priv.res.document = returneddocument;
priv.res.return_value = returneddocument;
// transform date into ms
priv.res.document.lastModified =
new Date(priv.res.document.lastModified).getTime();
priv.res.document.creationDate =
new Date(priv.res.document.creationDate).getTime();
priv.res.return_value.lastModified =
new Date(priv.res.return_value.lastModified).getTime();
priv.res.return_value.creationDate =
new Date(priv.res.return_value.creationDate).getTime();
};
priv.fail_saveDocument = function () {
priv.res.isSaved = false;
priv.res.message = 'Unable to save document.';
};
priv.done_saveDocument = function () {
priv.res.message = 'Document saved.';
priv.res.isSaved = true;
};
priv.fail_getDocumentList = function () {
priv.res.list = [];
priv.res.message = 'Unable to retrieve document list.';
};
priv.done_getDocumentList = function ( documentlist ) {
var i;
priv.res.message = 'Document list received.';
priv.res.list = documentlist;
for (i = 0; i < priv.res.list.length; i += 1) {
priv.res.list[i].lastModified =
new Date(priv.res.list[i].lastModified).getTime();
priv.res.list[i].creationDate =
new Date(priv.res.list[i].creationDate).getTime();
priv.res.return_value = documentlist;
for (i = 0; i < priv.res.return_value.length; i += 1) {
priv.res.return_value[i].lastModified =
new Date(priv.res.return_value[i].lastModified).getTime();
priv.res.return_value[i].creationDate =
new Date(priv.res.return_value[i].creationDate).getTime();
}
};
priv.fail_removeDocument = function () {
priv.res.isRemoved = false;
priv.res.message = 'Unable to removed document.';
};
priv.done_removeDocument = function () {
priv.res.message = 'Document removed.';
priv.res.isRemoved = true;
};
priv.retryLater = function () {
......@@ -1001,9 +999,13 @@ var JIO =
// - true if the job was added or replaced
// example :
// jio.checkNameAvailability({'userName':'myName','callback':
// function (result) { alert('is available? ' +
// result.isAvailable); }});
// jio.checkNameAvailability({'userName':'myName','callback':
// function (result) {
// if (result.status === 'done') {
// if (result.return_value === true) { // available
// } else { } // not available
// } else { } // Error
// }});
var settings = $.extend ({
'userName': priv.storage.userName,
......@@ -1033,8 +1035,10 @@ var JIO =
// - true if the job was added or replaced
// jio.saveDocument({'fileName':'file','fileContent':'content',
// 'callback': function (result) { alert('saved?' +
// result.isSaved); }});
// 'callback': function (result) {
// if (result.status === 'done') { // Saved
// } else { } // Error
// }});
var settings = $.extend({
'storage': priv.storage,
......@@ -1064,9 +1068,14 @@ var JIO =
// - true if the job was added or replaced
// jio.loadDocument({'fileName':'file','callback':
// function (result) { alert('content: '+
// result.doc.fileContent + ' creation date: ' +
// result.doc.creationDate); }});
// function (result) {
// if (result.status === 'done') { // Loaded
// } else { } // Error
// }});
// result.return_value is a document object that looks like {
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
var settings = $.extend ({
'storage': priv.storage,
......@@ -1094,7 +1103,13 @@ var JIO =
// - true if the job was added or replaced
// jio.getDocumentList({'callback':
// function (result) { alert('list: '+result.list); }});
// function (result) {
// if (result.status === 'done') { // OK
// console.log(result.return_value);
// } else { } // Error
// }});
// result.return_value is an Array that contains documents objects.
var settings = $.extend ({
'storage': priv.storage,
......@@ -1121,7 +1136,10 @@ var JIO =
// - true if the job was added or replaced
// jio.removeDocument({'fileName':'file','callback':
// function (result) { alert('removed? '+result.isRemoved); }});
// function (result) {
// if(result.status === 'done') { // Removed
// } else { } // Not Removed
// }});
var settings = $.extend ({
'storage': priv.storage,
......
......@@ -518,18 +518,30 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// if the name already exists in a storage, it is not available.
// this.job.userName: the name we want to check.
// this.job.storage.storageArray: An Array of storages.
// TODO
var newjob = {}, isavailable = true, i = 'id',
var newjob = {}, i = 'id', done = false,
res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result);
if (result.status === 'fail') {
res.status = 'fail';
}
if (!result.isAvailable) { isavailable = false; }
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
that.done(isavailable);
if (!done) {
if (result.status === 'fail') {
res.status = 'fail';
} else {
if (result.return_value === false) {
that.done (false);
done = true;
return;
}
}
if (priv.returnsValuesArray.length ===
priv.length) {
if (res.status === 'fail') {
that.fail ('Unable to check name availability.',0);
} else {
that.done (true);
}
done = true;
return;
}
}
};
priv.execJobsFromStorageArray(callback);
......@@ -543,7 +555,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.applicant.ID: the applicant ID.
// this.job.fileName: the document name.
// this.job.fileContent: the document content.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
......@@ -577,7 +588,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date}
// TODO
var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false,
......@@ -585,7 +595,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.document);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -607,16 +617,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// the list is [object,object] -> object = {'fileName':string,
// the list is [object,object,...] -> object = {'fileName':string,
// 'lastModified':date,'creationDate':date}
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (!done) {
if (result.status !== 'fail') {
that.done (result.list);
that.done (result.return_value);
done = true;
} else {
if (priv.returnsValuesArray.length ===
......@@ -637,7 +646,6 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.userName: the user name.
// this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'key', done = false,
callback = function (result) {
......
This diff is collapsed.
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