Conflicts:
	config/routes.rb
This commit is contained in:
z9hang 2015-01-15 09:42:41 +08:00
commit 8dab2057a9
13 changed files with 193 additions and 140 deletions

View File

@ -1,5 +1,5 @@
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 :is_member_of_course, :only => [:index,:show]
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy]
@ -54,7 +54,9 @@ class PollController < ApplicationController
end
def edit
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
end
def update
@ -82,8 +84,30 @@ class PollController < ApplicationController
end
#添加单选题
def add_mc
def create_poll_question
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,
:question_number => @poll.poll_questions.count + 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
#提交答案

View File

@ -1,33 +1,45 @@
<div><!--编辑单选start-->
<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>
<div>
<!--编辑单选start-->
<div class="ur_editor radio">
<div class="ur_editor_title">
<label >问题:&nbsp;&nbsp;</label>
<input class="ur_question_title" type="text" name="title" placeholder="请输入单选题标题"/>
<input type="checkbox" name="required" value="true" checked=""/>
<label >必答</label>
<label>问题:&nbsp;&nbsp;</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">01</span> </label>
<input type="text" name="option" placeholder="新建选项"/>
<a class="icon_add" title="向下插入选项"></a>
<a class="icon_remove" title="删除"></a>
<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">01</span> </label>
<input type="text" name="option" placeholder="新建选项"/>
<a class="icon_add" title="向下插入选项"></a>
<a class="icon_remove" title="删除"></a>
<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>
<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">确定</a>
<a class="btn btn_light btn_cancel" data-button="cancel">取消</a>
<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="$(this).parent().parent().parent().parent().remove();">取消</a>
</div>
<div class="cl"></div>
</div>
</div><!--编辑单选 end-->
<!--编辑单选 end-->
</div>
<% end%>

View File

@ -0,0 +1,83 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问卷调查_问卷编辑</title>
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<script type="text/javascript">
function add_MC(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_MC') %>");}
function add_MCQ(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_MCQ') %>");}
function add_single(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_single') %>");}
function add_mulit(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_mulit') %>");}
//单选题
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["+(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)
{
if(doc.parent().siblings("li").length == 0)
{
doc.parent().parent().parent().parent().parent().parent().remove();
}
else
{
doc.parent().remove();
}
}
</script>
</head>
<body>
<div class=" polls_content polls_edit" id="polls">
<div class="tabs_1">
<ul class="tabs_list">
<li class="tab_item02 " >
<a title="<%= l(:label_MC) %>" class="tab_icon icon_radio" onclick="add_MC();">
<%= l(:label_MC) %>
</a>
</li>
<li class="tab_item02 " >
<a title="<%= l(:label_MCQ) %>" class=" tab_icon icon_checkbox" onclick="add_MCQ();">
<%= l(:label_MCQ) %>
</a>
</li>
<li class="tab_item02 " >
<a title="<%= l(:label_single) %>" class="tab_icon icon_text" onclick="add_single();">
<%= l(:label_single) %>
</a>
</li>
<li class="tab_item02 " >
<a title="<%= l(:label_mulit)%>" class="tab_icon icon_textarea" onclick="add_mulit();">
<%= l(:label_mulit)%>
</a>
</li>
</ul>
<div class="cl"></div>
</div><!--选项 end-->
<%= render :partial => 'edit_head'%>
<div>
<% @poll.poll_questions.each do |poll_question|%>
<%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %>
<% end%>
</div>
<div id="poll_content">
<%#= render :partial => 'edit_MC'%>
</div>
<div class="ur_buttons">
<a href="#" class="ur_button_submit" >
<%= l(:label_memo_create)%>
</a>
</div>
<div class="cl"></div>
</div><!--编辑end-->
</body>
</html>

View File

@ -1,10 +1,13 @@
<div class="ur_question_item radio ur_editor02">
<div class="ur_title">
<span class="title_index">
第<%= question_index%>题:
第<%= poll_question.question_number%>题:
</span>
<%= poll_questions.question_title%>
<%= poll_question.question_title %>
<%if poll_question.is_necessary == 1%>
<span class="ur_required" title="必答">*</span>
<%end%>
</div>
<a href="#" class="ur_icon_de" title="删除"></a>
<a href="#" class="ur_icon_edit" title="编辑"></a>
@ -12,24 +15,16 @@
<div class="ur_inputs">
<table class="ur_table" >
<tbody>
<% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %>
<tr>
<td>
<label >
<input class="ur_radio" type="radio" value="新建选项" >
新建选项
<label>
<input class="ur_radio" type="radio" name="<%= poll_question %>" value="<%= poll_answer.answer_text%>" >
<%= poll_answer.answer_text%>
</label>
</td>
</tr>
<tr >
<td>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
</td>
</tr>
<tr>
<td>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>

View File

@ -0,0 +1,8 @@
<div class="ur_page_head ur_editor02" ><!--头部显示 start-->
<h1 class="ur_page_title">标题标题标题标题标题标题标题</h1>
<p class="ur_prefix_content">描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述
描述描述描述描述描述描述描述描述描述描述描述描述
</p>
<a href="#" class="ur_icon_edit" title="编辑"></a>
<div class="cl"></div>
</div><!--头部显示 end-->

View File

@ -1,13 +1,2 @@
<script type="text/javascript">
function submit_poll_edit()
{
$('#edit_poll_<%= @poll.id%>').submit();
}
</script>
<%= form_for(@poll) do |f|%>
<%= f.text_field :polls_name, :required => true, :name => "polls_name"%>
<a href="#" class="tijiao" onclick="submit_poll_edit();">
<%= l(:label_button_ok) %>
</a>
<% end%>
<%= render :partial => 'poll_form'%>

View File

@ -26,6 +26,11 @@
method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml20 mr10") %>
<% end%>
</li>
<li>
<% if @is_teacher%>
<%= link_to l(:button_edit), edit_poll_path(poll.id), :class => "polls_de fr ml20"%>
<% end%>
</li>
<li class="polls_date fr">
<%= format_time poll.created_at%>
</li>

View File

@ -1,59 +1 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问卷调查_问卷编辑</title>
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<script type="text/javascript">
function add_MC(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_MC') %>");}
function add_MCQ(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_MCQ') %>");}
function add_single(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_single') %>");}
function add_mulit(){$("#poll_content").append("<%= escape_javascript(render :partial => 'edit_mulit') %>");}
</script>
</head>
<body>
<div class=" polls_content polls_edit" id="polls">
<div class="tabs_1">
<ul class="tabs_list">
<li class="tab_item02 " >
<a title="<%= l(:label_MC) %>" class="tab_icon icon_radio" onclick="add_MC();">
<%= l(:label_MC) %>
</a>
</li>
<li class="tab_item02 " >
<a title="<%= l(:label_MCQ) %>" class=" tab_icon icon_checkbox" onclick="add_MCQ();">
<%= l(:label_MCQ) %>
</a>
</li>
<li class="tab_item02 " >
<a title="<%= l(:label_single) %>" class="tab_icon icon_text" onclick="add_single();">
<%= l(:label_single) %>
</a>
</li>
<li class="tab_item02 " >
<a title="<%= l(:label_mulit)%>" class="tab_icon icon_textarea" onclick="add_mulit();">
<%= l(:label_mulit)%>
</a>
</li>
</ul>
<div class="cl"></div>
</div><!--选项 end-->
<%= render :partial => 'edit_head'%>
<div id="poll_content">
</div>
<div class="ur_buttons">
<a href="#" class="ur_button_submit" >
<%= l(:label_memo_create)%>
</a>
</div>
<div class="cl"></div>
</div><!--编辑end-->
</body>
</html>
<%= render :partial => 'poll_form'%>

View File

@ -2249,5 +2249,7 @@ zh:
label_MCQ: 多选题
label_single: 单行文字
label_mulit: 多行文字
label_enter_single_title: 请输入单选题标题
label_new_answer: 新建选项

View File

@ -61,8 +61,8 @@ RedmineApp::Application.routes.draw do
resources :poll do
member do
get 'statistics_result'
get 'add_mc'
post 'commit_answer'
post 'create_poll_question'
end
end

View File

@ -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"], :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|
t.integer "project_id", :null => false
t.integer "user_id", :null => false

View File

@ -13,6 +13,11 @@ div,html,img,ul,li,p,body,h1,h2,h3,h4,p,a,table,tr,td,fieldset,input,span{ margi
#polls .fl{ float: left;}
#polls .fr{ float:right;}
/*问卷按钮*/
.polls_btn{ height:33px;border-top:1px solid #15bed1; border-bottom:1px solid #15bed1;border-right:1px solid #cee6e6; width:225px; padding:7px 0 0 15px; }
.polls_btn a{font-size:14px; color:#444444;font-weight:bold;}
.polls_btn span{ color:#15bed1; font-size:12px; font-weight:normal;}
/*问卷列表*/
.polls_content{ width:615px;}
.polls_head{ width:677px; height:48px; background:#eaeaea;}