This commit is contained in:
wanglinchun 2014-06-04 20:29:15 +08:00
parent da26c70f6c
commit ae70081288
11 changed files with 81 additions and 50 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,11 @@
<%= error_messages_for @contestnotifications %>
<div class="add_frame_header" >
<%= l(:label_news_new) %>
</div>
<div class="box tabular">
<p><%= f.text_field :title, :required => true, :size => 60, :style => "width:488px;" %></p>
<p><%= f.text_area :description, :required => true, :cols => 60, :rows => 11, :class => 'wiki-edit', :style => "width:490px;" %></p>
<p id="attachments_form" style="margin-left:-10px;"><label style="padding-right: 15px;"><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @contestnotifications} %></p>
</div>
<%= wikitoolbar_for 'news_description' %>

View File

@ -10,16 +10,16 @@
<td colspan="2" valign="top" width="50" ><img src="/images/new/news.png" width="40" height="40"/></td>
<td><table width="580px" border="0">
<tr>
<td colspan="2" valign="top"><strong> <%=link_to contestnotifications.author,contestnotifications_path(contestnotifications)%></strong>
<a class="font_lighter"><%= l(:label_project_newshare) %></a> <%= link_to h(contestnotifications.title), news_path(contestnotifications) %>
<td colspan="2" valign="top"><strong> <%=link_to contestnotifications.author,contest_contestnotification_path(contestnotifications)%></strong>
<a class="font_lighter"><%= l(:label_project_newshare) %></a> <%= link_to h(contestnotifications.title), contest_contestnotification_path(contestnotifications) %>
</td>
</tr>
<tr>
<td colspan="2" width="580px" ><p class="font_description"><%=h contestnotifications.description%></p></td>
</tr>
<tr>
<td align="left"><a class="font_lighter"> <%= contestnotifications.created_on %></a></td>
<td width="200" align="right" class="a"><%= link_to l(:label_project_newother),contestnotifications_path(contestnotifications)%>
<td align="left"><a class="font_lighter"> <%= contestnotifications.created_at %></a></td>
<td width="200" align="right" class="a"><%= link_to l(:label_project_newother),contest_contestnotification_path(contestnotifications)%>
<%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count > 0 %>
</td>
</tr>

View File

@ -7,10 +7,10 @@
<h3><%=l(:label_news)%></h3>
<%= 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 %>
<div id="preview" class="wiki"></div>

View File

@ -1,29 +1,22 @@
<!--begin-->
<%
btn_tips = l(:label_news_new)
label_tips = l(:label_news)
%>
<span style="font-size: 16px; border-bottom:1px solid #f0f0f0; margin-right: 15px;">
<%= label_tips %>
<%= l(:label_news) %>
</span>
<%= 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) %>
<div id="add-news" class="add_frame" style="display:none;">
<%= labelled_form_for @contestnotifications, :url => contestnotifications_path(@contest),
:html => {:id => 'news-form', :multipart => true} do |f| %>
<div id="add-contestnotifications" class="add_frame" style="display:none;">
<%= labelled_form_for @contestnotifications, :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', :name => nil %><!-- button-submit --> |
<%= preview_link preview_contestnotification_path(:contest_id => @contest), 'news-form', target='preview', {:class => 'whiteButton m3p10'} %>
<%= submit_tag l(:button_create), :class => 'whiteButton m3p10 h30', :name => nil %>
<%= preview_link preview_contestnotifications_path(:contest_id => @contest), 'contestnotifications-form', target='preview', {:class => 'whiteButton m3p10'} %>
|
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-news").hide()', :class => 'whiteButton m3p10' %>
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-contestnotifications").hide(); return false;', :class => 'whiteButton m3p10' %>
<% end if @contest %>
<div id="preview" class="wiki"></div>
</div>
@ -44,8 +37,8 @@
<tr>
<td colspan="2" valign="top">
<strong><%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %></strong><span style="margin-left: 4px;" class="font_lighter"><%= l(:label_project_notice) %></span><span><%= link_to h(contestnotifications.title), contestnotification_path(contestnotifications) %></span>
<span style="float: right"><%= delete_link contestnotification_path(contestnotifications) if User.current.allowed_to?(:manage_contestnotification, @contest) %> </span>
<strong><%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %></strong><span style="margin-left: 4px;" class="font_lighter"><%= l(:label_project_notice) %></span><span><%= link_to h(contestnotifications.title), contest_contestnotification_path(contestnotifications) %></span>
<span style="float: right"><%= delete_link contest_contestnotification_path(contestnotifications) if User.current.allowed_to?(:manage_contestnotifications, @contest) %> </span>
</td>
</tr>
<tr>
@ -55,7 +48,7 @@
<tr>
<td align="left"><span class="font_lighter"> <%= l :label_update_time %>
&nbsp;<%= format_time(contestnotifications.created_at) %></span></td>
<td width="350" align="right" class="a"><%= link_to l(:label_project_newother), contestnotification_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %></td>
<td width="350" align="right" class="a"><%= link_to l(:label_project_newother), contest_contestnotification_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %></td>
</tr>
</table>
</td>

View File

@ -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 %>
<div id="preview" class="wiki"></div>

View File

@ -50,10 +50,10 @@
<% if authorize_for('contestnotifications', 'edit') %>
<div id="edit-news" style="display:none;">
<%= labelled_form_for :contestnotifications, @contestnotifications, :url => contestnotifications_path(@contestnotifications),
:html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
:html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= preview_link preview_contestnotifications_path(:contest_id => @contest, :id => @contestnotifications), 'news-form',target='preview',{:class => ''} %> |
<%= preview_link preview_contestnotifications_path(:contest_id => @contest, :id => @contestnotifications), 'contestnotifications-form',target='preview',{:class => ''} %> |
<%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %>
<% end %>
<div id="preview" class="wiki"></div>

View File

@ -70,6 +70,10 @@ RedmineApp::Application.routes.draw do
end
end
#resources :contestnotifications, :only => [:index, :show, :edit, :update, :destroy]
match '/contestnotifications/:id/comments', :to => 'comments#create', :via => :post
match '/contestnotifications/:id/comments/:comment_id', :to => 'comments#destroy', :via => :delete
match '/contestnotifications/preview', :controller => 'previews', :action => 'contestnotifications', :as => 'preview_contestnotifications', :via => [:get, :post, :put]
## new added by linchun #新竞赛相关
resources :contests, only: [:index] do
resources :contestnotifications#, except: [:index]

View File

@ -23,6 +23,11 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type"
add_index "activities", ["user_id"], :name => "index_activities_on_user_id"
create_table "applied_projects", :force => true do |t|
t.integer "project_id", :null => false
t.integer "user_id", :null => false
end
create_table "apply_project_masters", :force => true do |t|
t.integer "user_id"
t.string "apply_type"