AutoCommit Sam Aug 1 22:03:01 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-08-01 22:03:01 +02:00
parent 2a7ae7c2bf
commit 2b01a87d15
9 changed files with 25 additions and 10 deletions

View File

@@ -18,15 +18,19 @@ class Survey::ChoicesController < ApplicationController
respond_to do |format|
format.html {redirect_to @survey_choice.question}
format.json { render json: @survey_choice }
format.js
end
end
# GET /survey/choices/new
# GET /survey/choices/new.json
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|
format.js
format.html # new.html.erb
format.json { render json: @survey_choice }
end
@@ -43,13 +47,16 @@ class Survey::ChoicesController < ApplicationController
# POST /survey/choices
# POST /survey/choices.json
include PluginsHelper
def create
@survey_choice = Survey::Choice.new(params[:survey_choice])
@divid = divid_for(@survey_choice)
respond_to do |format|
if @survey_choice.save
format.html { redirect_to @survey_choice, notice: 'Choice was successfully created.' }
format.json { render json: @survey_choice, status: :created, location: @survey_choice }
format.js
else
format.html { render action: "new" }
format.json { render json: @survey_choice.errors, status: :unprocessable_entity }

View File

@@ -20,7 +20,10 @@ class Survey::QuestionsController < ApplicationController
end
@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
# GET /survey/questions/1
# GET /survey/questions/1.json

View File

@@ -1,6 +1,6 @@
class Survey::Choice < ActiveRecord::Base
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'
include ActionView::Helpers::TagHelper
mount_uploader :picture, PictureUploader

View File

@@ -7,7 +7,7 @@ if current_user.nil?
else
value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0
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
%>

View File

@@ -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.input :text %>
<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 :question %>
<%= f.input :picture, as: :uploader %>
<%= f.hidden_field :picture_cache %>
@@ -45,3 +46,4 @@ $("#openselect").on('click', function(){$('#dialog').dialog('open')});
</p>
</div>
<% end %>

View File

@@ -0,0 +1 @@
$('#<%= @divid %>').replaceWith("<%= escape_javascript(render @survey_choice) %>")

View File

@@ -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>")

View File

@@ -0,0 +1 @@
$('#<%= divid_for(@survey_choice) %>').replaceWith("<%= escape_javascript(render @survey_choice) %>")

View File

@@ -3,15 +3,16 @@
<%= render partial: "survey/questions/answeredquestion", object: question %>
<% end %>
<% else %>
<div class="contentbox" id="<%= divid_for(question)%>" style="">
<div class="contentbox" id ="<%= divid_for(question) %>" style="">
<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">
<ul class="choice-list">
<% question.choices.each do |c| %>
<li><%= render c %></li>
<% end %>
</ul>
<%= link_to "+" , new_survey_choice_path(params:{question_id: question.id}), remote: true%>
</div>
<%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0%>