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-25 15:45:24 +00:00
|
|
|
this.add = null;
|
2018-08-05 15:05:18 +00:00
|
|
|
this.write = null;
|
2018-07-23 13:20:03 +00:00
|
|
|
this.queryPrev = '';
|
|
|
|
this.queryCur = '';
|
2018-08-08 15:49:00 +00:00
|
|
|
var parent = this;
|
2018-08-08 16:32:54 +00:00
|
|
|
const FILELOCATION = 'content/data.ndtl';
|
2018-07-13 15:56:09 +00:00
|
|
|
|
2018-07-15 14:23:07 +00:00
|
|
|
this.install = function()
|
|
|
|
{
|
2018-08-11 15:43:33 +00:00
|
|
|
var oReq = new XMLHttpRequest();
|
|
|
|
oReq.open('GET', FILELOCATION);
|
|
|
|
oReq.overrideMimeType("text/plain");
|
|
|
|
oReq.addEventListener("load", function() { parent.setup(this.responseText); } );
|
|
|
|
oReq.send();
|
2018-08-08 15:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setup = function(data)
|
|
|
|
{
|
|
|
|
this.db = new Wrap();
|
|
|
|
this.db.install(data);
|
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-24 11:50:04 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
if (window.showAdd != undefined && window.showAdd)
|
2018-07-24 11:50:04 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
this.add = new Add();
|
|
|
|
this.add.install();
|
|
|
|
var escape = document.getElementById("escape");
|
|
|
|
escape.onclick = function()
|
|
|
|
{
|
|
|
|
main.load(main.queryPrev);
|
|
|
|
}
|
2018-07-24 11:50:04 +00:00
|
|
|
}
|
2018-08-08 15:49:00 +00:00
|
|
|
|
|
|
|
this.start();
|
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-24 11:50:04 +00:00
|
|
|
document.activeElement.blur();
|
|
|
|
if (this.queryCur != 'add')
|
|
|
|
{
|
|
|
|
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')
|
|
|
|
{
|
2018-08-09 15:26:29 +00:00
|
|
|
if (window.showAdd != undefined && window.showAdd)
|
|
|
|
{
|
|
|
|
this.add.show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.hash = this.queryPrev;
|
|
|
|
}
|
2018-07-23 13:20:03 +00:00
|
|
|
}
|
|
|
|
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-25 15:45:24 +00:00
|
|
|
window.addEventListener("hashchange", function() { main.load(window.document.location.hash); });
|