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 | 24 | # Click a .one_click_select field, select the contents |
25 | 25 | $(".one_click_select").live 'click', -> $(this).select() |
26 | 26 | |
27 | + # Initialize chosen selects | |
28 | + $('select.chosen').chosen() | |
29 | + | |
27 | 30 | # Disable form buttons while a form is submitting |
28 | 31 | $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> |
29 | 32 | buttons = $('[type="submit"]', this) | ... | ... |
app/views/admin/projects/_form.html.haml
... | ... | @@ -32,7 +32,7 @@ |
32 | 32 | - unless project.new_record? |
33 | 33 | .clearfix |
34 | 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 | 37 | - if project.repo_exists? |
38 | 38 | .clearfix |
... | ... | @@ -69,7 +69,6 @@ |
69 | 69 | |
70 | 70 | :javascript |
71 | 71 | $(function(){ |
72 | - $('#project_owner_id').chosen(); | |
73 | 72 | new Projects(); |
74 | 73 | }) |
75 | 74 | ... | ... |
app/views/admin/projects/show.html.haml
... | ... | @@ -71,25 +71,11 @@ |
71 | 71 | %th Project Access: |
72 | 72 | |
73 | 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 | 77 | %tr |
78 | 78 | %td= submit_tag 'Add', class: "btn primary" |
79 | 79 | %td |
80 | 80 | Read more about project permissions |
81 | 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 | 8 | .clearfix |
9 | 9 | %label Project Access: |
10 | 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 | 13 | %br |
14 | 14 | .actions |
15 | 15 | = f.submit 'Save', class: "btn primary" |
16 | 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 | 68 | %th Project Access: |
69 | 69 | |
70 | 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 | 74 | %tr |
75 | 75 | %td= submit_tag 'Add', class: "btn primary" |
... | ... | @@ -97,17 +97,3 @@ |
97 | 97 | %td= select_tag :tm_project_access, options_for_select(Project.access_options, tm.project_access), class: "medium project-access-select", disabled: :disabled |
98 | 98 | %td= link_to 'Edit Access', edit_admin_team_member_path(tm), class: "btn small" |
99 | 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 | 1 | %ul.nav.nav-tabs |
2 | 2 | %li |
3 | 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 | 5 | = hidden_field_tag :destination, "commits" |
6 | 6 | |
7 | 7 | %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"} |
... | ... | @@ -26,8 +26,3 @@ |
26 | 26 | %span.rss-icon |
27 | 27 | = link_to project_commits_path(@project, :atom, { private_token: current_user.private_token, ref: @ref }), title: "Feed" do |
28 | 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 | 18 | = f.label :assignee_id do |
19 | 19 | %i.icon-user |
20 | 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 | 22 | .issue_milestone |
23 | 23 | = f.label :milestone_id do |
24 | 24 | %i.icon-time |
25 | 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 | 28 | .issue_description |
29 | 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 | 16 | .padded |
17 | 17 | = f.label :source_branch, "From", class: "control-label" |
18 | 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 | 20 | .mr_source_commit |
21 | 21 | |
22 | 22 | .span2 |
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | .padded |
29 | 29 | = f.label :target_branch, "To", class: "control-label" |
30 | 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 | 32 | .mr_target_commit |
33 | 33 | |
34 | 34 | %h4.cdark 2. Fill info |
... | ... | @@ -43,7 +43,7 @@ |
43 | 43 | = f.label :assignee_id do |
44 | 44 | %i.icon-user |
45 | 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 | 48 | .control-group |
49 | 49 | |
... | ... | @@ -56,18 +56,12 @@ |
56 | 56 | = link_to project_merge_request_path(@project, @merge_request), class: "btn cancel-btn" do |
57 | 57 | Cancel |
58 | 58 | |
59 | - | |
60 | - | |
61 | 59 | :javascript |
62 | 60 | $(function(){ |
63 | 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 | 62 | var source_branch = $("#merge_request_source_branch"); |
68 | 63 | var target_branch = $("#merge_request_target_branch"); |
69 | 64 | |
70 | - | |
71 | 65 | $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: source_branch.val() }); |
72 | 66 | $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: target_branch.val() }); |
73 | 67 | |
... | ... | @@ -79,4 +73,3 @@ |
79 | 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 | 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 | 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 | 19 | .entry.clearfix |
20 | 20 | = f.label :name, "Branch" |
21 | 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 | 24 | = f.submit 'Protect', class: "primary btn" |
25 | 25 | |
... | ... | @@ -46,6 +46,3 @@ |
46 | 46 | %td |
47 | 47 | - if can? current_user, :admin_project, @project |
48 | 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 | 1 | %ul.nav.nav-tabs |
2 | 2 | %li |
3 | 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 | 5 | = hidden_field_tag :destination, "tree" |
6 | 6 | = hidden_field_tag :path, params[:path] |
7 | 7 | %li{class: "#{'active' if (controller.controller_name == "refs") }"} | ... | ... |
app/views/refs/_tree.html.haml
app/views/refs/blame.html.haml
app/views/snippets/_form.html.haml
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | .input= f.text_field :file_name, placeholder: "example.rb" |
17 | 17 | .clearfix |
18 | 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 | 20 | .clearfix |
21 | 21 | = f.label :content, "Code" |
22 | 22 | .input= f.text_area :content, class: "span8" |
... | ... | @@ -26,11 +26,3 @@ |
26 | 26 | = link_to "Cancel", project_snippets_path(@project), class: " btn" |
27 | 27 | - unless @snippet.new_record? |
28 | 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 | 10 | |
11 | 11 | %h6 1. Choose people you want in the team |
12 | 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 | 16 | %h6 2. Set access level for them |
18 | 17 | .clearfix |
19 | 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 | 21 | .actions |
24 | 22 | = f.submit 'Save', class: "btn save-btn" |
25 | 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(); | ... | ... |