Use 'Zotero' object instead of this._zotero in autocomplete
This commit is contained in:
parent
00484c5e69
commit
89833e2da7
|
@ -40,13 +40,7 @@ var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
||||||
/*
|
/*
|
||||||
* Implements nsIAutoCompleteSearch
|
* Implements nsIAutoCompleteSearch
|
||||||
*/
|
*/
|
||||||
function ZoteroAutoComplete() {
|
function ZoteroAutoComplete() {}
|
||||||
// Get the Zotero object
|
|
||||||
this._zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
||||||
.getService(Components.interfaces.nsISupports)
|
|
||||||
.wrappedJSObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (searchString, searchParams, previousResult, listener) {
|
ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (searchString, searchParams, previousResult, listener) {
|
||||||
// FIXME
|
// FIXME
|
||||||
|
@ -61,7 +55,7 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s
|
||||||
this._listener = listener;
|
this._listener = listener;
|
||||||
this._cancelled = false;
|
this._cancelled = false;
|
||||||
|
|
||||||
this._zotero.debug("Starting autocomplete search with data '"
|
Zotero.debug("Starting autocomplete search with data '"
|
||||||
+ searchParams + "'" + " and string '" + searchString + "'");
|
+ searchParams + "'" + " and string '" + searchString + "'");
|
||||||
|
|
||||||
searchParams = JSON.parse(searchParams);
|
searchParams = JSON.parse(searchParams);
|
||||||
|
@ -183,7 +177,7 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'accessDate':
|
case 'accessDate':
|
||||||
var fieldID = this._zotero.ItemFields.getID('accessDate');
|
var fieldID = Zotero.ItemFields.getID('accessDate');
|
||||||
|
|
||||||
var sql = "SELECT DISTINCT DATE(value, 'localtime') AS val, NULL AS comment FROM itemData "
|
var sql = "SELECT DISTINCT DATE(value, 'localtime') AS val, NULL AS comment FROM itemData "
|
||||||
+ "WHERE fieldID=? AND value LIKE ? ORDER BY value";
|
+ "WHERE fieldID=? AND value LIKE ? ORDER BY value";
|
||||||
|
@ -191,9 +185,9 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var fieldID = this._zotero.ItemFields.getID(fieldName);
|
var fieldID = Zotero.ItemFields.getID(fieldName);
|
||||||
if (!fieldID) {
|
if (!fieldID) {
|
||||||
this._zotero.debug("'" + fieldName + "' is not a valid autocomplete scope", 1);
|
Zotero.debug("'" + fieldName + "' is not a valid autocomplete scope", 1);
|
||||||
this.updateResults([], false, Ci.nsIAutoCompleteResult.RESULT_IGNORED);
|
this.updateResults([], false, Ci.nsIAutoCompleteResult.RESULT_IGNORED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +226,7 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s
|
||||||
}
|
}
|
||||||
var resultCode;
|
var resultCode;
|
||||||
try {
|
try {
|
||||||
let results = yield this._zotero.DB.queryAsync(sql, sqlParams, { onRow: onRow });
|
let results = yield Zotero.DB.queryAsync(sql, sqlParams, { onRow: onRow });
|
||||||
// Post-process the results
|
// Post-process the results
|
||||||
if (resultsCallback) {
|
if (resultsCallback) {
|
||||||
resultsCallback(results);
|
resultsCallback(results);
|
||||||
|
@ -243,12 +237,12 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
resultCode = null;
|
resultCode = null;
|
||||||
this._zotero.debug("Autocomplete query completed");
|
Zotero.debug("Autocomplete query completed");
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.debug(e, 1);
|
Zotero.debug(e, 1);
|
||||||
resultCode = Ci.nsIAutoCompleteResult.RESULT_FAILURE;
|
resultCode = Ci.nsIAutoCompleteResult.RESULT_FAILURE;
|
||||||
this._zotero.debug("Autocomplete query aborted");
|
Zotero.debug("Autocomplete query aborted");
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
this.updateResults(null, null, false, resultCode);
|
this.updateResults(null, null, false, resultCode);
|
||||||
|
@ -257,7 +251,7 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s
|
||||||
|
|
||||||
|
|
||||||
ZoteroAutoComplete.prototype.updateResult = function (result, comment) {
|
ZoteroAutoComplete.prototype.updateResult = function (result, comment) {
|
||||||
this._zotero.debug("Appending autocomplete value '" + result + "'" + (comment ? " (" + comment + ")" : ""));
|
Zotero.debug("Appending autocomplete value '" + result + "'" + (comment ? " (" + comment + ")" : ""));
|
||||||
// Add to nsIAutoCompleteResult
|
// Add to nsIAutoCompleteResult
|
||||||
this._result.appendMatch(result, comment ? comment : null);
|
this._result.appendMatch(result, comment ? comment : null);
|
||||||
// Add to our own list
|
// Add to our own list
|
||||||
|
@ -283,12 +277,12 @@ ZoteroAutoComplete.prototype.updateResults = function (results, comments, ongoin
|
||||||
|
|
||||||
if (this._results.indexOf(result) == -1) {
|
if (this._results.indexOf(result) == -1) {
|
||||||
comment = comments[i] ? comments[i] : null;
|
comment = comments[i] ? comments[i] : null;
|
||||||
this._zotero.debug("Adding autocomplete value '" + result + "'" + (comment ? " (" + comment + ")" : ""));
|
Zotero.debug("Adding autocomplete value '" + result + "'" + (comment ? " (" + comment + ")" : ""));
|
||||||
this._result.appendMatch(result, comment, null, null);
|
this._result.appendMatch(result, comment, null, null);
|
||||||
this._results.push(result);
|
this._results.push(result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//this._zotero.debug("Skipping existing value '" + result + "'");
|
//Zotero.debug("Skipping existing value '" + result + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +310,7 @@ ZoteroAutoComplete.prototype.updateResults = function (results, comments, ongoin
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
ZoteroAutoComplete.prototype.stopSearch = function(){
|
ZoteroAutoComplete.prototype.stopSearch = function(){
|
||||||
this._zotero.debug('Stopping autocomplete search');
|
Zotero.debug('Stopping autocomplete search');
|
||||||
this._cancelled = true;
|
this._cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user