Skip to content
This repository
Browse code

OPEN - task 2: Reports per site

  • Loading branch information...
commit 9885adc8f848550bcf21aac69e102e5b763091b3 1 parent 55fe7aa
Onno authored
9 app/controllers/users_controller.rb
@@ -112,22 +112,19 @@ def toggle_change_report_notification
112 112 end
113 113
114 114 # Action #notification creates or deletes (toggles) a notification of a certain type for a Page and Site
115   - # params[:page_id] can now also be a Wiki
116 115 def notification
117 116 @user = User.find(params[:user_id])
118   - #@site = Site.find(params[:site_id])
119   - #@page = Page.find(params[:page_id])
120 117 @type = params[:notification_type]
121 118 if session['user'] == @user || cadmin?
122   - n = Notification.find(:first, :conditions => ["user_id=? and page_id=? and notification_type=?", @user.id, params[:page_id], @type])
  119 + n = Notification.find(:first, :conditions => ["user_id=? and page_id=? and notification_type=?", @user.id, params[:id], @type])
123 120 if n
124 121 n.destroy
125 122 else
126   - n = Notification.create(:user => session['user'], :page_id => params[:page_id], :notification_type => @type)
  123 + n = Notification.create(:user => session['user'], :page_id => params[:id], :notification_type => @type)
127 124 end
128 125 respond_to do |format|
129 126 format.js { render :update do |page|
130   - page.replace_html params['div_id'], :inline => "<%= link_to_notification_toggle(@page, @type, @user)%>"
  127 + page.replace_html params['div_id'], :inline => "<%= link_to_notification_toggle(params[:id], @type, @user)%>"
131 128 page.visual_effect :highlight, params['div_id'], :duration => 2
132 129 end}
133 130 end
8 app/helpers/application_helper.rb
@@ -111,17 +111,17 @@ def link_to_page(page)
111 111 end
112 112
113 113 # Helper #link_to_notification_toggle
114   - def link_to_notification_toggle(page, notification_type, user = session['user'])
  114 + def link_to_notification_toggle(id, notification_type, user = session['user'])
115 115 html = []
116   - notification = Notification.find(:first, :conditions => ["user_id=? and page_id=? and notification_type=?", user.id, page.id, notification_type])
  116 + notification = Notification.find(:first, :conditions => ["user_id=? and page_id=? and notification_type=?", user.id, id, notification_type])
117 117 if session['user'] && (mine?(user) || cadmin?)
118   - div_id = "notification_" + page.id.to_s + "_" + notification_type
  118 + div_id = "notification_" + id.to_s + "_" + notification_type
119 119 html << raw("<span id=\"" + div_id + "\">")
120 120 txt = raw "<input type=checkbox>notify me of new comments and changes"
121 121 txt = raw "<input type=checkbox checked>notify me of new comments and changes" if notification
122 122 html << link_to(txt,
123 123 url_for(:div_id => div_id, :controller => "users", :action => "notification",
124   - :page_id => page.id,:user_id => user.id, # , :site_id => page.site.id
  124 + :id => id,:user_id => user.id, # , :site_id => page.site.id
125 125 :notification_type=> notification_type), :remote => true) # TODO Rails 3 was link_to_remote
126 126 html << raw("</span>")
127 127 else
2  app/views/pages/_relationships.rhtml
@@ -32,7 +32,7 @@
32 32 <li><%= link_to_user user %></li>
33 33 <% end %>
34 34 </ul>
35   - <%= link_to_notification_toggle(@page, Page.name) %>
  35 + <%= link_to_notification_toggle(@page.id, Page.name) %>
36 36 </td>
37 37 </tr>
38 38
2  app/views/pages/history.rhtml
@@ -3,7 +3,7 @@
3 3 <div id="menu">
4 4 <%= link_to('Edit', {:controller => 'pages', :action=> 'checkout', :id=> @page.id, :site_id => @wiki.id}) %>
5 5 <% if session['user'] %>
6   - | <%= link_to_notification_toggle(@page, Page.name) %>
  6 + | <%= link_to_notification_toggle(@page.id, Page.name) %>
7 7 <% end %>
8 8 <% if @versions && @versions.size > 1 && !@page.checkedout? %>
9 9 | <%= link_to_function("Rollback") do |page|
2  app/views/pages/show.rhtml
@@ -8,7 +8,7 @@
8 8 <% if cadmin? %>
9 9 | <%= link_to 'Destroy', {:action => 'destroy', :id => @page}, :confirm => 'Are you sure? This will remove the page, comments and versions from the database. This will remove all meta-data and could cause a corruption. To undo changes you should use rollback or checkout, checkin!' %>
10 10 <% end %>
11   - <%= link_to_notification_toggle(@page, Page.name) %>
  11 + <%= link_to_notification_toggle(@page.id, Page.name) %>
12 12 </div>
13 13
14 14 <p>
2  app/views/sites/description.rhtml
@@ -314,7 +314,7 @@
314 314 <p></>The following users will be notified of changes and new comments:
315 315 <%= Notification.find_all_users(@site, report).collect{|u|u.name}.join(', ') %>.
316 316 </p>
317   - <p><%= link_to_notification_toggle(@site, report) %></p>
  317 + <p><%= link_to_notification_toggle(@site.id, report) %></p>
318 318 </td>
319 319 </tr>
320 320 <% end %>
2  app/views/users/account.rhtml
@@ -20,7 +20,7 @@
20 20 <ul><% for notification in @user.reload.notifications %>
21 21 <% if Page.exists?(notification.page_id) %>
22 22 <% p = Page.find(notification.page_id)%>
23   - <li><%= link_to_notification_toggle(p, Page.name, @user) %> for <%= link_to_page p %> in Wiki <%= link_to_site p.site %></li>
  23 + <li><%= link_to_notification_toggle(p.id, Page.name, @user) %> for <%= link_to_page p %> in Wiki <%= link_to_site p.site %></li>
24 24 <% else %>
25 25 <% notification.destroy %>
26 26 <% end %>

0 comments on commit 9885adc

Please sign in to comment.
Something went wrong with that request. Please try again.