增加新建单选题功能
This commit is contained in:
parent
2af6121f82
commit
0433f7c87f
|
@ -1,5 +1,5 @@
|
||||||
class PollController < ApplicationController
|
class PollController < ApplicationController
|
||||||
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result]
|
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question]
|
||||||
before_filter :find_container, :only => [:new,:create, :index]
|
before_filter :find_container, :only => [:new,:create, :index]
|
||||||
before_filter :is_member_of_course, :only => [:index,:show]
|
before_filter :is_member_of_course, :only => [:index,:show]
|
||||||
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy]
|
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy]
|
||||||
|
@ -85,7 +85,28 @@ class PollController < ApplicationController
|
||||||
|
|
||||||
#添加单选题
|
#添加单选题
|
||||||
def create_poll_question
|
def create_poll_question
|
||||||
a = 1
|
question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
|
||||||
|
option = {
|
||||||
|
:is_necessary => params[:is_necessary] || true,
|
||||||
|
:question_title => question_title,
|
||||||
|
:question_type => params[:question_type] || 1
|
||||||
|
}
|
||||||
|
@poll_questions = @poll.poll_questions.new option
|
||||||
|
if params[:question_answer]
|
||||||
|
for i in 1..params[:question_answer].count
|
||||||
|
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
|
||||||
|
question_option = {
|
||||||
|
:answer_position => i,
|
||||||
|
:answer_text => params[:question_answer].values[i-1]
|
||||||
|
}
|
||||||
|
@poll_questions.poll_answers.new question_option
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if @poll_questions.save
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -4,15 +4,20 @@
|
||||||
<div class="ur_editor radio">
|
<div class="ur_editor radio">
|
||||||
<div class="ur_editor_title">
|
<div class="ur_editor_title">
|
||||||
<label>问题: </label>
|
<label>问题: </label>
|
||||||
|
<input type="hidden" name="question_type" value="1"/>
|
||||||
<input class="ur_question_title" type="text" name="poll_questions_title" placeholder="请输入单选题标题"/>
|
<input class="ur_question_title" type="text" name="poll_questions_title" placeholder="请输入单选题标题"/>
|
||||||
<input type="checkbox" name="is_necessary" value="true" checked/>
|
<input type="checkbox" name="is_necessary" value="true" checked/>
|
||||||
<label>必答</label>
|
<label>必答</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="ur_editor_content">
|
<div class="ur_editor_content">
|
||||||
<ul>
|
<ul>
|
||||||
<%= render :partial => 'question_answer'%>
|
<li class='ur_item'>
|
||||||
<%= render :partial => 'question_answer'%>
|
<label>选项<span class='ur_index'></span>:</label>
|
||||||
<%= render :partial => 'question_answer'%>
|
<input type='text' name='question_answer[0]' placeholder='新建选项'/>
|
||||||
|
<a class='icon_add' title='向下插入选项' onclick='add_single_answer($(this));'></a>
|
||||||
|
<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>
|
||||||
|
</li>
|
||||||
|
<div class='cl'></div>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="ur_editor_footer">
|
<div class="ur_editor_footer">
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
//单选题
|
//单选题
|
||||||
function add_single_answer(doc)
|
function add_single_answer(doc)
|
||||||
{
|
{
|
||||||
doc.parent().after("<%= escape_javascript(render :partial => 'question_answer') %>");
|
doc.parent().after("<li class='ur_item'><label>选项<span class='ur_index'></span>:</label><input type='text' name='question_answer["+(doc.parent().siblings("li").length + 1)+"]' placeholder='新建选项'/>" +
|
||||||
|
"<a class='icon_add' title='向下插入选项' onclick='add_single_answer($(this));'></a><a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>"+
|
||||||
|
"</li><div class='cl'></div>");
|
||||||
}
|
}
|
||||||
function remove_single_answer(doc)
|
function remove_single_answer(doc)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2249,5 +2249,7 @@ zh:
|
||||||
label_MCQ: 多选题
|
label_MCQ: 多选题
|
||||||
label_single: 单行文字
|
label_single: 单行文字
|
||||||
label_mulit: 多行文字
|
label_mulit: 多行文字
|
||||||
|
label_enter_single_title: 请输入单选题标题
|
||||||
|
label_new_answer: 新建选项
|
||||||
|
|
||||||
|
|
||||||
|
|
12
db/schema.rb
12
db/schema.rb
|
@ -23,18 +23,6 @@ ActiveRecord::Schema.define(:version => 20150114022710) do
|
||||||
add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type"
|
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"
|
add_index "activities", ["user_id"], :name => "index_activities_on_user_id"
|
||||||
|
|
||||||
create_table "api_keys", :force => true do |t|
|
|
||||||
t.string "access_token"
|
|
||||||
t.datetime "expires_at"
|
|
||||||
t.integer "user_id"
|
|
||||||
t.boolean "active", :default => true
|
|
||||||
t.datetime "created_at", :null => false
|
|
||||||
t.datetime "updated_at", :null => false
|
|
||||||
end
|
|
||||||
|
|
||||||
add_index "api_keys", ["access_token"], :name => "index_api_keys_on_access_token"
|
|
||||||
add_index "api_keys", ["user_id"], :name => "index_api_keys_on_user_id"
|
|
||||||
|
|
||||||
create_table "applied_projects", :force => true do |t|
|
create_table "applied_projects", :force => true do |t|
|
||||||
t.integer "project_id", :null => false
|
t.integer "project_id", :null => false
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
|
|
Loading…
Reference in New Issue