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"}");
@@ -1,194 +1,194
1 1 /*
2 2 * This is a manifest file that'll be compiled into application.css, which will include all the files
3 3 * listed below.
4 4 *
5 5 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 6 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7 7 *
8 8 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 9 * compiled file so the styles you add here take precedence over styles defined in any styles
10 10 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11 11 * file per style scope.
12 12 *
13 13 // bootstrap says that we should not do this, but @import each file instead
14 14 # *= require_tree .
15 15 # *= require_self
16 16 */
17 17
18 18 @import jquery.ui.all
19 19 @import jquery.ui.core
20 20 @import jquery.ui.core
21 21 @import jquery.ui.theme
22 22 @import jquery.ui.datepicker
23 23 @import jquery.ui.slider
24 24 @import jquery-ui-timepicker-addon
25 25 @import jquery-tablesorter/theme.metro-dark
26 26 @import tablesorter-theme.cafe
27 27
28 28 //bootstrap
29 29 @import bootstrap-sprockets
30 30 @import bootstrap
31 31 @import select2
32 32 @import select2-bootstrap
33 33 //@import bootstrap3-switch
34 34 @import bootstrap-toggle
35 35
36 36 .secondnavbar
37 37 top: 50px
38 38
39 39 .btn-file
40 40 position: relative
41 41 overflow: hidden
42 42
43 43 .btn-file input[type=file]
44 44 position: absolute
45 45 top: 0
46 46 right: 0
47 47 min-width: 100%
48 48 min-height: 100%
49 49 font-size: 100px
50 50 text-align: right
51 51 filter: alpha(opacity=0)
52 52 opacity: 0
53 53 outline: none
54 54 background: white
55 55 cursor: inherit
56 56 display: block
57 57
58 58 body
59 59 background: white image-url("topbg.jpg") repeat-x top center
60 60 //font-size: 13px
61 61 //font-family: Tahoma, "sans-serif"
62 62 margin: 10px
63 63 padding: 10px
64 64 padding-top: 100px
65 65
66 66
67 67 input
68 68 font-family: Tahoma, "sans-serif"
69 69
70 70
71 71 h1
72 72 font-size: 24px
73 73 color: #334488
74 74 line-height: 2em
75 75
76 76
77 77 h2
78 78 font-size: 18px
79 79 color: #5566bb
80 80 line-height: 1.5em
81 81
82 82
83 83 hr
84 84 border-top: 1px solid #dddddd
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
102 102 &.userbar
103 103 line-height: 1.5em
104 104 text-align: right
105 105 font-size: 12px
106 106
107 107 &.title
108 108 padding: 10px 0px
109 109 line-height: 1.5em
110 110 font-size: 13px
111 111
112 112 span.contest-over-msg
113 113 font-size: 15px
114 114 color: red
115 115
116 116 table
117 117 width: 100%
118 118 font-weight: bold
119 119
120 120 td
121 121 &.left-col
122 122 text-align: left
123 123 vertical-align: top
124 124 color: #444444
125 125
126 126 &.right-col
127 127 text-align: right
128 128 vertical-align: top
129 129 font-size: 18px
130 130 color: #116699
131 131
132 132
133 133 table.info
134 134 margin: 10px 0
135 135 border: 1px solid #666666
136 136 border-collapse: collapse
137 137 font-size: 12px
138 138
139 139 th
140 140 border: 1px solid #666666
141 141 line-height: 1.5em
142 142 padding: 0 0.5em
143 143
144 144 td
145 145 border-left: 1px solid #666666
146 146 border-right: 1px solid #666666
147 147 line-height: 1.5em
148 148 padding: 0 0.5em
149 149
150 150
151 151 tr
152 152 &.info-head
153 153 background: #777777
154 154 color: white
155 155
156 156 &.info-odd
157 157 background: #eeeeee
158 158
159 159 &.info-even
160 160 background: #fcfcfc
161 161
162 162 =basicbox
163 163 background: #eeeeff
164 164 border: 1px dotted #99aaee
165 165 padding: 5px
166 166 margin: 10px 0px
167 167 color: black
168 168 font-size: 13px
169 169
170 170 .infobox
171 171 +basicbox
172 172
173 173 .submitbox
174 174 +basicbox
175 175
176 176 .errorExplanation
177 177 border: 1px dotted gray
178 178 color: #bb2222
179 179 padding: 5px 15px 5px 15px
180 180 margin-bottom: 5px
181 181 background-color: white
182 182 font-weight: normal
183 183
184 184 h2
185 185 color: #cc1111
186 186 font-weight: bold
187 187
188 188
189 189 table.uinfo
190 190 border-collapse: collapse
191 191 border: 1px solid black
192 192 font-size: 13px
193 193
194 194
@@ -1,101 +1,101
1 1 class AnnouncementsController < ApplicationController
2 2
3 3 before_filter :admin_authorization
4 4
5 5 in_place_edit_for :announcement, :published
6 6
7 7 # GET /announcements
8 8 # GET /announcements.xml
9 9 def index
10 10 @announcements = Announcement.find(:all,
11 11 :order => "created_at DESC")
12 12
13 13 respond_to do |format|
14 14 format.html # index.html.erb
15 15 format.xml { render :xml => @announcements }
16 16 end
17 17 end
18 18
19 19 # GET /announcements/1
20 20 # GET /announcements/1.xml
21 21 def show
22 22 @announcement = Announcement.find(params[:id])
23 23
24 24 respond_to do |format|
25 25 format.html # show.html.erb
26 26 format.xml { render :xml => @announcement }
27 27 end
28 28 end
29 29
30 30 # GET /announcements/new
31 31 # GET /announcements/new.xml
32 32 def new
33 33 @announcement = Announcement.new
34 34
35 35 respond_to do |format|
36 36 format.html # new.html.erb
37 37 format.xml { render :xml => @announcement }
38 38 end
39 39 end
40 40
41 41 # GET /announcements/1/edit
42 42 def edit
43 43 @announcement = Announcement.find(params[:id])
44 44 end
45 45
46 46 # POST /announcements
47 47 # POST /announcements.xml
48 48 def create
49 49 @announcement = Announcement.new(params[:announcement])
50 50
51 51 respond_to do |format|
52 52 if @announcement.save
53 53 flash[:notice] = 'Announcement was successfully created.'
54 54 format.html { redirect_to(@announcement) }
55 55 format.xml { render :xml => @announcement, :status => :created, :location => @announcement }
56 56 else
57 57 format.html { render :action => "new" }
58 58 format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
59 59 end
60 60 end
61 61 end
62 62
63 63 # PUT /announcements/1
64 64 # PUT /announcements/1.xml
65 65 def update
66 66 @announcement = Announcement.find(params[:id])
67 67
68 68 respond_to do |format|
69 69 if @announcement.update_attributes(params[:announcement])
70 70 flash[:notice] = 'Announcement was successfully updated.'
71 71 format.html { redirect_to(@announcement) }
72 72 format.js {}
73 73 format.xml { head :ok }
74 74 else
75 75 format.html { render :action => "edit" }
76 76 format.js {}
77 77 format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
78 78 end
79 79 end
80 80 end
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
88 88 end
89 89
90 90 # DELETE /announcements/1
91 91 # DELETE /announcements/1.xml
92 92 def destroy
93 93 @announcement = Announcement.find(params[:id])
94 94 @announcement.destroy
95 95
96 96 respond_to do |format|
97 97 format.html { redirect_to(announcements_url) }
98 98 format.xml { head :ok }
99 99 end
100 100 end
101 101 end
@@ -1,15 +1,15
1 1 <!DOCTYPE html>
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
10 10
11 11 %body
12 12 = render 'layouts/header'
13 13
14 14 = content_tag(:p,flash[:notice],:style => "color:green") if flash[:notice]!=nil
15 15 = yield
@@ -1,27 +1,27
1 1 CafeGrader::Application.routes.draw do
2 2 root :to => 'main#login'
3 3
4 4 get "report/login"
5 5
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
13 13 resources :grader_configuration, controller: 'configurations'
14 14
15 15 match 'tasks/view/:file.:ext' => 'tasks#view'
16 16 match 'tasks/download/:id/:file.:ext' => 'tasks#download'
17 17 match 'heartbeat/:id/edit' => 'heartbeat#edit'
18 18
19 19 #main
20 20 get "main/list"
21 21
22 22 # See how all your routes lay out with "rake routes"
23 23
24 24 # This is a legacy wild controller route that's not recommended for RESTful applications.
25 25 # Note: This route will make all actions in every controller accessible via GET requests.
26 26 match ':controller(/:action(/:id))(.:format)'
27 27 end
deleted file
You need to be logged in to leave comments. Login now