AutoCommit Sam Aug 1 22:03:01 CEST 2015
This commit is contained in:
@@ -18,15 +18,19 @@ class Survey::ChoicesController < ApplicationController
|
|||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {redirect_to @survey_choice.question}
|
format.html {redirect_to @survey_choice.question}
|
||||||
format.json { render json: @survey_choice }
|
format.json { render json: @survey_choice }
|
||||||
|
format.js
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /survey/choices/new
|
# GET /survey/choices/new
|
||||||
# GET /survey/choices/new.json
|
# GET /survey/choices/new.json
|
||||||
def new
|
def new
|
||||||
@survey_choice = Survey::Choice.new
|
@question= Survey::Question.find(params[:question_id])
|
||||||
|
|
||||||
|
@choice=Survey::Choice.new
|
||||||
|
@choice.question=@question
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
format.json { render json: @survey_choice }
|
format.json { render json: @survey_choice }
|
||||||
end
|
end
|
||||||
@@ -43,13 +47,16 @@ class Survey::ChoicesController < ApplicationController
|
|||||||
|
|
||||||
# POST /survey/choices
|
# POST /survey/choices
|
||||||
# POST /survey/choices.json
|
# POST /survey/choices.json
|
||||||
|
include PluginsHelper
|
||||||
def create
|
def create
|
||||||
@survey_choice = Survey::Choice.new(params[:survey_choice])
|
@survey_choice = Survey::Choice.new(params[:survey_choice])
|
||||||
|
@divid = divid_for(@survey_choice)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @survey_choice.save
|
if @survey_choice.save
|
||||||
format.html { redirect_to @survey_choice, notice: 'Choice was successfully created.' }
|
format.html { redirect_to @survey_choice, notice: 'Choice was successfully created.' }
|
||||||
format.json { render json: @survey_choice, status: :created, location: @survey_choice }
|
format.json { render json: @survey_choice, status: :created, location: @survey_choice }
|
||||||
|
format.js
|
||||||
else
|
else
|
||||||
format.html { render action: "new" }
|
format.html { render action: "new" }
|
||||||
format.json { render json: @survey_choice.errors, status: :unprocessable_entity }
|
format.json { render json: @survey_choice.errors, status: :unprocessable_entity }
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ class Survey::QuestionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
@survey_question.do_answer(params[:survey_question][:selected],user)
|
@survey_question.do_answer(params[:survey_question][:selected],user)
|
||||||
render :show
|
respond_to do |format|
|
||||||
|
format.html { redirect_to action: :show}
|
||||||
|
format.js { render action: :show}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# GET /survey/questions/1
|
# GET /survey/questions/1
|
||||||
# GET /survey/questions/1.json
|
# GET /survey/questions/1.json
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Survey::Choice < ActiveRecord::Base
|
class Survey::Choice < ActiveRecord::Base
|
||||||
belongs_to :question, class_name: 'Survey::Question'
|
belongs_to :question, class_name: 'Survey::Question'
|
||||||
attr_accessible :picture, :sort, :text, :icon, :picture_cache, :remove_picture
|
attr_accessible :picture, :sort, :text, :icon, :picture_cache, :remove_picture, :question_id
|
||||||
has_many :answers, class_name: 'Survey::Answer'
|
has_many :answers, class_name: 'Survey::Answer'
|
||||||
include ActionView::Helpers::TagHelper
|
include ActionView::Helpers::TagHelper
|
||||||
mount_uploader :picture, PictureUploader
|
mount_uploader :picture, PictureUploader
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ if current_user.nil?
|
|||||||
else
|
else
|
||||||
value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0
|
value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0
|
||||||
cstyle=(value) ? "true" :"false"
|
cstyle=(value) ? "true" :"false"
|
||||||
t= link_to(raw("" + choice.html+ (( choice.picture.nil? || choice.picture.to_s.empty?) ? "":image_tag(choice.picture.thumb.url))), answer_survey_question_path(choice.question, params: {survey_question: {selected: [choice.id]}}),class: "choice-"+cstyle )
|
t= link_to(raw("" + choice.html+ (( choice.picture.nil? || choice.picture.to_s.empty?) ? "":image_tag(choice.picture.thumb.url))), answer_survey_question_path(choice.question, params: {survey_question: {selected: [choice.id]}}),class: "choice-"+cstyle,remote: true )
|
||||||
end
|
end
|
||||||
|
|
||||||
%>
|
%>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<%= semantic_form_for @choice do |f| %>
|
<%= div_tag_for(@choice) do %>
|
||||||
|
<%= semantic_form_for @choice, remote: true do |f| %>
|
||||||
<%= f.inputs do %>
|
<%= f.inputs do %>
|
||||||
<%= f.input :text %>
|
<%= f.input :text %>
|
||||||
<i id="icon" style="font-size:2em" class="<%= @choice.icon %>"></i><a href="#" id="openselect" onclick=""> Choose Icon</a>
|
<i id="icon" style="font-size:2em" class="<%= @choice.icon %>"></i><a href="#" id="openselect" onclick=""> Choose Icon</a>
|
||||||
|
|
||||||
<%= f.input :icon, :input_html=>{:id=>"iconfield"},:as=>:hidden %>
|
<%= f.input :icon, :input_html=>{:id=>"iconfield"},:as=>:hidden %>
|
||||||
|
<%= f.input :question %>
|
||||||
<%= f.input :picture, as: :uploader %>
|
<%= f.input :picture, as: :uploader %>
|
||||||
<%= f.hidden_field :picture_cache %>
|
<%= f.hidden_field :picture_cache %>
|
||||||
|
|
||||||
@@ -45,3 +46,4 @@ $("#openselect").on('click', function(){$('#dialog').dialog('open')});
|
|||||||
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|||||||
1
app/views/survey/choices/create.js.erb
Normal file
1
app/views/survey/choices/create.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$('#<%= @divid %>').replaceWith("<%= escape_javascript(render @survey_choice) %>")
|
||||||
@@ -1 +1 @@
|
|||||||
$('#<%= %>').find('ul.choice-list').append("<li><%= escape_javascript(render partial: "form", object:@choice) %></li>")
|
$('#<%= divid_for @question %>').find('ul.choice-list').append("<li><%= escape_javascript(render partial: "form", object:@choice) %></li>")
|
||||||
|
|||||||
1
app/views/survey/choices/show.js.erb
Normal file
1
app/views/survey/choices/show.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$('#<%= divid_for(@survey_choice) %>').replaceWith("<%= escape_javascript(render @survey_choice) %>")
|
||||||
@@ -5,13 +5,14 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<div class="contentbox" id ="<%= divid_for(question) %>" style="">
|
<div class="contentbox" id ="<%= divid_for(question) %>" style="">
|
||||||
<div class="contentbox">
|
<div class="contentbox">
|
||||||
<b><%= question.title%></b> <%=question.text%></div>
|
<b><%= question.title%></b> <%=question.text%><%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true%></div>
|
||||||
<div class="contentbox">
|
<div class="contentbox">
|
||||||
<ul class="choice-list">
|
<ul class="choice-list">
|
||||||
<% question.choices.each do |c| %>
|
<% question.choices.each do |c| %>
|
||||||
<li><%= render c %></li>
|
<li><%= render c %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
<%= link_to "+" , new_survey_choice_path(params:{question_id: question.id}), remote: true%>
|
||||||
</div>
|
</div>
|
||||||
<%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0%>
|
<%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0%>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user