From a4397d394e15d2c18fce19ecd9f972fd6d864368 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Wed, 10 Jun 2015 20:05:51 -0300 Subject: [PATCH] Refatored Repository form JS fetch_branches into JS Branch class --- app/assets/javascripts/repository/branch.js.coffee | 30 ++++++++++++++++++++++++++++-- app/views/repositories/_form.html.erb | 43 ++++++------------------------------------- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/app/assets/javascripts/repository/branch.js.coffee b/app/assets/javascripts/repository/branch.js.coffee index 5da9fdd..08ec645 100644 --- a/app/assets/javascripts/repository/branch.js.coffee +++ b/app/assets/javascripts/repository/branch.js.coffee @@ -3,14 +3,14 @@ class Repository.Branch @names = {} @request = null - @toggle: -> + toggle: -> scm_type_field = document.getElementById("repository_scm_type") index = scm_type_field.selectedIndex option = scm_type_field.options[index] if option.value != "SVN" $("#branches").show() - fetch_branches (document.getElementById("repository_address")) + @fetch_branches(document.getElementById("repository_address")) else $("#branches").hide() @@ -27,3 +27,29 @@ class Repository.Branch el.append($("") .attr("value", option) .text(option)) + + fetch_branches: (address_field) -> + @cancel_request() + address = address_field.value + + # Prevent a call with blank address + if address == "" + return + + el = $("#repository_branch") + el.empty() # remove old options + + if @names[address]? + @fill_options(@names[address], el) + return + + scm_type = $("#repository_scm_type option:selected").text() + + context = this + @request = $.get '/repository_branches', + {'url': address, 'scm_type': scm_type}, + (data) -> + options = data["branches"] + if options != null + context.names[address] = options + context.fill_options(options, el) diff --git a/app/views/repositories/_form.html.erb b/app/views/repositories/_form.html.erb index 78bbbae..50816ab 100644 --- a/app/views/repositories/_form.html.erb +++ b/app/views/repositories/_form.html.erb @@ -43,7 +43,7 @@
<%= f.label :scm_type, class: 'control-label' %> - <%= f.select( :scm_type, @repository_types, {}, class: 'tooltip-control', onchange: "Repository.Branch.toggle();" ) %> + <%= f.select( :scm_type, @repository_types, {}, class: 'tooltip-control', onchange: "_repository_branch.toggle();" ) %>

@@ -55,7 +55,7 @@

<%= f.label :address, class: 'control-label' %> - <%= f.text_field :address, :required => true, class: 'text-field form-control', onchange: "fetch_branches(this);" %> + <%= f.text_field :address, :required => true, class: 'text-field form-control', onchange: "_repository_branch.fetch_branches(this);" %>

@@ -109,41 +109,10 @@ <%= link_to t('back'), project_path(@project_id), class: 'btn btn-default' %>

- - - -- libgit2 0.21.2