From 19f72024f70c6700d561bd0be4218ae1d97b99b5 Mon Sep 17 00:00:00 2001
From: Rajko Albrecht <rajko.albrecht@7p-group.com>
Date: Mon, 17 Feb 2014 09:03:21 +0100
Subject: [PATCH 07/10] * display creation button below form * better logic for
 hiding the add repository button * added title for tooltip overlay to buttons

---
 app/views/repositories/_form.html.erb | 21 ++++++++++++++++-----
 lib/scm_repositories_helper_patch.rb  |  8 ++++++++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/app/views/repositories/_form.html.erb b/app/views/repositories/_form.html.erb
index e5f0ac8..13aadb3 100644
--- a/app/views/repositories/_form.html.erb
+++ b/app/views/repositories/_form.html.erb
@@ -18,14 +18,25 @@
 
 <% button_disabled = true %>
 <% if @repository %>
-<%   button_disabled = ! @repository.class.scm_available || ( !ScmConfig['allow_add_local'] && @repository.new_record?) %>
-<%=    repository_field_tags(f, @repository)%>
+    <%=    repository_field_tags(f, @repository)%>
+    <% button_enabled = @repository.class.scm_available && ((ScmConfig['allow_add_local'] && @repository.new_record?) || !@create_enabled || ! @repository.new_record?) %>
+    <% button_disabled = ! button_enabled %>
+    <% create_button_enabled = @create_enabled && @repository.new_record? && @repository.class.scm_available %>
 <% end %>
 </div>
 
+
 <p>
-  <% unless button_disabled %>
-    <%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save), :id => 'repository_save', :disabled => button_disabled) %>
-  <% end %>
+<% unless button_disabled %>
+    <%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save), :id => 'repository_save', :disabled => button_disabled, 
+                   :title => @repository.new_record? ? "Add existing repository" : "Save Settings" ) %>
+<% end %>
+<% if create_button_enabled %>
+    <% if defined? observe_field %>
+        <%= submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';", :title => "Create and add new repository") %>
+    <% else %>
+        <%= submit_tag(l(:button_create_new_repository), :onclick => "$('#repository_operation').val('add');", :title => "Create and add new repository" ) %>
+    <%end%>
+<% end %>
   <%= link_to l(:button_cancel), settings_project_path(@project, :tab => 'repositories') %>
 </p>
diff --git a/lib/scm_repositories_helper_patch.rb b/lib/scm_repositories_helper_patch.rb
index 1e4f10d..35e3ffa 100644
--- a/lib/scm_repositories_helper_patch.rb
+++ b/lib/scm_repositories_helper_patch.rb
@@ -68,6 +68,8 @@ module ScmRepositoriesHelperPatch
             svntags = subversion_field_tags_reduced(form,repository)
             svntags.gsub!('&lt;br /&gt;', '<br />')
 
+            @create_enabled = SubversionCreator.enabled?
+
             if @project.respond_to?(:repositories) &&
                 ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && @project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i
                 return svntags
@@ -111,6 +113,8 @@ module ScmRepositoriesHelperPatch
         def mercurial_field_tags_with_add(form, repository)
             hgtags = mercurial_field_tags_without_add(form, repository)
 
+            @create_enabled = MercurialCreator.enabled?
+
             if @project.respond_to?(:repositories) &&
                 ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && @project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i
                 return hgtags
@@ -156,6 +160,8 @@ module ScmRepositoriesHelperPatch
         def bazaar_field_tags_with_add(form, repository)
             bzrtags = bazaar_field_tags_without_add(form, repository)
 
+            @create_enabled = BazaarCreator.enabled?
+
             if @project.respond_to?(:repositories) &&
                 ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && @project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i
                 return bzrtags
@@ -207,6 +213,8 @@ module ScmRepositoriesHelperPatch
                 return gittags
             end
 
+            @create_enabled = GitCreator.enabled?
+
             if repository.new_record? && GitCreator.enabled?
                 if defined? observe_field # Rails 3.0 and below
                     add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';")
-- 
1.9.2

