2018-07-13 15:56:09 +00:00
|
|
|
function Main()
|
|
|
|
{
|
2018-07-17 13:08:20 +00:00
|
|
|
this.db = null;
|
2018-07-17 13:41:00 +00:00
|
|
|
this.view = null;
|
2018-07-23 13:20:03 +00:00
|
|
|
this.queryPrev = '';
|
|
|
|
this.queryCur = '';
|
2018-07-13 15:56:09 +00:00
|
|
|
|
2018-07-15 14:23:07 +00:00
|
|
|
this.install = function()
|
|
|
|
{
|
2018-07-21 14:35:55 +00:00
|
|
|
this.db = new Wrap(DATABASE);
|
2018-07-17 13:08:20 +00:00
|
|
|
this.db.install();
|
2018-07-21 14:35:55 +00:00
|
|
|
this.view = new View();
|
2018-07-17 13:41:00 +00:00
|
|
|
this.view.install();
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.start = function()
|
|
|
|
{
|
2018-07-22 19:45:04 +00:00
|
|
|
this.load(window.document.location.hash);
|
|
|
|
this.view.stats(this.db.stats());
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 19:45:04 +00:00
|
|
|
this.load = function(target)
|
2018-07-15 14:23:07 +00:00
|
|
|
{
|
2018-07-23 13:20:03 +00:00
|
|
|
this.queryPrev = this.queryCur;
|
2018-07-22 19:45:04 +00:00
|
|
|
target = target.substr(0,1) == "#" ? target.substr(1,target.length-1) : target;
|
2018-07-23 13:20:03 +00:00
|
|
|
this.queryCur = target.trim();
|
|
|
|
|
|
|
|
if (window.location.hash != this.queryCur)
|
|
|
|
{
|
|
|
|
window.location.hash = this.queryCur;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.queryCur == 'add')
|
|
|
|
{
|
|
|
|
this.view.add();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.view.display(this.db.filter(this.queryCur));
|
|
|
|
}
|
2018-07-15 14:23:07 +00:00
|
|
|
}
|
2018-07-13 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 13:20:03 +00:00
|
|
|
window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });
|
|
|
|
|
|
|
|
document.onkeydown = function(evt)
|
|
|
|
{
|
|
|
|
evt = evt || window.event;
|
|
|
|
var isEscape = false;
|
|
|
|
|
|
|
|
if ("key" in evt)
|
|
|
|
{
|
|
|
|
isEscape = (evt.key == "Escape" || evt.key == "Esc");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isEscape = (evt.keyCode == 27);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEscape)
|
|
|
|
{
|
|
|
|
if (main.queryCur == 'add')
|
|
|
|
{
|
|
|
|
main.load(main.queryPrev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|