From 94614b1d5b95aeaf67fad6f6d2e5b172cfe1327d Mon Sep 17 00:00:00 2001 From: HausdorffHimself Date: Sat, 24 Aug 2013 04:07:33 +0200 Subject: [PATCH] =?UTF-8?q?ADD:=20Dateieinbindung=20in=20TinyMCE=20f=C3=BC?= =?UTF-8?q?r=20Attachments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/application.js | 16 +++++++++++++++ app/controllers/attachments_controller.rb | 21 +++++++++++++------- app/models/attachment.rb | 5 +++-- app/models/themengruppe.rb | 1 - app/views/attachments/_form.html.erb | 3 ++- app/views/attachments/edit.html.erb | 4 ++-- app/views/attachments/new.html.erb | 2 +- app/views/themen/_form.html.erb | 24 +++++++++++++++++++++++ app/views/themen/show.html.erb | 12 +++++++++++- config/routes.rb | 6 ++++-- config/tinymce.yml | 3 ++- 11 files changed, 79 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 97ab022..c641b92 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,3 +21,19 @@ //= require bootstrap/load-image.min //= require bootstrap/image-gallery.min //= require jquery-fileupload + +function insertAttachment(url,name) { + var ext = url.split('.').pop(); + var img_ext = [ "jpg", "png", "bmp" , "jpeg" ]; + var text_ext = [ "pdf" ]; + + if ( img_ext.indexOf(ext) > -1) { + tinymce.activeEditor.setContent(tinymce.activeEditor.getContent({format : 'raw'}) + ""); + } + else if (text_ext.indexOf(ext) > -1) { + tinymce.activeEditor.setContent(tinymce.activeEditor.getContent({format : 'raw'}) + "" + name +""); + } + else { + alert("" + "Link"); + } +} diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index aa8ec7c..7647755 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -25,7 +25,9 @@ class AttachmentsController < ApplicationController # GET /attachments/new.json def new @attachment = Attachment.new - + @thema = Thema.find(params[:thema_id]) + @attachment.thema = @thema + respond_to do |format| format.html # new.html.erb format.json { render json: @attachment } @@ -35,17 +37,20 @@ class AttachmentsController < ApplicationController # GET /attachments/1/edit def edit @attachment = Attachment.find(params[:id]) + @thema = @attachment.thema end # POST /attachments # POST /attachments.json def create @attachment = Attachment.new(params[:attachment]) - + @thema = Thema.find(params[:thema_id]) + @attachment.thema_id = @thema.id + respond_to do |format| if @attachment.save - format.html { redirect_to @attachment, notice: 'Attachment was successfully created.' } - format.json { render json: @attachment, status: :created, location: @attachment } + format.html { redirect_to @thema, notice: 'Attachment was successfully created.' } + format.json { render json: @thema, status: :created, location: @thema } else format.html { render action: "new" } format.json { render json: @attachment.errors, status: :unprocessable_entity } @@ -57,10 +62,11 @@ class AttachmentsController < ApplicationController # PUT /attachments/1.json def update @attachment = Attachment.find(params[:id]) - + @thema = @attachment.thema + respond_to do |format| if @attachment.update_attributes(params[:attachment]) - format.html { redirect_to @attachment, notice: 'Attachment was successfully updated.' } + format.html { redirect_to @thema, notice: 'Attachment was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } @@ -74,9 +80,10 @@ class AttachmentsController < ApplicationController def destroy @attachment = Attachment.find(params[:id]) @attachment.destroy + @thema = Thema.find(params[:thema_id]) respond_to do |format| - format.html { redirect_to attachments_url } + format.html { redirect_to @thema } format.json { head :no_content } end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f375f87..06f2929 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -4,6 +4,7 @@ # # id :integer not null, primary key # name :string(255) +# datei :string(255) # created_at :datetime not null # updated_at :datetime not null # thema_id :integer @@ -11,9 +12,9 @@ class Attachment < ActiveRecord::Base has_paper_trail - attr_accessible :name + attr_accessible :name, :datei belongs_to :thema - + mount_uploader :datei, BeispieldateiUploader validates :thema, :presence => true validates :name, :presence => true end diff --git a/app/models/themengruppe.rb b/app/models/themengruppe.rb index ef59efd..371ff69 100644 --- a/app/models/themengruppe.rb +++ b/app/models/themengruppe.rb @@ -7,7 +7,6 @@ # text :text # created_at :datetime not null # updated_at :datetime not null -# class Themengruppe < ActiveRecord::Base WORD_COUNT = 50 diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index 75bc493..e27d683 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -1,6 +1,7 @@ -<%= semantic_form_for @attachment do |f| %> +<%= semantic_form_for [@thema,@attachment] do |f| %> <%= f.inputs do %> <%= f.input :name %> + <%= f.input :datei, :as => :file %> <% end %> <%= f.actions do %> diff --git a/app/views/attachments/edit.html.erb b/app/views/attachments/edit.html.erb index b2a2cfe..919ea5c 100644 --- a/app/views/attachments/edit.html.erb +++ b/app/views/attachments/edit.html.erb @@ -2,5 +2,5 @@ <%= render 'form' %> -<%= link_to 'Show', @attachment %> | -<%= link_to 'Back', attachments_path %> + +<%= link_to 'Back', thema_attachments_path(@attachment.thema,@attachment) %> diff --git a/app/views/attachments/new.html.erb b/app/views/attachments/new.html.erb index b7a66aa..5049aaf 100644 --- a/app/views/attachments/new.html.erb +++ b/app/views/attachments/new.html.erb @@ -2,4 +2,4 @@ <%= render 'form' %> -<%= link_to 'Back', attachments_path %> +<%= link_to 'Back', @thema %> diff --git a/app/views/themen/_form.html.erb b/app/views/themen/_form.html.erb index 53e9944..954b0d5 100644 --- a/app/views/themen/_form.html.erb +++ b/app/views/themen/_form.html.erb @@ -8,7 +8,31 @@ <% end %> <%= tinymce %> + +

Attachments:

+<% @thema.attachments.each do |attachment| %> + +<% end %> + <%= f.actions do %> <%= f.action :submit, :as => :input %> <% end %> <% end %> + + + diff --git a/app/views/themen/show.html.erb b/app/views/themen/show.html.erb index 936995f..6fe1cd7 100644 --- a/app/views/themen/show.html.erb +++ b/app/views/themen/show.html.erb @@ -20,6 +20,16 @@

<% end %> +<%= link_to 'Neue Frage', new_frage_path %>

-<%= link_to 'Neue Frage', new_frage_path %> +

Attachments:

+<% @thema.attachments.each do |attachment| %> + +<% end %> +<%= link_to 'Neues Attachment', new_thema_attachment_path(@thema) %> +
diff --git a/config/routes.rb b/config/routes.rb index cef5142..d575bd8 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,8 +66,10 @@ resources :beispiele - resources :attachment - resources :themen + resources :themen do + resources :attachments + end + resources :themengruppen do resources :themen, :only=>[:new, :show] end diff --git a/config/tinymce.yml b/config/tinymce.yml index 6f0cfd9..4563521 100755 --- a/config/tinymce.yml +++ b/config/tinymce.yml @@ -7,4 +7,5 @@ theme_advanced_buttons3_add: - fullscreen plugins: - table - - fullscreen \ No newline at end of file + - fullscreen + - advimage