From cdef150da09061daf03f87664dc785c52d7d41d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 18 Oct 2015 10:31:03 -0400 Subject: [PATCH] contrib/opportunity: store local participant's name in a cookie MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/opportunity/src/templates/meetup.nit | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 -- 1.7.9.5