parent
aed36229f8
commit
9fbccfbb6d
|
@ -65,8 +65,6 @@ class BidsController < ApplicationController
|
|||
end
|
||||
|
||||
def fork
|
||||
@new_bid = Bid.new
|
||||
@new_bid.safe_attributes = params[:bid]
|
||||
@courses = []
|
||||
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||
@membership.each do |membership|
|
||||
|
@ -99,7 +97,14 @@ class BidsController < ApplicationController
|
|||
end
|
||||
redirect_to respond_path(@homework)
|
||||
else
|
||||
@homework.safe_attributes = params[:bid]
|
||||
@bid.safe_attributes = params[:bid]
|
||||
@courses = []
|
||||
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
||||
@membership.each do |membership|
|
||||
if membership.project.project_type == 1
|
||||
@courses << membership.project
|
||||
end
|
||||
end
|
||||
render :action => 'fork'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -109,7 +109,7 @@ class ProjectsController < ApplicationController
|
|||
# @project_pages = Paginator.new @project_count, @limit, params['page']
|
||||
# @offset ||= @project_pages.offset
|
||||
# @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
|
||||
|
||||
@project_type = params[:project_type]
|
||||
@offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
@projects_status = ProjectStatus.visible
|
||||
# @projects.each do |project|
|
||||
|
@ -124,13 +124,13 @@ class ProjectsController < ApplicationController
|
|||
# @projects.each do |project|
|
||||
# ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count)
|
||||
# end
|
||||
#@projects_status = Project.visible.like(params[:name]) if params[:name].present?
|
||||
# @projects_status = Project.visible.like(params[:name]) if params[:name].present?
|
||||
@project_count = @projects_status.count
|
||||
@project_pages = Paginator.new @project_count, @limit, params['page']
|
||||
|
||||
@offset ||= @project_pages.reverse_offset
|
||||
|
||||
#@projects = @projects.offset(@offset).limit(@limit).order('created_on DESC').all
|
||||
# @projects = @projects.offset(@offset).limit(@limit).order('created_on DESC').all
|
||||
if params[:project_sort_type].present?
|
||||
case params[:project_sort_type]
|
||||
when '0'
|
||||
|
@ -347,7 +347,7 @@ class ProjectsController < ApplicationController
|
|||
@course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
|
||||
@course.safe_attributes = params[:project][:course]
|
||||
@course.tea_id = User.current.id
|
||||
@course.save
|
||||
# @course.save
|
||||
# project = ProjectInfo.create(:user_id => User.current.id, :project_id => @project.id)
|
||||
# project_status = ProjectStatus.create(:project_id => @project.id)
|
||||
end
|
||||
|
@ -358,42 +358,96 @@ class ProjectsController < ApplicationController
|
|||
if @course_tag == '1'
|
||||
@project.identifier = @course.extra
|
||||
end
|
||||
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
# Add current user as a project member if he is not admin
|
||||
unless User.current.admin?
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => User.current, :roles => [r])
|
||||
project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
|
||||
if params[:project][:is_public] == '1' || @course_tag=="1"
|
||||
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0)
|
||||
end
|
||||
@project.members << m
|
||||
@project.project_infos << project
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:continue]
|
||||
attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
|
||||
redirect_to new_project_path(attrs, :course => '0')
|
||||
#Added by young
|
||||
|
||||
elsif params[:course_continue]
|
||||
redirect_to new_project_path(:course => '1')
|
||||
#Ended by young
|
||||
else
|
||||
redirect_to settings_project_path(@project)
|
||||
if @course_tag == '1'
|
||||
if@course.save
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
# Add current user as a project member if he is not admin
|
||||
unless User.current.admin?
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => User.current, :roles => [r])
|
||||
project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
|
||||
if params[:project][:is_public] == '1' || @course_tag=="1"
|
||||
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0)
|
||||
end
|
||||
@project.members << m
|
||||
@project.project_infos << project
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:continue]
|
||||
attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
|
||||
redirect_to new_project_path(attrs, :course => '0')
|
||||
#Added by young
|
||||
|
||||
elsif params[:course_continue]
|
||||
redirect_to new_project_path(:course => '1')
|
||||
#Ended by young
|
||||
else
|
||||
redirect_to settings_project_path(@project)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||
end
|
||||
else
|
||||
@course.destroy
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base'}#Added by young
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
else
|
||||
if validate_parent_id && @project.save
|
||||
@project.delete
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base'}#Added by young
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base'}#Added by young
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base'}#Added by young
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
# Add current user as a project member if he is not admin
|
||||
unless User.current.admin?
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => User.current, :roles => [r])
|
||||
project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
|
||||
if params[:project][:is_public] == '1' || @course_tag=="1"
|
||||
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0)
|
||||
end
|
||||
@project.members << m
|
||||
@project.project_infos << project
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:continue]
|
||||
attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
|
||||
redirect_to new_project_path(attrs, :course => '0')
|
||||
#Added by young
|
||||
|
||||
elsif params[:course_continue]
|
||||
redirect_to new_project_path(:course => '1')
|
||||
#Ended by young
|
||||
else
|
||||
redirect_to settings_project_path(@project)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'new', :layout => 'base'}#Added by young
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1012,6 +1012,11 @@ module ApplicationHelper
|
|||
|
||||
def error_messages_for(*objects)
|
||||
html = ""
|
||||
# modified by fq
|
||||
if objects.first.is_a?(Array)
|
||||
objects = objects.first
|
||||
end
|
||||
# end
|
||||
objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
|
||||
errors = objects.map {|o| o.errors.full_messages}.flatten
|
||||
if errors.any?
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class Course < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term
|
||||
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password
|
||||
belongs_to :project, :class_name => 'Project', :foreign_key => :extra # 定义一个project方法, 该方法通过extra来调用project表
|
||||
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表
|
||||
has_many :bid
|
||||
validates_presence_of :state, :term
|
||||
validates_presence_of :password, :term
|
||||
safe_attributes 'extra',
|
||||
'time',
|
||||
'name',
|
||||
|
@ -13,7 +13,7 @@ class Course < ActiveRecord::Base
|
|||
'code',
|
||||
'location',
|
||||
'tea_id',
|
||||
'state',
|
||||
'password',
|
||||
'term'
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class Project < ActiveRecord::Base
|
|||
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||
has_many :homework_for_courses, :dependent => :destroy
|
||||
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
|
||||
has_many :students_for_courses, :dependent => :destroy
|
||||
# has_many :students_for_courses, :dependent => :destroy
|
||||
has_many :student, :through => :students_for_courses, :source => :user
|
||||
# has_one :cour, :class_name => 'Course', :foreign_key => :extra, :dependent => :destroy
|
||||
|
||||
|
@ -72,7 +72,7 @@ class Project < ActiveRecord::Base
|
|||
##added by xianbo
|
||||
has_one :course, :dependent => :destroy ,:order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
|
||||
accepts_nested_attributes_for :course
|
||||
##end
|
||||
##end
|
||||
# Custom field for the project issues
|
||||
has_and_belongs_to_many :issue_custom_fields,
|
||||
:class_name => 'IssueCustomField',
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
:onChange => "show('bid_reward_type', 'bid_budget', '"+l(:label_bids_reward_what)+"','"+l(:label_bids_new_money)+"','"+l(:label_bids_new_credit)+"','"+l(:label_bids_new_content)+"')" %>
|
||||
<%= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;", :placeholder => l(:label_bids_reward_what) %>
|
||||
</p> -->
|
||||
<p><%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>
|
||||
<p><%= f.text_field :deadline, :value => nil,:required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>
|
||||
</p>
|
||||
<p><%= f.select :homework_type, homework_type_option %>
|
||||
</p>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!-- fq -->
|
||||
<h3><%=l(:label_new_call)%></h3>
|
||||
|
||||
<%= labelled_form_for @new_bid, :url => {:controller => 'bids', :action => 'create_fork', :id => @bid.id} do |f| %>
|
||||
<%= labelled_form_for @bid, :url => {:controller => 'bids', :action => 'create_fork', :id => @bid.id} do |f| %>
|
||||
<div class="box tabular">
|
||||
<%= render :partial => 'fork_form', :locals => { :f => f } %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<%= error_messages_for 'project' %>
|
||||
<%= error_messages_for 'course' %>
|
||||
<% object = [] %>
|
||||
<% object << 'project' %>
|
||||
<% object << 'course' %>
|
||||
<%= error_messages_for object %>
|
||||
|
||||
|
||||
<!--[form:project]-->
|
||||
<% unless @project.new_record? %>
|
||||
<p><%= render :partial=>"avatar/avatar_form",:locals=> {source:@project} %></p>
|
||||
<% end %>
|
||||
|
||||
<p><%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;" %></p>
|
||||
|
||||
<p style="margin-left:-10px;padding-right: 20px;"><%= f.text_area :description, :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %></p><!--by young-->
|
||||
|
|
|
@ -52,6 +52,6 @@
|
|||
<p class="font_description">
|
||||
<table width="660"><tr><td><%=link_to image_tag(url_to_avatar(@user), :class => "avatar"), user_path(@user)%></td><td colspan="2">
|
||||
<table width="580">
|
||||
<tr><td ><%=link_to @user.login.to_s,user_path(@user) %> <%= l(:label_user_create_project) %> <%=link_to @project.name %><strong> !</strong></td></tr>
|
||||
<tr><td ><%=link_to (h @user.lastname<<@user.firstname), user_path(@user) %> <%= l(:label_user_create_project) %> <%=link_to @project.name %><strong> !</strong></td></tr>
|
||||
<tr><td class="font_lighter" style="float: right"><%= format_time(@project.created_on) %></table></td></tr></table></p>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue