This commit is contained in:
Kameron Kenny 2019-07-18 10:55:52 -04:00
parent 8e99107681
commit a5c96e7efe
1 changed files with 137 additions and 430 deletions

View File

@ -8,19 +8,27 @@ var config = {
appId: "1:999467953896:web:a4ded59b12ccb9ff" appId: "1:999467953896:web:a4ded59b12ccb9ff"
}; };
var logging = false;
function consoleLog(logMessage) {
if ( logging === true ) {
console.log(logMessage);
}
}
//firebase.initializeApp(firebaseConfig); //firebase.initializeApp(firebaseConfig);
if (!firebase.apps.length) { if (!firebase.apps.length) {
firebase.initializeApp(config); firebase.initializeApp(config);
} }
function initApp() { function initApp() {
console.log("function: initApp()"); consoleLog("function: initApp()");
// Auth state changes. // Auth state changes.
// [START authstatelistener] // [START authstatelistener]
firebase.auth().onAuthStateChanged(function(user){ firebase.auth().onAuthStateChanged(function(user){
console.log(`in onAuthStateChanged`); consoleLog(`in onAuthStateChanged`);
if (user) { if (user) {
console.log(`${user.displayName}`); consoleLog(`${user.displayName}`);
// User is signed in. // User is signed in.
var displayName = user.displayName; var displayName = user.displayName;
var email = user.email; var email = user.email;
@ -56,7 +64,7 @@ function initApp() {
// AUTH // // AUTH //
// [START googlecallback] // [START googlecallback]
function onSignIn(googleUser) { function onSignIn(googleUser) {
console.log('Google Auth Response', googleUser); consoleLog('Google Auth Response', googleUser);
// We need to register an Observer on Firebase Auth to make sure auth is initialized. // We need to register an Observer on Firebase Auth to make sure auth is initialized.
var unsubscribe = firebase.auth().onAuthStateChanged(function(firebaseUser) { var unsubscribe = firebase.auth().onAuthStateChanged(function(firebaseUser) {
unsubscribe(); unsubscribe();
@ -90,7 +98,7 @@ function onSignIn(googleUser) {
// [END authwithcred] // [END authwithcred]
} else { } else {
var user = googleUser; var user = googleUser;
console.log('User already signed-in Firebase.'); consoleLog('User already signed-in Firebase.');
var displayName = user.displayName; var displayName = user.displayName;
var email = user.email; var email = user.email;
var emailVerified = user.emailVerified; var emailVerified = user.emailVerified;
@ -136,7 +144,7 @@ function handleSignOut() {
} }
function writeUserData(userId, name, email, imageUrl) { function writeUserData(userId, name, email, imageUrl) {
console.log("function: writeUserData(" + userId + ", " + name + ", " + email + ", " + imageUrl + ")"); consoleLog("function: writeUserData(" + userId + ", " + name + ", " + email + ", " + imageUrl + ")");
firebase.database().ref('users/' + userId).update({ firebase.database().ref('users/' + userId).update({
username: name, username: name,
email: email, email: email,
@ -150,7 +158,7 @@ function writeUserData(userId, name, email, imageUrl) {
//}); //});
function newPunch(uid, subject, priority, progress, needBy, notes, tags) { function newPunch(uid, subject, priority, progress, needBy, notes, tags) {
console.log("function: newPunch(" + uid + ", " + subject + ", " + priority + ", " + progress + ", " + needBy + ", " + notes + ", " + tags + ")"); consoleLog("function: newPunch(" + uid + ", " + subject + ", " + priority + ", " + progress + ", " + needBy + ", " + notes + ", " + tags + ")");
var punchData = { var punchData = {
uid: uid, uid: uid,
subject: subject, subject: subject,
@ -172,10 +180,10 @@ function newPunch(uid, subject, priority, progress, needBy, notes, tags) {
} }
function genDaily() { function genDaily() {
console.log("function: genDaily()"); consoleLog("function: genDaily()");
var daily = [ "Check Workday", "Check Expenses", "Check Change Cases", "Check TD's", "Check at-mentions" ]; var daily = [ "Check Workday", "Check Expenses", "Check Change Cases", "Check TD's", "Check at-mentions" ];
console.log(`${daily[1]}`); consoleLog(`${daily[1]}`);
priority = parseInt("3"); priority = parseInt("3");
var d = new Date(); var d = new Date();
@ -192,12 +200,12 @@ function genDaily() {
} }
function genWeekly() { function genWeekly() {
console.log("function: genWeekly()"); consoleLog("function: genWeekly()");
//get next monday: //get next monday:
// var d = new Date(); // var d = new Date();
// d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7); // d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
// console.log(d) // consoleLog(d)
// }; // };
var weekly = [ "Update ORB Notes", "Prep Weekly Meeting", "Build out Broadcast Timer" ]; var weekly = [ "Update ORB Notes", "Prep Weekly Meeting", "Build out Broadcast Timer" ];
@ -217,7 +225,7 @@ function genWeekly() {
// standard functions // standard functions
function setPriority(sortObject, newPosition) { function setPriority(sortObject, newPosition) {
console.log("function: setPriority(" + sortObject + ", " + newPosition + ")"); consoleLog("function: setPriority(" + sortObject + ", " + newPosition + ")");
var priority = {}; var priority = {};
@ -229,109 +237,113 @@ function setPriority(sortObject, newPosition) {
} }
function startPunch(reference) { function startPunch(reference) {
console.log("function: startPunch(" + reference + ")"); consoleLog("function: startPunch(" + reference + ")");
var start = new Date().getTime();
// Write the new punch data
var progress = {};
var startTime = {};
progress['users/' + window.uid + '/punches/' + reference + '/progress'] = "in progress";
startTime['users/' + window.uid + '/punches/' + reference + '/startTime'] = start;
firebase.database().ref().update(progress);
firebase.database().ref().update(startTime);
$( "#" + reference )
.removeClass( "waiting" )
$( "#" + reference )
.removeClass( "punch-default" )
$( "#" + reference )
.addClass( "inProgress" );
$( "#progress" + reference )
.removeClass( "waiting" )
$( "#progress" + reference )
.removeClass( "punch-default" )
$( "#progress" + reference )
.addClass( "inProgress" );
var exists = document.getElementById("timer" + reference); var exists = document.getElementById("timer" + reference);
if ( exists === null ) { if ( exists === null ) {
console.log("Generate Element: timer" + reference); consoleLog("Generate Element: timer" + reference);
genPunchListItem('<div id="timer' + reference + '" class="three columns punch-default started"></div>', '#details-col-one' + reference); genPunchListItem('<div id="timer' + reference + '" class="three columns punch-default started"></div>', '#details-col-one' + reference);
} }
var timerExists = exists.innerHTML; var timerExists = exists.innerHTML;
console.log(timerExists); consoleLog(timerExists);
if (timerExists === null || timerExists === '') { if (timerExists === null || timerExists === '') {
console.log("createTimer(" + reference + ", " + time + ")"); consoleLog("createTimer(" + reference + ", " + time + ")");
var time = new Date(start).getTime(); var time = new Date(start).getTime();
createTimer("timer" + reference, time); createTimer("timer" + reference, time);
} }
} }
function completePunch(reference) { function completePunch(reference) {
console.log("function: completePunch(" + reference + ")");
var end = new Date().getTime();
// Write the new punch data consoleLog("function: completePunch(" + reference + ")");
var progress = {};
var endTime = {};
progress['users/' + window.uid + '/punches/' + reference + '/progress'] = "done";
endTime['users/' + window.uid + '/punches/' + reference + '/endTime'] = end;
firebase.database().ref().update(progress);
firebase.database().ref().update(endTime);
deletePunchElement(reference); deletePunchElement(reference);
// loadPunches(window.uid);
} }
function waitingPunch(reference) { function setPunchProgress(reference, p) {
console.log("function: waitingPunch(" + reference + ")");
consoleLog("function: setPunchProgress(" + reference + ", " + p + ")");
var progress = {}; var progress = {};
progress['users/' + window.uid + '/punches/' + reference + '/progress'] = "waiting"; progress['users/' + window.uid + '/punches/' + reference + '/progress'] = p;
firebase.database().ref().update(progress); firebase.database().ref().update(progress);
$( "#" + reference ) switch(p.toLowerCase()) {
.removeClass( "punch-default" ) case "in progress":
$( "#" + reference ) // execute
.removeClass( "inProgress" ) var refClass = "inProgress";
$( "#" + reference ) var rmClass = [ "punch-default", "waiting" ];
.addClass( "waiting" );
$( "#progress" + reference )
.removeClass( "inProgress" )
$( "#progress" + reference )
.removeClass( "punch-default" )
$( "#progress" + reference )
.addClass( "waiting" );
// loadPunches(window.uid); var start = new Date().getTime();
var startTime = {};
startTime['users/' + window.uid + '/punches/' + reference + '/startTime'] = start;
firebase.database().ref().update(startTime);
//startPunch(reference);
break;
case "waiting":
// execute
var refClass = "waiting";
var rmClass = [ "punch-default", "inProgress" ];
break;
case "done":
var end = new Date().getTime();
var endTime = {};
endTime['users/' + window.uid + '/punches/' + reference + '/endTime'] = end;
firebase.database().ref().update(endTime);
positionLoop();
//completePunch(reference);
break;
default:
consoleLog("function: setStyle(" + reference + ", " + progress + "), did not match a condition. :(");
}
// setStyle(reference, p);
} }
function mkPunchNew(reference) { function setStyle(reference, progress) {
console.log("function: mkPunchNew(" + reference + ")");
var progress = {};
progress['users/' + window.uid + '/punches/' + reference + '/progress'] = "new";
firebase.database().ref().update(progress);
console.log("setting classes"); switch(progress.toLowerCase()) {
$( "#" + reference ) case "new":
.removeClass( "waiting" ) // execute
$( "#" + reference ) var refClass = "punch-default";
.removeClass( "inProgress" ) var rmClass = [ "waiting", "inProgress" ];
$( "#" + reference ) break;
.addClass( "punch-default" ); case "in progress":
$( "#progress" + reference ) // execute
.removeClass( "waiting" ) var refClass = "inProgress";
$( "#progress" + reference ) var rmClass = [ "punch-default", "waiting" ];
.removeClass( "inProgress" ) startPunch(reference);
$( "#progress" + reference ) break;
.addClass( "punch-default" ); case "waiting":
// loadPunches(window.uid); // execute
var refClass = "waiting";
var rmClass = [ "punch-default", "inProgress" ];
break;
case "done":
completePunch(reference);
break;
default:
consoleLog("function: setStyle(" + reference + ", " + progress + "), did not match a condition. :(");
}
elementIds = [ '#' + reference, '#progress' + reference ];
var c;
var i;
consoleLog("Element Ids: " + elementIds);
for (i in elementIds) {
for (c in rmClass) {
consoleLog("Removing: " + rmClass[c] + ", from: " + elementIds[i]);
$( elementIds[i] ).removeClass( rmClass[c] );
}
consoleLog("Adding: " + refClass + ", to: " + elementIds[i]);
$( elementIds[i] ).addClass( refClass );
}
} }
function clearDefault(a){ function clearDefault(a){
@ -348,16 +360,16 @@ function positionLoop() {
var nPriority = i; var nPriority = i;
if ( parseInt(cPriority) < 100 ) { if ( parseInt(cPriority) < 100 ) {
console.log("Updating: " + l.id + " priority, from: " + cPriority + ", to: " + nPriority); consoleLog("Updating: " + l.id + " priority, from: " + cPriority + ", to: " + nPriority);
setPriority(l.id, nPriority); setPriority(l.id, nPriority);
} }
}); });
//console.log("i: " + i + " l: " + l.id); //consoleLog("i: " + i + " l: " + l.id);
}); });
} }
function mkSortable(){ function mkSortable(){
console.log("function: mkSortable()"); consoleLog("function: mkSortable()");
$( function() { $( function() {
$( "#sortable" ).sortable({ $( "#sortable" ).sortable({
cancel: ".portlet-toggle", cancel: ".portlet-toggle",
@ -365,15 +377,15 @@ function mkSortable(){
revert: true, revert: true,
distance: 50, distance: 50,
start: function(event, ui) { start: function(event, ui) {
//console.log($( this ).( "li" )); //consoleLog($( this ).( "li" ));
console.log(ui.item.context.id); consoleLog(ui.item.context.id);
console.log(`Start Position: ${ui.item.index()}`); consoleLog(`Start Position: ${ui.item.index()}`);
}, },
stop: function(event, ui) { stop: function(event, ui) {
// setPriority(window.sortObjectUUID, ui.item.index()); // setPriority(window.sortObjectUUID, ui.item.index());
console.log(event, ui); consoleLog(event, ui);
setPriority(ui.item.context.id, ui.item.index()); setPriority(ui.item.context.id, ui.item.index());
console.log(`New Position: ${ui.item.index()}`); consoleLog(`New Position: ${ui.item.index()}`);
positionLoop(); positionLoop();
} }
}); });
@ -381,7 +393,7 @@ function mkSortable(){
} }
function enableDetail(){ function enableDetail(){
console.log("function: enableDetail()"); consoleLog("function: enableDetail()");
$(function() { $(function() {
$( ".portlet" ) $( ".portlet" )
.addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
@ -406,12 +418,12 @@ function enableDetail(){
// some element functions... // some element functions...
function enableElement(element) { function enableElement(element) {
console.log(`enabling ${element}`); consoleLog(`enabling ${element}`);
document.getElementById(element).style.display = "block"; document.getElementById(element).style.display = "block";
} }
function disableElement(element) { function disableElement(element) {
console.log(`disabling ${element}`); consoleLog(`disabling ${element}`);
document.getElementById(element).style.display = "none"; document.getElementById(element).style.display = "none";
} }
@ -452,7 +464,7 @@ function editPunch(uuid) {
punchRef.once('value').then(function(snapshot) { punchRef.once('value').then(function(snapshot) {
var data = snapshot.val(); var data = snapshot.val();
console.log(data); consoleLog(data);
var nDate = new Date(data.needByDate); var nDate = new Date(data.needByDate);
var notes = data.notes; var notes = data.notes;
@ -531,13 +543,13 @@ function createTimer(element,timeTo) {
if (seconds < 0) { seconds = -(seconds); } if (seconds < 0) { seconds = -(seconds); }
if (seconds < 10) { seconds = ('0' + seconds); } if (seconds < 10) { seconds = ('0' + seconds); }
//console.log("Setting Timer on element:" + element); //consoleLog("Setting Timer on element:" + element);
var exists = document.getElementById(element); var exists = document.getElementById(element);
if (exists != null) { if (exists != null) {
document.getElementById(element).innerHTML = days + "day(s), " + hours + ":" + minutes + ":" + seconds; document.getElementById(element).innerHTML = days + "day(s), " + hours + ":" + minutes + ":" + seconds;
} else { } else {
// console.log("Could not update: " + element + ", because: " + exists); // consoleLog("Could not update: " + element + ", because: " + exists);
} }
}, 1000); }, 1000);
} }
@ -571,27 +583,28 @@ function updateElementData(element, d) {
var e = document.getElementById(element).innerHTML; var e = document.getElementById(element).innerHTML;
if ( d != e ) { if ( d != e ) {
console.log("updating: " + element + ", with: " + d + ", was: " + e); consoleLog("updating: " + element + ", with: " + d + ", was: " + e);
document.getElementById(element).innerHTML = d; document.getElementById(element).innerHTML = d;
} else if ( d === e ) { } else if ( d === e ) {
console.log("Not Updating: " + element + ", because: " + d + " === " + e); consoleLog("Not Updating: " + element + ", because: " + d + " === " + e);
} else { } else {
console.log("Not updating: " + element + ", because: Something weird happened with: " + d + " & " + e); consoleLog("Not updating: " + element + ", because: Something weird happened with: " + d + " & " + e);
} }
} else { } else {
console.log("add new element"); consoleLog("add new element");
} }
} }
function updatePunchElement(childKey, childData) { function updatePunchElement(childKey, childData) {
setStyle(childKey, childData.progress);
if (childData.progress.toLowerCase != "done") {
updateElementData("priority" + childKey, childData.priority); updateElementData("priority" + childKey, childData.priority);
updateElementData("subject" + childKey, childData.subject); updateElementData("subject" + childKey, childData.subject);
updateElementData("progress" + childKey, childData.progress); updateElementData("progress" + childKey, childData.progress);
updateElementData("neededby-data" + childKey, childData.needByDate); updateElementData("neededby-data" + childKey, childData.needByDate);
}
//tags
} }
@ -616,10 +629,10 @@ function addPunchElement(childKey, childData) {
genPunchListItem('<div id="dropdown-wrapper' + childKey + '" class="dropdown"></div>', '#details-container' + childKey); genPunchListItem('<div id="dropdown-wrapper' + childKey + '" class="dropdown"></div>', '#details-container' + childKey);
genPunchListItem('<img class="top dropbtn" onclick=progressMenuDrop("' + childKey + '") src="images/down-carrot.png">', '#dropdown-wrapper' + childKey); genPunchListItem('<img class="top dropbtn" onclick=progressMenuDrop("' + childKey + '") src="images/down-carrot.png">', '#dropdown-wrapper' + childKey);
genPunchListItem('<div id="progressDropdown' + childKey + '" class="dropdown-content punch-default"></div>', '#dropdown-wrapper' + childKey); genPunchListItem('<div id="progressDropdown' + childKey + '" class="dropdown-content punch-default"></div>', '#dropdown-wrapper' + childKey);
genPunchListItem('<a href="#" onClick=mkPunchNew("' + childKey + '")>New</a>', '#progressDropdown' + childKey); genPunchListItem('<a href="#" onClick=\'setPunchProgress("' + childKey + '", "new")\'>New</a>', '#progressDropdown' + childKey);
genPunchListItem('<a href="#" onClick=startPunch("' + childKey + '")>Start</a>', '#progressDropdown' + childKey); genPunchListItem('<a href="#" onClick=\'setPunchProgress("' + childKey + '", "in progress")\'>Start</a>', '#progressDropdown' + childKey);
genPunchListItem('<a href="#" onClick=waitingPunch("' + childKey + '")>Waiting</a>', '#progressDropdown' + childKey); genPunchListItem('<a href="#" onClick=\'setPunchProgress("' + childKey + '", "waiting")\'>Waiting</a>', '#progressDropdown' + childKey);
genPunchListItem('<a href="#" onClick=completePunch("' + childKey + '")>Finish</a>', '#progressDropdown' + childKey); genPunchListItem('<a href="#" onClick=\'setPunchProgress("' + childKey + '", "done")\'>Finish</a>', '#progressDropdown' + childKey);
genPunchListItem('<div id="details-col-three' + childKey + '" class="needby-container punch-default"></div>', '#details-container' + childKey); genPunchListItem('<div id="details-col-three' + childKey + '" class="needby-container punch-default"></div>', '#details-container' + childKey);
genPunchListItem('<div id="details-col-five' + childKey + '" class="five columns punch-default"></div>', '#details-container' + childKey); genPunchListItem('<div id="details-col-five' + childKey + '" class="five columns punch-default"></div>', '#details-container' + childKey);
@ -670,14 +683,14 @@ function deletePunchElement(childKey) {
} }
function clearTagFilter() { function clearTagFilter() {
console.log("clearing tags"); consoleLog("clearing tags");
$( "li" ) $( "li" )
.removeClass( "hide" ); .removeClass( "hide" );
} }
function tagFilter(reference) { function tagFilter(reference) {
console.log("Filtering Punches on: " + reference); consoleLog("Filtering Punches on: " + reference);
$( "li" ) $( "li" )
.addClass( "hide" ); .addClass( "hide" );
@ -688,14 +701,14 @@ function tagFilter(reference) {
} }
function loadPunches(uid) { function loadPunches(uid) {
console.log("Loading Punches..."); consoleLog("Loading Punches...");
//document.getElementById("sortable").innerHTML = ''; //document.getElementById("sortable").innerHTML = '';
var punchesRef = firebase.database().ref('users/' + uid + '/punches').orderByChild('priority'); var punchesRef = firebase.database().ref('users/' + uid + '/punches').orderByChild('priority');
var itemStyle = "punches"; var itemStyle = "punches";
// list = '<ol id="sortable">'; // list = '<ol id="sortable">';
punchesRef.on('child_added', function(data) { punchesRef.on('child_added', function(data) {
console.log("child Added"); consoleLog("child Added");
addPunchElement(data.key, data.val()); addPunchElement(data.key, data.val());
}); });
@ -703,10 +716,10 @@ function loadPunches(uid) {
} }
function sortList() { function sortList() {
console.log('function: sortList()'); consoleLog('function: sortList()');
var items = $('li'); var items = $('li');
items.sort(function(a, b){ items.sort(function(a, b){
console.log($(a).data('priority')); consoleLog($(a).data('priority'));
return +$(a).data('priority') - +$(b).data('priority'); return +$(a).data('priority') - +$(b).data('priority');
}); });
@ -717,14 +730,14 @@ var looper = setInterval(function() {
var uid = window.uid; var uid = window.uid;
var punchesRef = firebase.database().ref('users/' + uid + '/punches').orderByChild('priority'); var punchesRef = firebase.database().ref('users/' + uid + '/punches').orderByChild('priority');
punchesRef.on('child_changed', function(data) { punchesRef.on('child_changed', function(data) {
console.log("Child Changed"); consoleLog("Child Changed");
updatePunchElement(data.key, data.val()); updatePunchElement(data.key, data.val());
// deletePunchElement(data.key); // deletePunchElement(data.key);
// addPunchElement(data.key, data.val()); // addPunchElement(data.key, data.val());
}); });
punchesRef.on('child_removed', function(data) { punchesRef.on('child_removed', function(data) {
console.log("child Removed"); consoleLog("child Removed");
deletePunchElement(data.key); deletePunchElement(data.key);
}); });
}, 1000); }, 1000);
@ -757,7 +770,7 @@ function createNewEvent() {
var noSpaces = stripLeadingSpace.replace(/ /g, '_'); var noSpaces = stripLeadingSpace.replace(/ /g, '_');
var newTags = noSpaces.split(","); var newTags = noSpaces.split(",");
newPunch(window.uid, subjectField, priorityField, progressField, nDateField, notesField, newTags) newPunch(window.uid, subjectField, priorityField, progressField, nDateField, notesField, newTags);
disableElement("newEvent"); disableElement("newEvent");
enableElement("punchListAll"); enableElement("punchListAll");
@ -771,309 +784,3 @@ window.onload = function() {
initApp(); initApp();
}; };
//
//
//
// old script
//
//
//
/*
function tagFilter(tagItem) {
console.log(`In tagFilter function`);
window.tagFilterItem = tagItem;
getJson();
}
function cleartagfilter() {
console.log(`clear tags`);
window.tagfilteritem = undefined;
getjson();
}
function getStatus(punchList, statusFilter) {
return punchList.filter(function(punch) { return punch.progress.toLowerCase() != statusFilter; });
}
window.punches = '';
function startPunch(uuid) {
var punchList = window.punches;
item = findArrayId(uuid);
if ( punchList[item].startTime === undefined ) {
punchList[item].startTime = new Date().getTime();
}
punchList[item].progress = "In Progress";
punchList[item].priority = 0;
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
}
function completePunch(uuid) {
var punchList = window.punches;
item = findArrayId(uuid);
if ( punchList[item].doneTime === undefined ) {
punchList[item].doneTime = new Date().getTime();
}
punchList[item].progress = "Done";
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
}
function waitingPunch(uuid) {
var punchList = window.punches;
item = findArrayId(uuid);
punchList[item].progress = "Waiting";
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
}
function mkPunchNew(uuid) {
var punchList = window.punches;
item = findArrayId(uuid);
punchList[item].progress = "New";
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
}
function enablePunchDetail(uuid) {
var punchList = window.punches;
item = findArrayId(uuid);
console.log(`inside enablePunchDetail`);
disableElement("punchListAll");
enableElement("punchDetail");
// html = "";
html = "<p>subject: " + punchList[item].subject + "<br />Created: " + punchList[item].cDate + "<br />Modified Date: " + punchList[item].mDate + "<br />Priority: " + punchList[item].priority + "<br />Progress: " + punchList[item].progress + "<br /><textarea>" + punchList[item].notes + "</textarea><br /><input onfocus='clearDefault(this)' type='text' id='tag' value='Add tag'><input onClick='addTag()' type=button value='Add' /></p><input type=button value=close onClick=getJson()>";
document.getElementById("punchDetail").innerHTML = html;
}
function genEventForm() {
document.getElementById("newSubject").value = "subject";
document.getElementById("newPriority").value = "priority";
document.getElementById("timepickerCreate").value = "date";
document.getElementById("newNotes").value = '';
disableElement('punchListAll');
enableElement('newEvent');
}
function createNewEvent() {
getJson();
// console.log(`${punchList}`);
// console.log(`${window.punches}`);
// disableElement("punchList");
// disableElement("punchDetail");
punchList = window.punches;
var subjectField = document.getElementById("newSubject").value;
var priorityField = document.getElementById("newPriority").value;
var progressField = document.getElementById("newProgress").value;
var nDateField = document.getElementById("timepickerCreate").value;
var notesField = document.getElementById("newNotes").value;
var newTag = document.getElementById("tagsCreate").value.toLowerCase();
var stripLeadingSpace = newTag.replace(/, /g, ',');
var noSpaces = stripLeadingSpace.replace(/ /g, '_');
var newTags = noSpaces.split(",");
// make sure tags object exists
var newEventJson = { uuid: genUid(), nDate: nDateField, subject: subjectField, priority: priorityField, progress: progressField, tags: newTags, notes: notesField };
punchList.push(newEventJson);
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
disableElement("newEvent");
enableElement("punchListAll");
// document.getElementById("newEventList").innerHTML = jsonStr;
}
function deletePunch(uuid) {
getJson();
// console.log(`${punchList}`);
// console.log(`${window.punches}`);
punchList = window.punches;
item = findArrayId(uuid);
console.log(`splicing ${item}`);
punchList.splice(item, 1);
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
// document.getElementById("newEventList").innerHTML = jsonStr;
}
function enableElement(element) {
console.log(`enabling ${element}`);
document.getElementById(element).style.display = "block";
}
function disableElement(element) {
console.log(`disabling ${element}`);
document.getElementById(element).style.display = "none";
}
function displayMeta() {
document.getElementById("meta").innerHTML = "Version: " + version ;
}
function toggleShowDone() {
if (showDone === false) {
window.showDone = true;
} else if (showDone === true) {
window.showDone = false;
} else {
window.showDone = false;
}
getJson();
}
function editPunch(uuid) {
disableElement("punchListAll");
enableElement("editPunch");
punchList = window.punches;
item = findArrayId(uuid);
if ( punchList[item].tags === undefined ) {
punchList[item].tags = [];
}
var id = item;
var subject = punchRef.subject;
var priority = punchRef.priority;
var progress = punchRef.progress;
var nDate = punchRef.nDate;
var notes = punchRef.notes;
var tags = punchRef.tags;
var html = '<div class="container listWrapper">';
html += '<input type=hidden id="editID" value="' + uuid + '">';
html += '<div class="edit-row"><div class="three columns">Subject:</div><div class="nine columns"><input class="twelve columns" type=text id="editSubject" value="' + subject + '"></div></div>';
html += '<div class="three columns">Priority:</div><div class="nine columns"><input type=text id="editPriority" value="' + priority + '"></div>';
html += '<div class="three columns">Need By:</div><div class="nine columns"><input type=text id="timepickerEdit" value="' + nDate + '"></div>';
html += '<div class="three columns">Progress:</div><div id="editProgress" class="nine columns">';
html += progress;
html += '</div>';
html += '<div class="three columns">Tags:</div><div class="nine columns">' + tags + '&nbsp; </div>';
html += '<div class="three columns">Add Tag:</div><div class="nine columns"><input type="text" id="addTag-' + uuid + '"><button onClick=addTag("' + uuid + '")>Add Tag</button></div>';
html += '<div class="three columns">Notes: </div><div class="nine columns"><textarea class="edit-text-box" id="editNotes">' + notes + '</textarea></div>';
html += '<button onClick=submitEditPunch("' + uuid + '")>Update</button>';
html += '<button onClick=\'disableElement("editPunch"),enableElement("punchListAll")\'>Close</button>';
html += '</div>';
document.getElementById("editPunch").innerHTML = html;
}
function submitEditPunch(uuid) {
punchList = window.punches;
// var uuid = document.getElementById("editID").value;
var id = findArrayId(uuid);
var subjectField = document.getElementById("editSubject").value;
var priorityField = document.getElementById("editPriority").value;
var progressField = document.getElementById("editProgress").innerHTML;
var nDateField = document.getElementById("timepickerEdit").value;
//var tagsField = document.getElementById("editTags").value.toLowerCase();
var notesField = document.getElementById("editNotes").value;
punchRef.subject = subjectField;
punchRef.priority = priorityField;
punchRef.progress = progressField;
punchRef.nDate = nDateField;
//punchRef.tags = tagsField;
punchRef.notes = notesField;
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
disableElement("editPunch");
}
function addTag(uuid) {
var item = findArrayId(uuid);
// var item = document.getElementById("addTag-" + uuid).value;
var newTag = document.getElementById("addTag-" + uuid).value.toLowerCase();
var stripLeadingSpace = newTag.replace(', ', ',');
var noSpaces = stripLeadingSpace.replace(' ', '_');
var newTags = noSpaces.split(",");
// make sure tags object exists
if (punchList[item].tags === undefined) {
console.log(`Adding tags object to punchList[${item}]`);
punchList[item].tags = [];
}
for ( nt = 0; nt < newTags.length; nt++ ) {
punchList[item].tags.push(newTags[nt]);
console.log(`${punchList[item].tags}`);
}
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
editpunch(uuid);
// disableelement("editpunch");
// enableelement("punchlistall");
disableelement("punchlistall");
}
function cleardefault(a){
if (a.defaultvalue === a.value) {
a.value="";
}
}
function genuid() {
function chr4() {
return math.random().tostring(16).slice(-4);
}
return chr4() + chr4() +
'-' + chr4() +
'-' + chr4() +
'-' + chr4() +
'-' + chr4() + chr4() + chr4();
}
//google stuff
function onsignin(googleuser) {
// var profile = googleuser.getbasicprofile();
// console.log('id: ' + profile.getid()); // do not send to your backend! use an id token instead.
// console.log('name: ' + profile.getname());
// console.log('image url: ' + profile.getimageurl());
// console.log('email: ' + profile.getemail()); // this is null if the 'email' scope is not present.
// getjson();
}
function signout() {
var auth2 = gapi.auth2.getauthinstance();
auth2.signout().then(function () {
console.log('user signed out.');
});
}
$('li').on("click", function(event){
var target = event.target,
index = $(target).index();
console.log(target, index);
document.getelementbyid("debug1").innerhtml = target + "<br />" + index;
});
*/