nitdoc: Fix bug when signing in
[nit.git] / share / nitdoc / scripts / js-facilities.js
index 315f7d6..180aab2 100644 (file)
@@ -19,6 +19,7 @@ var shaMaster;
 var repoExist = false;\r
 var branchExist = false;\r
 var githubRepo;\r
+var loginProcess = false; \r
 \r
 // Spinner vars\r
 var opts = {\r
@@ -76,7 +77,6 @@ $(document).ready(function() {
        $('a[id=cancelBtn]').hide();\r
        // Hide Authenfication form\r
        $(".popover").hide();\r
-       githubRepo = $('#repoName').attr('name');\r
        // Update display\r
        updateDisplaying();\r
        /*\r
@@ -427,13 +427,22 @@ $(document).ready(function() {
                        {\r
                                userName = $('#loginGit').val();\r
                                password = $('#passwordGit').val();\r
-                               repoName = $('#repositoryGit').val();\r
+                               githubRepo = $('#repositoryGit').val();\r
                                branchName = $('#branchGit').val();\r
                                userB64 = "Basic " +  base64.encode(userName+':'+password);\r
-                               setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+repoName+':'+branchName), 1);\r
-                               $('#loginGit').val("");\r
-                               $('#passwordGit').val("");\r
-                               reloadComment();\r
+                               // Check if repo exist\r
+                               isRepoExisting();\r
+                               if(repoExist){            \r
+                                       $.when(isBranchExisting()).done(function(){  \r
+                                               loginProcess = true;            \r
+                                               if(branchExist){\r
+                                                       setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+githubRepo+':'+branchName), 1);        \r
+                                                       $('#loginGit').val("");\r
+                                                       $('#passwordGit').val("");\r
+                                                       reloadComment();\r
+                                               }\r
+                                       });\r
+                               } \r
                        }\r
                }       \r
                else\r
@@ -530,9 +539,8 @@ $(document).ready(function() {
                        displayMessage("You need to be loggued before commit something", 100, 40);\r
                        $('.popover').show();\r
                        return;\r
-               }               \r
+               }\r
                else{ userB64 = "Basic " + getUserPass("logginNitdoc"); }\r
-               githubRepo = repoName;\r
                // Check if repo exist\r
                isRepoExisting();\r
                if(repoExist){\r
@@ -579,9 +587,18 @@ $(document).ready(function() {
                        createBranch();\r
                        commitMessage = $('#commitMessage').val();\r
                        if(commitMessage == ""){ commitMessage = "New commit"; }\r
-                       if(userB64 != ""){      \r
-                               if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); }\r
-                       else{ startCommitProcess(); }\r
+                       if(userB64 != ""){                      \r
+                       if(loginProcess){\r
+                                       setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+githubRepo+':'+branchName), 1);        \r
+                                       $('#loginGit').val("");\r
+                                       $('#passwordGit').val("");\r
+                                       loginProcess = false;          \r
+                                       displayLogginModal();\r
+                       }\r
+                       else{\r
+                                       if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); }\r
+                                       else{ startCommitProcess(); }\r
+                               } \r
                    }\r
                }\r
                else\r
@@ -614,7 +631,7 @@ $(document).ready(function() {
                                branchName = $(this).text();\r
                        }\r
                });\r
-               $.when(updateCookie(userName, password, repoName, branchName)).done(function(){\r
+               $.when(updateCookie(userName, password, githubRepo, branchName)).done(function(){\r
                        closeAllCommentInEdtiting();\r
                        reloadComment();\r
                });\r
@@ -799,7 +816,7 @@ function checkCookie()
                cookie = base64.decode(cookie);\r
                userName = cookie.split(':')[0];\r
                password = cookie.split(':')[1];\r
-               repoName = cookie.split(':')[2];                \r
+               githubRepo = cookie.split(':')[2];              \r
                branchName = cookie.split(':')[3];\r
                return true;\r
        }\r
@@ -1108,18 +1125,18 @@ function getCommentLastCommit(path){
        var urlRaw;\r
        getLastCommit();\r
        if(shaLastCommit != ""){\r
-               if (checkCookie()) { urlRaw="https://rawgithub.com/"+ userName +"/"+ repoName +"/" + shaLastCommit + "/" + path; }\r
-               else{ urlRaw="https://rawgithub.com/StefanLage/"+ $('#repoName').attr('name') +"/" + shaLastCommit + "/" + path; }\r
-\r
-               $.ajax({  \r
-               type: "GET",                \r
-               url: urlRaw,        \r
-               async: false,\r
-               success: function(success)\r
-               {\r
-                       currentfileContent = success;   \r
-               }\r
-           });\r
+               if (checkCookie()) {\r
+                       urlRaw="https://rawgithub.com/"+ userName +"/"+ githubRepo +"/" + shaLastCommit + "/" + path;\r
+                       $.ajax({  \r
+                           type: "GET",\r
+                           url: urlRaw,\r
+                           async: false,\r
+                           success: function(success)\r
+                           {\r
+                             currentfileContent = success;\r
+                           }\r
+                       });\r
+               }\r
        }\r
 }\r
 \r