From 48fc0455c739d3f1e2dd07935e62b75a8da4ba40 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Fri, 7 Feb 2014 22:15:05 +0100 Subject: [PATCH] =?UTF-8?q?themen=20fix=20+=20remote=20form=20f=C3=BCr=20t?= =?UTF-8?q?hemen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/fragen_controller.rb | 10 +++++++++- app/controllers/themen_controller.rb | 1 + app/controllers/themengruppen_controller.rb | 7 ++++--- app/views/fragen/_frage.html.erb | 2 +- app/views/fragen/_liste.html.erb | 3 +++ app/views/fragen/_rform.html.erb | 12 ++++++++++++ app/views/fragen/create.js.erb | 1 + app/views/themen/_small.html.erb | 8 +++++--- app/views/themen/show.html.erb | 9 +++++---- 9 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 app/views/fragen/_liste.html.erb create mode 100644 app/views/fragen/_rform.html.erb create mode 100644 app/views/fragen/create.js.erb diff --git a/app/controllers/fragen_controller.rb b/app/controllers/fragen_controller.rb index cac35da..8e0eddc 100644 --- a/app/controllers/fragen_controller.rb +++ b/app/controllers/fragen_controller.rb @@ -1,3 +1,4 @@ + class FragenController < ApplicationController # GET /fragen # GET /fragen.json @@ -42,14 +43,16 @@ class FragenController < ApplicationController # POST /fragen.json def create @frage = Frage.new(params[:frage]) - + @fragen=@frage.thema.fragen respond_to do |format| if @frage.save format.html { redirect_to @frage.thema, notice: 'Frage was successfully created.' } format.json { render json: @frage, status: :created, location: @frage } + format.js else format.html { render action: "new" } format.json { render json: @frage.errors, status: :unprocessable_entity } + format.js end end end @@ -74,11 +77,16 @@ class FragenController < ApplicationController # DELETE /fragen/1.json def destroy @frage = Frage.find(params[:id]) + @thema=@frage.thema @frage.destroy respond_to do |format| format.html { redirect_to @frage.thema } format.json { head :no_content } + format.js { + @fragen=@thema.fragen + render :create + } end end end diff --git a/app/controllers/themen_controller.rb b/app/controllers/themen_controller.rb index 118a586..51a24dc 100644 --- a/app/controllers/themen_controller.rb +++ b/app/controllers/themen_controller.rb @@ -16,6 +16,7 @@ class ThemenController < ApplicationController # GET /themen/1.json def show @thema = Thema.find(params[:id]) + @fragen=@thema.fragen @toolbar_elements = [{:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('thema.edit'), :path=>edit_thema_path(@thema)}] @toolbar_elements << {:hicon=>'icon-remove-circle', :text=>I18n.t('thema.remove'), :path=>thema_path(@thema), :method=>:delete, :confirm=>I18n.t('thema.sure')} diff --git a/app/controllers/themengruppen_controller.rb b/app/controllers/themengruppen_controller.rb index daa296d..29ada1f 100644 --- a/app/controllers/themengruppen_controller.rb +++ b/app/controllers/themengruppen_controller.rb @@ -16,9 +16,10 @@ class ThemengruppenController < ApplicationController # GET /themengruppen/1.json def show @themengruppe = Themengruppe.find(params[:id]) - @toolbar_elements = [{:icon=>:plus, :hicon=>'icon-plus-sign', :text=>I18n.t('thema.add'), :path=>new_themengruppe_thema_path(@themengruppe)}] - @toolbar_elements << {:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('themengruppe.edit'), :path=>edit_themengruppe_path(@themengruppe)} - @toolbar_elements << {:hicon=>'icon-remove-circle',:text=>I18n.t('themengruppe.remove'), :path=>themengruppe_path(@themengruppe), :method=>:delete,:confirm=>I18n.t('themengruppe.sure')} + @toolbar_elements = [] + @toolbar_elements << {:icon=>:plus, :hicon=>'icon-plus-sign', :text=>I18n.t('thema.add'), :path=>new_themengruppe_thema_path(@themengruppe)} if can? :new, Themengruppe + @toolbar_elements << {:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('themengruppe.edit'), :path=>edit_themengruppe_path(@themengruppe)} if can? :edit, @themengruppe + @toolbar_elements << {:hicon=>'icon-remove-circle',:text=>I18n.t('themengruppe.remove'), :path=>themengruppe_path(@themengruppe), :method=>:delete,:confirm=>I18n.t('themengruppe.sure')} if can? :delete, @themengruppe respond_to do |format| diff --git a/app/views/fragen/_frage.html.erb b/app/views/fragen/_frage.html.erb index 5b9e67a..1fbc55a 100644 --- a/app/views/fragen/_frage.html.erb +++ b/app/views/fragen/_frage.html.erb @@ -4,5 +4,5 @@
<%= link_to 'Edit', edit_frage_path(frage) %> | -<%= link_to 'Destroy',frage, method: :delete, data: { confirm: 'Are you sure?' } %> +<%= link_to 'Destroy',frage, method: :delete, :remote=> true , data: { confirm: 'Are you sure?' } %>

diff --git a/app/views/fragen/_liste.html.erb b/app/views/fragen/_liste.html.erb new file mode 100644 index 0000000..daac219 --- /dev/null +++ b/app/views/fragen/_liste.html.erb @@ -0,0 +1,3 @@ +<% @fragen.each do |frage| %> +<%= render frage %> +<% end %> diff --git a/app/views/fragen/_rform.html.erb b/app/views/fragen/_rform.html.erb new file mode 100644 index 0000000..a3780d1 --- /dev/null +++ b/app/views/fragen/_rform.html.erb @@ -0,0 +1,12 @@ +<%= tinymce_assets %> +<%= semantic_form_for @frage , :remote=>true do |f| %> + <%= f.inputs do %> + <%= f.input :title %> + <%= f.input :thema %> + <%= f.input :text, :as=>:tinymce_text%> + <% end %> + + <%= f.actions do %> + <%= f.action :submit, :as => :input %> + <% end %> +<% end %> diff --git a/app/views/fragen/create.js.erb b/app/views/fragen/create.js.erb new file mode 100644 index 0000000..e57d3a9 --- /dev/null +++ b/app/views/fragen/create.js.erb @@ -0,0 +1 @@ +$("#fragen").html("<%=escape_javascript( render :partial=>'fragen/liste' )%>") \ No newline at end of file diff --git a/app/views/themen/_small.html.erb b/app/views/themen/_small.html.erb index 2c268f1..58c03bd 100644 --- a/app/views/themen/_small.html.erb +++ b/app/views/themen/_small.html.erb @@ -10,6 +10,8 @@


<% end %> -<% @small_elements = [{:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('thema.edit'), :path=>small}] -@small_elements << {:hicon=>'icon-remove-circle',:text=>I18n.t('thema.remove'), :path=>small, :method=>:delete,:confirm=>I18n.t('thema.sure')}%> -<%= render :partial=>'layouts/pretty_toolbar', :object=>@small_elements %> +<% +@small_elements = [] +@small_elements << {:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('thema.edit'), :path=>small} if can? :edit, small +@small_elements << {:hicon=>'icon-remove-circle',:text=>I18n.t('thema.remove'), :path=>small, :method=>:delete,:confirm=>I18n.t('thema.sure')} if can? :delete, small %> +<%= render :partial=>'layouts/pretty_toolbar', :object=>@small_elements unless @small_elements.empty? %> diff --git a/app/views/themen/show.html.erb b/app/views/themen/show.html.erb index 177becf..27e38a9 100644 --- a/app/views/themen/show.html.erb +++ b/app/views/themen/show.html.erb @@ -12,10 +12,11 @@ <%= render :partial=>'layouts/pretty_toolbar' %>

FAQs:

-<% @thema.fragen.each do |frage| %> -<%= render frage %> -<% end %> - +
+<%= render :partial=>'fragen/liste' %> +
+<% @frage=Frage.new; @frage.thema=@thema %> +<%= render :partial=>'fragen/rform' %> <% @frage_elements = [{:icon=>:plus, :hicon=>'icon-plus', :text=>I18n.t('frage.add'), :path=>new_frage_path}] %> <%= render :partial=>'layouts/pretty_toolbar', :object=>@frage_elements %>