From: Alexis Laferrière Date: Sun, 18 Oct 2015 14:31:03 +0000 (-0400) Subject: contrib/opportunity: store local participant's name in a cookie X-Git-Tag: v0.7.9~26^2 X-Git-Url: http://nitlanguage.org contrib/opportunity: store local participant's name in a cookie Signed-off-by: Alexis Laferrière --- diff --git a/contrib/opportunity/src/templates/meetup.nit b/contrib/opportunity/src/templates/meetup.nit index 0358f33..043c86b 100644 --- a/contrib/opportunity/src/templates/meetup.nit +++ b/contrib/opportunity/src/templates/meetup.nit @@ -211,7 +211,11 @@ class OpportunityMeetupPage .fail(function(data){ //TODO: Notify of failure }); + + // Remember the participant's name client-side + set_cookie("opportunity_participant_name", pname); } + function remove_people(ele){ var arr = ele.id.split("_") var pid = arr[1] @@ -226,6 +230,7 @@ class OpportunityMeetupPage } }); } + // ID of line currently open for modification var in_modification_id = null; function modify_people(ele, id){ @@ -248,6 +253,30 @@ class OpportunityMeetupPage in_modification_id = null; } } + + function get_cookie(cookie_name) { + var name = cookie_name + "="; + var ca = document.cookie.split(';'); + for(var i = 0; i < ca.length; i ++) { + var c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1); + if (c.indexOf(name) == 0) return c.substring(name.length, c.length); + } + return ""; + } + + function set_cookie(cookie_name, value) { + var date = new Date(); + date.setTime(date.getTime() + (365*24*60*60*1000)); + var expires = "expires="+date.toUTCString(); + document.cookie = cookie_name + "=" + value + "; " + expires; + } + + // Retrieve the last client-side participant's name + window.onload = function () { + var name_field = document.getElementById("new_name"); + name_field.value = get_cookie("opportunity_participant_name"); + } """ end