From 6bca7f6bb7caa752f8ba37a46a5992f78c8f545e Mon Sep 17 00:00:00 2001 From: Sungmin kim Date: Wed, 24 Apr 2013 15:57:13 +0900 Subject: [PATCH] [title] Set cookie about infomation of user action (login ID, selected Distribution ID) --- dibs-web/public/index.html | 18 ++++++++++---- dibs-web/public/javascripts/build.js | 19 ++++++++++++++- dibs-web/public/javascripts/main.js | 26 +++++++++++++++++++- dibs-web/public/javascripts/projects.js | 18 +++++++++++++- dibs-web/public/javascripts/session.js | 32 ++++++++++++++++++++++++- 5 files changed, 105 insertions(+), 8 deletions(-) diff --git a/dibs-web/public/index.html b/dibs-web/public/index.html index 447d53e..18bf04b 100644 --- a/dibs-web/public/index.html +++ b/dibs-web/public/index.html @@ -100,11 +100,21 @@ Contributors:
- - - + + + + + + + + + + + + +
-
+
Cancel Log in
diff --git a/dibs-web/public/javascripts/build.js b/dibs-web/public/javascripts/build.js index a71ce34..e491e5a 100644 --- a/dibs-web/public/javascripts/build.js +++ b/dibs-web/public/javascripts/build.js @@ -37,7 +37,8 @@ function buildInit() { }); /* default distribution selection */ - $("#build-distribution-select option:eq(0)").attr("selected", "selected"); + defualt_dist_id = buildGetCookieDistribution(); + $("#build-distribution-select").val(defualt_dist_id); $("#build-distribution-select").selectmenu('refresh'); // query Project list @@ -58,6 +59,8 @@ function buildInit() { function buildQueryProjectList() { var distId = $("#build-distribution-select option:selected").val(); + buildSetCookieDistribution(distId); + queryProjectsInDistribution( distId, function(xml) { $("#build-git-table").empty(); $("#build-binary-table").empty(); @@ -327,3 +330,17 @@ function buildClear() { $("#build-git-table").empty(); $("#build-binary-table").empty(); } + +function buildSetCookieDistribution(id) +{ + saveCookie("build_distribution", id, 7); +} + +function buildGetCookieDistribution() +{ + id = getCookie("build_distribution"); + if(id == "") { + id = 0; + } + return id; +} diff --git a/dibs-web/public/javascripts/main.js b/dibs-web/public/javascripts/main.js index 828c968..b5d997d 100644 --- a/dibs-web/public/javascripts/main.js +++ b/dibs-web/public/javascripts/main.js @@ -69,7 +69,8 @@ $( document ).bind( "pagechange", function( event, data ){ clearFormData('signup-form'); break; case "login": - clearFormData('login-form'); + clearLoginData(); + getUserId(); break; case "projects": generateNavigationBar(id); @@ -320,3 +321,26 @@ function dibsWebClear(){ buildClear(); jobsClear(); } + +function getCookie(key) +{ + var cook = document.cookie + ";"; + var idx = cook.indexOf(key, 0); + var val = ""; + + if (idx != -1) { + cook = cook.substring(idx, cook.length); + begin = cook.indexOf("=", 0) + 1; + end = cook.indexOf(";", begin); + val = unescape(cook.substring(begin, end)); + } + + return val; +} + +function saveCookie(key, value, expire_days) +{ + var today = new Date(); + today.setDate(today.getDate() + expire_days); + document.cookie = key + "=" + escape(value) + "; path=/; expires=" + today.toGMTString() + ";"; +} diff --git a/dibs-web/public/javascripts/projects.js b/dibs-web/public/javascripts/projects.js index 74d56b9..1aa86c6 100644 --- a/dibs-web/public/javascripts/projects.js +++ b/dibs-web/public/javascripts/projects.js @@ -37,7 +37,8 @@ function projectsInit() { }); /* default distribution selection */ - $("#projects-distribution-select option:eq(0)").attr("selected", "selected"); + defualt_dist_id = projectsGetCookieDistribution(); + $("#projects-distribution-select").val(defualt_dist_id); $("#projects-distribution-select").selectmenu('refresh'); $('#projects-type-select input[type="radio"]').attr("checked",false).checkboxradio("refresh"); @@ -52,6 +53,8 @@ function projectsInit() { function projectsQueryProjectListType() { var dist_id = $("#projects-distribution-select option:selected").val(); + projectsSetCookieDistribution(dist_id); + queryProjectsInfoInDistribution( dist_id, function(xml) { $("#projects-project-list").empty(); @@ -164,3 +167,16 @@ function projectsClear() { $("#projects-project-list").empty(); } +function projectsSetCookieDistribution(id) +{ + saveCookie("projects_distribution", id, 7); +} + +function projectsGetCookieDistribution() +{ + id = getCookie("projects_distribution"); + if(id == "") { + id = 0; + } + return id; +} diff --git a/dibs-web/public/javascripts/session.js b/dibs-web/public/javascripts/session.js index 89c1e2b..244107f 100644 --- a/dibs-web/public/javascripts/session.js +++ b/dibs-web/public/javascripts/session.js @@ -119,11 +119,41 @@ function sessionLogin() { sessionStorage.sessionInfoName = name; sessionStorage.sessionInfoGroup = group; sessionStorage.sessionInfoAdmin = admin; + + saveUserId(email); + $.mobile.changePage("#index"); } else { alert(message); - } + } }); } + +function clearLoginData() +{ + $("#login-form-email").val(""); + $("#login-form-password").val(""); +} +function getUserId() +{ + id = getCookie("user_email"); + if(id != "") { + $("#login-form-email").val(id); + } +} + +function saveUserId(id) +{ + if($("#login-form-save").attr("checked") == "checked") { + if (id != "") { + saveCookie("user_email", id, 7); + } else { + saveCookie("user_email", id, -1); + } + } + else { + saveCookie("user_email", id, -1); + } +} -- 2.34.1