themengruppen verwalten form

This commit is contained in:
Andreas Stephanides
2014-02-16 15:32:04 +01:00
parent e466ed5679
commit 87d7cc247a
12 changed files with 78 additions and 56 deletions

View File

@@ -32,6 +32,7 @@ class AttachmentsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.json { render json: @attachment } format.json { render json: @attachment }
format.js
end end
end end
@@ -46,15 +47,17 @@ class AttachmentsController < ApplicationController
def create def create
@attachment = Attachment.new(params[:attachment]) @attachment = Attachment.new(params[:attachment])
@thema = Thema.find(params[:thema_id]) @thema = Thema.find(params[:thema_id])
@attachment.thema_id = @thema.id @attachment.thema_id = @thema.id
respond_to do |format| respond_to do |format|
if @attachment.save if @attachment.save
format.html { redirect_to @thema, notice: 'Attachment was successfully created.' } format.html { redirect_to @thema, notice: 'Attachment was successfully created.' }
format.json { render json: @thema, status: :created, location: @thema } format.json { render json: @thema, status: :created, location: @thema }
format.js { @attachment = Attachment.new }
else else
format.html { render action: "new" } format.html { render action: "new" }
format.json { render json: @attachment.errors, status: :unprocessable_entity } format.json { render json: @attachment.errors, status: :unprocessable_entity }
format.js { render action: "new"}
end end
end end
end end
@@ -69,9 +72,11 @@ class AttachmentsController < ApplicationController
if @attachment.update_attributes(params[:attachment]) if @attachment.update_attributes(params[:attachment])
format.html { redirect_to @thema, notice: 'Attachment was successfully updated.' } format.html { redirect_to @thema, notice: 'Attachment was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
format.js {@attachment=Attachment.new; render action:"create"}
else else
format.html { render action: "edit" } format.html { render action: "edit" }
format.json { render json: @attachment.errors, status: :unprocessable_entity } format.json { render json: @attachment.errors, status: :unprocessable_entity }
format.js { render action: "new"}
end end
end end
end end

View File

@@ -31,28 +31,34 @@ class FragenController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: @frage } format.json { render json: @frage }
format.js
end end
end end
# GET /fragen/1/edit # GET /fragen/1/edit
def edit def edit
@frage = Frage.find(params[:id]) @frage = Frage.find(params[:id])
respond_to do |format|
format.html
format.js {render action: :new}
end
end end
# POST /fragen # POST /fragen
# POST /fragen.json # POST /fragen.json
def create def create
@frage = Frage.new(params[:frage]) @frage = Frage.new(params[:frage])
thema=@frage.thema
@fragen=@frage.thema.fragen @fragen=@frage.thema.fragen
respond_to do |format| respond_to do |format|
if @frage.save if @frage.save
format.html { redirect_to @frage.thema, notice: 'Frage was successfully created.' } format.html { redirect_to @frage.thema, notice: 'Frage was successfully created.' }
format.json { render json: @frage, status: :created, location: @frage } format.json { render json: @frage, status: :created, location: @frage }
format.js format.js {@frage=Frage.new ; @frage.thema=thema}
else else
format.html { render action: "new" } format.html { render action: "new" }
format.json { render json: @frage.errors, status: :unprocessable_entity } format.json { render json: @frage.errors, status: :unprocessable_entity }
format.js format.js
end end
end end
end end
@@ -66,9 +72,11 @@ class FragenController < ApplicationController
if @frage.update_attributes(params[:frage]) if @frage.update_attributes(params[:frage])
format.html { redirect_to @frage, notice: 'Frage was successfully updated.' } format.html { redirect_to @frage, notice: 'Frage was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
format.js {@frage=Frage.new; render action: "new"}
else else
format.html { render action: "edit" } format.html { render action: "edit" }
format.json { render json: @frage.errors, status: :unprocessable_entity } format.json { render json: @frage.errors, status: :unprocessable_entity }
format.js {render action: "edit"}
end end
end end
end end

View File

@@ -40,6 +40,10 @@ class ThemenController < ApplicationController
# GET /themen/1/edit # GET /themen/1/edit
def edit def edit
@thema = Thema.find(params[:id]) @thema = Thema.find(params[:id])
respond_to do |format|
format.html
format.js
end
end end
# POST /themen # POST /themen
@@ -57,7 +61,13 @@ class ThemenController < ApplicationController
end end
end end
end end
def fragen
@thema = Thema.find(params[:thema_id])
@fragen=@thema.fragen
respond_to do |format|
format.js
end
end
# PUT /themen/1 # PUT /themen/1
# PUT /themen/1.json # PUT /themen/1.json
def update def update
@@ -67,9 +77,11 @@ class ThemenController < ApplicationController
if @thema.update_attributes(params[:thema]) if @thema.update_attributes(params[:thema])
format.html { redirect_to @thema, notice: 'Thema was successfully updated.' } format.html { redirect_to @thema, notice: 'Thema was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
format.js
else else
format.html { render action: "edit" } format.html { render action: "edit" }
format.json { render json: @thema.errors, status: :unprocessable_entity } format.json { render json: @thema.errors, status: :unprocessable_entity }
format.js { render action: "edit" }
end end
end end
end end

View File

@@ -3,6 +3,6 @@
<%= raw(frage.text) %> <%= raw(frage.text) %>
<br/> <br/>
<%= link_to 'Edit', edit_frage_path(frage) %> | <%= link_to 'Edit', edit_frage_path(frage),:remote=>true %> |
<%= link_to 'Destroy',frage, method: :delete, :remote=> true , data: { confirm: 'Are you sure?' } %> <%= link_to 'Destroy',frage, method: :delete, :remote=> true , data: { confirm: 'Are you sure?' } %>
</p> </p>

View File

@@ -1 +1,2 @@
$("#fragen").html("<%=escape_javascript( render :partial=>'fragen/liste' )%>") $("#fragen").html("<%=escape_javascript( render :partial=>'fragen/liste' )%>")
$("#fragenform").html("<%=escape_javascript( render :partial=>'fragen/rform' )%>")

View File

@@ -10,7 +10,7 @@ Verwendung: Aufruf mit
<% toolbar_elements.each do |t| %> <% toolbar_elements.each do |t| %>
<% unless t[:method]==:versions %> <% unless t[:method]==:versions %>
<% text='<i class="'.html_safe+ t[:hicon].to_s.html_safe + '"></i>'.html_safe+t[:text] %> <% text='<i class="'.html_safe+ t[:hicon].to_s.html_safe + '"></i>'.html_safe+t[:text] %>
<%= link_to text, t[:path], :method=>t[:method], :confirm=>t[:confirm].to_s, :data=>t[:data], :class=>((t[:method].to_s=='delete') ? "btn btn-danger" : "btn") %> <%= link_to text, t[:path], :method=>t[:method], :confirm=>t[:confirm].to_s, :data=>t[:data], :class=>((t[:method].to_s=='delete') ? "btn btn-danger" : "btn") ,:remote=>(t[:remote])?true : false %>
<% else %> <% else %>
<div class="btn-group"> <div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">

View File

@@ -1,41 +1,32 @@
<%= tinymce_assets %> <%= tinymce_assets %>
<%= semantic_form_for @thema do |f| %> <div class="container-fluid">
<%= semantic_form_for @thema, :remote=>true do |f| %>
<%= f.inputs do %> <%= f.inputs do %>
<div class="row-fluid">
<div class="span6">
<%= f.input :title %> <%= f.input :title %>
</div>
<div class="span6">
<%= f.input :themengruppe %> <%= f.input :themengruppe %>
<%= f.input :text, :as=>:tinymce_text%> </div>
<% end %> <div class="row-fluid">
<%= tinymce %> <div class="span12">
<%= f.input :text, :as=>:tinymce_text,:label=>false %>
</div>
</div>
<h2>Attachments:</h2> </div>
<%= render :partial => "themen/select", :object => @thema,:locals =>{ :editor => :true} %>
<%= f.actions do %> <%= f.actions do %>
<%= f.action :submit, :as => :input %> <%= f.action :submit, :as => :input %>
<% end %> <%= f.action :cancel, :as => :link %>
<% end %>
<!-- <% end %><% end %>
<% @thema.attachments.each do |attachment| %> <%= tinymce %>
<ul> <h2>Attachments:</h2>
<li> <%= render :partial => "themen/select", :object => @thema,:locals =>{ :editor => :true} %>
<%= link_to attachment.name, edit_thema_attachment_path(@thema,attachment) %>
<button type="button" onclick="insertAttachment(<%="\"" + attachment.datei.url + "\""%>,<%="\""+attachment.name+"\""%>)">Insert Me!</button>
</li>
</ul>
<% end %>
<% end %>
-->
<!--
<script>
function insertAttachment(url) {
tinymce.activeEditor.setContent(tinymce.activeEditor.getContent({format : 'raw'}) + "Test");
//editor.setContent(editor.getContent + "<img src=\"" + url + "\">")
}
</script>
-->

View File

@@ -24,8 +24,9 @@
</br> </br>
<% unless @thema.id.nil? %> <% unless @thema.id.nil? %>
<% @att_elements = [{:icon=>:plus, :hicon=>'icon-plus', :text=>I18n.t('attachment.add'), :path=>new_thema_attachment_path(@thema)}] %> <% @att_elements = [{:icon=>:plus, :hicon=>'icon-plus', :text=>I18n.t('attachment.add'), :path=>new_thema_attachment_path(@thema),:remote=>true}] %>
<div id="attachmentform">
</div>
<%= render :partial=>'layouts/pretty_toolbar', :object=>@att_elements %> <%= render :partial=>'layouts/pretty_toolbar', :object=>@att_elements %>
<% end %> <% end %>
<br/> <br/>

View File

@@ -1,5 +1,5 @@
<div id="themaview">
<h1>Editing thema</h1> <h1>Editing thema</h1>
<%= render 'form' %> <%= render 'form' %>
</div>
</br><%= link_to 'Back', @thema %> </br><%= link_to 'Back', @thema %>

View File

@@ -11,18 +11,14 @@
--> -->
<%= render :partial=>'layouts/pretty_toolbar' %> <%= render :partial=>'layouts/pretty_toolbar' %>
<h2>FAQs:</h2> <%= render :partial=>'themen/fragen' %>
<div id="fragen">
<%= render :partial=>'fragen/liste' %>
</div>
<% @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 %>
<!-- <!--
<%= link_to 'Neue Frage', new_frage_path %> <br/> <%= link_to 'Neue Frage', new_frage_path %> <br/>
--> -->
<br/> <br/>
<h2><%= I18n.t('attachment.title')%>:</h2> <h2><%= I18n.t('attachment.title')%>:</h2>
<div id="attachmentform">
</div>
<%= link_to new_thema_attachment_path(@thema) ,:remote=>true do %> new Attachment <% end %>
<%= render :partial => "themen/select", :object => @thema, :locals=>{:editor => :false} %> <%= render :partial => "themen/select", :object => @thema, :locals=>{:editor => :false} %>

View File

@@ -2,18 +2,26 @@
#themen { list-style-type: none; margin: 0; padding: 0; margin-bottom: 15px;zoom: 1; } #themen { list-style-type: none; margin: 0; padding: 0; margin-bottom: 15px;zoom: 1; }
#themen li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 95%; } #themen li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 95%; }
</style> </style>
<div class="container-fluid">
<div class="row-fluid">
<div class="span4">
<ul id="themen" class="sort" > <ul id="themen" class="sort" >
<% @themen.each do |thema| %> <% @themen.each do |thema| %>
<li id="themen_<%= thema.id %>" class="sort" ><div class="contentbox" ><h2><%= thema.title %></h2> </div></li> <li id="themen_<%= thema.id %>" class="sort" ><div class="contentbox handle" ><h2><%= thema.title %></h2> </div> <%= link_to edit_thema_path(thema),:remote=>true do %> Edit <% end %> <%= link_to thema_fragen_path(thema),:remote=>true do %> Fragen <% end %></li>
<% end %> <% end %>
</ul> </ul>
</div>
<div class="span8">
<div id="themaview"></div>
</div>
<script> <script>
$( document ).ready(function(){ $( document ).ready(function(){
$("#themen").sortable({ $("#themen").sortable({
cursor: 'crosshair', cursor: 'crosshair',
drag:true, drag:true,
handle: '.handle',
update: function(){ update: function(){
$.ajax({ $.ajax({
url: '<%= themengruppe_sort_themen_path(@themengruppe) %>', url: '<%= themengruppe_sort_themen_path(@themengruppe) %>',

View File

@@ -104,9 +104,9 @@ end
resources :beispiele resources :beispiele
resources :themen do resources :themen do
get :fragen
resources :attachments resources :attachments
end end
resources :themengruppen do resources :themengruppen do
get :verwalten get :verwalten