Commit ef05423f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Finish select2-ajax for users. Added Select2Helper for tests

parent 10f14136
......@@ -19,7 +19,7 @@ $ ->
multiple: $('.ajax-users-select').hasClass('multiselect')
minimumInputLength: 0
ajax: # instead of writing the function to execute the request we use Select2's convenient helper
url: "/api/v3/users.json"
url: "/api/" + gon.api_version + "/users.json"
dataType: "json"
data: (term, page) ->
search: term # search term
......@@ -33,11 +33,11 @@ $ ->
initSelection: (element, callback) ->
id = $(element).val()
if id isnt ""
$.ajax("http://api.rottentomatoes.com/api/public/v1.0/users/" + id + ".json",
$.ajax(
"/api/" + gon.api_version + "/users/" + id + ".json",
dataType: "json"
data:
apikey: "ju6z9mjyajq2djue3gbvv26t"
dataType: "jsonp"
private_token: gon.api_token
).done (data) ->
callback data
......
......@@ -15,7 +15,7 @@
@import "gitlab_bootstrap.scss";
@import "common.scss";
@import "ref_select.scss";
@import "selects.scss";
@import "sections/header.scss";
@import "sections/nav.scss";
......
......@@ -555,17 +555,3 @@ img.emoji {
display: none;
}
.ajax-users-select {
width: 400px;
}
.user-result {
.user-image {
float: left;
}
.user-name {
}
.user-username {
color: #999;
}
}
.ajax-users-select {
width: 400px;
}
.user-result {
.user-image {
float: left;
}
.user-name {
}
.user-username {
color: #999;
}
}
.select2-no-results {
padding: 7px;
color: #666;
}
/** Branch/tag selector **/
.project-refs-form {
margin: 0;
......
......@@ -152,9 +152,8 @@ class ApplicationController < ActionController::Base
def add_gon_variables
gon.default_issues_tracker = Project.issues_tracker.default_value
if current_user
gon.api_token = current_user.private_token
gon.gravatar_url = request.ssl? ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url
end
gon.api_version = Gitlab::API.version
gon.api_token = current_user.private_token if current_user
gon.gravatar_url = request.ssl? ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url
end
end
......@@ -11,6 +11,7 @@ Feature: Project Team management
Then I should be able to see myself in team
And I should see "Sam" in team list
@javascript
Scenario: Add user to project
Given I click link "New Team Member"
And I select "Mike" as "Reporter"
......
......@@ -2,6 +2,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
include Select2Helper
Then 'I should be able to see myself in team' do
page.should have_content(@user.name)
......@@ -20,8 +21,9 @@ class ProjectTeamManagement < Spinach::FeatureSteps
And 'I select "Mike" as "Reporter"' do
user = User.find_by_name("Mike")
select2(user.id, from: "#user_ids", multiple: true)
within "#new_team_member" do
select "#{user.name} (#{user.username})", :from => "user_ids"
select "Reporter", :from => "project_access"
end
click_button "Add users"
......
This diff is collapsed.
......@@ -14,7 +14,7 @@ require 'spinach/capybara'
require 'sidekiq/testing/inline'
%w(stubbed_repository valid_commit).each do |f|
%w(stubbed_repository valid_commit select2_helper).each do |f|
require Rails.root.join('spec', 'support', f)
end
......
......@@ -46,6 +46,7 @@ Feature: UserTeams
When I visit team merge requests page
Then I should see merge requests from this team assigned to me
@javascript
Scenario: I should add user to projects in Team
Given I have team with projects and members
Given I have new user "John"
......
# Select2 ajax programatic helper
# It allows you to select value from select2
#
# Params
# value - real value of selected item
# opts - options containing css selector
#
# Usage:
#
# select2(2, from: '#user_ids')
#
module Select2Helper
def select2(value, options={})
raise "Must pass a hash containing 'from'" if not options.is_a?(Hash) or not options.has_key?(:from)
selector = options[:from]
if options[:multiple]
page.execute_script("$('#{selector}').select2('val', ['#{value}']);")
else
page.execute_script("$('#{selector}').select2('val', '#{value}');")
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment