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 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]
@ -19,8 +19,8 @@ class PollController < ApplicationController
def show def show
@poll = Poll.find params[:id] @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| respond_to do |format|
format.html {render :layout => 'base_courses'} format.html {render :layout => 'base_courses'}
end end
@ -54,7 +54,9 @@ class PollController < ApplicationController
end end
def edit def edit
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
end end
def update def update
@ -83,8 +85,30 @@ class PollController < ApplicationController
end 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 end
private private

View File

@ -3,7 +3,7 @@ class Poll < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :user 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 :poll_users, :dependent => :destroy
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
end end

View File

@ -3,6 +3,6 @@ class PollQuestion < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :poll 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 has_many :poll_votes, :dependent => :destroy
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 class="ur_editor radio"> <div>
<div class="ur_editor_title"> <!--编辑单选start-->
<label >问题:&nbsp;&nbsp;</label> <div class="ur_editor radio">
<input class="ur_question_title" type="text" name="title" placeholder="请输入单选题标题"/> <div class="ur_editor_title">
<input type="checkbox" name="required" value="true" checked=""/> <label>问题:&nbsp;&nbsp;</label>
<label >必答</label> <input type="hidden" name="question_type" value="1"/>
</div> <input class="ur_question_title" type="text" name="poll_questions_title" placeholder="请输入单选题标题"/>
<div class="ur_editor_content"> <input type="checkbox" name="is_necessary" value="true" checked/>
<ul> <label>必答</label>
<li class="ur_item"> </div>
<label >选项 <span class="ur_index">01</span> </label> <div class="ur_editor_content">
<input type="text" name="option" placeholder="新建选项"/> <ul>
<a class="icon_add" title="向下插入选项"></a> <li class='ur_item'>
<a class="icon_remove" title="删除"></a> <label>选项<span class='ur_index'></span></label>
</li> <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="$(this).parent().parent().parent().parent().remove();">取消</a>
</div>
<div class="cl"></div> <div class="cl"></div>
<li class="ur_item"> </div>
<label >选项 <span class="ur_index">01</span> </label> <!--编辑单选 end-->
<input type="text" name="option" placeholder="新建选项"/>
<a class="icon_add" title="向下插入选项"></a>
<a class="icon_remove" title="删除"></a>
</li>
<div class="cl"></div>
</ul>
</div> </div>
<div class="ur_editor_footer"> <% end%>
<a class="btn btn_dark btn_submit" data-button="ok">确定</a>
<a class="btn btn_light btn_cancel" data-button="cancel">取消</a>
</div>
<div class="cl"></div>
</div>
</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_question_item radio ur_editor02">
<div class="ur_title"> <div class="ur_title">
<span class="title_index"> <span class="title_index">
第<%= question_index%>题: 第<%= poll_question.question_number%>题:
</span> </span>
<%= poll_questions.question_title%> <%= poll_question.question_title %>
<span class="ur_required" title="必答">*</span> <%if poll_question.is_necessary == 1%>
<span class="ur_required" title="必答">*</span>
<%end%>
</div> </div>
<a href="#" class="ur_icon_de" title="删除"></a> <a href="#" class="ur_icon_de" title="删除"></a>
<a href="#" class="ur_icon_edit" title="编辑"></a> <a href="#" class="ur_icon_edit" title="编辑"></a>
@ -12,24 +15,16 @@
<div class="ur_inputs"> <div class="ur_inputs">
<table class="ur_table" > <table class="ur_table" >
<tbody> <tbody>
<tr> <% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %>
<td> <tr>
<label > <td>
<input class="ur_radio" type="radio" value="新建选项" > <label>
新建选项 <input class="ur_radio" type="radio" name="<%= poll_question %>" value="<%= poll_answer.answer_text%>" >
</label> <%= poll_answer.answer_text%>
</td> </label>
</tr> </td>
<tr > </tr>
<td> <% end %>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
</td>
</tr>
<tr>
<td>
<label ><input class="ur_radio" type="radio" value="新建选项" > 新建选项</label>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </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"> <%= render :partial => 'poll_form'%>
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%>

View File

@ -26,6 +26,11 @@
method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml20 mr10") %> method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml20 mr10") %>
<% end%> <% end%>
</li> </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"> <li class="polls_date fr">
<%= format_time poll.created_at%> <%= format_time poll.created_at%>
</li> </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"> <%= render :partial => 'poll_form'%>
<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>

View File

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

View File

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

View File

@ -61,7 +61,7 @@ RedmineApp::Application.routes.draw do
resources :poll do resources :poll do
member do member do
get 'statistics_result' get 'statistics_result'
get 'add_mc' post 'create_poll_question'
end end
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

@ -815,8 +815,9 @@ ActiveRecord::Schema.define(:version => 20150112090810) 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"
end end
create_table "poll_users", :force => true do |t| 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 .fl{ float: left;}
#polls .fr{ float:right;} #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_content{ width:615px;}
.polls_head{ width:677px; height:48px; background:#eaeaea;} .polls_head{ width:677px; height:48px; background:#eaeaea;}