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) {
spec = spec || {};
var that = my.basicStorage( spec, my ), priv = {};
priv.return_value_array = []; var that, cloned_option, priv = {},
priv.storagelist = spec.storagelist || []; super_serialized = that.serialized;
priv.nb_storage = priv.storagelist.length;
var super_serialized = that.serialized; spec = spec || {};
that.serialized = function () { that = my.basicStorage(spec, my);
var o = super_serialized();
o.storagelist = priv.storagelist;
return o;
};
that.validateState = function () { priv.return_value_array = [];
if (priv.storagelist.length === 0) { priv.storagelist = spec.storagelist || [];
return 'Need at least one parameter: "storagelist" '+ priv.nb_storage = priv.storagelist.length;
'containing at least one storage.';
} that.serialized = function () {
return ''; var o = super_serialized();
}; o.storagelist = priv.storagelist;
return o;
};
priv.isTheLast = function (error_array) { that.validateState = function () {
return (error_array.length === priv.nb_storage); if (priv.storagelist.length === 0) {
}; return 'Need at least one parameter: "storagelist" ' +
'containing at least one storage.';
}
return '';
};
priv.doJob = function (command,errormessage,nodocid) { priv.isTheLast = function (error_array) {
var done = false, error_array = [], i, return (error_array.length === priv.nb_storage);
error = function (err) { };
if (!done) {
error_array.push(err); priv.doJob = function (command, errormessage, nodocid) {
if (priv.isTheLast(error_array)) { var done = false,
that.error ({ error_array = [],
status:207, i,
statusText:'Multi-Status', error = function (err) {
error:'multi_status', if (!done) {
message:'All '+errormessage+ error_array.push(err);
(!nodocid?' "'+command.getDocId()+'"':' ') + if (priv.isTheLast(error_array)) {
' requests have failed.', that.error({
reason:'requests fail', status: 207,
array:error_array statusText: 'Multi-Status',
}); error: 'multi_status',
} message: 'All ' + errormessage + (!nodocid ? ' "' +
} command.getDocId() + '"' : ' ') + ' requests have failed.',
}, reason: 'requests fail',
success = function (val) { array: error_array
if (!done) { });
done = true; }
that.success (val); }
} },
}; success = function (val) {
for (i = 0; i < priv.nb_storage; i+= 1) { if (!done) {
var cloned_option = command.cloneOption(); done = true;
that.addJob (command.getLabel(),priv.storagelist[i], that.success(val);
command.cloneDoc(),cloned_option,success,error);
} }
}; };
for (i = 0; i < priv.nb_storage; i += 1) {
cloned_option = command.cloneOption();
that.addJob(command.getLabel(), priv.storagelist[i],
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();
}; };
/** /**
* Save a document in several storages. * Save a document in several storages.
* @method put * @method put
*/ */
that.put = function (command) { that.put = function (command) {
priv.doJob (command,'put'); priv.doJob(command, 'put');
that.end(); that.end();
}; };
/** /**
* Load a document from several storages, and send the first retreived * Load a document from several storages, and send the first retreived
* document. * document.
* @method get * @method get
*/ */
that.get = function (command) { that.get = function (command) {
priv.doJob (command,'get'); priv.doJob(command, 'get');
that.end(); that.end();
}; };
/** /**
* Get a document list from several storages, and returns the first * Get a document list from several storages, and returns the first
* retreived document list. * retreived document list.
* @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();
}; };
/** /**
* Remove a document from several storages. * Remove a document from several storages.
* @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