The Unified and Autonomous Development Platform
Implemented "remember my choice" with cookies
Andrea Del Bene45f9f0117d23
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/info/project-info.js b/server-core/src/main/java/io/onedev/server/web/page/project/info/project-info.jsindex 68ff5220ea..422d849739 100644--- a/server-core/src/main/java/io/onedev/server/web/page/project/info/project-info.js+++ b/server-core/src/main/java/io/onedev/server/web/page/project/info/project-info.js@@ -1,18 +1,34 @@onedev.server.projectInfo = {+ selectedProtocol: '',+ cookieKey: 'onedev.server.projectInfo.selectedProtocol',onDomReady: function(switchId) {- var alternativeProtocol = 'SSH';+ //by default we start with HTTPS protocol+ this.selectedProtocol = 'HTTPS';+ var savedProtocol = Cookies.get(this.cookieKey) || 'HTTPS';+ if (savedProtocol === 'SSH') {+ this.switchCloneURL(switchId);+ }++ //handle the 'switch protocol' click+ const projectInfo = this;$("#" + switchId).click(function() {- $(".clone").toggleClass('hidden');- $("#noKeyWarning").toggleClass('hidden');-- if (alternativeProtocol === 'HTTPS') {- alternativeProtocol = 'SSH';- } else {- alternativeProtocol = 'HTTPS';- }-- $(this).text('Use ' + alternativeProtocol);+ projectInfo.switchCloneURL(switchId);});+ },+ switchCloneURL : function(switchId) {+ $(".clone").toggleClass('hidden');+ $("#noKeyWarning").toggleClass('hidden');++ var oldProtocol = this.selectedProtocol;++ if (this.selectedProtocol === 'HTTPS') {+ this.selectedProtocol = 'SSH';+ } else {+ this.selectedProtocol = 'HTTPS';+ }++ Cookies.set(this.cookieKey, this.selectedProtocol);+ $("#" + switchId).text('Use ' + oldProtocol);}};\ No newline at end of file