From ed8794be62639748c8c6b43abca535f69fa332f0 Mon Sep 17 00:00:00 2001 From: Stefan Lage Date: Thu, 23 May 2013 20:55:52 -0400 Subject: [PATCH] nitdoc: Add a function to check the repo github. Check if the repository, informed by the user when he signed in, is existing, obviously the function is called before the commit signed-off by: Stefan Lage --- share/nitdoc/scripts/js-facilities.js | 55 ++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/share/nitdoc/scripts/js-facilities.js b/share/nitdoc/scripts/js-facilities.js index d2d331a..f310216 100644 --- a/share/nitdoc/scripts/js-facilities.js +++ b/share/nitdoc/scripts/js-facilities.js @@ -11,6 +11,7 @@ var shaNewTree; var shaNewCommit; var shaBlob; var shaMaster; +var repoExist = false; /* * JQuery Case Insensitive :icontains selector @@ -504,21 +505,26 @@ $(document).ready(function() { } else{ userB64 = "Basic " + getUserPass("logginNitdoc"); } githubRepo = repoName; - editComment -= 1; - commitMessage = $('#commitMessage').val(); - if(commitMessage == ""){ commitMessage = "New commit";} - if(sessionStarted){ - if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); } - else{ startCommitProcess(); } - } - $('#modal, #modalQuestion').fadeOut(function() { - $('#login').val(""); - $('#password').val(""); - $('textarea').hide(); - $('textarea').prev().show(); - }); - $('a[id=cancelBtn]').hide(); - $('a[id=commitBtn]').hide(); + // Check if repo exist + isRepoExisting(); + if(repoExist){ + editComment -= 1; + commitMessage = $('#commitMessage').val(); + if(commitMessage == ""){ commitMessage = "New commit";} + if(sessionStarted){ + if ($.trim(updateComment) == ''){ this.value = (this.defaultValue ? this.defaultValue : ''); } + else{ startCommitProcess(); } + } + $('#modal, #modalQuestion').fadeOut(function() { + $('#login').val(""); + $('#password').val(""); + $('textarea').hide(); + $('textarea').prev().show(); + }); + $('a[id=cancelBtn]').hide(); + $('a[id=commitBtn]').hide(); + } + else{ editComment -= 1; } }); }); @@ -1015,3 +1021,22 @@ function displayMessage(msg, widthDiv, margModal){ $('body').append('
'); $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); } + +// Check if the repo already exist +function isRepoExisting(){ + $.ajax({ + beforeSend: function (xhr) { + if (userB64 != "") { xhr.setRequestHeader ("Authorization", userB64); } + }, + type: "GET", + url: "https://api.github.com/repos/"+userName+"/"+githubRepo, + async:false, + dataType:'json', + success: function(){ repoExist = true; }, + error: function() + { + displayMessage('Repo not found !', 35, 45); + repoExist = false; + } + }); +} -- 1.7.9.5