diff --git a/app/assets/javascripts/sitewide/string_utils.js b/app/assets/javascripts/sitewide/string_utils.js index b1489bdc2..3f47285ef 100644 --- a/app/assets/javascripts/sitewide/string_utils.js +++ b/app/assets/javascripts/sitewide/string_utils.js @@ -28,12 +28,12 @@ function truncateLongString( el, chars ) { /* * Usefull for converting locals messages to error format - * (i.e. lower cased capital and no dot at the end). + * (i.e. no dot at the end). */ String.prototype.strToErrorFormat = function() { var length = this.length; if (this[length - 1] === ".") { length -= 1; } - return this.charAt(0).toLowerCase() + this.slice(1, length); + return this.slice(0, length); } diff --git a/app/assets/javascripts/users/settings/organizations/add_user_modal.js b/app/assets/javascripts/users/settings/organizations/add_user_modal.js index b432829b1..dcdfbab68 100644 --- a/app/assets/javascripts/users/settings/organizations/add_user_modal.js +++ b/app/assets/javascripts/users/settings/organizations/add_user_modal.js @@ -119,6 +119,9 @@ modal disableInviteBtn(); }) .on("ajax:error", inviteExistingForm.selector, function(ev, data, status) { + //Clear previous info + inviteExistingResults.html(""); + // Display form errors inviteExistingForm.renderFormErrors("", data.responseJSON); }); diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 543fd5a21..e1200965f 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -12,7 +12,8 @@ class OrganizationsController < ApplicationController begin if params[:file].size > FILE_MAX_SIZE.megabytes - error = t("organizations.parse_sheet.errors.file_size_exceeded") + error = t 'general.file.size_exceeded', file_size: FILE_MAX_SIZE + format.html { flash[:alert] = error redirect_to session.delete(:return_to) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 6215888a3..1ba1ce95a 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -2,8 +2,6 @@ class SearchController < ApplicationController before_filter :load_vars, only: :index before_filter :load_markdown, only: :index - MIN_QUERY_CHARS = 2 - def index if not @search_query redirect_to new_search_path @@ -50,21 +48,27 @@ class SearchController < ApplicationController @search_page = params[:page].to_i || 1 @display_query = @search_query - if @search_query.length < MIN_QUERY_CHARS - flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS + if @search_query.length < NAME_MIN_LENGTH + flash[:error] = t 'general.query.length_too_short', + min_length: NAME_MIN_LENGTH return redirect_to :back end # splits the search query to validate all entries @splited_query = @search_query.split - if @splited_query.first.length < MIN_QUERY_CHARS - flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS + if @splited_query.first.length < NAME_MIN_LENGTH + flash[:error] = t 'general.query.length_too_short', + min_length: NAME_MIN_LENGTH + redirect_to :back + elsif @splited_query.first.length > TEXT_MAX_LENGTH + flash[:error] = t 'general.query.length_too_long', + max_length: TEXT_MAX_LENGTH redirect_to :back elsif @splited_query.length > 1 @search_query = '' @splited_query.each_with_index do |w, i| - @search_query += "#{@splited_query[i]} " if w.length >= MIN_QUERY_CHARS + @search_query += "#{@splited_query[i]} " if w.length >= NAME_MIN_LENGTH end else @search_query = @splited_query.join(' ') diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index c1cc604f7..50596bb53 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -120,19 +120,27 @@ class Users::SettingsController < ApplicationController respond_to do |format| format.json { if params.include? :existing_query and - (query = params[:existing_query].strip()).present? - if query.length < 3 + query = params[:existing_query].strip() + if query.length < NAME_MIN_LENGTH render json: { "existing_query": [ - I18n.t("users.settings.organizations.edit.modal_add_user.existing_query_too_short") - ]}, - status: :unprocessable_entity + t('general.query.length_too_short', min_length: NAME_MIN_LENGTH) + ] + }, + status: :unprocessable_entity + elsif query.length > NAME_MAX_LENGTH + render json: { + "existing_query": [ + t('general.query.length_too_long', max_length: NAME_MAX_LENGTH) + ] + }, + status: :unprocessable_entity else # Okay, query exists and is non-blank, find users nr_of_results = User.search(true, query, @org).count - users = User.search(false, query, @org).limit(5) + users = User.search(false, query, @org).limit(EXISTING_USERS_SEARCH_LIMIT) nr_of_members = User.organization_search(false, query, @org).count @@ -150,11 +158,7 @@ class Users::SettingsController < ApplicationController } end else - render json: { - "existing_query": [ - I18n.t("users.settings.organizations.edit.modal_add_user.existing_query_blank") - ]}, - status: :unprocessable_entity + render json: {}, status: :bad_request end } end diff --git a/app/views/search/new.html.erb b/app/views/search/new.html.erb index 7172eb574..65ee6e162 100644 --- a/app/views/search/new.html.erb +++ b/app/views/search/new.html.erb @@ -1,11 +1,17 @@ <% provide(:head_title, t("search.index.head_title")) %> - +<%= form_tag search_path, method: :get, id: 'search-bar', class: 'navbar-form navbar-left', role: 'search' do %>
- <%= text_field_tag :q, '', class: 'form-control', size: 25, maxlength: 50, pattern: '.{0,50}', required: '', title: t('search.index.error.max_length', n: 50) %> +
+ + + + +
- <%= button_tag 'Search', name: '', class: 'btn btn-default' %> <% end %> ---> diff --git a/app/views/shared/_navigation.html.erb b/app/views/shared/_navigation.html.erb index 519d91220..a3d29f26d 100644 --- a/app/views/shared/_navigation.html.erb +++ b/app/views/shared/_navigation.html.erb @@ -107,7 +107,7 @@ <%= form_tag search_path, method: :get, id: 'search-bar', class: 'navbar-form navbar-right', role: 'search' do %>
- +