Conflicts:
	app/controllers/poll_controller.rb
This commit is contained in:
huang 2015-01-16 11:18:39 +08:00
commit eacc1079b0
28 changed files with 859 additions and 283 deletions

View File

@ -1,9 +1,9 @@
class PollController < ApplicationController
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question]
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer]
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]
include PollHelper
def index
if @course
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
@ -19,12 +19,18 @@ class PollController < ApplicationController
def show
@poll = Poll.find params[:id]
#已提交问卷的用户不能再访问该界面
if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
render_403
else
@can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin?
poll_questions = @poll.poll_questions
@poll_questions = paginateHelper poll_questions,3 #分页
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
end
end
def new
if @course
@ -60,12 +66,14 @@ class PollController < ApplicationController
end
def update
@poll.polls_name = params[:polls_name]
@poll.polls_name = params[:polls_name].empty? ? l(:label_poll_title) : params[:polls_name]
@poll.polls_description = params[:polls_description].empty? ? l(:label_poll_description) : params[:polls_description]
if @poll.save
respond_to do |format|
format.html { redirect_to poll_index_url(:polls_type => @course.class.to_s, :polls_group_id => @course.id) }
format.js
end
else
render_404
end
end
@ -79,10 +87,8 @@ class PollController < ApplicationController
def statistics_result
@poll = Poll.find(params[:id])
@offset, @limit = api_offset_and_limit({:limit => 10})
@poll_questions = @poll.poll_questions
@poll_questions_count = @poll_questions.count
@poll_questions_pages = Paginator.new @poll_questions_count, @limit, params['page']
poll_questions = @poll.poll_questions
@poll_questions = paginateHelper poll_questions,3 #分页
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
@ -96,11 +102,12 @@ class PollController < ApplicationController
@every_answer_count = poll_answer.poll_votes.count
end
#添加单选题
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,
:is_necessary => (params[:is_necessary]=="true" ? 1 : 0),
:question_title => question_title,
:question_type => params[:question_type] || 1,
:question_number => @poll.poll_questions.count + 1
@ -111,7 +118,7 @@ class PollController < ApplicationController
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]
:answer_text => answer
}
@poll_questions.poll_answers.new question_option
end
@ -123,6 +130,135 @@ class PollController < ApplicationController
end
end
#修改单选题
def update_poll_question
@poll_question = PollQuestion.find params[:poll_question]
@poll = @poll_question.poll
@poll_question.is_necessary = params[:is_necessary]=="true" ? 1 : 0
@poll_question.question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title]
################处理选项
if params[:question_answer]
@poll_question.poll_answers.each do |answer|
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
end
for i in 1..params[:question_answer].count
question = @poll_question.poll_answers.find_by_id params[:question_answer].keys[i-1]
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]
if question
question.answer_position = i
question.answer_text = answer
question.save
else
question_option = {
:answer_position => i,
:answer_text => answer
}
@poll_question.poll_answers.new question_option
end
end
end
@poll_question.save
respond_to do |format|
format.js
end
end
#删除单选题
def delete_poll_question
@poll_question = PollQuestion.find params[:poll_question]
@poll = @poll_question.poll
poll_questions = @poll.poll_questions.where("question_number > #{@poll_question.question_number}")
poll_questions.each do |question|
question.question_number -= 1
question.save
end
if @poll_question && @poll_question.destroy
respond_to do |format|
format.js
end
end
end
#提交答案
def commit_answer
pq = PollQuestion.find(params[:poll_question_id])
if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
render :text => 'failure'
return
end
if pq.question_type == 1
#单选题
pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id)
if pv.nil?
pv = PollVote.new
pv.user_id = User.current.id
pv.poll_question_id = params[:poll_question_id]
end
pv.poll_answer_id = params[:poll_answer_id]
if pv.save
render :text => "ok"
else
render :text => "failure"
end
elsif pq.question_type == 2
pv = PollVote.find_by_poll_answer_id_and_user_id(params[:poll_answer_id],User.current.id)
if pv.nil?
pv = PollVote.new
pv.user_id = User.current.id
pv.poll_question_id = params[:poll_question_id]
pv.poll_answer_id = params[:poll_answer_id]
if pv.save
render :text => "true"
else
render :text => "failure"
end
else
if pv.delete
render :text => "false"
else
render :text => "failure"
end
end
elsif pq.question_type == 3 || pq.question_type == 4
pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id)
if pv.nil?
pv = PollVote.new
pv.user_id = User.current.id
pv.poll_question_id = params[:poll_question_id]
end
pv.vote_text = params[:vote_text]
if pv.save
render :text => pv.vote_text
else
render :text => "failure"
end
else
render :text => "failure"
end
end
#提交问卷
def commit_poll
@uncomplete_question = get_uncomplete_question(@poll)
if @uncomplete_question.count < 1
pu = get_poll_user(@poll.id,User.current.id)
pu.user_id = User.current.id
pu.poll_id = @poll.id
if pu.save
#redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
@status = 0 #提交成功
else
@status = 2 #未知错误
end
else
@status = 1 #有未做得必答题
end
respond_to do |format|
format.js
end
end
private
def find_poll_and_course
@poll = Poll.find params[:id]
@ -152,4 +288,24 @@ class PollController < ApplicationController
render_403 unless(@course && User.current.allowed_to?(:as_teacher,@course))
end
#获取未完成的题目
def get_uncomplete_question poll
necessary_questions = poll.poll_questions.where("#{PollQuestion.table_name}.is_necessary = 1")
uncomplete_question = []
necessary_questions.each do |question|
if question.poll_votes.nil? || question.poll_votes.count < 1
uncomplete_question << question
end
end
uncomplete_question
end
#PollUser记录用户是否已提交问卷有对应的记录则已提交没有则新建一个
def get_poll_user poll_id,user_id
pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
if pu.nil?
pu = PollUser.new
end
pu
end
end

View File

@ -0,0 +1,50 @@
# encoding: utf-8
#
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module PollHelper
#判断选项是否被选中
def answer_be_selected?(answer,user)
pv = answer.poll_votes.where("#{PollVote.table_name}.user_id = #{user.id} ")
if !pv.nil? && pv.count > 0
true
else
false
end
end
#获取文本题答案
def get_anwser_vote_text(question_id,user_id)
pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id)
if pv.nil?
''
else
pv.vote_text
end
end
#判断用户是否已经提交了问卷
def has_commit_poll?(poll_id,user_id)
pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
if pu.nil?
false
else
true
end
end
end

View File

@ -0,0 +1,12 @@
<div id="popbox" style="text-align: center;margin-top: 25px">
<% if status == 0 %>
<h3 style="font-weight: normal;color: green">提交成功!</h3>
<%= link_to "确定", poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course'),:class => 'commit'%>
<% elsif status == 1 %>
<h3 style="font-weight: normal;color: red">您还有尚未作答的题目请完成后在提交!</h3>
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
<% else %>
<h3 style="font-weight: normal;color: red">发生未知错误,请检查您的网络。</h3>
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
<% end %>
</div>

View File

@ -1,45 +1,31 @@
<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>
<div>
<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
<!--编辑单选start-->
<div class="ur_editor radio">
<div class="ur_editor_title">
<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/>
<input type="hidden" name="question_type" value="<%= poll_question.question_type%>"/>
<input class="ur_question_title" type="text" name="poll_questions_title" id="poll_questions_title_<%=poll_question.id%>" placeholder="请输入单选题标题" value="<%= poll_question.question_title%>"/>
<input type="checkbox" name="is_necessary" value="true" <%= poll_question.is_necessary == 1 ? "checked" : ""%>/>
<label>必答</label>
</div>
<div class="ur_editor_content">
<ul>
<% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %>
<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='新建选项'/>
<input type='text' name='question_answer[<%= poll_answer.id %>]' placeholder='新建选项' value="<%= poll_answer.answer_text%>"/>
<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>
<% end%>
</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>
<a class="btn btn_dark btn_submit" data-button="ok" onclick="$(this).parent().parent().parent().submit();">确定</a>
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="pollQuestionCancel(<%= poll_question.id%>);">取消</a>
</div>
<div class="cl"></div>
</div>
<!--编辑单选 end-->
</div>
<% end%>

View File

@ -1,21 +1,15 @@
<script type="text/javascript">
function regexPollsTitle()
{
var polls_title = $.trim($("#polls_title").val());
alert(polls_title);
}
</script>
<%= form_for @poll,:remote => true do |f|%>
<div class="ur_editor ur_title_editor"> <!--编辑头部start-->
<div class="ur_title_editor_title">
<input type="text" name="title" id="polls_title" class="input_title" placeholder="问卷标题" onkeyup="regexPollsTitle();"/>
<input type="text" name="polls_name" id="polls_title" value="<%= @poll.polls_name %>" class="input_title" placeholder="问卷标题"/>
</div>
<div class="ur_title_editor_prefix">
<textarea name="prefix" class="textarea_editor" placeholder="问卷描述">
</textarea>
<textarea name="polls_description" id="polls_description" class="textarea_editor"><%= @poll.polls_description%></textarea>
</div>
<div class="ur_editor_footer">
<a class="btn_submit" data-button="ok">确定</a>
<a class="btn_cancel" data-button="cancel">取消</a>
<a class="btn_submit" data-button="ok" onclick="$(this).parent().parent().parent().submit();">确定</a>
<a class="btn_cancel" data-button="cancel" onclick="pollsCancel();">取消</a>
</div>
<div class="cl"></div>
</div><!--编辑头部 end-->
<% end%>

View File

@ -0,0 +1,45 @@
<%= 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 type="hidden" name="question_type" value="1"/>
<input class="ur_question_title" type="text" name="poll_questions_title" id="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="$(this).parent().parent().parent().parent().remove();">取消</a>
</div>
<div class="cl"></div>
</div>
<!--编辑单选 end-->
</div>
<% end%>

View File

@ -0,0 +1,33 @@
<div><!--编辑多选start-->
<div class="ur_editor checkbox">
<div class="ur_editor_title">
<label >问题:&nbsp;&nbsp;</label>
<input class="ur_question_title" type="text" name="poll_questions_title" id="poll_questions_title" placeholder="请输入多选题题标题"/>
<input type="checkbox" name="required" 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>
<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>
</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>
</div>
<div class="cl"></div>
</div>
</div><!--编辑多选 end-->

View File

@ -0,0 +1,18 @@
<div class="ur_editor textarea"> <!--编辑多行文字start-->
<div class="ur_editor_title">
<label for="ur_question_title">问题:&nbsp;&nbsp;</label>
<input id="poll_questions_title" class="ur_question_title" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入多行文字标题"/>
<input type="checkbox" name="required" value="true" id="ur_question_require" checked=""/>
<label for="ur_question_require">必答</label>
</div>
<div class="ur_editor_toolbar">
<label>尺寸:</label>
<label>宽 <input name="cols" type="number" min="1" value="60"> 字</label>,
<label>高 <input name="rows" type="number" min="1" value="5"> 行</label>
</div>
<div class="ur_editor_footer">
<a class="btn_submit" data-button="ok">确定</a>
<a class="btn_cancel" data-button="cancel">取消</a>
</div>
<div class="cl"></div>
</div><!--编辑多行文字end-->

View File

@ -0,0 +1,13 @@
<div class="ur_editor text "> <!--编辑单行文字start-->
<div class="ur_editor_title">
<label for="ur_question_title">问题:&nbsp;&nbsp;</label>
<input id="poll_questions_title" class="ur_question_title" contenteditable="true" type="text" name="title" placeholder="请输入单行文字标题"/>
<input type="checkbox" name="required" value="true" id="ur_question_require_2" checked=""/>
<label for="ur_question_require">必答</label>
</div>
<div class="ur_editor_footer">
<a class="btn_submit" data-button="ok">确定</a>
<a class="btn_cancel" data-button="cancel">取消</a>
</div>
<div class="cl"></div>
</div><!--编辑单行文字end-->

View File

@ -0,0 +1,10 @@
<% poll.poll_questions.each do |poll_question|%>
<div id="poll_questions_<%= poll_question.id%>">
<div id="show_poll_questions_<%= poll_question.id %>">
<%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %>
</div>
<div id="edit_poll_questions_<%= poll_question.id %>" style="display: none;">
<%= render :partial => 'edit_MC', :locals => {:poll_question => poll_question} %>
</div>
</div>
<% end %>

View File

@ -4,16 +4,42 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问卷调查_问卷编辑</title>
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<%#= javascript_include_tag "polls" %>
<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_MC(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MC') %>");
$("#poll_questions_title").focus();
}
function add_MCQ(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MCQ') %>");
$("#poll_questions_title").focus();
}
function add_single(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_single') %>");
$("#poll_questions_title").focus();
}
function add_mulit(){
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_mulit') %>");
$("#poll_questions_title").focus();
}
//问卷头
function pollsCancel(){$("#polls_head_edit").hide();$("#polls_head_show").show();}
function pollsEdit(){$("#polls_head_edit").show();$("#polls_head_show").hide();}
//
function pollQuestionCancel(question_id){
$("#show_poll_questions_"+question_id).show();
$("#edit_poll_questions_"+question_id).hide();
}
function pollQuestionEdit(question_id){
$("#show_poll_questions_"+question_id).hide();
$("#edit_poll_questions_"+question_id).show();
$("#poll_questions_title_"+question_id).focus();
}
//单选题
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='新建选项'/>" +
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>");
}
@ -21,7 +47,7 @@
{
if(doc.parent().siblings("li").length == 0)
{
doc.parent().parent().parent().parent().parent().parent().remove();
alert("选择题至少有一个选项");
}
else
{
@ -60,15 +86,21 @@
<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 id="polls_head_show">
<%= render :partial => 'show_head', :locals => {:poll => @poll}%>
</div>
<div id="polls_head_edit" style="display: none;">
<%= render :partial => 'edit_head', :locals => {:poll => @poll}%>
</div>
<!-- 问题 -->
<div id="poll_content">
<%#= render :partial => 'edit_MC'%>
<%= render :partial => 'poll_content', :locals => {:poll => @poll}%>
</div>
<!-- 新增问题 -->
<div id="new_poll_question">
</div>
<div class="ur_buttons">

View File

@ -0,0 +1,12 @@
<tbody>
<% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %>
<tr>
<td>
<label>
<input class="ur_radio" type="radio" name="<%= poll_question %>" value="<%= poll_answer.answer_text%>" >
<%= poll_answer.answer_text%>
</label>
</td>
</tr>
<% end %>
</tbody>

View File

@ -9,8 +9,9 @@
<%end%>
</div>
<a href="#" class="ur_icon_de" title="删除"></a>
<a href="#" class="ur_icon_edit" title="编辑"></a>
<%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id),
method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %>
<a class="ur_icon_edit" title="编辑" onclick="pollQuestionEdit(<%= poll_question.id%>);"></a>
<div class="cl"></div>
<div class="ur_inputs">
<table class="ur_table" >

View File

@ -1,8 +1,10 @@
<div class="ur_page_head ur_editor02"><!--头部显示 start-->
<h1 class="ur_page_title">标题标题标题标题标题标题标题</h1>
<p class="ur_prefix_content">描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述
描述描述描述描述描述描述描述描述描述描述描述描述
<a href="#" class="ur_icon_edit" title="编辑" onclick="pollsEdit();"></a>
<h1 class="ur_page_title" id="polls_name_h">
<%= poll.polls_name%>
</h1>
<p class="ur_prefix_content" id="polls_description_p">
<%= @poll.polls_description%>
</p>
<a href="#" class="ur_icon_edit" title="编辑"></a>
<div class="cl"></div>
</div><!--头部显示 end-->

View File

@ -0,0 +1,3 @@
<% if @pv_saved %>
$('#poll_vote_poll_answer_id_<%= @pv.poll_answer_id %>').checked = true;
<% end %>

View File

@ -0,0 +1,9 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status}) %>');
showModal('ajax-modal', '400px');
$('#ajax-modal').css('height','100px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<span style='float: right;cursor:pointer;'>" +
"<a href='#' onclick='hidden_atert_form();'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
$('#ajax-modal').parent().removeClass("alert_praise");
$('#ajax-modal').parent().css("top","").css("left","");
$('#ajax-modal').parent().addClass("alert_box");

View File

@ -0,0 +1,10 @@
$("#new_poll_question").html("");
$("#poll_content").append("<div id='poll_questions_<%= @poll_questions.id%>'>" +
"<div id='show_poll_questions_<%= @poll_questions.id %>'>" +
"<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_questions}) %>" +
"</div>" +
"<div id='edit_poll_questions_<%= @poll_questions.id %>' style='display: none;'>" +
"<%= escape_javascript(render :partial => 'edit_MC', :locals => {:poll_question => @poll_questions}) %>" +
"</div>" +
"</div>");

View File

@ -0,0 +1 @@
$("#poll_content").html("<%= escape_javascript(render :partial => 'poll_content', :locals => {:poll => @poll}) %>");

View File

@ -13,7 +13,11 @@
<% @polls.each do |poll|%>
<ul id="polls_<%= poll.id %>">
<li>
<% if has_commit_poll?(poll.id ,User.current) %>
<sapn class="polls_title fl"> <%= poll.polls_name %></sapn>
<% else %>
<%= link_to poll.polls_name, poll_path(poll.id), :class => "polls_title fl" %>
<% end %>
</li>
<li>
<%if @is_teacher%>

View File

@ -4,6 +4,27 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问卷调查_问卷页面</title>
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<style type="text/css">
.alert_box{width:480px;height:180px;position:fixed;z-index:100;left:55%;top:50%;margin:-215px 0 0 -300px; background:#fff; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; box-shadow:0px 0px 8px #194a81; overflow:auto;}
.commit{
height: 28px;
display: block;
width: 80px;
color: #fff !important;
background: #15bccf;
text-align: center;
padding-top: 4px;
margin-left: 130px;
margin-top: 4px;
margin-right: 10px;
}
</style>
<script type="text/javascript">
function hidden_atert_form(cur_page,cur_type)
{
hideModal($("#popbox"));
}
</script>
</head>
<body>
@ -33,13 +54,30 @@
</div>
<div class="cl"></div>
<div class="ur_inputs">
<form>
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label >
<input class="ur_radio" type="radio" value="新建选项" >
<script>
function click_<%= pa.id %>(obj)
{
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_answer_id: <%= pa.id %>,
poll_question_id: <%= pq.id %>
},
success: function (data) {
obj.checked = true;
}
});
}
</script>
<%= radio_button "poll_vote","poll_answer_id",pa.id,:class=>"ur_radio",:onclick =>"click_#{pa.id}(this);return false;",:checked => answer_be_selected?(pa,User.current),:disabled => !@can_edit_poll %>
<%= pa.answer_text %>
</label>
</td>
@ -47,6 +85,7 @@
<% end %>
</tbody>
</table>
</form>
</div>
</li>
<% elsif pq.question_type == 2 %>
@ -61,13 +100,37 @@
</div>
<div class="cl"></div>
<div class="ur_inputs">
<form>
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label >
<input class="ur_checkbox" type="checkbox" value="新建选项" >
<script>
function click_<%= pa.id %>(obj)
{
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_answer_id: <%= pa.id %>,
poll_question_id: <%= pq.id %>
},
success: function (data) {
if(data == "true")
{
obj.checked = true;
}
else
{
obj.checked = false;
}
}
});
}
</script>
<input class="ur_checkbox" type="checkbox" onclick="click_<%= pa.id %>(this);return false;" <%= answer_be_selected?(pa,User.current) ? "checked":"" %> <%= @can_edit_poll?"":"disabled=disabled" %> >
<%= pa.answer_text %>
</label>
</td>
@ -75,6 +138,7 @@
<% end %>
</tbody>
</table>
</form>
</div>
</li>
<% elsif pq.question_type == 3 %>
@ -89,9 +153,27 @@
</div>
<div class="cl"></div>
<div class="ur_inputs">
<input class="ur_text ur_textbox" type="text" size="" maxlength=""value="">
<script>
function onblur_<%= pq.id %>(obj)
{
$(window).unbind('beforeunload');
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_question_id: <%= pq.id %> ,
vote_text: obj.value
},
success: function (data) {
// obj.value = data;
}
});
}
</script>
<input class="ur_text ur_textbox" type="text" size="" maxlength="" value="<%= get_anwser_vote_text(pq.id,User.current.id) %>" onblur="onblur_<%= pq.id %>(this);" <%= @can_edit_poll?"":"disabled=disabled" %>>
</div>
</li><!--当行输入 end-->
</li><!--行输入 end-->
<% elsif pq.question_type == 4 %>
<!-- 多行文字-->
<li class="ur_question_item textarea">
@ -105,7 +187,23 @@
</div>
<div class="cl"></div>
<div class="ur_inputs">
<textarea class="ur_textbox" rows="5" cols="60"></textarea>
<script>
function onblur_<%= pq.id %>(obj)
{
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_question_id: <%= pq.id %> ,
vote_text: obj.innerHTML
},
success: function (data) {
// obj.value = data;
}
});
}
</script>
<div contenteditable='<%= @can_edit_poll %>' class="ur_textbox" style="min-height: 150px;width: 100%;<%= @can_edit_poll?"":"background-color:#DCDCDC;" %>" onblur="onblur_<%= pq.id %>(this);"><%= get_anwser_vote_text(pq.id,User.current.id) %></div>
</div>
</div>
</li><!--多行输入 end-->
@ -119,7 +217,7 @@
</ul>
<div class="cl"></div>
<div class="ur_buttons" style="width: 100px;">
<a href="#" class="ur_button" >提交</a>
<%= link_to "提交",commit_poll_poll_path(@poll), :method => :post,:class => "ur_button",:format => 'js',:remote=>true %>
</div>
<div class="cl"></div>
<div class="ur_progress_text">答题已完成 <strong class="ur_progress_number">0%</strong> </div>

View File

@ -22,10 +22,11 @@
<%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %>
</li>
</ol>
<div class="pagination">
<%= pagination_links_full @poll_questions_pages, @poll_questions_count %>
</div>
<% end %>
<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">
<!--<a href="#" class=" ur_button" >上一页</a>-->
<!--<a href="#" class="ur_button" >下一页</a>-->

View File

@ -0,0 +1,6 @@
$("#polls_title").val("<%= @poll.polls_name%>");
$("#polls_description").val("<%= @poll.polls_description %>");
$("#polls_name_h").html("<%= @poll.polls_name %>");
$("#polls_description_p").html("<%= @poll.polls_description %>");
$("#polls_head_edit").hide();
$("#polls_head_show").show();

View File

@ -0,0 +1,6 @@
$("#poll_questions_<%= @poll_question.id%>").html("<div id='show_poll_questions_<%= @poll_question.id %>'>" +
"<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_question}) %>" +
"</div>" +
"<div id='edit_poll_questions_<%= @poll_question.id %>' style='display: none;'>" +
"<%= escape_javascript(render :partial => 'edit_MC', :locals => {:poll_question => @poll_question}) %>" +
"</div>");

View File

@ -2251,5 +2251,7 @@ zh:
label_mulit: 多行文字
label_enter_single_title: 请输入单选题标题
label_new_answer: 新建选项
label_poll_title: 问卷标题
label_poll_description: 问卷描述

View File

@ -61,7 +61,13 @@ RedmineApp::Application.routes.draw do
resources :poll do
member do
get 'statistics_result'
post 'commit_answer'
post 'create_poll_question'
post 'commit_poll'
end
collection do
delete 'delete_poll_question'
post 'update_poll_question'
end
end

View File

@ -0,0 +1,65 @@
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>问题:&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'></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();}
}

View File

@ -27,6 +27,7 @@ a.newbtn{ float:right; display:block; width:80px; height:30px; background:#64bdd
a:hover.newbtn{ background:#55a1b9; text-decoration:none;}
.polls_list ul{ padding-left:10px; border-bottom:1px dashed #c9c9c9; height:32px; padding-top:8px;}
a.polls_title{ font-weight:bold; color:#3e6d8e;}
.polls_title{ font-weight:bold; color:#3e6d8e;}
a.pollsbtn{ display:block; width:66px; height:22px; text-align:center; border:1px solid #64bdd9; color:#64bdd9;}
a:hover.pollsbtn{ background:#64bdd9; color:#fff; text-decoration:none;}
.polls_date{ color:#666666;}