Commit e45edf9f authored by Sven Franck's avatar Sven Franck

jslint pass replicatestorage.js

parent a8f62949
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global jIO: true */
jIO.addStorageType('replicate', function (spec, my) { jIO.addStorageType('replicate', function (spec, my) {
var that, cloned_option, priv = {},
super_serialized = that.serialized;
spec = spec || {}; spec = spec || {};
var that = my.basicStorage( spec, my ), priv = {}; that = my.basicStorage(spec, my);
priv.return_value_array = []; priv.return_value_array = [];
priv.storagelist = spec.storagelist || []; priv.storagelist = spec.storagelist || [];
priv.nb_storage = priv.storagelist.length; priv.nb_storage = priv.storagelist.length;
var super_serialized = that.serialized;
that.serialized = function () { that.serialized = function () {
var o = super_serialized(); var o = super_serialized();
o.storagelist = priv.storagelist; o.storagelist = priv.storagelist;
...@@ -15,7 +20,7 @@ jIO.addStorageType('replicate', function (spec, my) { ...@@ -15,7 +20,7 @@ jIO.addStorageType('replicate', function (spec, my) {
that.validateState = function () { that.validateState = function () {
if (priv.storagelist.length === 0) { if (priv.storagelist.length === 0) {
return 'Need at least one parameter: "storagelist" '+ return 'Need at least one parameter: "storagelist" ' +
'containing at least one storage.'; 'containing at least one storage.';
} }
return ''; return '';
...@@ -25,21 +30,22 @@ jIO.addStorageType('replicate', function (spec, my) { ...@@ -25,21 +30,22 @@ jIO.addStorageType('replicate', function (spec, my) {
return (error_array.length === priv.nb_storage); return (error_array.length === priv.nb_storage);
}; };
priv.doJob = function (command,errormessage,nodocid) { priv.doJob = function (command, errormessage, nodocid) {
var done = false, error_array = [], i, var done = false,
error_array = [],
i,
error = function (err) { error = function (err) {
if (!done) { if (!done) {
error_array.push(err); error_array.push(err);
if (priv.isTheLast(error_array)) { if (priv.isTheLast(error_array)) {
that.error ({ that.error({
status:207, status: 207,
statusText:'Multi-Status', statusText: 'Multi-Status',
error:'multi_status', error: 'multi_status',
message:'All '+errormessage+ message: 'All ' + errormessage + (!nodocid ? ' "' +
(!nodocid?' "'+command.getDocId()+'"':' ') + command.getDocId() + '"' : ' ') + ' requests have failed.',
' requests have failed.', reason: 'requests fail',
reason:'requests fail', array: error_array
array:error_array
}); });
} }
} }
...@@ -47,18 +53,18 @@ jIO.addStorageType('replicate', function (spec, my) { ...@@ -47,18 +53,18 @@ jIO.addStorageType('replicate', function (spec, my) {
success = function (val) { success = function (val) {
if (!done) { if (!done) {
done = true; done = true;
that.success (val); that.success(val);
} }
}; };
for (i = 0; i < priv.nb_storage; i+= 1) { for (i = 0; i < priv.nb_storage; i += 1) {
var cloned_option = command.cloneOption(); cloned_option = command.cloneOption();
that.addJob (command.getLabel(),priv.storagelist[i], that.addJob(command.getLabel(), priv.storagelist[i],
command.cloneDoc(),cloned_option,success,error); command.cloneDoc(), cloned_option, success, error);
} }
}; };
that.post = function (command) { that.post = function (command) {
priv.doJob (command,'post'); priv.doJob(command, 'post');
that.end(); that.end();
}; };
...@@ -67,7 +73,7 @@ jIO.addStorageType('replicate', function (spec, my) { ...@@ -67,7 +73,7 @@ jIO.addStorageType('replicate', function (spec, my) {
* @method put * @method put
*/ */
that.put = function (command) { that.put = function (command) {
priv.doJob (command,'put'); priv.doJob(command, 'put');
that.end(); that.end();
}; };
...@@ -77,7 +83,7 @@ jIO.addStorageType('replicate', function (spec, my) { ...@@ -77,7 +83,7 @@ jIO.addStorageType('replicate', function (spec, my) {
* @method get * @method get
*/ */
that.get = function (command) { that.get = function (command) {
priv.doJob (command,'get'); priv.doJob(command, 'get');
that.end(); that.end();
}; };
...@@ -87,7 +93,7 @@ jIO.addStorageType('replicate', function (spec, my) { ...@@ -87,7 +93,7 @@ jIO.addStorageType('replicate', function (spec, my) {
* @method allDocs * @method allDocs
*/ */
that.allDocs = function (command) { that.allDocs = function (command) {
priv.doJob (command,'allDocs',true); priv.doJob(command, 'allDocs', true);
that.end(); that.end();
}; };
...@@ -96,9 +102,9 @@ jIO.addStorageType('replicate', function (spec, my) { ...@@ -96,9 +102,9 @@ jIO.addStorageType('replicate', function (spec, my) {
* @method remove * @method remove
*/ */
that.remove = function (command) { that.remove = function (command) {
priv.doJob (command,'remove'); priv.doJob(command, 'remove');
that.end(); that.end();
}; };
return that; return that;
}; });
\ No newline at end of file
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