65 lines
4.1 KiB
JavaScript
65 lines
4.1 KiB
JavaScript
function add_MC(){
|
||
var now = new Date().getTime();
|
||
$("#poll_content").append("<div id='new_poll_question_" + now + "'>"+
|
||
"<form accept-charset='UTF-8' action='/poll/2/create_poll_question' class='new_poll_question' data-remote='true' id='new_poll_question' method='post'>"+
|
||
"<div>" +
|
||
"<div class='ur_editor radio'>" +
|
||
"<div class='ur_editor_title'>" +
|
||
"<label>问题: </label>" +
|
||
"<input type='hidden' name='question_type' value='1'/>" +
|
||
"<input class='ur_question_title' type='text' name='poll_questions_title' placeholder='请输入单选题标题'/>" +
|
||
"<input type='checkbox' name='is_necessary' value='true' checked/>" +
|
||
"<label>必答</label>" +
|
||
"</div>" +
|
||
"<div class='ur_editor_content'>" +
|
||
"<ul>" +
|
||
"<li class='ur_item'>" +
|
||
"<label>选项<span class='ur_index'></span>:</label>" +
|
||
"<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>" +
|
||
"<li class='ur_item'>" +
|
||
"<label>选项<span class='ur_index'></span>:</label>" +
|
||
"<input type='text' name='question_answer[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>" +
|
||
"<li class='ur_item'>" +
|
||
"<label>选项<span class='ur_index'></span>:</label>" +
|
||
"<input type='text' name='question_answer[2]' 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>" +
|
||
"</div>" +
|
||
"<div class='ur_editor_footer'>" +
|
||
"<a class='btn btn_dark btn_submit' data-button='ok' onclick='$(this).parent().parent().parent().parent().submit();'>确定</a>" +
|
||
"<a class='btn btn_light btn_cancel' data-button='cancel' onclick='$("+ '"#new_poll_question_' + now + '"' +").remove();'>取消</a>" +
|
||
"</div>" +
|
||
"<div class='cl'></div>" +
|
||
"</div>" +
|
||
"</div>" +
|
||
"</form>" +
|
||
"</div>");
|
||
}
|
||
function add_MCQ(){$("#poll_content").append("<%= escape_javascript(render :partial => 'new_MCQ') %>");}
|
||
function add_single(){$("#poll_content").append("<%= escape_javascript(render :partial => 'new_single') %>");}
|
||
function add_mulit(){$("#poll_content").append("<%= escape_javascript(render :partial => 'new_mulit') %>");}
|
||
//问卷头
|
||
function pollsCancel(){$("#polls_head_edit").hide();$("#polls_head_show").show();}
|
||
function pollsEdit(){$("#polls_head_edit").show();$("#polls_head_show").hide();}
|
||
//单选题
|
||
function add_single_answer(doc)
|
||
{
|
||
doc.parent().after("<li class='ur_item'><label>选项<span class='ur_index'></span>:</label><input type='text' name='question_answer["+new Date().getTime()+"]' 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)
|
||
{
|
||
if(doc.parent().siblings("li").length == 0){doc.parent().parent().parent().parent().parent().parent().remove();}else{doc.parent().remove();}
|
||
} |