Advanced Search WIP: new mechanism for passing the dictionary to the client side. Hopefully faster than before thanks to the browser's cache.

SVN:b1162[5453]
This commit is contained in:
Denis Flaven
2018-03-16 17:44:55 +00:00
parent 52f56e1bb0
commit f8f6e201b9
5 changed files with 135 additions and 32 deletions

View File

@@ -694,4 +694,59 @@ function DisplayHistory(sSelector, sFilter, iCount, iStart)
$(sSelector).html(data).unblock();
}
);
}
// Very simple equivalent to format: placeholders are %1$s %2$d ...
function Format()
{
var args = [];
var str = '';
if (arguments[0] instanceof Array)
{
str = arguments[0][0].toString();
args = arguments[0];
}
else
{
str = arguments[0].toString();
if (arguments.length > 1)
{
var t = typeof arguments[1];
args = ("string" === t || "number" === t) ? Array.prototype.slice.call(arguments) : arguments[1];
}
}
var key;
for (key in args)
{
str = str.replace(new RegExp("\\%" + key + "\\$.", "gi"), args[key]);
}
return str;
}
var Dict = {};
if (aDictEntries == undefined)
{
Dict._entries = {}; // Entries have not been loaded (we are in the setup ?)
}
else
{
Dict._entries = aDictEntries; // Entries were loaded asynchronously via their own js files
}
Dict.S = function(sEntry)
{
if (sEntry in Dict._entries)
{
return Dict._entries[sEntry];
}
else
{
return sEntry;
}
};
Dict.Format = function()
{
var args = Array.from(arguments);
args[0] = Dict.S(arguments[0]);
return Format(args);
}