Conflicts:
	db/schema.rb
This commit is contained in:
huang 2015-01-14 16:37:45 +08:00
commit 2b0775da26
17 changed files with 307 additions and 213 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]
@ -19,8 +19,8 @@ class PollController < ApplicationController
def show
@poll = Poll.find params[:id]
@poll_questions = @poll.poll_questions
poll_questions = @poll.poll_questions
@poll_questions = paginateHelper poll_questions,3 #分页
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
@ -54,7 +54,9 @@ class PollController < ApplicationController
end
def edit
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
end
def update
@ -83,8 +85,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
private

View File

@ -3,7 +3,7 @@ class Poll < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :user
has_many :poll_questions, :dependent => :destroy
has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number"
has_many :poll_users, :dependent => :destroy
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
end

View File

@ -3,6 +3,6 @@ class PollQuestion < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :poll
has_many :poll_answers, :dependent => :destroy
has_many :poll_answers, :order => "#{PollAnswer.table_name}.answer_position",:dependent => :destroy
has_many :poll_votes, :dependent => :destroy
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

@ -20,86 +20,105 @@
<div class="ur_card">
<ol class="ur_questions">
<% @poll_questions.each do |pq| %>
<% if pq.question_type == 1 %>
<!-- 单选题 -->
<li class="ur_question_item radio">
<div class="ur_title">
<span class="title_index">第1题</span> 单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题单选题 <span class="ur_required" title="必答">*</span>
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<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>
<tr>
<td>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
<label >
<input class="ur_radio" type="radio" value="新建选项" >
<%= pa.answer_text %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</li><!--单选题 end-->
</li>
<% elsif pq.question_type == 2 %>
<!-- 多选题 -->
<li class="ur_question_item checkbox">
<div class="ur_title">
<span class="title_index">第2题</span> 多选题 <span class="ur_required" title="必答">*</span>
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<table class="ur_table">
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label ><input class="ur_checkbox" type="checkbox" value="新建选项" > 新建选项 </label>
</td>
</tr>
<tr class="ur_tr_even">
<td>
<label ><input class="ur_checkbox" type="checkbox" value="新建选项" > 新建选项 </label>
</td>
</tr>
<tr>
<td>
<label ><input class="ur_checkbox" type="checkbox" value="新建选项" > 新建选项 </label>
<label >
<input class="ur_checkbox" type="checkbox" value="新建选项" >
<%= pa.answer_text %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</li><!--多选题 end-->
</li>
<% elsif pq.question_type == 3 %>
<!-- 单行文字-->
<li class="ur_question_item text">
<div class="ur_title">
<span class="title_index">第3题</span> 单行主观
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<input class="ur_text ur_textbox" type="text" size="" maxlength=""value="">
</div>
</li><!--当行输入 end-->
<% elsif pq.question_type == 4 %>
<!-- 多行文字-->
<li class="ur_question_item textarea">
<div class="ur_preview">
<div class="ur_title">
<span class="title_index">第4题</span> 多行主观
<span class="title_index">第<%= pq.question_number %>题:</span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<textarea class="ur_textbox" rows="5" cols="60"></textarea>
</div>
</div>
</li><!--多行输入 end-->
<% else %>
<!-- 未知题型 -->
<% end %>
<% end %>
</ol>
<div class="ur_buttons">
<a href="#" class=" ur_button" >下一页</a>
<ul class="wlist">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
</ul>
<div class="cl"></div>
<div class="ur_buttons" style="width: 100px;">
<a href="#" class="ur_button" >提交</a>
</div>
<div class="cl"></div>

View File

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

View File

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

View File

@ -0,0 +1,9 @@
class AddQuestionNumberToPollQuestions < ActiveRecord::Migration
def self.up
add_column :poll_questions, :question_number, :integer
end
def self.down
remove_column :poll_questions, :question_number
end
end

View File

@ -817,6 +817,7 @@ ActiveRecord::Schema.define(:version => 20150112090810) do
t.integer "poll_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "question_number"
end
create_table "poll_users", :force => true do |t|

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;}