diff --git a/app/controllers/contestnotifications_controller.rb b/app/controllers/contestnotifications_controller.rb index f2c0fb80f..0f485e65b 100644 --- a/app/controllers/contestnotifications_controller.rb +++ b/app/controllers/contestnotifications_controller.rb @@ -41,7 +41,7 @@ class ContestnotificationsController < ApplicationController @limit = 10 end - scope = @contest ? @contest.contestnotifications.visible : Contestnotification.visible + scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible @contestnotifications_count = scope.count @contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page'] @@ -80,14 +80,14 @@ class ContestnotificationsController < ApplicationController # GET /contestnotifications/new # GET /contestnotifications/new.json def new - @contestnotification = Contestnotification.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @contestnotification } - end - # @contestnotifications = Contestnotifications.new(:contest => @contest, :author => User.current) - # render :layout => 'base_contest' + # @contestnotification = Contestnotification.new +# + # respond_to do |format| + # format.html # new.html.erb + # format.json { render json: @contestnotification } + # end + @contestnotification = Contestnotification.new(:contest => @contest, :author => User.current) + render :layout => 'base_newcontest' end # GET /contestnotifications/1/edit @@ -109,15 +109,15 @@ class ContestnotificationsController < ApplicationController # format.json { render json: @contestnotification.errors, status: :unprocessable_entity } # end # end - @contestnotifications = Contestnotifications.new(:contest => @contest, :author => User.current) - @contestnotifications.safe_attributes = params[:contestnotifications] - @news.save_attachments(params[:attachments]) - if @contestnotifications.save - render_attachment_warning_if_needed(@contestnotifications) + @contestnotification = Contestnotification.new(:contest => @contest, :author => User.current) + @contestnotification.safe_attributes = params[:contestnotification] + @contestnotification.save_attachments(params[:attachments]) + if @contestnotification.save + render_attachment_warning_if_needed(@contestnotification) flash[:notice] = l(:notice_successful_create) - redirect_to project_news_index_path(@contest) + redirect_to contest_contestnotifications_path(@contest) else - layout_file = 'base_contest' + layout_file = 'base_newcontest' render :action => 'new', :layout => layout_file end end diff --git a/app/controllers/previews_controller.rb b/app/controllers/previews_controller.rb index 0083116d2..2ca2cef9e 100644 --- a/app/controllers/previews_controller.rb +++ b/app/controllers/previews_controller.rb @@ -16,10 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class PreviewsController < ApplicationController - before_filter :find_project, :find_attachments + before_filter :find_project, :find_attachments, :find_contest def issue @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? + @issue = @contest.issues.find_by_id(params[:id]) unless params[:id].blank? if @issue @description = params[:issue] && params[:issue][:description] if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") @@ -50,4 +51,20 @@ class PreviewsController < ApplicationController render_404 end + def contestnotifications + if params[:id].present? && contestnotifications = Contestnotifications.visible.find_by_id(params[:id]) + @previewed = contestnotifications + end + @text = (params[:contestnotifications] ? params[:contestnotifications][:description] : nil) + render :partial => 'common/preview' + end + + private + def find_contest + contest_id = (params[:issue] && params[:issue][:contest_id]) || params[:contest_id] + @contest = Contest.find(contest_id) + rescue ActiveRecord::RecordNotFound + render_404 + end + end diff --git a/app/models/contestnotification.rb b/app/models/contestnotification.rb index f6b0fd168..b983778e4 100644 --- a/app/models/contestnotification.rb +++ b/app/models/contestnotification.rb @@ -19,7 +19,7 @@ class Contestnotification < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :add_author_as_watcher, :reset_counters! + after_create :add_author_as_watcher after_create :act_as_activity diff --git a/app/views/contestnotifications/_form.html.erb b/app/views/contestnotifications/_form.html.erb index e69de29bb..acfa20a7c 100644 --- a/app/views/contestnotifications/_form.html.erb +++ b/app/views/contestnotifications/_form.html.erb @@ -0,0 +1,11 @@ +<%= error_messages_for @contestnotifications %> +
+ <%= l(:label_news_new) %> +
+
+

<%= f.text_field :title, :required => true, :size => 60, :style => "width:488px;" %>

+

<%= f.text_area :description, :required => true, :cols => 60, :rows => 11, :class => 'wiki-edit', :style => "width:490px;" %>

+

<%= render :partial => 'attachments/form', :locals => {:container => @contestnotifications} %>

+
+ +<%= wikitoolbar_for 'news_description' %> diff --git a/app/views/contestnotifications/_contestnotifications.html.erb b/app/views/contestnotifications/_news.html.erb similarity index 81% rename from app/views/contestnotifications/_contestnotifications.html.erb rename to app/views/contestnotifications/_news.html.erb index 4a062f3b5..1621c5813 100644 --- a/app/views/contestnotifications/_contestnotifications.html.erb +++ b/app/views/contestnotifications/_news.html.erb @@ -10,16 +10,16 @@ - - - + diff --git a/app/views/contestnotifications/edit.html.erb b/app/views/contestnotifications/edit.html.erb index 121b15d9a..3d3403818 100644 --- a/app/views/contestnotifications/edit.html.erb +++ b/app/views/contestnotifications/edit.html.erb @@ -7,10 +7,10 @@

<%=l(:label_news)%>

-<%= labelled_form_for @contestnotifications, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> +<%= labelled_form_for @contestnotifications, :html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <%= submit_tag l(:button_save) %> -<%= preview_link preview_news_path(:project_id => @contest, :id => @contestnotifications), 'news-form' %> +<%= preview_link preview_news_path(:project_id => @contest, :id => @contestnotifications), 'contestnotifications-form' %> <% end %>
diff --git a/app/views/contestnotifications/index.html.erb b/app/views/contestnotifications/index.html.erb index 090b72a36..e114b610c 100644 --- a/app/views/contestnotifications/index.html.erb +++ b/app/views/contestnotifications/index.html.erb @@ -1,29 +1,22 @@ - - -<% - btn_tips = l(:label_news_new) - label_tips = l(:label_news) -%> - - <%= label_tips %> + <%= l(:label_news) %> -<%= link_to(btn_tips, +<%= link_to(l(:label_news_new), new_contest_contestnotification_path(@contest), :class => 'icon icon-add', - :onclick => 'showAndScrollTo("add-news", "news_title"); return false;') %> + :onclick => 'showAndScrollTo("add-contestnotifications", "contestnotifications_title"); return false;') %> <% if @contest && User.current.allowed_to?(:manage_contestnotifications, @contest) %> - @@ -55,7 +48,7 @@ - +
<%=link_to contestnotifications.author,contestnotifications_path(contestnotifications)%> - <%= l(:label_project_newshare) %> <%= link_to h(contestnotifications.title), news_path(contestnotifications) %> + <%=link_to contestnotifications.author,contest_contestnotification_path(contestnotifications)%> + <%= l(:label_project_newshare) %> <%= link_to h(contestnotifications.title), contest_contestnotification_path(contestnotifications) %>

<%=h contestnotifications.description%>

<%= contestnotifications.created_on %><%= link_to l(:label_project_newother),contestnotifications_path(contestnotifications)%> + <%= contestnotifications.created_at %><%= link_to l(:label_project_newother),contest_contestnotification_path(contestnotifications)%> <%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count > 0 %>
- <%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %><%= l(:label_project_notice) %><%= link_to h(contestnotifications.title), contestnotification_path(contestnotifications) %> - <%= delete_link contestnotification_path(contestnotifications) if User.current.allowed_to?(:manage_contestnotification, @contest) %> + <%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %><%= l(:label_project_notice) %><%= link_to h(contestnotifications.title), contest_contestnotification_path(contestnotifications) %> + <%= delete_link contest_contestnotification_path(contestnotifications) if User.current.allowed_to?(:manage_contestnotifications, @contest) %>
<%= l :label_update_time %>  <%= format_time(contestnotifications.created_at) %><%= link_to l(:label_project_newother), contestnotification_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %><%= link_to l(:label_project_newother), contest_contestnotification_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %>
diff --git a/app/views/contestnotifications/new.html.erb b/app/views/contestnotifications/new.html.erb index 2ad240014..c4e322ec8 100644 --- a/app/views/contestnotifications/new.html.erb +++ b/app/views/contestnotifications/new.html.erb @@ -1,6 +1,7 @@ -<%#= labelled_form_for @contestnotifications, :url => contest_contestnotifications_path(@contest), :html => { :id => 'news-form', :multipart => true } do |f| %> - <%#= render :partial => 'contestnotifications/form', :locals => { :f => f } %> - <%#= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %> -<%# end %> +<%= labelled_form_for @contestnotification, :url => contest_contestnotifications_path(@contest), :html => { :id => 'contestnotifications-form', :multipart => true } do |f| %> + <%= render :partial => 'contestnotifications/form', :locals => { :f => f } %> + <%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %> + <%= preview_link preview_contestnotifications_path(:contest_id => @contest), 'contestnotifications-form' ,target='preview',{:class => 'whiteButton m3p10'}%> +<% end %>
diff --git a/app/views/contestnotifications/show.html.erb b/app/views/contestnotifications/show.html.erb index a8069c73c..517f60bca 100644 --- a/app/views/contestnotifications/show.html.erb +++ b/app/views/contestnotifications/show.html.erb @@ -50,10 +50,10 @@ <% if authorize_for('contestnotifications', 'edit') %>