问卷的上移、下移

This commit is contained in:
cxt 2016-10-27 15:11:52 +08:00
parent a00fd27eee
commit c79676d426
8 changed files with 51 additions and 33 deletions

View File

@ -1,6 +1,6 @@
#encoding utf-8
class PollController < ApplicationController
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll,:export_poll,:save_poll]
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer,:publish_poll,:republish_poll,:poll_result,:close_poll,:export_poll,:save_poll,:update_question_num]
before_filter :find_container, :only => [:new,:create, :index]
before_filter :is_logged, :only => [:index, :show, :poll_result,:new,:create,:edit,:update,:destroy,:publish_poll,:republish_poll,:close_poll,:export_poll,:commit_answer,:commit_poll,:statistics_result,:save_poll]
before_filter :is_member_of_course, :only => [:index,:show,:poll_result]
@ -135,25 +135,25 @@ class PollController < ApplicationController
end
def update_question_num
member = SyllabusMember.find(params[:id])
@syllabus = member.syllabus
members = @syllabus.syllabus_members
if params[:opr] == 'up' && member.rank > 1
before_mem = members.where("rank = #{member.rank - 1}").first
if before_mem && member.update_attribute('rank', member.rank - 1)
before_mem.update_attribute('rank', before_mem.rank + 1)
@poll_question = PollQuestion.find params[:ques_id]
poll_questions = @poll.poll_questions
if @poll_question
if params[:opr] == 'up' && @poll_question.question_number > 1
@before_que = poll_questions.where("question_number = #{@poll_question.question_number - 1}").first
if @before_que && @poll_question.update_attribute('question_number', @poll_question.question_number - 1)
@before_que.update_attribute('question_number', @before_que.question_number + 1)
end
elsif params[:opr] == 'down' && member.rank < members.count
after_mem = members.where("rank = #{member.rank + 1}").first
if after_mem && member.update_attribute('rank', member.rank + 1)
after_mem.update_attribute('rank', after_mem.rank - 1)
elsif params[:opr] == 'down' && @poll_question.question_number < members.count
@after_que = poll_questions.where("question_number = #{@poll_question.question_number + 1}").first
if @after_que && @poll_question.update_attribute('question_number', @poll_question.question_number + 1)
@after_que.update_attribute('question_number', @after_que.question_number - 1)
end
end
@members = @syllabus.syllabus_members.order("rank asc")
respond_to do |format|
format.js
end
end
end
#添加题目
def create_poll_question

View File

@ -1,7 +1,7 @@
<div class="poll-container">
<div class="pool-tool-bar">
<p class="mt10 mb10">
<span class="questionLabel"><%= poll_question.question_number%></span>
<span class="questionLabel" id="poll_question_number_<%=poll_question.id %>"><%= poll_question.question_number%></span>
<%if poll_question.is_necessary == 1%>
<span class="c_red questionLabel ml5" title="必答">*</span>
<%end%>

View File

@ -1,7 +1,7 @@
<div class="poll-container">
<div class="pool-tool-bar">
<p class="mt10 mb10">
<span class="questionLabel"><%= poll_question.question_number%></span>
<span class="questionLabel" id="poll_question_number_<%=poll_question.id %>"><%= poll_question.question_number%></span>
<%if poll_question.is_necessary == 1%>
<span class="c_red questionLabel ml5" title="必答">*</span>
<%end%>

View File

@ -1,7 +1,7 @@
<div class="poll-container">
<div class="pool-tool-bar">
<p class="mt10 mb10">
<span class="questionLabel"><%= poll_question.question_number%></span>
<span class="questionLabel" id="poll_question_number_<%=poll_question.id %>"><%= poll_question.question_number%></span>
<%if poll_question.is_necessary == 1%>
<span class="c_red questionLabel ml5" title="必答">*</span>
<%end%>

View File

@ -1,7 +1,7 @@
<div class="poll-container">
<div class="pool-tool-bar">
<p class="mt10 mb10">
<span class="questionLabel"><%= poll_question.question_number%></span>
<span class="questionLabel" id="poll_question_number_<%=poll_question.id %>"><%= poll_question.question_number%></span>
<%if poll_question.is_necessary == 1%>
<span class="c_red questionLabel ml5" title="必答">*</span>
<%end%>

View File

@ -0,0 +1,17 @@
//$("#poll_content").html('<%#= escape_javascript(render :partial => 'poll_content', :locals => {:poll => @poll})%>');
<% if @before_que %>
$("#poll_questions_<%= @poll_question.id%>").insertBefore($("#poll_questions_<%= @before_que.id%>"));
$("#poll_question_number_<%=@before_que.id %>").html("<%=@before_que.question_number %>");
<% elsif @after_que %>
$("#poll_questions_<%= @poll_question.id%>").insertAfter($("#poll_questions_<%= @after_que.id%>"));
$("#poll_question_number_<%=@after_que.id %>").html("<%=@after_que.question_number %>");
<% end %>
<% if poll_question.question_type == 1%>
$("#show_poll_questions_<%= @poll_question.id %>").html("<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_question}) %>");
<% elsif poll_question.question_type == 2%>
$("#show_poll_questions_<%= @poll_question.id %>").html("<%= escape_javascript(render :partial => 'show_MCQ', :locals => {:poll_question => @poll_question}) %>");
<% elsif poll_question.question_type == 3%>
$("#show_poll_questions_<%= @poll_question.id %>").html("<%= escape_javascript(render :partial => 'show_single', :locals => {:poll_question => @poll_question}) %>");
<% elsif poll_question.question_type == 4%>
$("#show_poll_questions_<%= @poll_question.id %>").html("<%= escape_javascript(render :partial => 'show_mulit', :locals => {:poll_question => @poll_question}) %>");
<% end%>

View File

@ -0,0 +1,6 @@
class AddColumnToPollQuestions < ActiveRecord::Migration
def change
add_column :poll_questions, :max_choices, :integer, :default => 0
add_column :poll_questions, :min_choices, :integer, :default => 0
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20161019020422) do
ActiveRecord::Schema.define(:version => 20161027070249) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -333,8 +333,6 @@ ActiveRecord::Schema.define(:version => 20161019020422) do
t.date "commit_date"
t.string "scmid"
t.integer "user_id"
t.integer "project_id"
t.integer "type", :default => 0
end
add_index "changesets", ["committed_on"], :name => "index_changesets_on_committed_on"
@ -995,10 +993,6 @@ ActiveRecord::Schema.define(:version => 20161019020422) do
t.datetime "updated_at", :null => false
end
create_table "innodb_monitor", :id => false, :force => true do |t|
t.integer "a"
end
create_table "invite_lists", :force => true do |t|
t.integer "project_id"
t.integer "user_id"
@ -1465,6 +1459,8 @@ ActiveRecord::Schema.define(:version => 20161019020422) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "question_number"
t.integer "max_choices", :default => 0
t.integer "min_choices", :default => 0
end
create_table "poll_users", :force => true do |t|
@ -1545,7 +1541,6 @@ ActiveRecord::Schema.define(:version => 20161019020422) do
t.integer "board_num", :default => 0
t.integer "attach_num", :default => 0
t.datetime "commit_time"
t.integer "pull_request_num", :default => 0
end
create_table "project_statuses", :force => true do |t|