From 2ea24f42fcc3b7ab15b04c8d5646d725d2c07733 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Thu, 7 May 2015 15:50:55 +0300 Subject: [PATCH] Registrar: domain form autocompletes registrar and contact code --- Gemfile | 1 + Gemfile.lock | 3 +++ app/assets/javascripts/registrar-manifest.coffee | 3 +++ app/assets/javascripts/shared/general.coffee | 5 +++++ app/assets/stylesheets/registrar-manifest.sass | 2 ++ app/controllers/registrar/domains_controller.rb | 6 ++++++ app/views/registrar/domains/form_partials/_contacts.haml | 8 ++++++-- app/views/registrar/domains/form_partials/_general.haml | 5 +++-- 8 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 6ec04a0eb..1cc434a7b 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,7 @@ gem 'kaminari', '~> 0.16.3' # pagination gem 'nprogress-rails', '~> 0.1.6.5' # visual loader gem 'html5_validators', '~> 1.1.3' # model requements now automatically on html form gem 'coderay', '~> 1.1.0' # xml console visualize +gem 'select2-rails', '~> 3.5.9.3' # for autocomplete # rights gem 'devise', '~> 3.4.1' # authenitcation diff --git a/Gemfile.lock b/Gemfile.lock index 8511fafc0..317012473 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -410,6 +410,8 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + select2-rails (3.5.9.3) + thor (~> 0.14) selectize-rails (0.11.2) sexp_processor (4.5.0) shoulda-matchers (2.6.2) @@ -548,6 +550,7 @@ DEPENDENCIES rubycritic (~> 1.1.1) sass-rails (~> 5.0.1) sdoc (~> 0.4.0) + select2-rails (~> 3.5.9.3) selectize-rails (~> 0.11.2) shoulda-matchers (~> 2.6.1) simplecov (~> 0.9.1) diff --git a/app/assets/javascripts/registrar-manifest.coffee b/app/assets/javascripts/registrar-manifest.coffee index c0596f09d..50d127bc5 100644 --- a/app/assets/javascripts/registrar-manifest.coffee +++ b/app/assets/javascripts/registrar-manifest.coffee @@ -7,5 +7,8 @@ #= require jquery.nested_attributes #= require shared/jquery.validate.bootstrap #= require jquery-ui/datepicker +#= require select2 + #= require shared/general + #= require registrar/application diff --git a/app/assets/javascripts/shared/general.coffee b/app/assets/javascripts/shared/general.coffee index 9d4ae3390..baa2282da 100644 --- a/app/assets/javascripts/shared/general.coffee +++ b/app/assets/javascripts/shared/general.coffee @@ -19,3 +19,8 @@ $(document).on 'ready page:load', -> dateFormat: "yy-mm-dd", maxDate: tomorrow ); + + $('.js-combobox').select2 + width: "100%" + selectOnBlur: true + dropdownAutoWidth: if self==top then true else false diff --git a/app/assets/stylesheets/registrar-manifest.sass b/app/assets/stylesheets/registrar-manifest.sass index 23c1641a0..8de8ff95a 100644 --- a/app/assets/stylesheets/registrar-manifest.sass +++ b/app/assets/stylesheets/registrar-manifest.sass @@ -1,6 +1,8 @@ //= require 'shared/general-manifest' //= require 'registrar/registrar-bootstrap' //= require 'jquery-ui/datepicker' +//= require 'select2' +//= require 'select2-bootstrap' @import shared/fonts @import shared/general @import nprogress diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index 5a62c5ad5..815856086 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -1,5 +1,6 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller before_action :init_domain, except: :new + before_action :init_contacts_autocomplete_map, only: [:new, :edit, :create, :update] def index authorize! :view, Depp::Domain @@ -116,4 +117,9 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller def init_domain @domain = Depp::Domain.new(current_user: depp_current_user) end + + def init_contacts_autocomplete_map + @contacts_autocomplete_map ||= + current_user.registrar.contacts.pluck(:name, :code).map {|c| ["#{c.second} #{c.first}", c.second]} + end end diff --git a/app/views/registrar/domains/form_partials/_contacts.haml b/app/views/registrar/domains/form_partials/_contacts.haml index 7f0ce0250..38cc47564 100644 --- a/app/views/registrar/domains/form_partials/_contacts.haml +++ b/app/views/registrar/domains/form_partials/_contacts.haml @@ -17,11 +17,15 @@ .col-md-3.control-label = label_tag "domain_contacts_attributes_#{k}_code", t(:contact_code), class: 'required' .col-md-7.has-feedback - = text_field_tag("domain[contacts_attributes][#{k}][code]", v['code'], - class: 'form-control', placeholder: t(:contact_code), autocomplete: 'off', required: true) + = select_tag "domain[contacts_attributes][#{k}][code]", + options_for_select(@contacts_autocomplete_map, selected: v['code']), + include_blank: true, class: 'js-combobox', required: true + :coffee $("#domain-contacts").nestedAttributes bindAddTo: $(".add-domain-contact") afterAdd: (item) -> item.find('select').each (k, v) -> $(v).val($(v).find('option:first-child').val()) + + diff --git a/app/views/registrar/domains/form_partials/_general.haml b/app/views/registrar/domains/form_partials/_general.haml index ac342f79f..bde4ff67f 100644 --- a/app/views/registrar/domains/form_partials/_general.haml +++ b/app/views/registrar/domains/form_partials/_general.haml @@ -20,5 +20,6 @@ .col-md-3.control-label = label_tag :domain_registrant, t(:registrant), class: 'required' .col-md-7 - = text_field_tag('domain[registrant]', @domain_params[:registrant], - class: 'form-control', placeholder: t(:contact_code), autocomplete: 'off', required: true) + = select_tag "domain[registrant]", + options_for_select(@contacts_autocomplete_map, selected: @domain_params[:registrant]), + include_blank: true, class: 'js-combobox', required: true