From c964194d85a7ada908ef05a5874174d211b7c759 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Mon, 12 Jan 2015 16:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=97=AE=E5=8D=B7=E8=B0=83?= =?UTF-8?q?=E6=9F=A5=E7=9B=B8=E5=85=B3=E7=9A=84=E8=B7=AF=E7=94=B1=E3=80=81?= =?UTF-8?q?action=E3=80=81=E4=BB=A5=E5=8F=8A=E9=83=A8=E5=88=86=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 110 +++++++++++++++++++++++++++++ app/views/poll/add_answer.html.erb | 0 app/views/poll/destroy.js.erb | 1 + app/views/poll/edit.html.erb | 13 ++++ app/views/poll/index.html.erb | 7 ++ app/views/poll/new.html.erb | 0 config/routes.rb | 9 +++ 7 files changed, 140 insertions(+) create mode 100644 app/views/poll/add_answer.html.erb create mode 100644 app/views/poll/destroy.js.erb create mode 100644 app/views/poll/edit.html.erb create mode 100644 app/views/poll/index.html.erb create mode 100644 app/views/poll/new.html.erb diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index a21fdb549..fbfef025e 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -1,2 +1,112 @@ class PollController < ApplicationController + before_filter :find_poll_and_course, :only => [:edit,:update,:destory] + before_filter :find_container, :only => [:new,:create, :index] + + def index + if @course + @polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}") + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + elsif @project + #项目的问卷调查相关代码 + end + end + + def show + @poll = Poll.find params[:id] + end + + def new + if @course + option = { + :polls_name => "未命名问卷", + :polls_type => @course.class.to_s, + :polls_group_id => @course.id, + :polls_status => 1, + :user_id => User.current.id, + :published_at => Time.now, + :closed_at => Time.now, + :polls_description => "" + } + @poll = Poll.create option + if @poll + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + end + elsif @project + #项目的问卷调查相关代码 + end + end + + def create + end + + def edit + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + end + + def update + @poll.polls_name = params[:polls_name] + if @poll.save + respond_to do |format| + format.html { redirect_to poll_index_url(:polls_type => @course.class.to_s, :polls_group_id => @course.id) } + end + else + end + end + + def destroy + if @poll.destroy + respond_to do |format| + format.js + end + end + end + + #修改问卷标题和描述 + def save_polls + + end + + #添加问题 + def add_question + end + + #添加选项 + def add_answer + puts '1111111111111' + end + + #选答案 + def vote + end + + #统计 + def statistics + end + + private + def find_poll_and_course + @poll = Poll.find params[:id] + @course = Course.find @poll.polls_group_id + rescue Exception => e + render_404 + end + + def find_container + if params[:polls_type] && params[:polls_group_id] + case params[:polls_type] + when "Course" + @course = Course.find_by_id params[:polls_group_id] + when "Project" + @project = Project.find_by_id params[:polls_group_id] + end + else + render_404 + end + end end \ No newline at end of file diff --git a/app/views/poll/add_answer.html.erb b/app/views/poll/add_answer.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/poll/destroy.js.erb b/app/views/poll/destroy.js.erb new file mode 100644 index 000000000..a9efe790e --- /dev/null +++ b/app/views/poll/destroy.js.erb @@ -0,0 +1 @@ +alert("删除成功"); \ No newline at end of file diff --git a/app/views/poll/edit.html.erb b/app/views/poll/edit.html.erb new file mode 100644 index 000000000..a35b1d2e7 --- /dev/null +++ b/app/views/poll/edit.html.erb @@ -0,0 +1,13 @@ + +<%= form_for(@poll) do |f|%> + <%= f.text_field :polls_name, :required => true, :name => "polls_name"%> + + <%= l(:label_button_ok) %> + +<% end%> + diff --git a/app/views/poll/index.html.erb b/app/views/poll/index.html.erb new file mode 100644 index 000000000..4cf90d210 --- /dev/null +++ b/app/views/poll/index.html.erb @@ -0,0 +1,7 @@ +<% @polls.each do |poll|%> + <%= poll.id%>#####<%= poll.polls_name%> + <%= link_to l(:button_edit), edit_poll_path(poll.id)%> + <%= link_to(l(:button_delete), poll, + method: :delete, :confirm => l(:text_are_you_sure), :remote => true ) %> +
+<%end%> \ No newline at end of file diff --git a/app/views/poll/new.html.erb b/app/views/poll/new.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/routes.rb b/config/routes.rb index 5611ed2b6..222fe17eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,6 +58,15 @@ RedmineApp::Application.routes.draw do end end + resources :poll do + member do + get 'add_question' + get 'add_answer' + get 'vote' + get 'statistics' + end + end + resources :contest_notification resources :open_source_projects do