2023-03-01 19:31:51 +01:00
|
|
|
|
/* version: 1.3.2 */
|
2022-10-01 00:18:32 +02:00
|
|
|
|
var Scrutari = {};
|
|
|
|
|
Scrutari.log = function (msg) {
|
|
|
|
|
if ((console) && (console.log)) {
|
|
|
|
|
console.log(msg);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.logError = function (error) {
|
|
|
|
|
var errorMessage = "Scrutari Request Error [key = " + error.key + " | parameter = " + error.parameter;
|
|
|
|
|
if (error.hasOwnProperty("value")) {
|
|
|
|
|
errorMessage += " | value = " + error.value;
|
|
|
|
|
}
|
|
|
|
|
if (error.hasOwnProperty("array")) {
|
|
|
|
|
errorMessage += " | array = (";
|
|
|
|
|
for(var i = 0; i < error.array.length; i++) {
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
errorMessage += ";";
|
|
|
|
|
}
|
|
|
|
|
var obj = error.array[i];
|
|
|
|
|
errorMessage += obj.key;
|
|
|
|
|
if (obj.hasOwnProperty("value")) {
|
|
|
|
|
errorMessage += "=" + obj.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
errorMessage += ")";
|
|
|
|
|
}
|
|
|
|
|
errorMessage += "}";
|
|
|
|
|
Scrutari.log(errorMessage);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.convert = function (jqArgument) {
|
|
|
|
|
if (jqArgument.jquery) {
|
|
|
|
|
return jqArgument;
|
|
|
|
|
} else {
|
|
|
|
|
return $(jqArgument);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.exists = function (jqArgument) {
|
|
|
|
|
return Scrutari.convert(jqArgument).length > 0;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.escape = function (text) {
|
|
|
|
|
var result = "";
|
|
|
|
|
for(var i = 0; i < text.length; i++) {
|
|
|
|
|
carac = text.charAt(i);
|
|
|
|
|
switch (carac) {
|
|
|
|
|
case '&':
|
|
|
|
|
result += "&";
|
|
|
|
|
break;
|
|
|
|
|
case '"':
|
|
|
|
|
result += """;
|
|
|
|
|
break;
|
|
|
|
|
case '<':
|
|
|
|
|
result += "<";
|
|
|
|
|
break;
|
|
|
|
|
case '>':
|
|
|
|
|
result += ">";
|
|
|
|
|
break;
|
|
|
|
|
case '\'':
|
|
|
|
|
result += "'";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
result += carac;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.$ = function (jqArgument, properties) {
|
|
|
|
|
if (!properties) {
|
|
|
|
|
properties = jqArgument;
|
|
|
|
|
jqArgument = null;
|
|
|
|
|
}
|
|
|
|
|
var query = Scrutari.toCssQuery(properties);
|
|
|
|
|
if (jqArgument) {
|
|
|
|
|
return Scrutari.convert(jqArgument).find(query);
|
|
|
|
|
} else {
|
|
|
|
|
return $(query);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.$children = function (jqArgument, properties) {
|
|
|
|
|
return Scrutari.convert(jqArgument).children(Scrutari.toCssQuery(properties));
|
|
|
|
|
};
|
|
|
|
|
Scrutari.$parents = function (jqArgument, properties) {
|
|
|
|
|
return Scrutari.convert(jqArgument).parents(Scrutari.toCssQuery(properties));
|
|
|
|
|
};
|
|
|
|
|
Scrutari.toCssQuery = function (properties) {
|
|
|
|
|
var query = "";
|
|
|
|
|
var elementName = false;
|
|
|
|
|
var suffix = "";
|
|
|
|
|
for(let key in properties) {
|
|
|
|
|
let value = properties[key];
|
|
|
|
|
if (!key.startsWith("_")) {
|
|
|
|
|
if (value === true) {
|
|
|
|
|
query += "[" + Scrutari.toDataAttribute(key) + "]";
|
|
|
|
|
} else {
|
|
|
|
|
query += "[" + Scrutari.toDataAttribute(key) + "='" + value + "']";
|
|
|
|
|
}
|
|
|
|
|
} else if (key === "_checked") {
|
|
|
|
|
if (value) {
|
|
|
|
|
suffix += ":checked";
|
|
|
|
|
} else {
|
|
|
|
|
suffix += ":not(:checked)";
|
|
|
|
|
}
|
|
|
|
|
} else if (key === "_type") {
|
|
|
|
|
query += "[type='" + value + "']";
|
|
|
|
|
} else if (key === "_name") {
|
|
|
|
|
query += "[name='" + value + "']";
|
|
|
|
|
} else if (key === "_value") {
|
|
|
|
|
query += "[value='" + value + "']";
|
|
|
|
|
} else if (key === "_element") {
|
|
|
|
|
elementName = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (elementName) {
|
|
|
|
|
query = elementName + query;
|
|
|
|
|
}
|
|
|
|
|
query += suffix;
|
|
|
|
|
return query;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.toDataAttribute = function (camelCaseString) {
|
|
|
|
|
return "data-" + camelCaseString.replace(/[A-Z]/g, function (upperLetter) {
|
|
|
|
|
return "-" + upperLetter.toLowerCase();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Config = function (name, engineUrl, lang, origin, options) {
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.engineUrl = engineUrl;
|
|
|
|
|
this.lang = lang;
|
|
|
|
|
this.origin = origin;
|
|
|
|
|
this.options = {
|
|
|
|
|
dataType: "json",
|
|
|
|
|
queryVariant: "query",
|
|
|
|
|
ficheFields: null,
|
|
|
|
|
motcleFields: null,
|
|
|
|
|
paginationLength: 50,
|
|
|
|
|
subsearchThreshold: 250,
|
|
|
|
|
groupSortFunction: _ficheCountSort
|
|
|
|
|
};
|
|
|
|
|
if (options) {
|
|
|
|
|
for(var key in options) {
|
|
|
|
|
this.options[key] = options[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _ficheCountSort(group1, group2) {
|
|
|
|
|
let count1 = group1.ficheCount;
|
|
|
|
|
let count2 = group2.ficheCount;
|
|
|
|
|
if (count1 > count2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
let rank1 = group1.category.rank;
|
|
|
|
|
let rank2 = group1.category.rank;
|
|
|
|
|
if (rank1 < rank2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (rank1 > rank2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Config.prototype.getJsonUrl = function () {
|
|
|
|
|
return this.engineUrl + "json";
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Config.prototype.getDownloadUrl = function (qId, extension) {
|
|
|
|
|
switch(extension) {
|
|
|
|
|
case "ods":
|
|
|
|
|
case "csv":
|
|
|
|
|
return this.engineUrl + "export/" + "result_" + qId + "_" + this.lang + "." + extension;
|
|
|
|
|
case "atom":
|
|
|
|
|
return this.engineUrl + "feed/" + "fiches_" + this.lang + ".atom?qid=" + qId + "&all=" + _getCurrentDate();
|
|
|
|
|
default:
|
|
|
|
|
Scrutari.log("Unknown extension: " + extension);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
function _getCurrentDate() {
|
|
|
|
|
var date = new Date();
|
|
|
|
|
var dateString = date.getFullYear() + "-";
|
|
|
|
|
var mois = date.getMonth() + 1;
|
|
|
|
|
if (mois < 10) {
|
|
|
|
|
dateString += "0";
|
|
|
|
|
}
|
|
|
|
|
dateString += mois;
|
|
|
|
|
dateString += "-";
|
|
|
|
|
var jour = date.getDate();
|
|
|
|
|
if (jour < 10) {
|
|
|
|
|
dateString += "0";
|
|
|
|
|
}
|
|
|
|
|
dateString += jour;
|
|
|
|
|
return dateString;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Config.prototype.getPermalinkUrl = function (qId, permalinkPattern) {
|
|
|
|
|
var permalink = permalinkPattern.replace("$LANG", this.lang);
|
|
|
|
|
permalink = permalink.replace("$QID", qId);
|
|
|
|
|
return permalink;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax = {};
|
|
|
|
|
Scrutari.Ajax.loadBaseArray = function (scrutariConfig, requestParameters, baseArrayCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "base";
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "baseArray", baseArrayCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadCategoryArray = function (scrutariConfig, requestParameters, categoryArrayCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "category";
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "categoryArray", categoryArrayCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadCorpusArray = function (scrutariConfig, requestParameters, corpusArrayCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "corpus";
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "corpusArray", corpusArrayCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadEngineInfo = function (scrutariConfig, requestParameters, engineInfoCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "engine";
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "info", "all");
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "engineInfo", engineInfoCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadFicheArray = function (scrutariConfig, requestParameters, ficheArrayCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "fiche";
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fieldvariant", "data");
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, ["ficheArray", "motcleArray"], ficheArrayCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadGeoJson = function (scrutariConfig, requestParameters, geojsonCallback, apiErrorCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "geojson";
|
|
|
|
|
if ((scrutariConfig.options.ficheFields) || (scrutariConfig.options.motcleFields)) {
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fichefields", scrutariConfig.options.ficheFields);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "motclefields", scrutariConfig.options.motcleFields);
|
|
|
|
|
}
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fieldvariant", scrutariConfig.options.queryVariant);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "origin", scrutariConfig.origin);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
if (data.hasOwnProperty("error")) {
|
|
|
|
|
if (apiErrorCallback) {
|
|
|
|
|
apiErrorCallback(data.error);
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.logError(data.error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.Ajax.logWarnings(data);
|
|
|
|
|
geojsonCallback(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadMotcleArray = function (scrutariConfig, requestParameters, motcleArrayCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "motcle";
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fieldvariant", "data");
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "motcleArray", motcleArrayCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadThesaurusArray = function (scrutariConfig, requestParameters, thesaurusArrayCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "thesaurus";
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "thesaurusArray", thesaurusArrayCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadFicheSearchResult = function (scrutariConfig, requestParameters, ficheSearchResultCallback, apiErrorCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "q-fiche";
|
|
|
|
|
if (scrutariConfig.options.ficheFields !== null) {
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fichefields", scrutariConfig.options.ficheFields);
|
|
|
|
|
}
|
|
|
|
|
if (scrutariConfig.options.motcleFields !== null) {
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "motclefields", scrutariConfig.options.motcleFields);
|
|
|
|
|
}
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fieldvariant", scrutariConfig.options.queryVariant);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "q-mode", "intersection");
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "origin", scrutariConfig.origin);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "start", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "limit", scrutariConfig.options.paginationLength * 2);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "starttype", "in_all");
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "ficheSearchResult", ficheSearchResultCallback, apiErrorCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadExistingFicheSearchResult = function (scrutariConfig, requestParameters, existingFicheSearchResultCallback) {
|
|
|
|
|
if (!requestParameters) {
|
|
|
|
|
requestParameters = new Object();
|
|
|
|
|
}
|
|
|
|
|
requestParameters.type = "q-fiche";
|
|
|
|
|
if ((scrutariConfig.options.ficheFields) || (scrutariConfig.options.motcleFields)) {
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fichefields", scrutariConfig.options.ficheFields);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "motclefields", scrutariConfig.options.motcleFields);
|
|
|
|
|
}
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "lang", scrutariConfig.lang);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "fieldvariant", scrutariConfig.options.queryVariant);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "insert", "-searchmeta,-motclearray");
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "warnings", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "version", 3);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "start", 1);
|
|
|
|
|
Scrutari.Ajax.check(requestParameters, "limit", scrutariConfig.options.paginationLength * 2);
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: scrutariConfig.getJsonUrl(),
|
|
|
|
|
dataType: scrutariConfig.options.dataType,
|
|
|
|
|
data: requestParameters,
|
|
|
|
|
success: function (data, textStatus) {
|
|
|
|
|
Scrutari.Ajax.success(data, "ficheSearchResult", existingFicheSearchResultCallback);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.success = function(ajaxResult, objectNames, objectCallback, apiErrorCallback) {
|
|
|
|
|
if (ajaxResult.hasOwnProperty("error")) {
|
|
|
|
|
if (apiErrorCallback) {
|
|
|
|
|
apiErrorCallback(ajaxResult.error);
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.logError(ajaxResult.error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.Ajax.logWarnings(ajaxResult);
|
|
|
|
|
if (Array.isArray(objectNames)) {
|
|
|
|
|
let apiObjectArray = new Array();
|
|
|
|
|
for(let objectName of objectNames) {
|
|
|
|
|
if (!ajaxResult.hasOwnProperty(objectName)) {
|
|
|
|
|
apiObjectArray.push(null);
|
|
|
|
|
} else {
|
|
|
|
|
apiObjectArray.push(ajaxResult[objectName]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
objectCallback.apply(this, apiObjectArray);
|
|
|
|
|
} else {
|
|
|
|
|
let objectName = objectNames;
|
|
|
|
|
if (!ajaxResult.hasOwnProperty(objectName)) {
|
|
|
|
|
$.error(objectName + " object is missing in json response");
|
|
|
|
|
} else {
|
|
|
|
|
objectCallback(ajaxResult[objectName]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.logWarnings = function (ajaxResult) {
|
|
|
|
|
if (ajaxResult.hasOwnProperty("warnings")) {
|
|
|
|
|
var warningsMessage = "Scrutari Request Warnings [";
|
|
|
|
|
for(var i = 0; i < ajaxResult.warnings.length; i++) {
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
warningsMessage += ";";
|
|
|
|
|
}
|
|
|
|
|
var warning = ajaxResult.warnings[i];
|
|
|
|
|
warningsMessage += "key = ";
|
|
|
|
|
warningsMessage += warning.key;
|
|
|
|
|
warningsMessage += " | parameter = ";
|
|
|
|
|
warningsMessage += warning.parameter;
|
|
|
|
|
if (warning.hasOwnProperty("value")) {
|
|
|
|
|
warningsMessage += " | value = ";
|
|
|
|
|
warningsMessage += warning.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
warningsMessage += "]";
|
|
|
|
|
Scrutari.log(warningsMessage);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.check = function (obj, name, defaultValue) {
|
|
|
|
|
if (!obj.hasOwnProperty(name)) {
|
|
|
|
|
if (defaultValue) {
|
|
|
|
|
obj[name] = defaultValue;
|
|
|
|
|
} else {
|
|
|
|
|
obj[name] = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta = function (engineInfo) {
|
|
|
|
|
this.engineInfo = engineInfo;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.load = function(scrutariConfig, callback) {
|
|
|
|
|
Scrutari.Ajax.loadEngineInfo(scrutariConfig, null, function (engineInfo) {
|
|
|
|
|
let scrutariMeta = new Scrutari.Meta(engineInfo);
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(scrutariMeta);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getAttributeArray = function (familyName) {
|
|
|
|
|
if (!this.engineInfo.hasOwnProperty("attributes")) {
|
|
|
|
|
return new Array();
|
|
|
|
|
}
|
|
|
|
|
if (!this.engineInfo.attributes.hasOwnProperty(familyName)) {
|
|
|
|
|
return new Array();
|
|
|
|
|
}
|
|
|
|
|
return this.engineInfo.attributes[familyName];
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getBase = function (code) {
|
|
|
|
|
var key = "code_" + code;
|
|
|
|
|
if (this.engineInfo.baseMap.hasOwnProperty(key)) {
|
|
|
|
|
return this.engineInfo.baseMap[key];
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getBaseArray = function (sortFunction) {
|
|
|
|
|
var array = new Array();
|
|
|
|
|
var baseMap = this.engineInfo.baseMap;
|
|
|
|
|
var p=0;
|
|
|
|
|
for(let prop in baseMap) {
|
|
|
|
|
array[p] = baseMap[prop];
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
if (sortFunction) {
|
|
|
|
|
array = array.sort(sortFunction);
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCategory = function (categoryName) {
|
|
|
|
|
if (this.engineInfo.hasOwnProperty("categoryMap")) {
|
|
|
|
|
if (this.engineInfo.categoryMap.hasOwnProperty(categoryName)) {
|
|
|
|
|
return this.engineInfo.categoryMap[categoryName];
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCategoryArray = function (sortFunction) {
|
|
|
|
|
var array = new Array();
|
|
|
|
|
if (!this.engineInfo.hasOwnProperty("categoryMap")) {
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
var categoryMap = this.engineInfo.categoryMap;
|
|
|
|
|
var p=0;
|
|
|
|
|
for(let prop in categoryMap) {
|
|
|
|
|
array[p] = categoryMap[prop];
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
if (sortFunction) {
|
|
|
|
|
array = array.sort(sortFunction);
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCategoryForCorpus = function (code) {
|
|
|
|
|
if (!this.engineInfo.hasOwnProperty("categoryMap")) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var categoryMap = this.engineInfo.categoryMap;
|
|
|
|
|
for(let prop in categoryMap) {
|
|
|
|
|
let category = categoryMap[prop];
|
|
|
|
|
for(let codecorpus of category.codecorpusArray) {
|
|
|
|
|
if (codecorpus === code) {
|
|
|
|
|
return category;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getComplementTitle = function(code, complementNumber) {
|
|
|
|
|
var corpus = this.getCorpus(code);
|
|
|
|
|
if (!corpus) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
var key = "complement_" + complementNumber;
|
|
|
|
|
if (corpus.phraseMap.hasOwnProperty(key)) {
|
|
|
|
|
return corpus.phraseMap[key];
|
|
|
|
|
} else {
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCorpus = function (code) {
|
|
|
|
|
var key = "code_" + code;
|
|
|
|
|
if (this.engineInfo.corpusMap.hasOwnProperty(key)) {
|
|
|
|
|
return this.engineInfo.corpusMap[key];
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCorpusArray = function (sortFunction) {
|
|
|
|
|
var array = new Array();
|
|
|
|
|
var corpusMap = this.engineInfo.corpusMap;
|
|
|
|
|
var p=0;
|
|
|
|
|
for(let prop in corpusMap) {
|
|
|
|
|
array[p] = corpusMap[prop];
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
if (sortFunction) {
|
|
|
|
|
array = array.sort(sortFunction);
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCorpusArrayForBases = function (baseArray) {
|
|
|
|
|
var result = new Array();
|
|
|
|
|
for(let codebase of baseArray) {
|
|
|
|
|
let key = "code_" +codebase;
|
|
|
|
|
if (this.engineInfo.baseMap.hasOwnProperty(key)) {
|
|
|
|
|
result = result.concat(this.engineInfo.baseMap[key].codecorpusArray);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCorpusArrayForCategories = function (categoryArray) {
|
|
|
|
|
var result = new Array();
|
|
|
|
|
if (!this.engineInfo.hasOwnProperty("categoryMap")) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
for(let categoryName of categoryArray) {
|
|
|
|
|
if (this.engineInfo.categoryMap.hasOwnProperty(categoryName)) {
|
|
|
|
|
result = result.concat(this.engineInfo.categoryMap[categoryName].codecorpusArray);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCorpusFicheCount = function (code) {
|
|
|
|
|
var corpus = this.getCorpus(code);
|
|
|
|
|
if (!corpus) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return corpus.stats.fiche;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getCorpusLangFicheCount = function (code, langArray) {
|
|
|
|
|
var corpus = this.getCorpus(code);
|
|
|
|
|
if (!corpus) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
var ficheCount = 0;
|
|
|
|
|
for(let langObj of corpus.stats.langArray) {
|
|
|
|
|
if ($.inArray(langObj.lang, langArray) !== -1) {
|
|
|
|
|
ficheCount += langObj.fiche;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ficheCount;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getDefaultOptions = function () {
|
|
|
|
|
var options = {};
|
|
|
|
|
var attrMap = this.engineInfo.metadata.attrMap;
|
|
|
|
|
for(let key in attrMap) {
|
|
|
|
|
if (key.indexOf("scrutarijs:") === 0) {
|
|
|
|
|
let name = key.substring("scrutarijs:".length);
|
|
|
|
|
let values = attrMap[key];
|
|
|
|
|
if (values.length === 1) {
|
|
|
|
|
let value = values[0];
|
|
|
|
|
if (value === "false") {
|
|
|
|
|
value = false;
|
|
|
|
|
} else if (value === "true") {
|
|
|
|
|
value = true;
|
|
|
|
|
}
|
|
|
|
|
options[name] = value;
|
|
|
|
|
} else {
|
|
|
|
|
options[name] = values;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this[key] = options[key];
|
|
|
|
|
}
|
|
|
|
|
return options;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getEngineInfo = function () {
|
|
|
|
|
return this.engineInfo;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getGlobalFicheCount = function () {
|
|
|
|
|
return this.engineInfo.stats.fiche;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getGlobalLangFicheCount = function (langArray) {
|
|
|
|
|
var ficheCount = 0;
|
|
|
|
|
for(let langObj of this.engineInfo.stats.langArray) {
|
|
|
|
|
if ($.inArray(langObj.lang, langArray) !== -1) {
|
|
|
|
|
ficheCount += langObj.fiche;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ficheCount;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getLangArray = function (sortFunction) {
|
|
|
|
|
var array = new Array();
|
|
|
|
|
var length = this.engineInfo.stats.langArray.length;
|
|
|
|
|
for(let i = 0; i < length; i++) {
|
|
|
|
|
array[i] = this.engineInfo.stats.langArray[i];
|
|
|
|
|
}
|
|
|
|
|
if (sortFunction) {
|
|
|
|
|
array = array.sort(sortFunction);
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getLangLabel = function (iso) {
|
|
|
|
|
if (this.engineInfo.langMap.hasOwnProperty(iso)) {
|
|
|
|
|
return this.engineInfo.langMap[iso];
|
|
|
|
|
} else {
|
|
|
|
|
return iso;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getThesaurus = function (code) {
|
|
|
|
|
var key = "code_" + code;
|
|
|
|
|
if (this.engineInfo.thesaurusMap.hasOwnProperty(key)) {
|
|
|
|
|
return this.engineInfo.thesaurusMap[key];
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getThesaurusArray = function (sortFunction) {
|
|
|
|
|
var array = new Array();
|
|
|
|
|
var thesaurusMap = this.engineInfo.thesaurusMap;
|
|
|
|
|
var p=0;
|
|
|
|
|
for(let prop in thesaurusMap) {
|
|
|
|
|
array[p] = thesaurusMap[prop];
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
if (sortFunction) {
|
|
|
|
|
array = array.sort(sortFunction);
|
|
|
|
|
}
|
|
|
|
|
return array;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.getTitle = function () {
|
|
|
|
|
return this.engineInfo.metadata.title;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Meta.prototype.withCategory = function () {
|
|
|
|
|
return this.engineInfo.hasOwnProperty("categoryMap");
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete = {};
|
|
|
|
|
Scrutari.Complete.bythesaurusArray = function (fiche, scrutariMeta, motcleProvider) {
|
|
|
|
|
if (!fiche.hasOwnProperty("bythesaurusMap")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let thesaurusArray = scrutariMeta.getThesaurusArray();
|
|
|
|
|
let _bythesaurusArray = new Array();
|
|
|
|
|
for(let thesaurus of thesaurusArray) {
|
|
|
|
|
let codethesaurus = thesaurus.codethesaurus;
|
|
|
|
|
let key = "code_" + codethesaurus;
|
|
|
|
|
if (fiche.bythesaurusMap.hasOwnProperty(key)) {
|
|
|
|
|
let motcleArray = new Array();
|
|
|
|
|
for(let codemotcle of fiche.bythesaurusMap[key]) {
|
|
|
|
|
let motcle = motcleProvider(codemotcle);
|
|
|
|
|
if (motcle) {
|
|
|
|
|
motcleArray.push(motcle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_bythesaurusArray.push({
|
|
|
|
|
thesaurus: thesaurus,
|
|
|
|
|
motcleArray: motcleArray
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fiche._bythesaurusArray = _bythesaurusArray;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.complementTitle = function (fiche, scrutariMeta) {
|
|
|
|
|
if (fiche.hasOwnProperty("mcomplementArray")) {
|
|
|
|
|
for(let mcomplement of fiche.mcomplementArray) {
|
|
|
|
|
mcomplement.title = scrutariMeta.getComplementTitle(fiche.codecorpus, mcomplement.number);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.icon = function (fiche) {
|
|
|
|
|
if (fiche.hasOwnProperty("icon")) {
|
|
|
|
|
fiche._icon = fiche.icon;
|
|
|
|
|
return true;
|
|
|
|
|
} else if (fiche.hasOwnProperty("ficheicon")) {
|
|
|
|
|
fiche._icon = fiche.ficheicon;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.markedAttributeArray = function (fiche, scrutariMeta, familyName ) {
|
|
|
|
|
let attributeArray = scrutariMeta.getAttributeArray(familyName);
|
|
|
|
|
if (attributeArray.length === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let objArray = new Array();
|
|
|
|
|
for(let attribute of attributeArray) {
|
|
|
|
|
if (fiche.mattrMap.hasOwnProperty(attribute.name)) {
|
|
|
|
|
objArray.push({
|
|
|
|
|
name: attribute.name,
|
|
|
|
|
title: attribute.title,
|
|
|
|
|
type: attribute.type,
|
|
|
|
|
valueArray: fiche.mattrMap[attribute.name]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fiche["_" + familyName + "AttributeArray"] = objArray;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.motcleArray = function (fiche, motcleProvider) {
|
|
|
|
|
if (!fiche.hasOwnProperty("codemotcleArray")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let motcleArray = new Array();
|
|
|
|
|
for(let codemotcle of fiche.codemotcleArray) {
|
|
|
|
|
let motcle = motcleProvider(codemotcle);
|
|
|
|
|
if (motcle) {
|
|
|
|
|
motcleArray.push(motcle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (motcleArray.length > 0) {
|
|
|
|
|
fiche._motcleArray = motcleArray;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.target = function (fiche, target) {
|
|
|
|
|
fiche._target = target;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.thumbnail = function (fiche) {
|
|
|
|
|
if (fiche.hasOwnProperty("thumbnail")) {
|
|
|
|
|
fiche._thumbnail = fiche.thumbnail;
|
|
|
|
|
return true;
|
|
|
|
|
} else if (Scrutari.Complete.hasAttribute(fiche, "sct:thumbnail")) {
|
|
|
|
|
fiche._thumbnail = fiche.attrMap["sct:thumbnail"][0];
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.hasAttribute = function (fiche, attributeKey) {
|
|
|
|
|
if (!fiche.attrMap) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (attributeKey) {
|
|
|
|
|
return fiche.attrMap.hasOwnProperty(attributeKey);
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Complete.hasMarkedAttribute = function (fiche, attributeKey) {
|
|
|
|
|
if (!fiche.mattrMap) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (attributeKey) {
|
|
|
|
|
return fiche.mattrMap.hasOwnProperty(attributeKey);
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result = function (ficheSearchResult, requestParameters, groupSortFunction) {
|
|
|
|
|
this.ficheSearchResult = ficheSearchResult;
|
|
|
|
|
this.requestParameters = requestParameters;
|
|
|
|
|
this.searchMeta = ficheSearchResult.searchMeta;
|
|
|
|
|
this.ficheGroupArray = ficheSearchResult.ficheGroupArray;
|
|
|
|
|
if ((groupSortFunction) && (this.ficheGroupArray.length > 1)) {
|
|
|
|
|
this.ficheGroupArray = this.ficheGroupArray.sort(groupSortFunction);
|
|
|
|
|
}
|
|
|
|
|
this.motcleMap = new Object();
|
|
|
|
|
if (ficheSearchResult.hasOwnProperty("motcleArray")) {
|
|
|
|
|
for(let motcle of ficheSearchResult.motcleArray) {
|
|
|
|
|
this.motcleMap["code_" + motcle.codemotcle] = motcle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.newSearch = function (scrutariConfig, requestParameters, callback, apiErrorCallback) {
|
|
|
|
|
Scrutari.Ajax.loadFicheSearchResult(scrutariConfig, requestParameters, _ficheSearchResultCallback, apiErrorCallback);
|
|
|
|
|
function _ficheSearchResultCallback(ficheSearchResult) {
|
|
|
|
|
callback(new Scrutari.Result(ficheSearchResult, requestParameters, scrutariConfig.options.groupSortFunction));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getQId = function () {
|
|
|
|
|
if (this.searchMeta) {
|
|
|
|
|
return this.searchMeta.qId;
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getQ = function () {
|
|
|
|
|
if (this.searchMeta) {
|
|
|
|
|
return this.searchMeta.q;
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getFicheCount = function () {
|
|
|
|
|
if (this.searchMeta) {
|
|
|
|
|
return this.searchMeta.ficheCount;
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getFicheGroupType = function () {
|
|
|
|
|
var type = this.ficheSearchResult.ficheGroupType;
|
|
|
|
|
if (type === "none") {
|
|
|
|
|
type = "unique";
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getUniqueFicheArray = function () {
|
|
|
|
|
if (this.ficheGroupArray.length === 0) {
|
|
|
|
|
return new Array();
|
|
|
|
|
}
|
|
|
|
|
return this.ficheGroupArray[0].ficheArray;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.selectUniqueFicheArray = function (paginationLength, paginationNumber) {
|
|
|
|
|
var selectionArray = new Array();
|
|
|
|
|
if (this.ficheGroupArray.length === 0) {
|
|
|
|
|
return selectionArray;
|
|
|
|
|
}
|
|
|
|
|
var ficheArray = this.ficheGroupArray[0].ficheArray;
|
|
|
|
|
var startIndex = paginationLength * (paginationNumber - 1);
|
|
|
|
|
var length = ficheArray.length;
|
|
|
|
|
if (startIndex >= length) {
|
|
|
|
|
return selectionArray;
|
|
|
|
|
}
|
|
|
|
|
var min = Math.min(ficheArray.length, startIndex + paginationLength);
|
|
|
|
|
for(let i = startIndex; i < min; i++) {
|
|
|
|
|
selectionArray.push(ficheArray[i]);
|
|
|
|
|
}
|
|
|
|
|
return selectionArray;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.isUniquePaginationLoaded = function (paginationLength, paginationNumber) {
|
|
|
|
|
if (this.ficheGroupArray.length === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
var ficheCount = this.getFicheCount();
|
|
|
|
|
var ficheArray = this.ficheGroupArray[0].ficheArray;
|
|
|
|
|
var length = ficheArray.length;
|
|
|
|
|
if (length === ficheCount) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
var endIndex = (paginationLength * paginationNumber) - 1;
|
|
|
|
|
if (endIndex < length) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.loadUniquePagination = function (scrutariConfig, paginationLength, paginationNumber, callback) {
|
|
|
|
|
if (this.ficheGroupArray.length === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
var group = this.ficheGroupArray[0];
|
|
|
|
|
if (!group) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var ficheCount = this.getFicheCount();
|
|
|
|
|
var ficheArray = group.ficheArray;
|
|
|
|
|
var length = ficheArray.length;
|
|
|
|
|
if (length === ficheCount) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var _existingFicheSearchResultCallback = function (ficheSearchResult) {
|
|
|
|
|
var newCount = ficheSearchResult.ficheGroupArray.length;
|
|
|
|
|
if (newCount > 0) {
|
|
|
|
|
group.ficheArray = group.ficheArray.concat(ficheSearchResult.ficheGroupArray[0].ficheArray);
|
|
|
|
|
}
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var requestParameters = {
|
|
|
|
|
qid: this.getQId(),
|
|
|
|
|
start: length +1,
|
|
|
|
|
limit: (paginationLength * (paginationNumber + 2)) - length
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadExistingFicheSearchResult(scrutariConfig, requestParameters, _existingFicheSearchResultCallback);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.isCategoryPaginationLoaded = function (categoryName, paginationLength, paginationNumber) {
|
|
|
|
|
var group = this.getFicheGroupByCategoryName(categoryName);
|
|
|
|
|
if (!group) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
var categoryFicheCount = group.ficheCount;
|
|
|
|
|
var ficheArray = group.ficheArray;
|
|
|
|
|
var length = ficheArray.length;
|
|
|
|
|
if (length === categoryFicheCount) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
var endIndex = (paginationLength * paginationNumber) - 1;
|
|
|
|
|
if (endIndex < length) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.loadCategoryPagination = function (scrutariConfig, categoryName, paginationLength, paginationNumber, callback) {
|
|
|
|
|
var group = this.getFicheGroupByCategoryName(categoryName);
|
|
|
|
|
if (!group) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var categoryFicheCount = group.ficheCount;
|
|
|
|
|
var ficheArray = group.ficheArray;
|
|
|
|
|
var length = ficheArray.length;
|
|
|
|
|
if (length === categoryFicheCount) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var requestParameters = {
|
|
|
|
|
qid: this.getQId(),
|
|
|
|
|
start: length +1,
|
|
|
|
|
limit: (paginationLength * (paginationNumber + 2)) - length,
|
|
|
|
|
starttype: "in:" + categoryName
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Ajax.loadExistingFicheSearchResult(scrutariConfig, requestParameters, _existingFicheSearchResultCallback);
|
|
|
|
|
function _existingFicheSearchResultCallback(ficheSearchResult) {
|
|
|
|
|
for(let newGroup of ficheSearchResult.ficheGroupArray) {
|
|
|
|
|
if (newGroup.category.name === group.category.name) {
|
|
|
|
|
group.ficheArray = group.ficheArray.concat(newGroup.ficheArray);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.selectCategoryFicheArray = function (categoryName, paginationLength, paginationNumber) {
|
|
|
|
|
var selectionArray = new Array();
|
|
|
|
|
var ficheArray = this.getCategoryFicheArrayByName(categoryName);
|
|
|
|
|
var startIndex = paginationLength * (paginationNumber - 1);
|
|
|
|
|
var length = ficheArray.length;
|
|
|
|
|
if (startIndex >= length) {
|
|
|
|
|
return selectionArray;
|
|
|
|
|
}
|
|
|
|
|
var min = Math.min(ficheArray.length, startIndex + paginationLength);
|
|
|
|
|
for(let i = startIndex; i < min; i++) {
|
|
|
|
|
selectionArray.push(ficheArray[i]);
|
|
|
|
|
}
|
|
|
|
|
return selectionArray;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getCategoryCount = function () {
|
|
|
|
|
return this.ficheGroupArray.length;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getCategory = function (index) {
|
|
|
|
|
return this.ficheGroupArray[index].category;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getFicheGroupByCategoryName = function (categoryName) {
|
|
|
|
|
var groupCount = this.ficheGroupArray.length;
|
|
|
|
|
for(let i = 0; i < groupCount; i++) {
|
|
|
|
|
let group = this.ficheGroupArray[i];
|
|
|
|
|
if ((group.category) && (group.category.name === categoryName)) {
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getCategoryFicheCount = function (index) {
|
|
|
|
|
return this.ficheGroupArray[index].ficheCount;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getCategoryFicheCountByName = function (categoryName) {
|
|
|
|
|
for(let group of this.ficheGroupArray) {
|
|
|
|
|
if ((group.category) && (group.category.name === categoryName)) {
|
|
|
|
|
return group.ficheCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getCategoryFicheArray = function (index) {
|
|
|
|
|
return this.ficheGroupArray[index].ficheArray;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getCategoryFicheArrayByName = function (categoryName) {
|
|
|
|
|
var categoryCount = this.getCategoryCount();
|
|
|
|
|
for(let i = 0; i < categoryCount; i++) {
|
|
|
|
|
let category = this.getCategory(i);
|
|
|
|
|
if (category.name === categoryName) {
|
|
|
|
|
return this.getCategoryFicheArray(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Array();
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getMotcle = function (code) {
|
|
|
|
|
var key = "code_" + code;
|
|
|
|
|
if (this.motcleMap.hasOwnProperty(key)) {
|
|
|
|
|
return this.motcleMap[key];
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Result.prototype.getMotcleArray = function (motcleFilter) {
|
|
|
|
|
if (!motcleFilter) {
|
|
|
|
|
motcleFilter = _accept;
|
|
|
|
|
}
|
|
|
|
|
var result = new Array();
|
|
|
|
|
if (this.ficheSearchResult.hasOwnProperty("motcleArray")) {
|
|
|
|
|
for(let motcle of this.ficheSearchResult.motcleArray) {
|
|
|
|
|
if (motcleFilter(motcle)) {
|
|
|
|
|
result.push(motcle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
function _accept(motcle) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils = {};
|
|
|
|
|
Scrutari.Utils.divideIntoColumns = function (objectArray, jqArgument, objectTemplate) {
|
|
|
|
|
var objectCount = objectArray.length;
|
|
|
|
|
if (objectCount === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
var elementCount = $elements.length;
|
|
|
|
|
if (elementCount === 0) {
|
|
|
|
|
Scrutari.log("HtmlElement selection with jqArgument is empty ");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var objectCount = objectArray.length;
|
|
|
|
|
if (objectCount <= elementCount) {
|
|
|
|
|
for(var i = 0; i < objectCount; i++) {
|
|
|
|
|
$($elements[i]).append(objectTemplate(objectArray[i]));
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var modulo = objectCount % elementCount;
|
|
|
|
|
var columnLength = (objectCount - modulo) / elementCount;
|
|
|
|
|
var start = 0;
|
|
|
|
|
var stop = 0;
|
|
|
|
|
for(var i = 0; i< elementCount; i++) {
|
|
|
|
|
var $element = $($elements[i]);
|
|
|
|
|
stop += columnLength;
|
|
|
|
|
if (i < modulo) {
|
|
|
|
|
stop++;
|
|
|
|
|
}
|
|
|
|
|
for(var j = start; j < stop; j++) {
|
|
|
|
|
$element.append(objectTemplate(objectArray[j]));
|
|
|
|
|
}
|
|
|
|
|
start = stop;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.getTabArray = function (ficheCount, paginationLength, currentPaginationNumber) {
|
|
|
|
|
var result = new Array();
|
|
|
|
|
var paginationCount;
|
|
|
|
|
if (ficheCount <= paginationLength) {
|
|
|
|
|
paginationCount = 1;
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
var modulo = ficheCount % paginationLength;
|
|
|
|
|
paginationCount = (ficheCount - modulo) / paginationLength;
|
|
|
|
|
if (modulo > 0) {
|
|
|
|
|
paginationCount ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (currentPaginationNumber > paginationCount) {
|
|
|
|
|
currentPaginationNumber = paginationCount;
|
|
|
|
|
}
|
|
|
|
|
var paginationNumberStart = 1;
|
|
|
|
|
var paginationNumberEnd = 9;
|
|
|
|
|
if (currentPaginationNumber > 6) {
|
|
|
|
|
paginationNumberStart = currentPaginationNumber - 3;
|
|
|
|
|
paginationNumberEnd = currentPaginationNumber + 3;
|
|
|
|
|
}
|
|
|
|
|
if (paginationNumberEnd > paginationCount) {
|
|
|
|
|
paginationNumberEnd = paginationCount;
|
|
|
|
|
}
|
|
|
|
|
if (paginationNumberStart > 1) {
|
|
|
|
|
result.push({
|
|
|
|
|
number: 1,
|
|
|
|
|
title: "1",
|
|
|
|
|
state: 'enabled'
|
|
|
|
|
});
|
|
|
|
|
result.push({
|
|
|
|
|
number: 0,
|
|
|
|
|
title: "…",
|
|
|
|
|
state: 'disabled'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
for(var i = paginationNumberStart; i <= paginationNumberEnd; i++) {
|
|
|
|
|
var state = 'enabled';
|
|
|
|
|
if (i === currentPaginationNumber) {
|
|
|
|
|
state = 'active';
|
|
|
|
|
}
|
|
|
|
|
result.push({
|
|
|
|
|
number: i,
|
|
|
|
|
title: i.toString(),
|
|
|
|
|
state: state
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (paginationNumberEnd < paginationCount) {
|
|
|
|
|
result.push({
|
|
|
|
|
number: 0,
|
|
|
|
|
title: "…",
|
|
|
|
|
state: 'disabled'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.disable = function (jqArgument) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
$elements.prop('disabled', true);
|
|
|
|
|
return $elements;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.enable = function (jqArgument) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
$elements.prop('disabled', false);
|
|
|
|
|
return $elements;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.uncheck = function (jqArgument) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
$elements.prop('checked', false);
|
|
|
|
|
return $elements;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.check = function (jqArgument) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
$elements.prop('checked', true);
|
|
|
|
|
return $elements;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.toggle = function (jqElement, stateDataKey) {
|
|
|
|
|
var state = jqElement.data(stateDataKey);
|
|
|
|
|
if (state === 'off') {
|
|
|
|
|
state = 'on';
|
|
|
|
|
} else {
|
|
|
|
|
state = 'off';
|
|
|
|
|
}
|
|
|
|
|
jqElement.data(stateDataKey, state);
|
|
|
|
|
return state;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.toggle.disabled = function (jqArgument, state) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
if (state === 'off') {
|
|
|
|
|
$elements.prop('disabled', true);
|
|
|
|
|
} else {
|
|
|
|
|
$elements.prop('disabled', false);
|
|
|
|
|
}
|
|
|
|
|
return $elements;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.toggle.text = function (jqArgument, alterDataKey) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
var length = $elements.length;
|
|
|
|
|
for(var i = 0; i < length; i++) {
|
|
|
|
|
var jqEl = $($elements[i]);
|
|
|
|
|
var currentText =jqEl.text();
|
|
|
|
|
var alterText = jqEl.data(alterDataKey);
|
|
|
|
|
jqEl.text(alterText);
|
|
|
|
|
jqEl.data(alterDataKey, currentText);
|
|
|
|
|
}
|
|
|
|
|
return $elements;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.toggle.classes = function (jqArgument, state, onClass, offClass) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
if (state === 'off') {
|
|
|
|
|
$elements.addClass(offClass).removeClass(onClass);
|
|
|
|
|
} else {
|
|
|
|
|
$elements.removeClass(offClass).addClass(onClass);
|
|
|
|
|
}
|
|
|
|
|
return $elements;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.getBaseSortFunction = function (baseSortType, locales) {
|
|
|
|
|
var compareFunction = Scrutari.Utils.getCompareLocaleFunction(locales);
|
|
|
|
|
switch(baseSortType) {
|
|
|
|
|
case "fiche-count":
|
|
|
|
|
return _ficheCountSort;
|
|
|
|
|
case "title":
|
|
|
|
|
return _titleSort;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
function _ficheCountSort(base1, base2) {
|
|
|
|
|
var count1 = base1.stats.fiche;
|
|
|
|
|
var count2 = base2.stats.fiche;
|
|
|
|
|
if (count1 > count2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return Scrutari.Utils.compareCodebase(base1, base2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _titleSort(base1, base2) {
|
|
|
|
|
var title1 = base1.title;
|
|
|
|
|
var title2 = base2.title;
|
|
|
|
|
if (!title1) {
|
|
|
|
|
title1 = "";
|
|
|
|
|
}
|
|
|
|
|
if (!title2) {
|
|
|
|
|
title2 = "";
|
|
|
|
|
}
|
|
|
|
|
var comp = compareFunction(title1, title2);
|
|
|
|
|
if (comp !== 0) {
|
|
|
|
|
return comp;
|
|
|
|
|
} else {
|
|
|
|
|
return Scrutari.Utils.compareCodebase(base1, base2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.getCorpusSortFunction = function (corpusSortType, locales) {
|
|
|
|
|
var _ficheCountSort = function (corpus1, corpus2) {
|
|
|
|
|
var count1 = corpus1.stats.fiche;
|
|
|
|
|
var count2 = corpus2.stats.fiche;
|
|
|
|
|
if (count1 > count2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return Scrutari.Utils.compareCodecorpus(corpus1, corpus2);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var compareFunction = Scrutari.Utils.getCompareLocaleFunction(locales);
|
|
|
|
|
var _titleSort = function (corpus1, corpus2) {
|
|
|
|
|
var title1 = corpus1.title;
|
|
|
|
|
var title2 = corpus2.title;
|
|
|
|
|
if (!title1) {
|
|
|
|
|
title1 = "";
|
|
|
|
|
}
|
|
|
|
|
if (!title2) {
|
|
|
|
|
title2 = "";
|
|
|
|
|
}
|
|
|
|
|
var comp = compareFunction(title1, title2);
|
|
|
|
|
if (comp !== 0) {
|
|
|
|
|
return comp;
|
|
|
|
|
} else {
|
|
|
|
|
return Scrutari.Utils.compareCodecorpus(corpus1, corpus2);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
switch(corpusSortType) {
|
|
|
|
|
case "fiche-count":
|
|
|
|
|
return _ficheCountSort;
|
|
|
|
|
case "title":
|
|
|
|
|
return _titleSort;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.getCategorySortFunction = function (categorySortType, locales) {
|
|
|
|
|
var compareFunction = Scrutari.Utils.getCompareLocaleFunction(locales);
|
|
|
|
|
switch(categorySortType) {
|
|
|
|
|
case "rank":
|
|
|
|
|
return _rankSort;
|
|
|
|
|
case "fiche-count":
|
|
|
|
|
return _ficheCountSort;
|
|
|
|
|
case "title":
|
|
|
|
|
return _titleSort;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
function _rankSort(category1, category2) {
|
|
|
|
|
let count1 = category1.rank;
|
|
|
|
|
let count2 = category2.rank;
|
|
|
|
|
if (count1 > count2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
var code1 = category1.name;
|
|
|
|
|
var code2 = category2.name;
|
|
|
|
|
if (code1 < code2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (code1 > code2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _ficheCountSort(category1, category2) {
|
|
|
|
|
let count1 = category1.stats.fiche;
|
|
|
|
|
let count2 = category2.stats.fiche;
|
|
|
|
|
if (count1 > count2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return _rankSort(category1, category2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _titleSort(category1, category2) {
|
|
|
|
|
let title1 = category1.title;
|
|
|
|
|
let title2 = category2.title;
|
|
|
|
|
if (!title1) {
|
|
|
|
|
title1 = "";
|
|
|
|
|
}
|
|
|
|
|
if (!title2) {
|
|
|
|
|
title2 = "";
|
|
|
|
|
}
|
|
|
|
|
let comp = compareFunction(title1, title2);
|
|
|
|
|
if (comp !== 0) {
|
|
|
|
|
return comp;
|
|
|
|
|
} else {
|
|
|
|
|
return _rankSort(category1, category2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.getLangSortFunction = function (langSortType, locales) {
|
|
|
|
|
var compareFunction = Scrutari.Utils.getCompareLocaleFunction(locales);
|
|
|
|
|
switch(langSortType) {
|
|
|
|
|
case "code":
|
|
|
|
|
return _codeSort;
|
|
|
|
|
case "fiche-count":
|
|
|
|
|
return _ficheCountSort;
|
|
|
|
|
case "title":
|
|
|
|
|
return _titleSort;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
function _codeSort(lang1, lang2) {
|
|
|
|
|
let code1 = lang1.lang;
|
|
|
|
|
let code2 = lang2.lang;
|
|
|
|
|
if (code1 < code2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (code1 > code2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _ficheCountSort(lang1, lang2) {
|
|
|
|
|
let count1 = lang1.fiche;
|
|
|
|
|
let count2 = lang2.fiche;
|
|
|
|
|
if (count1 > count2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return _codeSort(lang1, lang2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _titleSort(lang1, lang2) {
|
|
|
|
|
let title1 = lang1.title;
|
|
|
|
|
let title2 = lang2.title;
|
|
|
|
|
if (!title1) {
|
|
|
|
|
title1 = lang1.lang;
|
|
|
|
|
}
|
|
|
|
|
if (!title2) {
|
|
|
|
|
title2 = lang2.lang;
|
|
|
|
|
}
|
|
|
|
|
let comp = compareFunction(title1, title2);
|
|
|
|
|
if (comp !== 0) {
|
|
|
|
|
return comp;
|
|
|
|
|
} else {
|
|
|
|
|
return _codeSort(lang1, lang2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.getGroupSortFunction = function (groupSortType) {
|
|
|
|
|
switch(groupSortType) {
|
|
|
|
|
case "fiche-count":
|
|
|
|
|
return _ficheCountSort;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
function _ficheCountSort(group1, group2) {
|
|
|
|
|
let count1 = group1.ficheCount;
|
|
|
|
|
let count2 = group2.ficheCount;
|
|
|
|
|
if (count1 > count2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
let rank1 = group1.category.rank;
|
|
|
|
|
let rank2 = group1.category.rank;
|
|
|
|
|
if (rank1 < rank2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (rank1 > rank2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.mark = function (markArray, classAttribute) {
|
|
|
|
|
if (!classAttribute) {
|
|
|
|
|
classAttribute = "scrutari-Mark";
|
|
|
|
|
}
|
|
|
|
|
var html = "";
|
|
|
|
|
var length = markArray.length;
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
var obj = markArray[i];
|
|
|
|
|
if (typeof obj === 'string') {
|
2023-03-01 19:31:51 +01:00
|
|
|
|
html += Scrutari.escape(obj);
|
2022-10-01 00:18:32 +02:00
|
|
|
|
} else if (obj.s) {
|
|
|
|
|
html += "<span class='" + classAttribute + "'>";
|
|
|
|
|
html += Scrutari.escape(obj.s);
|
|
|
|
|
html += "</span>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return html;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.formatSearchSequence = function (client, scrutariResult) {
|
|
|
|
|
var q = scrutariResult.getQ();
|
|
|
|
|
q = q.replace(/\&\&/g, client.loc('_ and'));
|
|
|
|
|
q = q.replace(/\|\|/g, client.loc('_ or'));
|
|
|
|
|
return q;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.render = function (templateString, object) {
|
|
|
|
|
var result = templateString;
|
|
|
|
|
for(var key in object) {
|
|
|
|
|
var normalReplace = new RegExp("{{:" + key + "}}", 'g');
|
|
|
|
|
var escapeReplace = new RegExp("{{>" + key + "}}", 'g');
|
|
|
|
|
var value = object[key];
|
|
|
|
|
result = result.replace(normalReplace, value);
|
|
|
|
|
result = result.replace(escapeReplace, Scrutari.escape(value));
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.compareCodebase = function (obj1, obj2) {
|
|
|
|
|
var code1 = obj1.codebase;
|
|
|
|
|
var code2 = obj2.codebase;
|
|
|
|
|
if (code1 < code2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (code1 > code2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.compareCodecorpus = function (obj1, obj2) {
|
|
|
|
|
var code1 = obj1.codecorpus;
|
|
|
|
|
var code2 = obj2.codecorpus;
|
|
|
|
|
if (code1 < code2) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (code1 > code2) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.getCompareLocaleFunction = function (locales) {
|
|
|
|
|
var _localeCompareSupportsLocales = function () {
|
|
|
|
|
try {
|
|
|
|
|
"a".localeCompare("b", "i");
|
|
|
|
|
} catch (exception) {
|
|
|
|
|
return exception.name === "RangeError";
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
var _localesCompare = function (string1, string2) {
|
|
|
|
|
return string1.localeCompare(string2, locales, {
|
|
|
|
|
usage: "sort",
|
|
|
|
|
sensitivity: "base",
|
|
|
|
|
ignorePunctuation: true});
|
|
|
|
|
};
|
|
|
|
|
var _oldCompare = function (string1, string2) {
|
|
|
|
|
string1 = string1.toLowerCase();
|
|
|
|
|
string2 = string2.toLowerCase();
|
|
|
|
|
return string1.localeCompare(string2);
|
|
|
|
|
};
|
|
|
|
|
if (_localeCompareSupportsLocales()) {
|
|
|
|
|
return _localesCompare;
|
|
|
|
|
} else {
|
|
|
|
|
return _oldCompare;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.buildCorpusMap = function (scrutariMeta, arrays) {
|
|
|
|
|
var corpusMap = new Object();
|
|
|
|
|
var finalCount = 0;
|
|
|
|
|
if (arrays.categoryArray) {
|
|
|
|
|
finalCount++;
|
|
|
|
|
var arrayForCategories = scrutariMeta.getCorpusArrayForCategories(arrays.categoryArray);
|
|
|
|
|
for(var i = 0; i < arrayForCategories.length; i++) {
|
|
|
|
|
var key = "code_" + arrayForCategories[i];
|
|
|
|
|
if (corpusMap.hasOwnProperty(key)) {
|
|
|
|
|
corpusMap[key] = corpusMap[key] + 1;
|
|
|
|
|
} else {
|
|
|
|
|
corpusMap[key] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (arrays.baseArray) {
|
|
|
|
|
finalCount++;
|
|
|
|
|
var arrayForBases = scrutariMeta.getCorpusArrayForBases(arrays.baseArray);
|
|
|
|
|
for(var i = 0; i < arrayForBases.length; i++) {
|
|
|
|
|
var key = "code_" + arrayForBases[i];
|
|
|
|
|
if (corpusMap.hasOwnProperty(key)) {
|
|
|
|
|
corpusMap[key] = corpusMap[key] + 1;
|
|
|
|
|
} else {
|
|
|
|
|
corpusMap[key] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (arrays.corpusArrays) {
|
|
|
|
|
finalCount++;
|
|
|
|
|
for(var i = 0; i < arrays.corpusArrays.length; i++) {
|
|
|
|
|
var key = "code_" + arrays.corpusArrays[i];
|
|
|
|
|
if (corpusMap.hasOwnProperty(key)) {
|
|
|
|
|
corpusMap[key] = corpusMap[key] + 1;
|
|
|
|
|
} else {
|
|
|
|
|
corpusMap[key] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
corpusMap.completeValue = finalCount;
|
|
|
|
|
return corpusMap;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Utils.checkKey = function (type, value) {
|
|
|
|
|
switch(type) {
|
|
|
|
|
case "base":
|
|
|
|
|
case "corpus":
|
|
|
|
|
return "code_" + value;
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Loc = function (map) {
|
|
|
|
|
if (map) {
|
|
|
|
|
this.map = map;
|
|
|
|
|
} else {
|
|
|
|
|
this.map = new Object();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Loc.prototype.putAll = function (map) {
|
|
|
|
|
for(var key in map) {
|
|
|
|
|
this.map[key] = map[key];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Loc.prototype.putLoc = function (locKey, locText) {
|
|
|
|
|
this.map[locKey] = locText;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Loc.prototype.loc = function (locKey, ...values) {
|
|
|
|
|
if (!this.map.hasOwnProperty(locKey)) {
|
|
|
|
|
return locKey;
|
|
|
|
|
}
|
|
|
|
|
var text = this.map[locKey];
|
|
|
|
|
var length = values.length;
|
|
|
|
|
if ((length === 1) && (Array.isArray(values[0]))) {
|
|
|
|
|
values = values[0];
|
|
|
|
|
length = values.length;
|
|
|
|
|
}
|
|
|
|
|
if (length > 0) {
|
|
|
|
|
for(let i = 0; i < length; i++) {
|
|
|
|
|
let mark = "{" + i + "}";
|
|
|
|
|
text = text.replace(mark, values[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return text;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Loc.prototype.escape = function (locKey, ...values) {
|
|
|
|
|
if ((values.length === 1) && (Array.isArray(values[0]))) {
|
|
|
|
|
values = values[0];
|
|
|
|
|
}
|
|
|
|
|
return Scrutari.escape(this.loc(locKey, values));
|
|
|
|
|
};
|
|
|
|
|
Scrutari.FilterState = function () {
|
|
|
|
|
this.empty = true;
|
|
|
|
|
this.langOnly = true;
|
|
|
|
|
this.all = {
|
|
|
|
|
category: true,
|
|
|
|
|
base: true,
|
|
|
|
|
corpus: true,
|
|
|
|
|
lang: true
|
|
|
|
|
};
|
|
|
|
|
this.maps = {
|
|
|
|
|
category: {},
|
|
|
|
|
base: {},
|
|
|
|
|
corpus: {},
|
|
|
|
|
lang: {}
|
|
|
|
|
};
|
|
|
|
|
this.titles = {
|
|
|
|
|
category: [],
|
|
|
|
|
base: [],
|
|
|
|
|
corpus: [],
|
|
|
|
|
lang: []
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
Scrutari.FilterState.prototype.contains = function (type, key) {
|
|
|
|
|
if (this.all[type]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
key = Scrutari.Utils.checkKey(type, key);
|
|
|
|
|
return this.maps[type].hasOwnProperty(key);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.FilterState.prototype.add = function (type, key, title) {
|
|
|
|
|
this.all[type] = false;
|
|
|
|
|
this.empty = false;
|
|
|
|
|
if (type !== "lang") {
|
|
|
|
|
this.langOnly = false;
|
|
|
|
|
}
|
|
|
|
|
key = Scrutari.Utils.checkKey(type, key);
|
|
|
|
|
if (!this.maps[type].hasOwnProperty(key)) {
|
|
|
|
|
if (!title) {
|
|
|
|
|
title = key;
|
|
|
|
|
}
|
|
|
|
|
this.maps[type][key] = title;
|
|
|
|
|
this.titles[type].push(title);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Stats = function (scrutariMeta) {
|
|
|
|
|
this.unitArray = new Array();
|
|
|
|
|
var maps = {
|
|
|
|
|
category: {},
|
|
|
|
|
base: {},
|
|
|
|
|
corpus: {},
|
|
|
|
|
lang: {}
|
|
|
|
|
};
|
|
|
|
|
this.maps = maps;
|
|
|
|
|
this.filterState = null;
|
|
|
|
|
for(let corpus of scrutariMeta.getCorpusArray()) {
|
|
|
|
|
let langArray = corpus.stats.langArray;
|
|
|
|
|
let category = scrutariMeta.getCategoryForCorpus(corpus.codecorpus);
|
|
|
|
|
let categoryName = "";
|
|
|
|
|
if (category) {
|
|
|
|
|
categoryName = category.name;
|
|
|
|
|
}
|
|
|
|
|
for(let lang of langArray) {
|
|
|
|
|
let unit = new Scrutari.Stats.Unit(categoryName, corpus.codebase, corpus.codecorpus, lang.lang, lang.fiche);
|
|
|
|
|
this.unitArray.push(unit);
|
|
|
|
|
_addInMap("category", unit, categoryName);
|
|
|
|
|
_addInMap("base", unit, "code_" + corpus.codebase);
|
|
|
|
|
_addInMap("corpus", unit, "code_" + corpus.codecorpus);
|
|
|
|
|
_addInMap("lang", unit, lang.lang);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _addInMap(type, unit, key) {
|
|
|
|
|
var map = maps[type];
|
|
|
|
|
if (!map.hasOwnProperty(key)) {
|
|
|
|
|
map[key] = new Array();
|
|
|
|
|
}
|
|
|
|
|
map[key].push(unit);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Stats.prototype.update = function (filterState) {
|
|
|
|
|
this.filterState = filterState;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Stats.prototype.getFicheCount = function (type, key) {
|
|
|
|
|
key = Scrutari.Utils.checkKey(type, key);
|
|
|
|
|
var map = this.maps[type];
|
|
|
|
|
if (!map.hasOwnProperty(key)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
var count = 0;
|
|
|
|
|
for(let unit of map[key]) {
|
|
|
|
|
count += unit.check(this.filterState);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Stats.Unit = function (category, base, corpus, lang, value) {
|
|
|
|
|
this.category = category;
|
|
|
|
|
this.base = base;
|
|
|
|
|
this.corpus = corpus;
|
|
|
|
|
this.lang = lang;
|
|
|
|
|
this.value = value;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Stats.Unit.prototype.check = function (filterState) {
|
|
|
|
|
if (!filterState) {
|
|
|
|
|
return this.value;
|
|
|
|
|
}
|
|
|
|
|
if (!filterState.contains("category", this.category)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!filterState.contains("base", this.base)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!filterState.contains("corpus", this.corpus)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!filterState.contains("lang", this.lang)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return this.value;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client = function (scrutariConfig, clientId) {
|
|
|
|
|
this.scrutariConfig = scrutariConfig;
|
|
|
|
|
this.clientId = clientId;
|
|
|
|
|
this.scrutariMeta = null;
|
|
|
|
|
this.stats = null;
|
|
|
|
|
this.isWaiting = false;
|
|
|
|
|
this.mainCurrentScrutariResult = null;
|
|
|
|
|
this.currentScrutariResult = null;
|
|
|
|
|
this.options = {
|
|
|
|
|
withCorpus: false,
|
|
|
|
|
baseSort: "fiche-count",
|
|
|
|
|
corpusSort: "fiche-count",
|
|
|
|
|
categorySort: "rank",
|
|
|
|
|
langSort: "code",
|
|
|
|
|
initialQuery: "",
|
|
|
|
|
initialQId: "",
|
|
|
|
|
initialFilters: null,
|
|
|
|
|
permalinkPattern: null,
|
|
|
|
|
ficheTarget: "_blank",
|
|
|
|
|
ignoreIcon: false,
|
|
|
|
|
ignoreThumbnail: false,
|
|
|
|
|
ficheBodyList: null,
|
|
|
|
|
mainTitle: null,
|
|
|
|
|
hooks: {}
|
|
|
|
|
};
|
|
|
|
|
this._locInstance = new Scrutari.Loc();
|
|
|
|
|
this._ignoreArray = new Array();
|
|
|
|
|
this._ficheBodyTemplateArray = [
|
|
|
|
|
"fiche_mtitre",
|
|
|
|
|
"fiche_msoustitre",
|
|
|
|
|
"fiche_year",
|
|
|
|
|
"fiche_primaryattributearray",
|
|
|
|
|
"fiche_mcomplementarray",
|
|
|
|
|
"fiche_secondaryattributearray",
|
|
|
|
|
"fiche_motclearray",
|
|
|
|
|
"fiche_bythesaurusarray"
|
|
|
|
|
];
|
|
|
|
|
this._structureMap = {};
|
|
|
|
|
this._templateMap = {};
|
|
|
|
|
this._scrutariResultMap = {};
|
|
|
|
|
this._historyNumber = 0;
|
|
|
|
|
this.functions = {};
|
|
|
|
|
if (typeof SCRUTARI_L10N !== 'undefined') {
|
|
|
|
|
this._locInstance.putAll(SCRUTARI_L10N);
|
|
|
|
|
}
|
|
|
|
|
if (typeof SCRUTARI_HTML !== 'undefined') {
|
|
|
|
|
this._htmlObject = SCRUTARI_HTML;
|
|
|
|
|
}
|
|
|
|
|
if (typeof SCRUTARI_FRAMEWORKINIT === 'function') {
|
|
|
|
|
SCRUTARI_FRAMEWORKINIT(this);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.loc = function (locKey) {
|
|
|
|
|
return this._locInstance.loc(locKey);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.toPermalink = function (qId) {
|
|
|
|
|
if (this.options.permalinkPattern) {
|
|
|
|
|
return this.scrutariConfig.getPermalinkUrl(qId, this.options.permalinkPattern);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.storeResult = function (historyName, scrutariResult) {
|
|
|
|
|
this._scrutariResultMap[historyName] = scrutariResult;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.unstoreResult = function (historyName) {
|
|
|
|
|
this._scrutariResultMap[historyName] = null;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.getResult = function (historyName) {
|
|
|
|
|
if (this._scrutariResultMap.hasOwnProperty(historyName)) {
|
|
|
|
|
return this._scrutariResultMap[historyName];
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.newHistoryNumber = function () {
|
|
|
|
|
this._historyNumber++;
|
|
|
|
|
return this._historyNumber;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.ignoreElement = function (elementName) {
|
|
|
|
|
return $.inArray(elementName, this._ignoreArray) > -1;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.getTemplate = function (templateName) {
|
|
|
|
|
var template = this.hook("getTemplate", templateName);
|
|
|
|
|
if (template) {
|
|
|
|
|
if (typeof template === "function") {
|
|
|
|
|
return template;
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.log("getTemplate hook does not return function for template name: " + templateName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (templateName.indexOf(":") === -1) {
|
|
|
|
|
templateName = "scrutari:" + templateName;
|
|
|
|
|
}
|
|
|
|
|
template = $.templates[templateName];
|
|
|
|
|
if (!template) {
|
|
|
|
|
return function () {
|
|
|
|
|
return "Unknown template : " + templateName;
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return template;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.render = function (templateName, context, helpers) {
|
|
|
|
|
var templateFunction = this.getTemplate(templateName);
|
|
|
|
|
return templateFunction(context, helpers);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.hook = function (name) {
|
|
|
|
|
if (!this.options.hooks.hasOwnProperty(name)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var hook = this.options.hooks[name];
|
|
|
|
|
if (typeof hook === "function") {
|
|
|
|
|
var newArgs = new Array();
|
|
|
|
|
var argLength = arguments.length;
|
|
|
|
|
if (argLength > 1) {
|
|
|
|
|
for(let i = 1; i < argLength; i++) {
|
|
|
|
|
newArgs.push(arguments[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hook.apply(this, newArgs);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.getFicheBodyTemplateArray = function (fiche, categoryName) {
|
|
|
|
|
var array = this.hook("getFicheBodyTemplateArray", fiche, categoryName);
|
|
|
|
|
if (array) {
|
|
|
|
|
return array;
|
|
|
|
|
} else {
|
|
|
|
|
return this._ficheBodyTemplateArray;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$ = function (properties) {
|
|
|
|
|
return Scrutari.$("#" + this.clientId, properties);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$area = function (name, action) {
|
|
|
|
|
var $area = this.$({scrutariArea: name});
|
|
|
|
|
if (action) {
|
|
|
|
|
switch(action) {
|
|
|
|
|
case 'show':
|
|
|
|
|
this.show ($area);
|
|
|
|
|
break;
|
|
|
|
|
case 'hide':
|
|
|
|
|
this.hide($area);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $area;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$block = function (name, action) {
|
|
|
|
|
var $block = this.$({scrutariBlock: name});
|
|
|
|
|
if (action) {
|
|
|
|
|
switch(action) {
|
|
|
|
|
case 'show':
|
|
|
|
|
this.show ($block);
|
|
|
|
|
break;
|
|
|
|
|
case 'hide':
|
|
|
|
|
this.hide($block);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $block;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$button = function (name, target) {
|
|
|
|
|
if (target) {
|
|
|
|
|
return this.$({scrutariButton: name, scrutariTarget: target});
|
|
|
|
|
} else {
|
|
|
|
|
return this.$({scrutariButton: name});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$count = function (name, action, value) {
|
|
|
|
|
var $count = this.$({scrutariCount: name});
|
|
|
|
|
if (action) {
|
|
|
|
|
switch(action) {
|
|
|
|
|
case 'update':
|
|
|
|
|
if (!value) {
|
|
|
|
|
value = 0;
|
|
|
|
|
}
|
|
|
|
|
Scrutari.$($count, {scrutariRole: "value"}).html(this.formatNumber(value));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $count;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$form = function (name) {
|
|
|
|
|
return this.$({scrutariForm: name});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$group = function (name) {
|
|
|
|
|
return this.$({scrutariGroup: name});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$hidden = function (name, action) {
|
|
|
|
|
var $hidden = this.$({scrutariHidden: name});
|
|
|
|
|
if (action) {
|
|
|
|
|
switch(action) {
|
|
|
|
|
case 'show':
|
|
|
|
|
this.show ($hidden);
|
|
|
|
|
break;
|
|
|
|
|
case 'hide':
|
|
|
|
|
this.hide($hidden);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $hidden;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$input = function (name, value) {
|
|
|
|
|
if (value) {
|
|
|
|
|
return this.$({_element: "input", _name: name, _value: value});
|
|
|
|
|
} else {
|
|
|
|
|
return this.$({_element: "input", _name: name});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$input_checked = function (name, value) {
|
|
|
|
|
if (value) {
|
|
|
|
|
return this.$({_element: "input", _name: name, _value: value, _checked: true});
|
|
|
|
|
} else {
|
|
|
|
|
return this.$({_element: "input", _name: name, _checked: true});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$label = function (name) {
|
|
|
|
|
return this.$({scrutariLabel: name});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$link = function (name) {
|
|
|
|
|
return this.$({scrutariLink: name});
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$modal = function (name, action) {
|
|
|
|
|
var $modal = this.$({scrutariModal: name});
|
|
|
|
|
if ((action) && (this.functions.hasOwnProperty("modalAction"))) {
|
|
|
|
|
this.functions.modalAction($modal, action);
|
|
|
|
|
}
|
|
|
|
|
return $modal;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$panel = function (name, action) {
|
|
|
|
|
var $panel = this.$({scrutariPanel: name});
|
|
|
|
|
if (action) {
|
|
|
|
|
switch(action) {
|
|
|
|
|
case 'show':
|
|
|
|
|
this.show ($panel);
|
|
|
|
|
break;
|
|
|
|
|
case 'hide':
|
|
|
|
|
this.hide($panel);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $panel;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.$title = function (name, action) {
|
|
|
|
|
var $title = this.$({scrutariTitle: name});
|
|
|
|
|
if (action) {
|
|
|
|
|
switch(action) {
|
|
|
|
|
case 'show':
|
|
|
|
|
this.show ($title);
|
|
|
|
|
break;
|
|
|
|
|
case 'hide':
|
|
|
|
|
this.hide($title);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $title;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.show = function (jqArgument) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
$elements.removeClass("scrutari-Hidden");
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.hide = function (jqArgument) {
|
|
|
|
|
var $elements = Scrutari.convert(jqArgument);
|
|
|
|
|
$elements.addClass("scrutari-Hidden");
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.scrollToResult = function () {
|
|
|
|
|
$(window).scrollTop(this.$area('result').offset().top);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.getStructureHtml = function (name) {
|
|
|
|
|
if (this._structureMap.hasOwnProperty(name)) {
|
|
|
|
|
return this._structureMap[name];
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.log("Unknown structure: " + name);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.getStructureNameArray = function () {
|
|
|
|
|
var result = new Array();
|
|
|
|
|
for(let prop in this._structureMap) {
|
|
|
|
|
result.push(prop);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.getTemplateHtml = function (name) {
|
|
|
|
|
if (this._templateMap.hasOwnProperty(name)) {
|
|
|
|
|
return this._templateMap[name];
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.log("Unknown template: " + name);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.prototype.formatNumber = function (number) {
|
|
|
|
|
if (Number.prototype.toLocaleString) {
|
|
|
|
|
return number.toLocaleString(this.scrutariConfig.lang);
|
|
|
|
|
} else {
|
|
|
|
|
return number;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.init = function (scrutariConfig, clientId, options, callback) {
|
|
|
|
|
if (!$.templates) {
|
|
|
|
|
throw new Error("JsRender is not installed");
|
|
|
|
|
}
|
|
|
|
|
$.views.helpers("scrutari_mark", function(markArray) {
|
|
|
|
|
return Scrutari.Utils.mark(markArray);
|
|
|
|
|
});
|
|
|
|
|
Scrutari.Meta.load(scrutariConfig, function (scrutariMeta) {
|
|
|
|
|
var client = new Scrutari.Client(scrutariConfig, clientId);
|
|
|
|
|
$.views.helpers({
|
|
|
|
|
scrutari_client: client,
|
|
|
|
|
scrutari_loc: function(key, ...values) {
|
|
|
|
|
return client.loc(key, values);
|
|
|
|
|
},
|
|
|
|
|
scrutari_format: function(number) {
|
|
|
|
|
return client.formatNumber(number);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
client.scrutariMeta = scrutariMeta;
|
|
|
|
|
client.stats = new Scrutari.Stats(scrutariMeta);
|
|
|
|
|
_checkOptions(client, options, scrutariMeta);
|
|
|
|
|
_initMaps(client);
|
|
|
|
|
Scrutari.Client.Ui.init(client);
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(client);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
function _checkOptions (client, options, scrutariMeta) {
|
|
|
|
|
var defaultOptions = scrutariMeta.getDefaultOptions();
|
|
|
|
|
for(let key in defaultOptions) {
|
|
|
|
|
client.options[key] = defaultOptions[key];
|
|
|
|
|
}
|
|
|
|
|
if (options) {
|
|
|
|
|
for(let key in options) {
|
|
|
|
|
client.options[key] = options[key];
|
|
|
|
|
}
|
|
|
|
|
if (options.locMap) {
|
|
|
|
|
client._locInstance.putAll(options.locMap);
|
|
|
|
|
}
|
|
|
|
|
if (options.ignoreList) {
|
|
|
|
|
let ignoreList = options.ignoreList;
|
|
|
|
|
let ignoreArray;
|
|
|
|
|
if (typeof ignoreList === "string") {
|
|
|
|
|
ignoreArray = ignoreList.split(",");
|
|
|
|
|
} else if (Array.isArray(ignoreList)) {
|
|
|
|
|
ignoreArray = ignoreList;
|
|
|
|
|
}
|
|
|
|
|
if (ignoreArray) {
|
|
|
|
|
for(let ignore of ignoreArray) {
|
|
|
|
|
client._ignoreArray.push(ignore.trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (options.ficheBodyList) {
|
|
|
|
|
let ficheBodyList = options.ficheBodyList;
|
|
|
|
|
let array1;
|
|
|
|
|
if (typeof ficheBodyList === "string") {
|
|
|
|
|
array1 = ficheBodyList.split(",");
|
|
|
|
|
} else if (Array.isArray(ficheBodyList)) {
|
|
|
|
|
array1 = ficheBodyList;
|
|
|
|
|
}
|
|
|
|
|
if (array1) {
|
|
|
|
|
let array2 = new Array();
|
|
|
|
|
for(let token of array1) {
|
|
|
|
|
token = token.trim();
|
|
|
|
|
if (token.length > 0) {
|
|
|
|
|
array2.push(token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (array2.length > 0) {
|
|
|
|
|
client._ficheBodyTemplateArray = array2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _initHtmlObject (client, htmlObject) {
|
|
|
|
|
if (htmlObject) {
|
|
|
|
|
if (htmlObject.structure) {
|
|
|
|
|
for(var key in htmlObject.structure) {
|
|
|
|
|
client._structureMap[key] = htmlObject.structure[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (htmlObject.templates) {
|
|
|
|
|
for(var key in htmlObject.templates) {
|
|
|
|
|
client._templateMap[key] = htmlObject.templates[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _initMaps (client) {
|
|
|
|
|
_initHtmlObject(client, client._htmlObject);
|
|
|
|
|
_initHtmlObject(client, options.htmlObject);
|
|
|
|
|
$("script[type='text/x-scrutari-structure']").each(function (index, element) {
|
|
|
|
|
client._structureMap[element.dataset.name] = $(element).html();
|
|
|
|
|
});
|
|
|
|
|
$("script[type='text/x-scrutari-template']").each(function (index, element) {
|
|
|
|
|
client._templateMap[element.dataset.name] = $(element).html();
|
|
|
|
|
});
|
|
|
|
|
for(var name in client._templateMap) {
|
|
|
|
|
var templateText = client._templateMap[name];
|
|
|
|
|
templateText = templateText.replace(/tmpl=\"([-_0-9a-z]+)\"/g, 'tmpl="scrutari:$1"');
|
|
|
|
|
$.templates("scrutari:" + name, templateText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result = {};
|
|
|
|
|
Scrutari.Client.Result.show = function (client, scrutariResult, searchOrigin) {
|
|
|
|
|
client.$hidden("start", 'show');
|
|
|
|
|
var ficheCount = scrutariResult.getFicheCount();
|
|
|
|
|
client.$count("stats-result", 'update', ficheCount);
|
|
|
|
|
var $ficheDisplayBlock = client.$block('ficheDisplay');
|
|
|
|
|
$ficheDisplayBlock.empty();
|
|
|
|
|
client.currentScrutariResult = scrutariResult;
|
|
|
|
|
if (searchOrigin === "mainsearch") {
|
|
|
|
|
Scrutari.Client.Result.setCurrentMain(client, scrutariResult);
|
|
|
|
|
Scrutari.Client.Result.addToHistory(client, scrutariResult);
|
|
|
|
|
} else if (searchOrigin === "subsearch") {
|
|
|
|
|
let subsearchText = "+ " + Scrutari.Utils.formatSearchSequence(client, scrutariResult) + " = " + scrutariResult.getFicheCount();
|
|
|
|
|
if (client.currentHistoryName) {
|
|
|
|
|
Scrutari.$(client.$block(client.currentHistoryName), {scrutariRole: "subsearch"}).text(subsearchText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ficheCount === 0) {
|
|
|
|
|
client.$hidden("empty", 'hide');
|
|
|
|
|
let withFilter;
|
|
|
|
|
if (searchOrigin === "subsearch") {
|
|
|
|
|
withFilter = true;
|
|
|
|
|
} else {
|
|
|
|
|
withFilter = _hasFilter(scrutariResult.requestParameters);
|
|
|
|
|
}
|
|
|
|
|
$ficheDisplayBlock.html(client.render("emptyfichedisplay", {withFilter: withFilter, scrutariResult: scrutariResult}));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
client.$hidden("empty", 'show');
|
|
|
|
|
if (ficheCount >= client.scrutariConfig.options.subsearchThreshold) {
|
|
|
|
|
client.$hidden("threshold", 'show');
|
|
|
|
|
} else {
|
|
|
|
|
client.$hidden("threshold", 'hide');
|
|
|
|
|
}
|
|
|
|
|
var qId = scrutariResult.getQId();
|
|
|
|
|
var permalink = client.toPermalink(qId);
|
|
|
|
|
if (permalink) {
|
|
|
|
|
client.$link("permalink").attr("href", permalink).html(permalink);
|
|
|
|
|
}
|
|
|
|
|
_updateDownloadHref("ods");
|
|
|
|
|
_updateDownloadHref("csv");
|
|
|
|
|
_updateDownloadHref("atom");
|
|
|
|
|
if (scrutariResult.getFicheGroupType() === 'category') {
|
|
|
|
|
var contextObj = {
|
|
|
|
|
scrutariResult: scrutariResult,
|
|
|
|
|
array: new Array()
|
|
|
|
|
};
|
|
|
|
|
var categoryCount = scrutariResult.getCategoryCount();
|
|
|
|
|
for(let i = 0; i < categoryCount; i++) {
|
|
|
|
|
let category = scrutariResult.getCategory(i);
|
|
|
|
|
let metaCategory = client.scrutariMeta.getCategory(category.name);
|
|
|
|
|
if (metaCategory) {
|
|
|
|
|
category = metaCategory;
|
|
|
|
|
} else {
|
|
|
|
|
category.phraseMap = {};
|
|
|
|
|
category.attrMap = {};
|
|
|
|
|
}
|
|
|
|
|
contextObj.array.push({
|
|
|
|
|
category: category,
|
|
|
|
|
active: (i === 0),
|
|
|
|
|
fichestat: scrutariResult.getCategoryFicheCount(i)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
$ficheDisplayBlock.html(client.render("categoryfichedisplay", contextObj));
|
|
|
|
|
for(let i = 0; i < categoryCount; i++) {
|
|
|
|
|
let category = scrutariResult.getCategory(i);
|
|
|
|
|
Scrutari.Client.Result.categoryPaginationChange(client, category.name, 1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$ficheDisplayBlock.html(client.render("uniquefichedisplay", {scrutariResult: scrutariResult}));
|
|
|
|
|
Scrutari.Client.Result.uniquePaginationChange(client, 1);
|
|
|
|
|
}
|
|
|
|
|
client.hook("showResult", scrutariResult, searchOrigin);
|
|
|
|
|
function _updateDownloadHref(extension) {
|
|
|
|
|
client.$link(extension).attr("href", client.scrutariConfig.getDownloadUrl(qId, extension));
|
|
|
|
|
}
|
|
|
|
|
function _hasFilter(requestParameters) {
|
|
|
|
|
for(var prop in requestParameters) {
|
|
|
|
|
switch(prop) {
|
|
|
|
|
case "baselist":
|
|
|
|
|
case "corpuslist":
|
|
|
|
|
case "categorylist":
|
|
|
|
|
case "langlist":
|
|
|
|
|
var value = requestParameters[prop];
|
|
|
|
|
if (value) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (prop.indexOf("flt") === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.displayError = function (client, error, searchOrigin) {
|
|
|
|
|
if (error.parameter !== "q") {
|
|
|
|
|
Scrutari.logError(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var title = client.loc(error.key);
|
|
|
|
|
if (title !== error.key) {
|
|
|
|
|
var alertMessage = title;
|
|
|
|
|
if (error.hasOwnProperty("array")) {
|
|
|
|
|
alertMessage += client.loc('_ colon');
|
|
|
|
|
for(var i = 0; i < error.array.length; i++) {
|
|
|
|
|
alertMessage += "\n";
|
|
|
|
|
var obj = error.array[i];
|
|
|
|
|
alertMessage += "- ";
|
|
|
|
|
alertMessage += client.loc(obj.key);
|
|
|
|
|
if (obj.hasOwnProperty("value")) {
|
|
|
|
|
alertMessage += client.loc('_ colon');
|
|
|
|
|
alertMessage += " ";
|
|
|
|
|
alertMessage += obj.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
alert(alertMessage);
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.logError(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.uniquePaginationChange = function (client, paginationNumber) {
|
|
|
|
|
var paginationLength = client.scrutariConfig.options.paginationLength;
|
|
|
|
|
var scrutariResult = client.currentScrutariResult;
|
|
|
|
|
var html = "";
|
|
|
|
|
if (!scrutariResult.isUniquePaginationLoaded(paginationLength, paginationNumber)) {
|
|
|
|
|
if (client.isWaiting) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
client.$block("fiches").html(client.render("ficheloading", {scrutariResult: scrutariResult}));
|
|
|
|
|
client.isWaiting = true;
|
|
|
|
|
scrutariResult.loadUniquePagination(client.scrutariConfig, paginationLength, paginationNumber, _paginationCallback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var paginationFicheArray = scrutariResult.selectUniqueFicheArray(paginationLength, paginationNumber);
|
|
|
|
|
var ficheTemplate = client.getTemplate("fiche");
|
|
|
|
|
for(let fiche of paginationFicheArray) {
|
|
|
|
|
html += ficheTemplate(Scrutari.Client.Result.completeFiche(client, scrutariResult, fiche));
|
|
|
|
|
}
|
|
|
|
|
client.$block("fiches").html(html);
|
|
|
|
|
var tabArray = Scrutari.Utils.getTabArray(scrutariResult.getFicheCount(), paginationLength, paginationNumber);
|
|
|
|
|
var template = client.getTemplate("tabs");
|
|
|
|
|
client.$block("topPagination").html(template({
|
|
|
|
|
tabArray: tabArray,
|
|
|
|
|
type: "unique",
|
|
|
|
|
position: "top"
|
|
|
|
|
}));
|
|
|
|
|
client.$block("bottomPagination").html(template({
|
|
|
|
|
tabArray: tabArray,
|
|
|
|
|
type: "unique",
|
|
|
|
|
position: "bottom"
|
|
|
|
|
}));
|
|
|
|
|
client.hook("paginationChange", paginationFicheArray, {paginationNumber:paginationNumber});
|
|
|
|
|
function _paginationCallback () {
|
|
|
|
|
client.isWaiting = false;
|
|
|
|
|
Scrutari.Client.Result.uniquePaginationChange(client, paginationNumber);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.categoryPaginationChange = function (client, categoryName, paginationNumber) {
|
|
|
|
|
var paginationLength = client.scrutariConfig.options.paginationLength;
|
|
|
|
|
var scrutariResult = client.currentScrutariResult;
|
|
|
|
|
var html = "";
|
|
|
|
|
if (!scrutariResult.isCategoryPaginationLoaded(categoryName, paginationLength, paginationNumber)) {
|
|
|
|
|
client.$block("fiches_" + categoryName).html(client.render("ficheloading", {scrutariResult: scrutariResult}));
|
|
|
|
|
if (client.isWaiting) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
client.isWaiting = true;
|
|
|
|
|
scrutariResult.loadCategoryPagination(client.scrutariConfig, categoryName, paginationLength, paginationNumber, _paginationCallback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var paginationFicheArray = scrutariResult.selectCategoryFicheArray(categoryName, paginationLength, paginationNumber);
|
|
|
|
|
var ficheTemplate = client.getTemplate("fiche");
|
|
|
|
|
for(let fiche of paginationFicheArray) {
|
|
|
|
|
html += ficheTemplate(Scrutari.Client.Result.completeFiche(client, scrutariResult, fiche, categoryName));
|
|
|
|
|
}
|
|
|
|
|
client.$block("fiches_" + categoryName).html(html);
|
|
|
|
|
var tabArray = Scrutari.Utils.getTabArray(scrutariResult.getCategoryFicheCountByName(categoryName), paginationLength, paginationNumber);
|
|
|
|
|
var template = client.getTemplate("tabs");
|
|
|
|
|
client.$block("topPagination_" + categoryName).html(template({
|
|
|
|
|
tabArray: tabArray,
|
|
|
|
|
type: "category",
|
|
|
|
|
category: categoryName,
|
|
|
|
|
position: "top"
|
|
|
|
|
}));
|
|
|
|
|
client.$block("bottomPagination_" + categoryName).html(template({
|
|
|
|
|
tabArray: tabArray,
|
|
|
|
|
type: "category",
|
|
|
|
|
category: categoryName,
|
|
|
|
|
position: "bottom"
|
|
|
|
|
}));
|
|
|
|
|
client.hook("paginationChange", paginationFicheArray, {categoryName: categoryName, paginationNumber:paginationNumber});
|
|
|
|
|
function _paginationCallback () {
|
|
|
|
|
client.isWaiting = false;
|
|
|
|
|
Scrutari.Client.Result.categoryPaginationChange(client, categoryName, paginationNumber);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.addToHistory = function (client, scrutariResult) {
|
|
|
|
|
var $historyListBlock = client.$block("historyList");
|
|
|
|
|
if (!Scrutari.exists($historyListBlock)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (client.currentHistoryName) {
|
|
|
|
|
var $historyBlock = client.$block(client.currentHistoryName);
|
|
|
|
|
$historyBlock.removeClass("scrutari-history-Active");
|
|
|
|
|
Scrutari.$($historyBlock, {scrutariRole: "subsearch"}).empty();
|
|
|
|
|
client.show(Scrutari.$($historyBlock, {scrutariRole: "remove"}));
|
|
|
|
|
}
|
|
|
|
|
var historyName = "history_" + client.newHistoryNumber();
|
|
|
|
|
Scrutari.Client.Result.setCurrentHistory(client, historyName);
|
|
|
|
|
client.storeResult(historyName, scrutariResult);
|
|
|
|
|
var contextObj = {
|
|
|
|
|
scrutariResult: scrutariResult,
|
|
|
|
|
name: historyName,
|
|
|
|
|
fichestat: scrutariResult.getFicheCount(),
|
|
|
|
|
sequence: Scrutari.Utils.formatSearchSequence(client, scrutariResult)
|
|
|
|
|
};
|
|
|
|
|
$historyListBlock.prepend(client.render("history", contextObj));
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.loadHistory = function (client, historyName) {
|
|
|
|
|
var historyScrutariResult = client.getResult(historyName);
|
|
|
|
|
if (historyScrutariResult) {
|
|
|
|
|
var $historyBlock = client.$block(historyName);
|
|
|
|
|
client.currentScrutariResult = historyScrutariResult;
|
|
|
|
|
Scrutari.Client.Result.setCurrentMain(client, historyScrutariResult);
|
|
|
|
|
Scrutari.Client.Result.setCurrentHistory(client, historyName);
|
|
|
|
|
$historyBlock.addClass("scrutari-history-Active");
|
|
|
|
|
client.hide(Scrutari.$($historyBlock, {scrutariRole: "remove"}));
|
|
|
|
|
Scrutari.Client.Result.show(client, historyScrutariResult);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.setCurrentHistory = function (client, historyName) {
|
|
|
|
|
if (client.currentHistoryName) {
|
|
|
|
|
var $historyBlock = client.$block(client.currentHistoryName);
|
|
|
|
|
$historyBlock.removeClass("scrutari-history-Active");
|
|
|
|
|
Scrutari.$($historyBlock, {scrutariRole: "subsearch"}).empty();
|
|
|
|
|
client.show (Scrutari.$($historyBlock, {scrutariRole: "remove"}));
|
|
|
|
|
}
|
|
|
|
|
client.currentHistoryName = historyName;
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.setCurrentMain = function (client, scrutariResult) {
|
|
|
|
|
client.mainCurrentScrutariResult = scrutariResult;
|
|
|
|
|
client.$block("currentSearchSequence").text(Scrutari.Utils.formatSearchSequence(client, scrutariResult) + " (" + scrutariResult.getFicheCount() + ")");
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Result.completeFiche = function(client, scrutariResult, fiche, categoryName) {
|
|
|
|
|
var scrutariMeta = client.scrutariMeta;
|
|
|
|
|
var options = client.options;
|
|
|
|
|
Scrutari.Complete.complementTitle(fiche, scrutariMeta);
|
|
|
|
|
Scrutari.Complete.motcleArray(fiche, _motcleProvider);
|
|
|
|
|
Scrutari.Complete.bythesaurusArray(fiche, scrutariMeta, _motcleProvider);
|
|
|
|
|
if (Scrutari.Complete.hasMarkedAttribute(fiche)) {
|
|
|
|
|
Scrutari.Complete.markedAttributeArray(fiche, scrutariMeta, "primary");
|
|
|
|
|
Scrutari.Complete.markedAttributeArray(fiche, scrutariMeta, "secondary");
|
|
|
|
|
}
|
|
|
|
|
if (!options.ignoreThumbnail) {
|
|
|
|
|
Scrutari.Complete.thumbnail(fiche);
|
|
|
|
|
}
|
|
|
|
|
if (!options.ignoreIcon) {
|
|
|
|
|
Scrutari.Complete.icon(fiche);
|
|
|
|
|
}
|
|
|
|
|
if (options.ficheTarget) {
|
|
|
|
|
Scrutari.Complete.target(fiche, options.ficheTarget);
|
|
|
|
|
}
|
|
|
|
|
fiche._bodyTemplateArray = client.getFicheBodyTemplateArray(fiche, categoryName);
|
|
|
|
|
client.hook("completeFiche", scrutariResult, fiche, categoryName);
|
|
|
|
|
return fiche;
|
|
|
|
|
function _motcleProvider(code) {
|
|
|
|
|
return scrutariResult.getMotcle(code);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui = {};
|
|
|
|
|
Scrutari.Client.Ui.filterChange = function (client) {
|
|
|
|
|
var globalFicheCount = client.scrutariMeta.getGlobalFicheCount();
|
|
|
|
|
var filterState = Scrutari.Client.Ui.buildFilterState(client);
|
|
|
|
|
var filterFicheCount;
|
|
|
|
|
if (filterState.empty) {
|
|
|
|
|
filterFicheCount = client.scrutariMeta.getGlobalFicheCount();
|
|
|
|
|
} else {
|
|
|
|
|
filterFicheCount = -1;
|
|
|
|
|
}
|
|
|
|
|
client.stats.update(filterState);
|
|
|
|
|
if (!_checkFilterFicheCount("base")) {
|
|
|
|
|
if (!_checkFilterFicheCount("corpus")) {
|
|
|
|
|
if (!_checkFilterFicheCount("category")) {
|
|
|
|
|
_checkFilterFicheCount("lang");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_updateState("base");
|
|
|
|
|
_updateState("corpus");
|
|
|
|
|
_updateState("category");
|
|
|
|
|
_updateState("lang");
|
|
|
|
|
var filterTitlesArray = new Array();
|
|
|
|
|
_addFilterTitles("base", "_ label_base_one", "_ label_base_many");
|
|
|
|
|
_addFilterTitles("corpus", "_ label_corpus_one", "_ label_corpus_many");
|
|
|
|
|
_addFilterTitles("lang", "_ label_lang_one", "_ label_lang_many");
|
|
|
|
|
_addFilterTitles("category", "_ label_category_one", "_ label_category_many");
|
|
|
|
|
var $filterFicheCount = client.$count('stats-filter', 'update', filterFicheCount);
|
|
|
|
|
var $filterValue = Scrutari.$($filterFicheCount, {scrutariRole: "value"});
|
|
|
|
|
if (filterFicheCount === globalFicheCount) {
|
|
|
|
|
$filterValue.removeClass("scrutari-stats-Filter").removeClass("scrutari-stats-None");
|
|
|
|
|
client.$hidden('filter', 'hide');
|
|
|
|
|
} else if (filterFicheCount === 0) {
|
|
|
|
|
$filterValue.removeClass("scrutari-stats-Filter").addClass("scrutari-stats-None");
|
|
|
|
|
client.$hidden('filter', 'show');
|
|
|
|
|
} else {
|
|
|
|
|
$filterValue.addClass("scrutari-stats-Filter").removeClass("scrutari-stats-None");
|
|
|
|
|
client.$hidden('filter', 'show');
|
|
|
|
|
}
|
|
|
|
|
var $filterTitles = Scrutari.$($filterFicheCount, {scrutariRole: "titles"});
|
|
|
|
|
if (filterTitlesArray.length > 0) {
|
|
|
|
|
$filterTitles.html(filterTitlesArray.join(" | "));
|
|
|
|
|
} else {
|
|
|
|
|
$filterTitles.html("");
|
|
|
|
|
}
|
|
|
|
|
function _checkFilterFicheCount(type) {
|
|
|
|
|
var $stat = client.$({scrutariStatType: type});
|
|
|
|
|
if ($stat.length > 0) {
|
|
|
|
|
filterFicheCount = 0;
|
|
|
|
|
$stat.each(function (index, element) {
|
|
|
|
|
let key = element.dataset.scrutariStatKey;
|
|
|
|
|
filterFicheCount += client.stats.getFicheCount(type, key);
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _updateState(type) {
|
|
|
|
|
client.$({scrutariStatType: type}).each(function (index, element) {
|
|
|
|
|
var $el = $(element);
|
|
|
|
|
var key = element.dataset.scrutariStatKey;
|
|
|
|
|
var ficheCount = client.stats.getFicheCount(type, key);
|
|
|
|
|
var $statTitle = Scrutari.$parents($el, {scrutariRole: "stat-text"});
|
|
|
|
|
if (ficheCount != element.dataset.scrutariStatDefault) {
|
|
|
|
|
if (ficheCount === 0) {
|
|
|
|
|
$el.html("");
|
|
|
|
|
$statTitle.addClass("scrutari-panel-Excluded");
|
|
|
|
|
} else {
|
|
|
|
|
$statTitle.removeClass("scrutari-panel-Excluded");
|
|
|
|
|
$el.html(client.formatNumber(ficheCount) + " / ");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$el.html("");
|
|
|
|
|
$statTitle.removeClass("scrutari-panel-Excluded");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function _addFilterTitles(type, oneLocKey, manyLocKey) {
|
|
|
|
|
var array = filterState.titles[type];
|
|
|
|
|
if (array.length > 0) {
|
|
|
|
|
var locKey = (array.length === 1)?oneLocKey:manyLocKey;
|
|
|
|
|
filterTitlesArray.push(client.loc(locKey) + client.loc('_ colon') + " " + array.join(", "));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.buildRequestParameters = function (client) {
|
|
|
|
|
var requestParameters = new Object();
|
|
|
|
|
_checkFilter("baselist", "base");
|
|
|
|
|
_checkFilter("corpuslist", "corpus");
|
|
|
|
|
_checkFilter("categorylist", "category");
|
|
|
|
|
_checkFilter("langlist", "lang");
|
|
|
|
|
requestParameters["q-mode"] = client.$input_checked("q-mode").val();
|
|
|
|
|
var ponderation = client.$input_checked("ponderation").val();
|
|
|
|
|
if (ponderation === 'date') {
|
|
|
|
|
requestParameters.ponderation = '10,80,5,5';
|
|
|
|
|
}
|
|
|
|
|
var periode = $.trim(client.$input("periode").val());
|
|
|
|
|
if (periode) {
|
|
|
|
|
requestParameters["flt-date"] = periode;
|
|
|
|
|
}
|
|
|
|
|
if (Scrutari.exists(client.$input_checked("wildchar"))) {
|
|
|
|
|
requestParameters.wildchar = "end";
|
|
|
|
|
} else {
|
|
|
|
|
requestParameters.wildchar = "none";
|
|
|
|
|
}
|
|
|
|
|
return requestParameters;
|
|
|
|
|
function _checkFilter (paramName, target) {
|
|
|
|
|
if (client.$button("enablePanel", target).data("scrutariState") === "on") {
|
|
|
|
|
var $inputs = client.$input_checked(target);
|
|
|
|
|
var value = "";
|
|
|
|
|
for(var i = 0; i < $inputs.length; i++) {
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
value += ",";
|
|
|
|
|
}
|
|
|
|
|
value += $inputs[i].value;
|
|
|
|
|
}
|
|
|
|
|
if (value.length > 0) {
|
|
|
|
|
requestParameters[paramName] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.buildFilterState = function (client) {
|
|
|
|
|
var filterState = new Scrutari.FilterState();
|
|
|
|
|
_check("base");
|
|
|
|
|
_check("corpus");
|
|
|
|
|
_check("category");
|
|
|
|
|
_check("lang");
|
|
|
|
|
return filterState;
|
|
|
|
|
function _check (target) {
|
|
|
|
|
if (client.$button("enablePanel", target).data("scrutariState") !== "on") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
client.$input_checked(target).each(function (index,element) {
|
|
|
|
|
filterState.add(target, element.value, element.dataset.scrutariTitle);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.init = function (client) {
|
|
|
|
|
var scrutariMeta = client.scrutariMeta;
|
|
|
|
|
Scrutari.Client.Ui.initHtml(client);
|
|
|
|
|
Scrutari.Client.Ui.initForms(client);
|
|
|
|
|
Scrutari.Client.Ui.initClicks(client);
|
|
|
|
|
Scrutari.Client.Ui.initMainTitle(client);
|
|
|
|
|
client.$count('stats-global', 'update', scrutariMeta.getGlobalFicheCount());
|
|
|
|
|
client.$hidden('init', 'show');
|
|
|
|
|
client.show(client.$button('parametersDisplay'));
|
|
|
|
|
var locales = client.scrutariConfig.lang;
|
|
|
|
|
var langArray = scrutariMeta.getLangArray();
|
|
|
|
|
if ((langArray.length > 1) && (Scrutari.exists(client.$panel('lang')))) {
|
|
|
|
|
for(var i = 0, len = langArray.length; i < len; i++) {
|
|
|
|
|
var title = "";
|
|
|
|
|
var code = langArray[i].lang;
|
|
|
|
|
var label = scrutariMeta.getLangLabel(code);
|
|
|
|
|
if (label !== code) {
|
|
|
|
|
title = label;
|
|
|
|
|
}
|
|
|
|
|
langArray[i].title = title;
|
|
|
|
|
}
|
|
|
|
|
var langSortFunction = Scrutari.Utils.getLangSortFunction(client.options.langSort, locales);
|
|
|
|
|
if (langSortFunction) {
|
|
|
|
|
langArray = langArray.sort(langSortFunction);
|
|
|
|
|
}
|
|
|
|
|
Scrutari.Utils.divideIntoColumns(langArray, client.$group("langColumns"), client.getTemplate("lang"));
|
|
|
|
|
client.$panel('lang', 'show');
|
|
|
|
|
}
|
|
|
|
|
if ((scrutariMeta.withCategory()) && (Scrutari.exists(client.$panel('category')))) {
|
|
|
|
|
var categoryArray = scrutariMeta.getCategoryArray(Scrutari.Utils.getCategorySortFunction(client.options.categorySort, locales));
|
|
|
|
|
Scrutari.Utils.divideIntoColumns(categoryArray, client.$group("categoryColumns"), client.getTemplate("category"));
|
|
|
|
|
client.$panel('category', 'show');
|
|
|
|
|
}
|
|
|
|
|
if (client.options.withCorpus) {
|
|
|
|
|
if (Scrutari.exists(client.$panel('corpus'))) {
|
|
|
|
|
var corpusArray = scrutariMeta.getCorpusArray(Scrutari.Utils.getCorpusSortFunction(client.options.corpusSort, locales));
|
|
|
|
|
if (corpusArray.length > 1) {
|
|
|
|
|
Scrutari.Utils.divideIntoColumns(corpusArray, client.$group("corpusColumns"), client.getTemplate("corpus"));
|
|
|
|
|
client.$panel('corpus', 'show');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (Scrutari.exists(client.$panel('base'))) {
|
|
|
|
|
var baseArray = scrutariMeta.getBaseArray(Scrutari.Utils.getBaseSortFunction(client.options.baseSort, locales));
|
|
|
|
|
if (baseArray.length > 1) {
|
|
|
|
|
Scrutari.Utils.divideIntoColumns(baseArray, client.$group("baseColumns"), client.getTemplate("base"));
|
|
|
|
|
client.$panel('base', 'show');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var initialFilters = client.options.initialFilters;
|
|
|
|
|
if (initialFilters) {
|
|
|
|
|
_initFilter("baselist", "base");
|
|
|
|
|
_initFilter("corpuslist","corpus");
|
|
|
|
|
_initFilter("categorylist", "category");
|
|
|
|
|
_initFilter("langlist", "lang");
|
|
|
|
|
}
|
|
|
|
|
var initialQuery = client.options.initialQuery;
|
|
|
|
|
var initialQId = client.options.initialQId;
|
|
|
|
|
if (initialQuery) {
|
|
|
|
|
var $mainSearchForm = client.$form('mainsearch');
|
|
|
|
|
if (Scrutari.exists($mainSearchForm)) {
|
|
|
|
|
$mainSearchForm.find("input[name='q']").val(initialQuery);
|
|
|
|
|
$mainSearchForm.submit();
|
|
|
|
|
}
|
|
|
|
|
} else if (initialQId) {
|
|
|
|
|
var requestParameters = Scrutari.Client.Ui.buildRequestParameters(client);
|
|
|
|
|
requestParameters["qid"] = initialQId;
|
|
|
|
|
client.$modal("loading", 'show');
|
|
|
|
|
client.hook("newSearch", requestParameters, "qidsearch");
|
|
|
|
|
Scrutari.Result.newSearch(client.scrutariConfig, requestParameters, _mainsearchScrutariResultCallback, _mainScrutariErrorCallback);
|
|
|
|
|
}
|
|
|
|
|
function _initFilter (optionName, target) {
|
|
|
|
|
if (!initialFilters.hasOwnProperty(optionName)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Scrutari.Client.Ui.initFilter(client, target, initialFilters[optionName].split(","));
|
|
|
|
|
}
|
|
|
|
|
function _initFilterByQuery (list, target) {
|
|
|
|
|
if (list) {
|
|
|
|
|
Scrutari.Client.Ui.initFilter(client, target, list.array);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _mainsearchScrutariResultCallback (scrutariResult) {
|
|
|
|
|
var $mainSearchForm = client.$form('mainsearch');
|
|
|
|
|
$mainSearchForm.find("input[name='q']").val(scrutariResult.searchMeta.q);
|
|
|
|
|
$mainSearchForm.find("input[name='q-mode'][value='operation']").click();
|
|
|
|
|
var searchOptions = scrutariResult.searchMeta.options;
|
|
|
|
|
if (searchOptions) {
|
|
|
|
|
_initFilterByQuery(searchOptions.baselist, "base");
|
|
|
|
|
_initFilterByQuery(searchOptions.corpuslist, "corpus");
|
|
|
|
|
_initFilterByQuery(searchOptions.categorylist, "category");
|
|
|
|
|
_initFilterByQuery(searchOptions.langlist, "lang");
|
|
|
|
|
}
|
|
|
|
|
Scrutari.Client.Result.show(client, scrutariResult, "mainsearch");
|
|
|
|
|
client.$modal("loading", 'hide');
|
|
|
|
|
var $parametersDisplayButton = client.$button('parametersDisplay');
|
|
|
|
|
if ($parametersDisplayButton.data("scrutariState") === "on") {
|
|
|
|
|
$parametersDisplayButton.click();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _mainScrutariErrorCallback (error) {
|
|
|
|
|
Scrutari.Client.Result.displayError(client, error, "mainsearch");
|
|
|
|
|
client.$modal("loading", 'hide');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.initHtml = function (client) {
|
|
|
|
|
var includedTexts = {};
|
|
|
|
|
var html = _getText("main");
|
|
|
|
|
html = html.replace(/_ [-_\.a-z0-9]+/g, function(match) {
|
|
|
|
|
return client.loc(match);
|
|
|
|
|
});
|
|
|
|
|
$("#" + client.clientId).html(html);
|
|
|
|
|
function _getText(name) {
|
|
|
|
|
if (name.endsWith('*')) {
|
|
|
|
|
return _getTextByPrefix(name.substring(0, name.length - 1));
|
|
|
|
|
}
|
|
|
|
|
if (includedTexts.hasOwnProperty(name)) {
|
|
|
|
|
Scrutari.log("Already included: " + name);
|
|
|
|
|
return "";
|
|
|
|
|
} else if (client.ignoreElement(name)) {
|
|
|
|
|
return "";
|
|
|
|
|
} else if ((name === "panel-base") && (client.options.withCorpus)) {
|
|
|
|
|
return "";
|
|
|
|
|
} else if ((name === "panel-corpus") && (!client.options.withCorpus)) {
|
|
|
|
|
return "";
|
|
|
|
|
} else if ((name === "result-share") && (!client.options.permalinkPattern)) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
includedTexts[name] = true;
|
|
|
|
|
var text = client.getStructureHtml(name);
|
|
|
|
|
text = text.replace(/{{([-a-zA-z0-9_]+\*?)}}/g, function (match, p1) {
|
|
|
|
|
return _getText(p1);
|
|
|
|
|
});
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
function _getTextByPrefix(namePrefix) {
|
|
|
|
|
var result = "";
|
|
|
|
|
for(let name of client.getStructureNameArray()) {
|
|
|
|
|
if (name.startsWith(namePrefix)) {
|
|
|
|
|
let text = _getText(name);
|
|
|
|
|
if (text.length > 0) {
|
|
|
|
|
if (result.length > 0) {
|
|
|
|
|
result = result + "\n";
|
|
|
|
|
}
|
|
|
|
|
result = result + text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.initForms = function (client) {
|
|
|
|
|
client.$form('mainsearch').submit(function () {
|
|
|
|
|
var q = this["q"].value.trim();
|
|
|
|
|
if (q.length > 0) {
|
|
|
|
|
var requestParameters = Scrutari.Client.Ui.buildRequestParameters(client);
|
|
|
|
|
requestParameters["log"] = "all";
|
|
|
|
|
requestParameters["q"] = q;
|
|
|
|
|
client.$modal("loading", 'show');
|
|
|
|
|
client.hook("newSearch", requestParameters, "mainsearch");
|
|
|
|
|
Scrutari.Result.newSearch(client.scrutariConfig, requestParameters, _mainsearchScrutariResultCallback, _mainScrutariErrorCallback);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
client.$form('subsearch').submit(function () {
|
|
|
|
|
var q = this["q"].value.trim();
|
|
|
|
|
if ((q.length > 0) && (client.mainCurrentScrutariResult)) {
|
|
|
|
|
var requestParameters = Scrutari.Client.Ui.buildRequestParameters(client);
|
|
|
|
|
requestParameters["q"] = q;
|
|
|
|
|
requestParameters["flt-qid"] = client.mainCurrentScrutariResult.getQId();
|
|
|
|
|
client.$modal("loading", 'show');
|
|
|
|
|
client.hook("newSearch", requestParameters, "subsearch");
|
|
|
|
|
Scrutari.Result.newSearch(client.scrutariConfig, requestParameters, _subsearchScrutariResultCallback, _subsearchScrutariErrorCallback);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
function _mainsearchScrutariResultCallback (scrutariResult) {
|
|
|
|
|
Scrutari.Client.Result.show(client, scrutariResult, "mainsearch");
|
|
|
|
|
client.$modal("loading", 'hide');
|
|
|
|
|
var $parametersDisplayButton = client.$button('parametersDisplay');
|
|
|
|
|
if ($parametersDisplayButton.data("scrutariState") === "on") {
|
|
|
|
|
$parametersDisplayButton.click();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _mainScrutariErrorCallback (error) {
|
|
|
|
|
Scrutari.Client.Result.displayError(client, error, "mainsearch");
|
|
|
|
|
client.$modal("loading", 'hide');
|
|
|
|
|
}
|
|
|
|
|
function _subsearchScrutariResultCallback (scrutariResult) {
|
|
|
|
|
Scrutari.Client.Result.show(client, scrutariResult, "subsearch");
|
|
|
|
|
client.$modal("loading", 'hide');
|
|
|
|
|
}
|
|
|
|
|
function _subsearchScrutariErrorCallback (error) {
|
|
|
|
|
Scrutari.Client.Result.displayError(client, error, "subsearch");
|
|
|
|
|
client.$modal("loading", 'hide');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.initClicks = function (client) {
|
|
|
|
|
$("#" + client.clientId).on("click", Scrutari.toCssQuery({scrutariButton: true}), function () {
|
|
|
|
|
var $this = $(this);
|
|
|
|
|
var action = this.dataset.scrutariButton;
|
|
|
|
|
var target = this.dataset.scrutariTarget;
|
|
|
|
|
switch(action) {
|
|
|
|
|
case 'enablePanel':
|
|
|
|
|
_enablePanel(this, target);
|
|
|
|
|
break;
|
|
|
|
|
case 'checkAll':
|
|
|
|
|
_checkAll(target);
|
|
|
|
|
break;
|
|
|
|
|
case 'uncheckAll':
|
|
|
|
|
_uncheckAll(target);
|
|
|
|
|
break;
|
|
|
|
|
case 'showModal':
|
|
|
|
|
client.$modal(target, 'show');
|
|
|
|
|
break;
|
|
|
|
|
case 'parametersDisplay':
|
|
|
|
|
let state = Scrutari.Utils.toggle($this, "scrutariState");
|
|
|
|
|
Scrutari.Utils.toggle.classes($this, state, "Scrutari-On", "");
|
|
|
|
|
if (state === 'on') {
|
|
|
|
|
client.$area('parameters', 'show');
|
|
|
|
|
} else {
|
|
|
|
|
client.$area('parameters', 'hide');
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'toggleBlock':
|
|
|
|
|
if (Scrutari.Utils.toggle($this, "scrutariState") === 'on') {
|
|
|
|
|
client.$block(target, 'show');
|
|
|
|
|
} else {
|
|
|
|
|
client.$block(target, 'hide');
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'removeHistory':
|
|
|
|
|
_removeHistory(target);
|
|
|
|
|
break;
|
|
|
|
|
case 'loadHistory':
|
|
|
|
|
_loadHistory(target);
|
|
|
|
|
break;
|
|
|
|
|
case 'categoryTab':
|
|
|
|
|
_categoryTab(this.dataset.scrutariCategory);
|
|
|
|
|
break;
|
|
|
|
|
case 'ficheTab':
|
|
|
|
|
_ficheTab(this);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Scrutari.log("Unknown action: " + action);
|
|
|
|
|
}
|
|
|
|
|
if ((this.tagName) && (this.tagName.toLowerCase() === 'a')) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#" + client.clientId).on("click", "input", function () {
|
|
|
|
|
var name = this.name;
|
|
|
|
|
if (name) {
|
|
|
|
|
switch(name) {
|
|
|
|
|
case 'q-mode':
|
|
|
|
|
if (this.value === 'operation') {
|
|
|
|
|
Scrutari.Utils.disable("input[name='wildchar']");
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.Utils.enable("input[name='wildchar']");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'lang':
|
|
|
|
|
case 'category':
|
|
|
|
|
case 'base':
|
|
|
|
|
case 'corpus':
|
|
|
|
|
_checkClick(name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
function _checkClick (target) {
|
|
|
|
|
var $button = client.$button("enablePanel", target);
|
|
|
|
|
if ($button.data('scrutariState') === 'off') {
|
|
|
|
|
$button.click();
|
|
|
|
|
$(this).focus();
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.Client.Ui.filterChange(client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _checkAll (target) {
|
|
|
|
|
Scrutari.Utils.check("input[name='" + target + "']");
|
|
|
|
|
Scrutari.Client.Ui.filterChange(client);
|
|
|
|
|
}
|
|
|
|
|
function _uncheckAll (target) {
|
|
|
|
|
Scrutari.Utils.uncheck("input[name='" + target + "']");
|
|
|
|
|
Scrutari.Client.Ui.filterChange(client);
|
|
|
|
|
}
|
|
|
|
|
function _enablePanel (button, target) {
|
|
|
|
|
var $button = $(button);
|
|
|
|
|
var state = Scrutari.Utils.toggle($button, "scrutariState");
|
|
|
|
|
_enableChekButtons();
|
|
|
|
|
Scrutari.Utils.toggle.classes($button, state, "scrutari-On", "");
|
|
|
|
|
Scrutari.Utils.toggle.classes(client.$group(target + "Columns"), state, "", "scrutari-panel-ColumnDisabled");
|
|
|
|
|
Scrutari.Utils.toggle.text($button.children("span"), "scrutariAlternate");
|
|
|
|
|
var $filterLabel = client.$label(target + "Filter");
|
|
|
|
|
Scrutari.Utils.toggle.text($filterLabel, "scrutariAlternate");
|
|
|
|
|
Scrutari.Utils.toggle.classes($filterLabel, state, "scrutari-panel-Active", "scrutari-Disabled");
|
|
|
|
|
Scrutari.Client.Ui.filterChange(client);
|
|
|
|
|
function _enableChekButtons () {
|
|
|
|
|
let disabled = false;
|
|
|
|
|
if (state === 'off') {
|
|
|
|
|
disabled = true;
|
|
|
|
|
}
|
|
|
|
|
client.$button("checkAll", target).prop('disabled', disabled);
|
|
|
|
|
client.$button("uncheckAll", target).prop('disabled', disabled);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function _removeHistory (historyName) {
|
|
|
|
|
client.unstoreResult(historyName);
|
|
|
|
|
client.$block(historyName).remove();
|
|
|
|
|
}
|
|
|
|
|
function _loadHistory (historyName) {
|
|
|
|
|
Scrutari.Client.Result.loadHistory(client, historyName);
|
|
|
|
|
}
|
|
|
|
|
function _categoryTab (categoryName) {
|
|
|
|
|
client.$({scrutariRole: "category-content"}).each(function (index, element) {
|
|
|
|
|
if (element.dataset.scrutariCategory === categoryName) {
|
|
|
|
|
client.show(element);
|
|
|
|
|
} else {
|
|
|
|
|
client.hide(element);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
client.$({scrutariRole: "category-tab"}).each(function (index, element) {
|
|
|
|
|
if (element.dataset.scrutariCategory === categoryName) {
|
|
|
|
|
element.classList.add("scrutari-On");
|
|
|
|
|
} else {
|
|
|
|
|
element.classList.remove("scrutari-On");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function _ficheTab (button) {
|
|
|
|
|
var newPaginationNumber = parseInt(button.dataset.scrutariNumber);
|
|
|
|
|
if (button.dataset.scrutariType === "unique") {
|
|
|
|
|
Scrutari.Client.Result.uniquePaginationChange(client, newPaginationNumber);
|
|
|
|
|
} else {
|
|
|
|
|
Scrutari.Client.Result.categoryPaginationChange(client, button.dataset.scrutariCategory, newPaginationNumber);
|
|
|
|
|
}
|
|
|
|
|
if (button.dataset.scrutariPosition === "bottom") {
|
|
|
|
|
client.scrollToResult();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.initMainTitle = function (client) {
|
|
|
|
|
var html = "";
|
|
|
|
|
var mainTitle = client.options.mainTitle;
|
|
|
|
|
if ((mainTitle) || (mainTitle === "")) {
|
|
|
|
|
if (typeof mainTitle === "function") {
|
|
|
|
|
html = mainTitle(client);
|
|
|
|
|
} else {
|
|
|
|
|
html = mainTitle;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
html += client.loc('_ title_main');
|
|
|
|
|
html += " – ";
|
|
|
|
|
var title = client.scrutariMeta.getTitle();
|
|
|
|
|
if (title) {
|
|
|
|
|
html += Scrutari.escape(title);
|
|
|
|
|
} else {
|
|
|
|
|
html += "[";
|
|
|
|
|
html += client.scrutariConfig.name;
|
|
|
|
|
html += "]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
client.$title('main').html(html);
|
|
|
|
|
};
|
|
|
|
|
Scrutari.Client.Ui.initFilter = function (client, target, checkedArray) {
|
|
|
|
|
var done = false;
|
|
|
|
|
for(var i = 0, len = checkedArray.length; i < len; i++) {
|
|
|
|
|
var $input = client.$input(target, checkedArray[i]);
|
|
|
|
|
if ($input.length > 0) {
|
|
|
|
|
$input.prop("checked", true);
|
|
|
|
|
done = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (done) {
|
|
|
|
|
client.$button("enablePanel", target).click();
|
|
|
|
|
}
|
|
|
|
|
};
|