问卷的上移、下移

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 #encoding utf-8
class PollController < ApplicationController 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 :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_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] before_filter :is_member_of_course, :only => [:index,:show,:poll_result]
@ -135,24 +135,24 @@ class PollController < ApplicationController
end end
def update_question_num def update_question_num
member = SyllabusMember.find(params[:id]) @poll_question = PollQuestion.find params[:ques_id]
@syllabus = member.syllabus poll_questions = @poll.poll_questions
members = @syllabus.syllabus_members if @poll_question
if params[:opr] == 'up' && member.rank > 1 if params[:opr] == 'up' && @poll_question.question_number > 1
before_mem = members.where("rank = #{member.rank - 1}").first @before_que = poll_questions.where("question_number = #{@poll_question.question_number - 1}").first
if before_mem && member.update_attribute('rank', member.rank - 1) if @before_que && @poll_question.update_attribute('question_number', @poll_question.question_number - 1)
before_mem.update_attribute('rank', before_mem.rank + 1) @before_que.update_attribute('question_number', @before_que.question_number + 1)
end
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 end
elsif params[:opr] == 'down' && member.rank < members.count respond_to do |format|
after_mem = members.where("rank = #{member.rank + 1}").first format.js
if after_mem && member.update_attribute('rank', member.rank + 1)
after_mem.update_attribute('rank', after_mem.rank - 1)
end end
end end
@members = @syllabus.syllabus_members.order("rank asc")
respond_to do |format|
format.js
end
end end
#添加题目 #添加题目

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
<div class="poll-container"> <div class="poll-container">
<div class="pool-tool-bar"> <div class="pool-tool-bar">
<p class="mt10 mb10"> <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%> <%if poll_question.is_necessary == 1%>
<span class="c_red questionLabel ml5" title="必答">*</span> <span class="c_red questionLabel ml5" title="必答">*</span>
<%end%> <%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. # 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| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -325,16 +325,14 @@ ActiveRecord::Schema.define(:version => 20161019020422) do
add_index "changeset_parents", ["parent_id"], :name => "changeset_parents_parent_ids" add_index "changeset_parents", ["parent_id"], :name => "changeset_parents_parent_ids"
create_table "changesets", :force => true do |t| create_table "changesets", :force => true do |t|
t.integer "repository_id", :null => false t.integer "repository_id", :null => false
t.string "revision", :null => false t.string "revision", :null => false
t.string "committer" t.string "committer"
t.datetime "committed_on", :null => false t.datetime "committed_on", :null => false
t.text "comments" t.text "comments"
t.date "commit_date" t.date "commit_date"
t.string "scmid" t.string "scmid"
t.integer "user_id" t.integer "user_id"
t.integer "project_id"
t.integer "type", :default => 0
end end
add_index "changesets", ["committed_on"], :name => "index_changesets_on_committed_on" 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 t.datetime "updated_at", :null => false
end end
create_table "innodb_monitor", :id => false, :force => true do |t|
t.integer "a"
end
create_table "invite_lists", :force => true do |t| create_table "invite_lists", :force => true do |t|
t.integer "project_id" t.integer "project_id"
t.integer "user_id" t.integer "user_id"
@ -1462,9 +1456,11 @@ ActiveRecord::Schema.define(:version => 20161019020422) do
t.integer "question_type" t.integer "question_type"
t.integer "is_necessary" t.integer "is_necessary"
t.integer "poll_id" t.integer "poll_id"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.integer "question_number" t.integer "question_number"
t.integer "max_choices", :default => 0
t.integer "min_choices", :default => 0
end end
create_table "poll_users", :force => true do |t| 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 "board_num", :default => 0
t.integer "attach_num", :default => 0 t.integer "attach_num", :default => 0
t.datetime "commit_time" t.datetime "commit_time"
t.integer "pull_request_num", :default => 0
end end
create_table "project_statuses", :force => true do |t| create_table "project_statuses", :force => true do |t|