all files / src/ ApiObject.js

72.73% Statements 16/22
25% Branches 2/8
80% Functions 4/5
72.73% Lines 16/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                  746×                            
'use strict';
 
var log = require('./Log.js').Logger('libZotero:ApiObject');
 
module.exports = function(){
	this.instance = 'Zotero.ApiObject';
	this.version = 0;
};
 
//associate Entry with a library so we can update it on the server
module.exports.prototype.associateWithLibrary = function(library){
	var apiObject = this;
	apiObject.owningLibrary = library;
	Eif(typeof this.apiObj.library == 'object'){
		this.apiObj.library.type = library.type;
		this.apiObj.library.id = library.libraryID;
	}
	return apiObject;
};
 
module.exports.prototype.fieldComparer = function(attr){
	Eif(Intl){
		var collator = new Intl.Collator();
		return function(a, b){
			return collator.compare(a.apiObj.data[attr], b.apiObj.data[attr]);
		};
	} else {
		return function(a, b){
			if(a.apiObj.data[attr].toLowerCase() == b.apiObj.data[attr].toLowerCase()){
				return 0;
			}
			if(a.apiObj.data[attr].toLowerCase() < b.apiObj.data[attr].toLowerCase()){
				return -1;
			}
			return 1;
		};
	}
};