2018-08-09 15:18:32 +00:00
|
|
|
if (window.showAdd != undefined && window.showAdd)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
const { ipcRenderer } = nodeRequire('electron');
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
function Add()
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
this.overlay = null;
|
|
|
|
this.display = null;
|
|
|
|
this.grid = null;
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.elementList = [];
|
|
|
|
this.keys = null;
|
|
|
|
var parent = this;
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
// STATE
|
|
|
|
this.enabledOverlay = false;
|
|
|
|
this.addedTitle = false
|
|
|
|
this.addedDate = false
|
|
|
|
this.addedPerson = false
|
|
|
|
this.addedSource = false
|
|
|
|
this.addedProject = false
|
|
|
|
this.addedType = false
|
|
|
|
this.addedLink = false
|
|
|
|
this.addedTags = false
|
|
|
|
this.addedNote = false
|
|
|
|
this.addedQuote = false
|
|
|
|
this.addedTerms = false
|
|
|
|
this.addedProgress = false
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.install = function()
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
this.grid = document.getElementById("grid");
|
|
|
|
this.overlay = document.getElementById("overlay");
|
|
|
|
|
|
|
|
this.setupElement('Title', 'TITLE', 'upper');
|
|
|
|
this.setupElement('Date', 'DATE', 'lower');
|
|
|
|
this.setupElement('Type', 'TYPE', 'lower');
|
|
|
|
this.setupElement('Link', 'LINK', 'url');
|
|
|
|
this.setupElement('Person', 'PERS', 'text');
|
|
|
|
this.setupElement('Source', 'SRCE', 'title');
|
|
|
|
this.setupElement('Project', 'PROJ', 'text');
|
|
|
|
this.setupElement('Tags', 'TAGS', 'tags');
|
|
|
|
this.setupElement('Progress', 'PROG', 'text');
|
|
|
|
this.setupElement('Note', 'NOTE', 'text'); // long
|
|
|
|
this.setupElement('Quote', 'QOTE', 'quote'); // long
|
|
|
|
this.setupElement('Terms', 'TERM', 'quote'); // long
|
|
|
|
// DONE
|
|
|
|
// REVI
|
|
|
|
this.keys = Object.keys(this.elementList);
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
// SETUP
|
|
|
|
this.overlay.innerHTML = '';
|
|
|
|
let content = `<div class="content">`
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
// ESCAPE
|
|
|
|
content += `<div class="content-menu">`;
|
|
|
|
content += `<a href="javascript:void(0);" id="escape">`;
|
|
|
|
content += `<div class="content-menu-option">`;
|
|
|
|
content += `<b>Esc</b>`;
|
|
|
|
content += `</div>`;
|
|
|
|
content += `</a>`;
|
|
|
|
content += `</div>`;
|
2018-07-26 16:12:02 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
// FORM
|
|
|
|
content += `<form>`;
|
|
|
|
for (var i = 0; i < this.keys.length; i++)
|
|
|
|
{
|
|
|
|
content += `<div class="row">
|
|
|
|
<div class="key" id="key${this.elementList[this.keys[i]].key}">${this.elementList[this.keys[i]].desc}</div>
|
|
|
|
<input placeholder="${this.elementList[this.keys[i]].key}" id="${this.elementList[this.keys[i]].key}">
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
content += `</form>`;
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
// DISPLAY
|
|
|
|
content += `<div class="display" id="display">`;
|
|
|
|
content += `</div>`;
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
// ENTER
|
|
|
|
content += `<div class="content-enter">`;
|
|
|
|
content += `<a href="javascript:void(0);" id="enter">`;
|
|
|
|
content += `<div class="content-menu-option">`;
|
|
|
|
content += `<b>Enter</b>`;
|
|
|
|
content += `</div>`;
|
|
|
|
content += `</a>`;
|
|
|
|
content += `</div>`;
|
|
|
|
|
|
|
|
content += `</div>`;
|
2018-08-05 15:05:18 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.overlay.innerHTML += content;
|
|
|
|
|
2018-09-14 02:57:15 +00:00
|
|
|
document.getElementById("escape").onclick = function()
|
|
|
|
{
|
|
|
|
console.log('escape onclick');
|
|
|
|
main.add.close();
|
|
|
|
}
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.display = document.getElementById("display");
|
|
|
|
|
|
|
|
document.getElementById("enter").addEventListener('click',
|
|
|
|
() =>
|
|
|
|
{
|
|
|
|
console.log('called write');
|
|
|
|
let content = this.display.innerHTML.replace(/\s?(<br\s?\/?>)\s?/g, "\r\n"); // replace line breaks
|
|
|
|
content = content.replace(/ /g, ' '); // replace tabs/spaces
|
|
|
|
// var content = content.replace(/\u00a0/g, ' ');
|
|
|
|
ipcRenderer.send('write', "\r\n" + "\r\n" + content);
|
2018-08-09 17:00:34 +00:00
|
|
|
this.setOverlay(false);
|
|
|
|
this.clearForm();
|
2018-08-09 15:18:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 0; i < this.keys.length; i++)
|
|
|
|
{
|
|
|
|
this.elementList[this.keys[i]].elem = document.getElementById(this.elementList[this.keys[i]].key);
|
|
|
|
this.elementList[this.keys[i]].elem.oninput = this.onElemChanged;
|
|
|
|
this.elementList[this.keys[i]].elem.onfocus = this.onElemFocus;
|
|
|
|
this.elementList[this.keys[i]].elem.onblur = this.onElemBlur;
|
|
|
|
this.elementList[this.keys[i]].elemKey = document.getElementById("key" + this.elementList[this.keys[i]].key);
|
|
|
|
}
|
|
|
|
setTimeout(function()
|
|
|
|
{
|
|
|
|
parent.setupData();
|
|
|
|
}, 100);
|
2018-08-09 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.clearForm = function()
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this.keys.length; i++)
|
|
|
|
{
|
|
|
|
this.elementList[this.keys[i]].elem.value = '';
|
|
|
|
}
|
2018-07-25 15:45:24 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.setupElement = function(key, desc, type)
|
|
|
|
{
|
|
|
|
this.elementList[key] = { key: key, desc: desc, type: type, added: false};
|
|
|
|
}
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.onElemChanged = function(e)
|
|
|
|
{
|
|
|
|
// TODO: Autocomplete tags, type
|
|
|
|
parent.setupData();
|
|
|
|
}
|
2018-07-25 15:45:24 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.onElemFocus = function(e)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
for (var i = 0; i < parent.keys.length; i++)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
if (e.target.id == parent.elementList[parent.keys[i]].key)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
if (!parent.elementList[parent.keys[i]].added)
|
|
|
|
{
|
|
|
|
parent.elementList[parent.keys[i]].added = true;
|
|
|
|
parent.elementList[parent.keys[i]].elemKey.style.visibility = "visible";
|
|
|
|
}
|
|
|
|
break;
|
2018-07-25 15:45:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.onElemBlur = function(e)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
for (var i = 0; i < parent.keys.length; i++)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
if (e.target.id == parent.elementList[parent.keys[i]].key)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
if (parent.elementList[parent.keys[i]].elem.value == '' && parent.elementList[parent.keys[i]].added)
|
|
|
|
{
|
|
|
|
parent.elementList[parent.keys[i]].added = false;
|
|
|
|
parent.elementList[parent.keys[i]].elemKey.style.visibility = "hidden";
|
|
|
|
}
|
|
|
|
break;
|
2018-07-25 15:45:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.setupData = function()
|
2018-07-26 16:12:02 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
let value = '';
|
|
|
|
for (var i = 0; i < parent.keys.length; i++)
|
2018-07-26 16:12:02 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
if (parent.elementList[parent.keys[i]].key == 'Title')
|
2018-07-26 16:12:02 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
if (parent.elementList[parent.keys[i]].elem.value != '')
|
|
|
|
{
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value.toUpperCase();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value += 'TITLE';
|
|
|
|
}
|
2018-07-26 16:12:02 +00:00
|
|
|
}
|
2018-08-09 15:18:32 +00:00
|
|
|
else if (parent.elementList[parent.keys[i]].elem.value != '')
|
2018-07-26 16:12:02 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
value += '<br>';
|
|
|
|
value += ' ';
|
|
|
|
value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : ';
|
2018-07-26 16:12:02 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
if (parent.elementList[parent.keys[i]].type == 'lower')
|
|
|
|
{
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value.toLowerCase();
|
|
|
|
}
|
|
|
|
else if (parent.elementList[parent.keys[i]].type == 'text')
|
|
|
|
{
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value;
|
|
|
|
}
|
|
|
|
else if (parent.elementList[parent.keys[i]].type == 'url')
|
|
|
|
{
|
|
|
|
// TODO: validate
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value;
|
|
|
|
}
|
|
|
|
else if (parent.elementList[parent.keys[i]].type == 'tags')
|
|
|
|
{
|
|
|
|
// TODO: Format
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value;
|
|
|
|
}
|
|
|
|
else if (parent.elementList[parent.keys[i]].type == 'quote')
|
|
|
|
{
|
|
|
|
// TODO: Format
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value;
|
|
|
|
}
|
|
|
|
else if (parent.elementList[parent.keys[i]].type == 'title')
|
|
|
|
{
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value.toProperCase();
|
|
|
|
}
|
|
|
|
else if (parent.elementList[parent.keys[i]].type == 'upper')
|
|
|
|
{
|
|
|
|
value += parent.elementList[parent.keys[i]].elem.value.toLowerCase();
|
|
|
|
}
|
2018-07-26 16:12:02 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-09 15:18:32 +00:00
|
|
|
parent.display.innerHTML = value;
|
2018-07-26 16:12:02 +00:00
|
|
|
}
|
2018-07-25 16:31:26 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.show = function()
|
|
|
|
{
|
2018-09-14 02:57:15 +00:00
|
|
|
console.log('add.show');
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.setOverlay(true);
|
2018-07-25 16:31:26 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
var date = new Date();
|
|
|
|
var dateString = "1" + date.getFullYear()
|
|
|
|
+ "-" + ("0"+(date.getMonth()+1)).slice(-2)
|
|
|
|
+ "-" + ("0" + date.getDate()).slice(-2);
|
|
|
|
this.elementList['Date'].elem.value = dateString;
|
|
|
|
this.elementList['Date'].added = true;
|
|
|
|
this.elementList['Date'].elemKey.style.visibility = "visible";
|
2018-07-25 15:45:24 +00:00
|
|
|
|
|
|
|
setTimeout(function()
|
2018-08-09 15:18:32 +00:00
|
|
|
{
|
|
|
|
parent.elementList['Title'].elem.focus();
|
|
|
|
}, 100);
|
2018-07-25 15:45:24 +00:00
|
|
|
}
|
2018-08-09 15:18:32 +00:00
|
|
|
|
2018-09-14 02:57:15 +00:00
|
|
|
this.close = function()
|
|
|
|
{
|
|
|
|
console.log('close. prev: ' + main.queryPrev);
|
|
|
|
main.load(main.queryPrev);
|
|
|
|
this.grid.style.display = "block";
|
|
|
|
this.setOverlay(false);
|
|
|
|
}
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
this.setOverlay = function(value)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-09-14 02:57:15 +00:00
|
|
|
console.log('add.setOverlay ' + value);
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
if (value && !this.enabledOverlay)
|
|
|
|
{
|
|
|
|
overlay.style.opacity = '1';
|
|
|
|
overlay.style.zIndex = '1000';
|
|
|
|
this.enabledOverlay = true;
|
2018-09-14 02:57:15 +00:00
|
|
|
// setTimeout(function()
|
|
|
|
// {
|
|
|
|
// this.grid.innerHTML = '';
|
|
|
|
// this.grid.style.height = 0;
|
|
|
|
// }, 200);
|
|
|
|
this.grid.style.display = "none";
|
2018-08-09 15:18:32 +00:00
|
|
|
}
|
|
|
|
else if (!value && this.enabledOverlay)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
overlay.style.opacity = '0';
|
|
|
|
setTimeout(function()
|
|
|
|
{
|
|
|
|
overlay.style.zIndex = '-100';
|
|
|
|
}, 200);
|
|
|
|
this.enabledOverlay = false;
|
|
|
|
}
|
2018-07-25 15:45:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-14 02:57:15 +00:00
|
|
|
String.prototype.toProperCase = function ()
|
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
|
|
|
};
|
2018-07-26 16:12:02 +00:00
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
document.onkeydown = function(evt)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-09-14 02:57:15 +00:00
|
|
|
console.log('onkeydown');
|
|
|
|
console.log(evt);
|
|
|
|
|
2018-08-09 15:18:32 +00:00
|
|
|
evt = evt || window.event;
|
|
|
|
if (!evt.ctrlKey)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
var isEscape = false;
|
|
|
|
var isA = false;
|
|
|
|
|
|
|
|
if ("key" in evt)
|
2018-07-25 15:45:24 +00:00
|
|
|
{
|
2018-08-09 15:18:32 +00:00
|
|
|
isEscape = (evt.key == "Escape" || evt.key == "Esc");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isEscape = (evt.keyCode == 27);
|
|
|
|
}
|
|
|
|
isA = (evt.keyCode == 65);
|
|
|
|
|
|
|
|
if (isEscape)
|
|
|
|
{
|
|
|
|
if (main.queryCur == 'add')
|
|
|
|
{
|
2018-09-14 02:57:15 +00:00
|
|
|
console.log('did it');
|
|
|
|
this.close();
|
2018-08-09 15:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isA && main.queryCur != 'add')
|
|
|
|
{
|
|
|
|
main.load('add');
|
2018-07-25 15:45:24 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-09 15:18:32 +00:00
|
|
|
};
|
|
|
|
}
|