Permalink
Browse files

Note controller almost works completely

  • Loading branch information...
1 parent 2a2e27d commit a111c9d63dea664a8723e5cc0ca314320af5d039 @NelleV NelleV committed Aug 14, 2011
@@ -1,4 +1,4 @@
-class NoteController < ApplicationController
+class NotesController < ApplicationController
before_filter :authorize_for_ta_and_admin
before_filter :ensure_can_modify, :only => [:edit, :update]
@@ -11,8 +11,10 @@ def notes_dialog
@highlight_field = params[:highlight_field]
@number_of_notes_field = params[:number_of_notes_field]
- @notes = Note.find(:all, :conditions => { :noteable_id => @noteable.id, :noteable_type => @noteable.class.name})
- render :partial => "note/modal_dialogs/notes_dialog.rjs"
+ @notes = Note.find(:all,
+ :conditions => {:noteable_id => @noteable.id,
+ :noteable_type => @noteable.class.name})
+ render :partial => "notes/modal_dialogs/notes_dialog.rjs"
end
def add_note
@@ -23,13 +25,13 @@ def add_note
@note.noteable_id = params[:noteable_id]
@note.noteable_type = params[:noteable_type]
if !@note.save
- render "note/modal_dialogs/notes_dialog_error.rjs"
+ render "notes/modal_dialogs/notes_dialog_error.rjs"
else
@note.reload
@number_of_notes_field = params[:number_of_notes_field]
@highlight_field = params[:highlight_field]
@number_of_notes = @note.noteable.notes.size
- render "note/modal_dialogs/notes_dialog_success.rjs"
+ render "notes/modal_dialogs/notes_dialog_success.rjs"
end
end
@@ -46,8 +48,6 @@ def new
end
def create
- return unless request.post?
-
@note = Note.new(params[:note])
@note.noteable_type = params[:noteable_type]
@note.creator_id = @current_user.id
@@ -87,8 +87,6 @@ def edit
end
def update
- return unless request.post?
-
if @note.update_attributes(params[:note])
flash[:success] = I18n.t('notes.update.success')
redirect_to :action => 'index'
@@ -97,9 +95,8 @@ def update
end
end
- def delete
- return unless request.delete?
-
+ def destroy
+ debugger
@note = Note.find(params[:id])
if @note.user_can_modify?(current_user)
@note.destroy
@@ -58,9 +58,9 @@
<% end %>
<% if @current_user.admin? || @current_user.ta? %>
- <span<% if controller.controller_name == 'note'%>
+ <span<% if controller.controller_name == 'notes'%>
id="menu_active"<%end%>>
- <%= link_to I18n.t('notes.title'), :controller => 'note'%>
+ <%= link_to I18n.t('notes.title'), notes_path() %>
</span>
<% end %>
@@ -1,22 +0,0 @@
-<% fields_for :note, :url => {:action => 'create'} do |f| %>
- <p>
- <%= label_tag "assignment_id", I18n.t("notes.noteables.Assignment") %>
- <%= select_tag "assignment_id",
- options_from_collection_for_select(@assignments,
- :id,
- :short_identifier),
- :onchange => remote_function(
- :url => new_update_groupings_note_path(),
- :with => 'Form.Element.serialize(this)',
- :before => "$('loading_groupings').show()",
- :success => "$('loading_groupings').hide()") %>
- </p>
-
- <p>
- <%= f.label :noteable_id, I18n.t("notes.noteables.Grouping") %>
- <%= f.select :noteable_id, @groupings.collect {|p| [p.group_name_with_student_user_names,p.id]} %>
- <span id="loading_groupings" style="display:none">
- <%=image_tag('spinner.gif')%> <%=I18n.t('notes.new.loading_groupings')%>
- </span>
- </p>
-<% end %>
@@ -1,2 +0,0 @@
-page.replace_html 'notes_error_list', :partial => 'note/modal_dialogs/notes_dialog_error_list', :locals => {:errors => @note.errors}
-page.show 'notes_error'
@@ -1,6 +1,6 @@
-<% fields_for :note, :url => {:action => 'create'} do |f| %>
+<%= fields_for :note, :url => {:action => 'create'} do |f| %>
<p>
<%= f.label :noteable_id, I18n.t("notes.noteables.Assignment")%>
<%= f.select :noteable_id, @assignments.map {|item| [item.short_identifier,item.id]}%>
</p>
-<% end %>
+<% end %>
@@ -0,0 +1,23 @@
+<% fields_for :note, :url => {:action => 'create'} do |f| %>
+ <p>
+ <%= label_tag "assignment_id", I18n.t("notes.noteables.Assignment") %>
+ <%= select_tag "assignment_id",
+ options_from_collection_for_select(@assignments,
+ :id,
+ :short_identifier),
+ :onchange => remote_function(
+ :url => new_update_groupings_notes_path(),
+ :with => 'Form.Element.serialize(this)',
+ :before => "$('loading_groupings').show()",
+ :success => "$('loading_groupings').hide()") %>
+ </p>
+
+ <p>
+ <%= f.label :noteable_id, I18n.t("notes.noteables.Grouping") %>
+ <%= f.select :noteable_id,
+ @groupings.collect {|p| [p.group_name_with_student_user_names,p.id]} %>
+ <span id="loading_groupings" style="display:none">
+ <%= image_tag('spinner.gif') %> <%= I18n.t('notes.new.loading_groupings') %>
+ </span>
+ </p>
+<% end %>
@@ -1,6 +1,6 @@
-<% fields_for :note, :url => {:action => 'create'} do |f| %>
+<%= fields_for :note, :url => {:action => 'create'} do |f| %>
<p>
<%= f.label :noteable_id, I18n.t("notes.noteables.Student") %>
<%= f.select :noteable_id, @students.collect {|p| [p.user_name,p.id]} %>
</p>
-<% end %>
+<% end %>
File renamed without changes.
File renamed without changes.
@@ -29,18 +29,20 @@
<% for note in @notes %>
<tr>
<td class="note">
- <%= I18n.t("notes.note_on", :user_name => note.user.user_name, :display_for => note.noteable.display_for_note ) %></b><br />
+ <%= I18n.t("notes.note_on",
+ :user_name => note.user.user_name,
+ :display_for => note.noteable.display_for_note ) %></b><br />
<small><%=note.format_date%></small>
</td>
<td class="note"><%=note.notes_message%></td>
<td class="note">
<% if note.user_can_modify?(@current_user) -%>
<%= link_to I18n.t('edit'),
- {:action => 'edit', :id => note.id} %>
+ edit_note_path(note.id) %>
|
<%= link_to I18n.t('delete'),
:method => 'delete',
- :url => {:action => 'delete',
+ :url => {:action => 'destroy',
:id => note.id},
:html => {
:class => 'delete',
@@ -0,0 +1,4 @@
+page.replace_html 'notes_error_list',
+ :partial => 'notes/modal_dialogs/notes_dialog_error_list',
+ :locals => {:errors => @note.errors}
+page.show 'notes_error'
@@ -1,7 +1,7 @@
<div id="title_bar"><h1><%= I18n.t('notes.new.title') %></h1></div>
<div class="wrapLeft">
-<%= form_for :note do |f| %>
+<%= form_for :note, :url => notes_path() do |f| %>
<%= f.error_messages %>
<fieldset>
@@ -14,7 +14,7 @@
item]}) %>
<%= observe_field :noteable_type,
:on => 'onchange',
- :url => {:action => :noteable_object_selector},
+ :url => noteable_object_selector_notes_path(),
:with => "noteable_type",
:before => "$('loading_selector').show()",
:success => "$('loading_selector').hide()" %>
@@ -34,6 +34,6 @@
</fieldset>
<%= f.submit I18n.t('save') %>
- <%= link_to I18n.t('cancel'), {:controller => 'note'}, :class => "button" %>
+ <%= link_to I18n.t('cancel'), notes_path(), :class => "button" %>
<% end %>
</div>
@@ -1 +1 @@
-page.replace_html 'noteable_selector', :partial => params[:noteable_type].downcase
+page.replace_html 'noteable_selector', :partial => params[:noteable_type].downcase
View
@@ -135,15 +135,16 @@
end
end
- resources :note do
+ resources :notes do
collection do
- get 'noteable_object_selector'
+ post 'noteable_object_selector'
get 'add_note'
+ get 'new_update_groupings'
+ post 'new_update_groupings'
end
member do
get 'student_interface'
- get 'new_update_groupings'
get 'notes_dialog'
post 'grades'
end
@@ -6,7 +6,7 @@
require File.dirname(__FILE__) + '/authenticated_controller_test'
require 'shoulda'
-class NoteControllerTest < AuthenticatedControllerTest
+class NotesControllerTest < AuthenticatedControllerTest
def setup
clear_fixtures
@@ -68,8 +68,8 @@ def setup
assert respond_with :missing
end
- should "DELETE on :delete" do
- get_as @student, :delete
+ should "DELETE on :destroy" do
+ delete_as @student, :destroy, :id => 1
assert respond_with :missing
end
end # student context
@@ -252,17 +252,19 @@ def setup
end
end
- context "DELETE on :delete" do
+ context "DELETE on :destroy" do
should "for a note belonging to themselves" do
@note = Note.make( :creator_id => @ta.id )
- delete_as @ta, :delete, {:id => @note.id}
+ delete_as @ta, :destroy, :id => @note.id
assert assign_to :note
assert set_the_flash.to(I18n.t('notes.delete.success'))
end
should "for a note belonging to someone else" do
@note = Note.make
- delete_as @ta, :delete, {:id => @note.id}
+ delete_as @ta,
+ :destroy,
+ :id => @note.id
assert assign_to :note
assert set_the_flash.to(I18n.t('notes.delete.error_permissions'))
end
@@ -459,20 +461,20 @@ def setup
end
end
- context "DELETE on :delete" do
+ context "DELETE on :destroy" do
context "for a note belonging to themselves" do
setup do
@note = Note.make( :creator_id => @admin.id )
- delete_as @admin, :delete, {:id => @note.id}
+ delete_as @admin, :destroy, {:id => @note.id}
end
should assign_to :note
should set_the_flash.to(I18n.t('notes.delete.success'))
end
context "for a note belonging to someone else" do
setup do
- @note = Note.make( :creator_id => Ta.make.id )
- delete_as @admin, :delete, {:id => @note.id}
+ @note = Note.make(:creator_id => Ta.make.id)
+ delete_as @admin, :destroy, {:id => @note.id}
end
should assign_to :note
should set_the_flash.to(I18n.t('notes.delete.success'))

0 comments on commit a111c9d

Please sign in to comment.