Description:
change announcement toggle into bootstrap button with processing state
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r557:47db9776ed2e - - 8 files changed: 75 inserted, 56 deleted

@@ -0,0 +1,15
1 + #js for announcement
2 + $ ->
3 + $('.ajax-toggle').on 'click', (event) ->
4 + console.log event.target.id
5 + target = $(event.target)
6 + target.removeClass 'btn-default'
7 + target.removeClass 'btn-success'
8 + target.addClass 'btn-warning'
9 + target.text '...'
10 + return
11 +
12 + $(document).ajaxError (event, jqxhr, settings, exception) ->
13 + if jqxhr.status
14 + alert 'We\'re sorry, but something went wrong (' + jqxhr.status + ')'
15 + return
@@ -0,0 +1,37
1 + %h1 Listing announcements
2 +
3 + = link_to '+ Add announcement', new_announcement_path, class: 'btn btn-success'
4 + %br
5 + %br
6 +
7 + %table.table.table-striped
8 + %tr
9 + %th Updated
10 + %th Announcement
11 + %th Author
12 + %th Published
13 + %th
14 + %th
15 + - for announcement in @announcements
16 + %tr
17 + - @announcement = announcement
18 + %td= time_ago_in_words announcement.updated_at
19 + %td
20 + - if !announcement.title.blank?
21 + %b Title:
22 + = h announcement.title
23 + %br/
24 + - if !announcement.notes.blank?
25 + %b
26 + Notes: #{h announcement.notes}
27 + %br/
28 + = h announcement.body
29 + %td= h announcement.author
30 + // %td= check_box_tag :published, 1, announcement.published, { class: 'bootstrap-toggle', id: "published-#{announcement.id}", data: {remote: true, method: 'PUT', url: url_for(controller: :announcements, action: :toggle, id: announcement), size: 'small', toggle: 'toggle' } }
31 + // <td><haml_loud> in_place_editor_field :announcement, :published, {}, :rows => 1 </haml_loud></td>
32 + %td= link_to (announcement.published? ? "Yes" : "No"), url_for(controller: :announcements, action: :toggle, id: announcement), { class: "btn btn-block btn-sm btn-#{(announcement.published? ? 'success' : 'default')} ajax-toggle", id: "published-#{announcement.id}", data: {remote: true, method: 'post' } }
33 + %td= link_to 'Edit', edit_announcement_path(announcement), class: 'btn btn-block btn-sm btn-info'
34 + %td= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete, class: "btn btn-block btn-sm btn-danger"
35 + %br
36 +
37 + = link_to '+ Add announcement', new_announcement_path, class: 'btn btn-success'
@@ -0,0 +1,8
1 + :plain
2 + var t = $("#published-#{@announcement.id}");
3 + t.removeClass('btn-default');
4 + t.removeClass('btn-success');
5 + t.removeClass('btn-warning');
6 + t.addClass("btn-#{@announcement.published? ? 'success' : 'default'}");
7 + t.attr("data-params","published=#{!@announcement.published?}");
8 + t.text("#{@announcement.published? ? "Yes" : "No"}");
@@ -85,17 +85,17
85 85 border-bottom: 1px solid #eeeeee
86 86
87 87
88 - a
89 - color: #6666cc
90 - text-decoration: none
91 -
92 - &:link, &:visited
93 - color: #6666cc
94 - text-decoration: none
95 -
96 - &:hover, &:focus
97 - color: #111166
98 - text-decoration: none
88 + //#a
89 + // color: #6666cc
90 + // text-decoration: none
91 + //
92 + // &:link, &:visited
93 + // color: #6666cc
94 + // text-decoration: none
95 + //
96 + // &:hover, &:focus
97 + // color: #111166
98 + // text-decoration: none
99 99
100 100
101 101 div
@@ -81,7 +81,7
81 81
82 82 def toggle
83 83 @announcement = Announcement.find(params[:id])
84 - @announcement.update_attributes( published: params[:published] == 1)
84 + @announcement.update_attributes( published: !@announcement.published? )
85 85 respond_to do |format|
86 86 format.js {}
87 87 end
@@ -2,8 +2,8
2 2 %html
3 3 %head
4 4 %title= GraderConfiguration['contest.name']
5 - = stylesheet_link_tag "application", :media => "all"
6 - = javascript_include_tag "application"
5 + = stylesheet_link_tag "application", params[:controller], :media => "all"
6 + = javascript_include_tag "application", params[:controller]
7 7 = csrf_meta_tags
8 8 = content_for :header
9 9 = yield :head
@@ -6,7 +6,7
6 6 resources :contests
7 7
8 8 resources :announcements
9 - match 'announcements/toggle/:id' => 'announcements#toggle', via: :put
9 + match 'announcements/toggle/:id' => 'announcements#toggle'
10 10
11 11 resources :sites
12 12
deleted file
You need to be logged in to leave comments. Login now