Commit 5604613025a9fa247144b6ae0f12e3649ef04bda
Exists in
master
and in
4 other branches
Merge pull request #1415 from tsigo/chosen_behavior
Reduce the amount of JavaScript written in views
Showing
18 changed files
with
22 additions
and
122 deletions
Show diff stats
app/assets/javascripts/main.js.coffee
@@ -24,6 +24,9 @@ $ -> | @@ -24,6 +24,9 @@ $ -> | ||
24 | # Click a .one_click_select field, select the contents | 24 | # Click a .one_click_select field, select the contents |
25 | $(".one_click_select").live 'click', -> $(this).select() | 25 | $(".one_click_select").live 'click', -> $(this).select() |
26 | 26 | ||
27 | + # Initialize chosen selects | ||
28 | + $('select.chosen').chosen() | ||
29 | + | ||
27 | # Disable form buttons while a form is submitting | 30 | # Disable form buttons while a form is submitting |
28 | $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> | 31 | $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> |
29 | buttons = $('[type="submit"]', this) | 32 | buttons = $('[type="submit"]', this) |
app/views/admin/projects/_form.html.haml
@@ -32,7 +32,7 @@ | @@ -32,7 +32,7 @@ | ||
32 | - unless project.new_record? | 32 | - unless project.new_record? |
33 | .clearfix | 33 | .clearfix |
34 | = f.label :owner_id | 34 | = f.label :owner_id |
35 | - .input= f.select :owner_id, User.all.map { |user| [user.name, user.id] } | 35 | + .input= f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'} |
36 | 36 | ||
37 | - if project.repo_exists? | 37 | - if project.repo_exists? |
38 | .clearfix | 38 | .clearfix |
@@ -69,7 +69,6 @@ | @@ -69,7 +69,6 @@ | ||
69 | 69 | ||
70 | :javascript | 70 | :javascript |
71 | $(function(){ | 71 | $(function(){ |
72 | - $('#project_owner_id').chosen(); | ||
73 | new Projects(); | 72 | new Projects(); |
74 | }) | 73 | }) |
75 | 74 |
app/views/admin/projects/show.html.haml
@@ -71,25 +71,11 @@ | @@ -71,25 +71,11 @@ | ||
71 | %th Project Access: | 71 | %th Project Access: |
72 | 72 | ||
73 | %tr | 73 | %tr |
74 | - %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), multiple: true | ||
75 | - %td= select_tag :project_access, options_for_select(Project.access_options), class: "project-access-select" | 74 | + %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' |
75 | + %td= select_tag :project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3"} | ||
76 | 76 | ||
77 | %tr | 77 | %tr |
78 | %td= submit_tag 'Add', class: "btn primary" | 78 | %td= submit_tag 'Add', class: "btn primary" |
79 | %td | 79 | %td |
80 | Read more about project permissions | 80 | Read more about project permissions |
81 | %strong= link_to "here", help_permissions_path, class: "vlink" | 81 | %strong= link_to "here", help_permissions_path, class: "vlink" |
82 | - | ||
83 | -:css | ||
84 | - form select { | ||
85 | - width:150px; | ||
86 | - } | ||
87 | - | ||
88 | - #user_ids { | ||
89 | - width:300px; | ||
90 | - } | ||
91 | - | ||
92 | -:javascript | ||
93 | - $('select#user_ids').chosen(); | ||
94 | - $('select#repo_access').chosen(); | ||
95 | - $('select#project_access').chosen(); |
app/views/admin/team_members/_form.html.haml
@@ -8,20 +8,9 @@ | @@ -8,20 +8,9 @@ | ||
8 | .clearfix | 8 | .clearfix |
9 | %label Project Access: | 9 | %label Project Access: |
10 | .input | 10 | .input |
11 | - = f.select :project_access, options_for_select(Project.access_options, @admin_team_member.project_access), {}, class: "project-access-select" | 11 | + = f.select :project_access, options_for_select(Project.access_options, @admin_team_member.project_access), {}, class: "project-access-select chosen span3" |
12 | 12 | ||
13 | %br | 13 | %br |
14 | .actions | 14 | .actions |
15 | = f.submit 'Save', class: "btn primary" | 15 | = f.submit 'Save', class: "btn primary" |
16 | = link_to 'Cancel', :back, class: "btn" | 16 | = link_to 'Cancel', :back, class: "btn" |
17 | - | ||
18 | -:css | ||
19 | - form select { | ||
20 | - width:300px; | ||
21 | - } | ||
22 | - | ||
23 | -:javascript | ||
24 | - $('select#team_member_user_id').chosen(); | ||
25 | - $('select#team_member_project_id').chosen(); | ||
26 | - $('select#team_member_repo_access').chosen(); | ||
27 | - $('select#team_member_project_access').chosen(); |
app/views/admin/users/show.html.haml
@@ -68,8 +68,8 @@ | @@ -68,8 +68,8 @@ | ||
68 | %th Project Access: | 68 | %th Project Access: |
69 | 69 | ||
70 | %tr | 70 | %tr |
71 | - %td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name), multiple: true | ||
72 | - %td= select_tag :project_access, options_for_select(Project.access_options), class: "project-access-select" | 71 | + %td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' |
72 | + %td= select_tag :project_access, options_for_select(Project.access_options), class: "project-access-select chosen span3" | ||
73 | 73 | ||
74 | %tr | 74 | %tr |
75 | %td= submit_tag 'Add', class: "btn primary" | 75 | %td= submit_tag 'Add', class: "btn primary" |
@@ -97,17 +97,3 @@ | @@ -97,17 +97,3 @@ | ||
97 | %td= select_tag :tm_project_access, options_for_select(Project.access_options, tm.project_access), class: "medium project-access-select", disabled: :disabled | 97 | %td= select_tag :tm_project_access, options_for_select(Project.access_options, tm.project_access), class: "medium project-access-select", disabled: :disabled |
98 | %td= link_to 'Edit Access', edit_admin_team_member_path(tm), class: "btn small" | 98 | %td= link_to 'Edit Access', edit_admin_team_member_path(tm), class: "btn small" |
99 | %td= link_to 'Remove from team', admin_team_member_path(tm), confirm: 'Are you sure?', method: :delete, class: "btn small danger" | 99 | %td= link_to 'Remove from team', admin_team_member_path(tm), confirm: 'Are you sure?', method: :delete, class: "btn small danger" |
100 | - | ||
101 | -:css | ||
102 | - form select { | ||
103 | - width:150px; | ||
104 | - } | ||
105 | - | ||
106 | - #project_ids { | ||
107 | - width:300px; | ||
108 | - } | ||
109 | - | ||
110 | -:javascript | ||
111 | - $('select#project_ids').chosen(); | ||
112 | - $('select#repo_access').chosen(); | ||
113 | - $('select#project_access').chosen(); |
app/views/commits/_head.html.haml
1 | %ul.nav.nav-tabs | 1 | %ul.nav.nav-tabs |
2 | %li | 2 | %li |
3 | = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do | 3 | = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do |
4 | - = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select" | 4 | + = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select chosen" |
5 | = hidden_field_tag :destination, "commits" | 5 | = hidden_field_tag :destination, "commits" |
6 | 6 | ||
7 | %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"} | 7 | %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"} |
@@ -26,8 +26,3 @@ | @@ -26,8 +26,3 @@ | ||
26 | %span.rss-icon | 26 | %span.rss-icon |
27 | = link_to project_commits_path(@project, :atom, { private_token: current_user.private_token, ref: @ref }), title: "Feed" do | 27 | = link_to project_commits_path(@project, :atom, { private_token: current_user.private_token, ref: @ref }), title: "Feed" do |
28 | = image_tag "rss_ui.png", title: "feed" | 28 | = image_tag "rss_ui.png", title: "feed" |
29 | - | ||
30 | -:javascript | ||
31 | - $(function(){ | ||
32 | - $('.project-refs-select').chosen(); | ||
33 | - }); |
app/views/issues/_form.html.haml
@@ -18,12 +18,12 @@ | @@ -18,12 +18,12 @@ | ||
18 | = f.label :assignee_id do | 18 | = f.label :assignee_id do |
19 | %i.icon-user | 19 | %i.icon-user |
20 | Assign to | 20 | Assign to |
21 | - .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select a user" }) | 21 | + .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select a user" }, {class: 'chosen'}) |
22 | .issue_milestone | 22 | .issue_milestone |
23 | = f.label :milestone_id do | 23 | = f.label :milestone_id do |
24 | %i.icon-time | 24 | %i.icon-time |
25 | Milestone | 25 | Milestone |
26 | - .input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }) | 26 | + .input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'}) |
27 | 27 | ||
28 | .issue_description | 28 | .issue_description |
29 | .clearfix | 29 | .clearfix |
app/views/issues/edit.html.haml
app/views/issues/new.html.haml
app/views/merge_requests/_form.html.haml
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | .padded | 16 | .padded |
17 | = f.label :source_branch, "From", class: "control-label" | 17 | = f.label :source_branch, "From", class: "control-label" |
18 | .controls | 18 | .controls |
19 | - = f.select(:source_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, style: "width:250px") | 19 | + = f.select(:source_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span3'}) |
20 | .mr_source_commit | 20 | .mr_source_commit |
21 | 21 | ||
22 | .span2 | 22 | .span2 |
@@ -28,7 +28,7 @@ | @@ -28,7 +28,7 @@ | ||
28 | .padded | 28 | .padded |
29 | = f.label :target_branch, "To", class: "control-label" | 29 | = f.label :target_branch, "To", class: "control-label" |
30 | .controls | 30 | .controls |
31 | - = f.select(:target_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, style: "width:250px") | 31 | + = f.select(:target_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span3'}) |
32 | .mr_target_commit | 32 | .mr_target_commit |
33 | 33 | ||
34 | %h4.cdark 2. Fill info | 34 | %h4.cdark 2. Fill info |
@@ -43,7 +43,7 @@ | @@ -43,7 +43,7 @@ | ||
43 | = f.label :assignee_id do | 43 | = f.label :assignee_id do |
44 | %i.icon-user | 44 | %i.icon-user |
45 | Assign to | 45 | Assign to |
46 | - .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select user" }, style: "width:250px") | 46 | + .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select user" }, {class: 'chosen span3'}) |
47 | 47 | ||
48 | .control-group | 48 | .control-group |
49 | 49 | ||
@@ -56,18 +56,12 @@ | @@ -56,18 +56,12 @@ | ||
56 | = link_to project_merge_request_path(@project, @merge_request), class: "btn cancel-btn" do | 56 | = link_to project_merge_request_path(@project, @merge_request), class: "btn cancel-btn" do |
57 | Cancel | 57 | Cancel |
58 | 58 | ||
59 | - | ||
60 | - | ||
61 | :javascript | 59 | :javascript |
62 | $(function(){ | 60 | $(function(){ |
63 | disableButtonIfEmptyField("#merge_request_title", ".save-btn"); | 61 | disableButtonIfEmptyField("#merge_request_title", ".save-btn"); |
64 | - $('select#merge_request_assignee_id').chosen(); | ||
65 | - $('select#merge_request_source_branch').chosen(); | ||
66 | - $('select#merge_request_target_branch').chosen(); | ||
67 | var source_branch = $("#merge_request_source_branch"); | 62 | var source_branch = $("#merge_request_source_branch"); |
68 | var target_branch = $("#merge_request_target_branch"); | 63 | var target_branch = $("#merge_request_target_branch"); |
69 | 64 | ||
70 | - | ||
71 | $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: source_branch.val() }); | 65 | $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: source_branch.val() }); |
72 | $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: target_branch.val() }); | 66 | $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: target_branch.val() }); |
73 | 67 | ||
@@ -79,4 +73,3 @@ | @@ -79,4 +73,3 @@ | ||
79 | $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: $(this).val() }); | 73 | $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: $(this).val() }); |
80 | }); | 74 | }); |
81 | }); | 75 | }); |
82 | - |
app/views/milestones/edit.html.haml
app/views/projects/_refs.html.haml
1 | = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do | 1 | = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do |
2 | - = select_tag "ref", grouped_options_refs, onchange: "this.form.submit();", class: "project-refs-select" | 2 | + = select_tag "ref", grouped_options_refs, onchange: "this.form.submit();", class: "project-refs-select chosen" |
3 | = hidden_field_tag :destination, destination | 3 | = hidden_field_tag :destination, destination |
4 | - | ||
5 | -:javascript | ||
6 | - $(function(){ | ||
7 | - $('.project-refs-select').chosen(); | ||
8 | - }) |
app/views/protected_branches/index.html.haml
@@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
19 | .entry.clearfix | 19 | .entry.clearfix |
20 | = f.label :name, "Branch" | 20 | = f.label :name, "Branch" |
21 | .span3 | 21 | .span3 |
22 | - = f.select(:name, @project.open_branches.map { |br| [br.name, br.name] } , { include_blank: "-- Select branch" }, { class: "span3" }) | 22 | + = f.select(:name, @project.open_branches.map { |br| [br.name, br.name] } , {include_blank: "Select branch"}, {class: "chosen span3"}) |
23 | | 23 | |
24 | = f.submit 'Protect', class: "primary btn" | 24 | = f.submit 'Protect', class: "primary btn" |
25 | 25 | ||
@@ -46,6 +46,3 @@ | @@ -46,6 +46,3 @@ | ||
46 | %td | 46 | %td |
47 | - if can? current_user, :admin_project, @project | 47 | - if can? current_user, :admin_project, @project |
48 | = link_to 'Unprotect', [@project, branch], confirm: 'Are you sure?', method: :delete, class: "danger btn small" | 48 | = link_to 'Unprotect', [@project, branch], confirm: 'Are you sure?', method: :delete, class: "danger btn small" |
49 | - | ||
50 | -:javascript | ||
51 | - $('select#protected_branch_name').chosen(); |
app/views/refs/_head.html.haml
1 | %ul.nav.nav-tabs | 1 | %ul.nav.nav-tabs |
2 | %li | 2 | %li |
3 | = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form", remote: true do | 3 | = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form", remote: true do |
4 | - = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select" | 4 | + = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select chosen" |
5 | = hidden_field_tag :destination, "tree" | 5 | = hidden_field_tag :destination, "tree" |
6 | = hidden_field_tag :path, params[:path] | 6 | = hidden_field_tag :path, params[:path] |
7 | %li{class: "#{'active' if (controller.controller_name == "refs") }"} | 7 | %li{class: "#{'active' if (controller.controller_name == "refs") }"} |
app/views/refs/_tree.html.haml
@@ -47,10 +47,7 @@ | @@ -47,10 +47,7 @@ | ||
47 | 47 | ||
48 | :javascript | 48 | :javascript |
49 | $(function(){ | 49 | $(function(){ |
50 | - $('.project-refs-select').chosen(); | ||
51 | - | ||
52 | history.pushState({ path: this.path }, '', "#{@history_path}"); | 50 | history.pushState({ path: this.path }, '', "#{@history_path}"); |
53 | - | ||
54 | }); | 51 | }); |
55 | 52 | ||
56 | // Load last commit log for each file in tree | 53 | // Load last commit log for each file in tree |
app/views/refs/blame.html.haml
app/views/snippets/_form.html.haml
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | .input= f.text_field :file_name, placeholder: "example.rb" | 16 | .input= f.text_field :file_name, placeholder: "example.rb" |
17 | .clearfix | 17 | .clearfix |
18 | = f.label "Lifetime" | 18 | = f.label "Lifetime" |
19 | - .input= f.select :expires_at, lifetime_select_options, {}, style: "width:200px;" | 19 | + .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} |
20 | .clearfix | 20 | .clearfix |
21 | = f.label :content, "Code" | 21 | = f.label :content, "Code" |
22 | .input= f.text_area :content, class: "span8" | 22 | .input= f.text_area :content, class: "span8" |
@@ -26,11 +26,3 @@ | @@ -26,11 +26,3 @@ | ||
26 | = link_to "Cancel", project_snippets_path(@project), class: " btn" | 26 | = link_to "Cancel", project_snippets_path(@project), class: " btn" |
27 | - unless @snippet.new_record? | 27 | - unless @snippet.new_record? |
28 | .right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}" | 28 | .right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}" |
29 | - | ||
30 | - | ||
31 | - | ||
32 | -:javascript | ||
33 | - $(function(){ | ||
34 | - $('select#snippet_expires_at').chosen(); | ||
35 | - }); | ||
36 | - |
app/views/team_members/_form.html.haml
@@ -10,21 +10,14 @@ | @@ -10,21 +10,14 @@ | ||
10 | 10 | ||
11 | %h6 1. Choose people you want in the team | 11 | %h6 1. Choose people you want in the team |
12 | .clearfix | 12 | .clearfix |
13 | - = f.label :user_ids, "Peolpe" | ||
14 | - .input= select_tag(:user_ids, options_from_collection_for_select(User.not_in_project(@project).all, :id, :name), { class: "xxlarge", multiple: true }) | ||
15 | - | 13 | + = f.label :user_ids, "People" |
14 | + .input= select_tag(:user_ids, options_from_collection_for_select(User.not_in_project(@project).all, :id, :name), {data: {placeholder: "Select users"}, class: "chosen xxlarge", multiple: true}) | ||
16 | 15 | ||
17 | %h6 2. Set access level for them | 16 | %h6 2. Set access level for them |
18 | .clearfix | 17 | .clearfix |
19 | = f.label :project_access, "Project Access" | 18 | = f.label :project_access, "Project Access" |
20 | - .input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select" | ||
21 | - | 19 | + .input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" |
22 | 20 | ||
23 | .actions | 21 | .actions |
24 | = f.submit 'Save', class: "btn save-btn" | 22 | = f.submit 'Save', class: "btn save-btn" |
25 | = link_to "Cancel", team_project_path(@project), class: "btn cancel-btn" | 23 | = link_to "Cancel", team_project_path(@project), class: "btn cancel-btn" |
26 | - | ||
27 | - | ||
28 | -:javascript | ||
29 | - $('select#user_ids').chosen(); | ||
30 | - $('select#project_access').chosen(); |