diff --git a/Gemfile b/Gemfile index 222dcac..b532080 100755 --- a/Gemfile +++ b/Gemfile @@ -93,3 +93,4 @@ gem "seed_dump", "~> 0.5.3" #gem "themes_for_rails" ,:git =>'git://github.com/tkriplean/themes_for_rails.git' #gem "themes_for_rails", :git=> 'git://github.com/lucasefe/themes_for_rails.git' gem 'themes_for_rails' +gem 'remotipart', :git =>'git://github.com/JangoSteve/remotipart.git' diff --git a/Gemfile.lock b/Gemfile.lock index c2a82fc..515aca0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: git://github.com/JangoSteve/remotipart.git + revision: aadc29e996c35096ee971bdc6cbf7ab148077a3a + specs: + remotipart (1.2.1) + GIT remote: git://github.com/airblade/paper_trail.git revision: 802b7d4ead71703860fcb9befc2c9b2ee05a8b9f diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 419fd4b..3492931 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -25,7 +25,7 @@ //= require bootstrap/load-image.min //= require bootstrap/image-gallery.min //= require jquery-fileupload - +//= require jquery.remotipart function insertAttachment(url,name) { var ext = url.split('.').pop().toLowerCase(); var img_ext = [ "jpg", "png", "bmp" , "jpeg" ]; diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 40494fa..4a37fb1 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -32,10 +32,11 @@ class AttachmentsController < ApplicationController respond_to do |format| format.html # new.html.erb format.json { render json: @attachment } + format.js end end - # GET /attachments/1/edit + # GET /attachments/1/edit def edit @attachment = Attachment.find(params[:id]) @thema = @attachment.thema @@ -46,15 +47,18 @@ class AttachmentsController < ApplicationController def create @attachment = Attachment.new(params[:attachment]) @thema = Thema.find(params[:thema_id]) - @attachment.thema_id = @thema.id - + @attachment.thema_id = @thema.id + @action="create" + logger.info "#{@attachment.inspect}" respond_to do |format| if @attachment.save format.html { redirect_to @thema, notice: 'Attachment was successfully created.' } format.json { render json: @thema, status: :created, location: @thema } + format.js { } else format.html { render action: "new" } format.json { render json: @attachment.errors, status: :unprocessable_entity } + format.js { render action: "new.js.erb"} end end end @@ -69,9 +73,11 @@ class AttachmentsController < ApplicationController if @attachment.update_attributes(params[:attachment]) format.html { redirect_to @thema, notice: 'Attachment was successfully updated.' } format.json { head :no_content } + format.js {@attachment=Attachment.new; render action:"create"} else format.html { render action: "edit" } format.json { render json: @attachment.errors, status: :unprocessable_entity } + format.js { render action: "new"} end end end diff --git a/app/controllers/beispiele_controller.rb b/app/controllers/beispiele_controller.rb index 1e2438f..ef93f78 100755 --- a/app/controllers/beispiele_controller.rb +++ b/app/controllers/beispiele_controller.rb @@ -43,15 +43,29 @@ class BeispieleController < ApplicationController # POST /beispiele # POST /beispiele.json def create + logger.info "Creating Beispiel..." @lva = Lva.find_by_id(params[:lva_id]) params.delete(:lva_id) @beispiel = Beispiel.new(params[:beispiel]) - @backlink = @beispiel.lva.nil? ? root_url : lva_path(@beispiel.lva) + @beispiel.lva=@lva + logger.info "New Beispiel: #{params.inspect}" + +# @backlink = @beispiel.lva.nil? ? root_url : lva_path(@beispiel.lva) + @beispiel.name=@beispiel.beispieldatei.filename + logger.info "New Beispiel: #{@beispiel.attributes.inspect}" + + @beispiel.datum=Time.now respond_to do |format| - @beispiel.name=@beispiel.beispieldatei.to_s.split('/').last + if @beispiel.save - format.html { redirect_to @backlink, notice: 'Beispiel was successfully created.' } - format.json { render json: @beispiel, status: :created, location: @beispiel } + format.html { + render :json => [@beispiel.to_jq_upload].to_json, + :content_type => 'text/html', + :layout => false + } + format.json { render json: {files: [@beispiel.to_jq_upload]}, status: :created, location: [@lva, @beispiel] } + # format.html { redirect_to @backlink, notice: 'Beispiel was successfully created.' } + # format.json { render json: @beispiel, status: :created, location: @beispiel } else format.html { render action: "new" } format.json { render json: @beispiel.errors, status: :unprocessable_entity } diff --git a/app/controllers/fragen_controller.rb b/app/controllers/fragen_controller.rb index 8e0eddc..223373a 100644 --- a/app/controllers/fragen_controller.rb +++ b/app/controllers/fragen_controller.rb @@ -31,28 +31,34 @@ class FragenController < ApplicationController respond_to do |format| format.html format.json { render json: @frage } + format.js end end - + # GET /fragen/1/edit def edit @frage = Frage.find(params[:id]) + respond_to do |format| + format.html + format.js {render action: :new} + end end # POST /fragen # POST /fragen.json def create @frage = Frage.new(params[:frage]) + thema=@frage.thema @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 + format.js {@frage=Frage.new ; @frage.thema=thema} else format.html { render action: "new" } format.json { render json: @frage.errors, status: :unprocessable_entity } - format.js + format.js end end end @@ -66,9 +72,11 @@ class FragenController < ApplicationController if @frage.update_attributes(params[:frage]) format.html { redirect_to @frage, notice: 'Frage was successfully updated.' } format.json { head :no_content } + format.js {@frage=Frage.new; render action: "new"} else format.html { render action: "edit" } format.json { render json: @frage.errors, status: :unprocessable_entity } + format.js {render action: "edit"} end end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 846c82b..4333ec6 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,8 @@ class HomeController < ApplicationController def index @beispiele = Beispiel.last([Beispiel.count, 3].min) + @neuigkeiten = Neuigkeit.recent + end def dev diff --git a/app/controllers/themen_controller.rb b/app/controllers/themen_controller.rb index 51a24dc..4435ec6 100644 --- a/app/controllers/themen_controller.rb +++ b/app/controllers/themen_controller.rb @@ -34,12 +34,17 @@ class ThemenController < ApplicationController respond_to do |format| format.html # new.html.erb format.json { render json: @thema } + format.js { render action: "edit" } end end # GET /themen/1/edit def edit @thema = Thema.find(params[:id]) + respond_to do |format| + format.html + format.js + end end # POST /themen @@ -57,7 +62,13 @@ class ThemenController < ApplicationController 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.json def update @@ -67,9 +78,11 @@ class ThemenController < ApplicationController if @thema.update_attributes(params[:thema]) format.html { redirect_to @thema, notice: 'Thema was successfully updated.' } format.json { head :no_content } + format.js else format.html { render action: "edit" } format.json { render json: @thema.errors, status: :unprocessable_entity } + format.js { render action: "edit" } end end end diff --git a/app/models/beispiel.rb b/app/models/beispiel.rb index 127ce65..6f87953 100755 --- a/app/models/beispiel.rb +++ b/app/models/beispiel.rb @@ -15,11 +15,22 @@ class Beispiel < ActiveRecord::Base has_paper_trail attr_accessible :desc, :name, :lva_id, :beispieldatei, :beispieldatei_cache, :datum belongs_to :lva - mount_uploader :beispieldatei, BeispieldateiUploader + mount_uploader :beispieldatei, AttachmentUploader validates :beispieldatei, :presence => true validates :name, :presence => true validates :lva_id, :presence => true validates :lva, :presence => true validates :datum, :presence => true - + def to_jq_upload + { + "id" => read_attribute(:id), + "title" => read_attribute(:title), + "description" => read_attribute(:desc), + "name" => read_attribute(:title), + "size" => beispieldatei.size, + "url" => beispieldatei.url, + "thumbnail_url" => beispieldatei.thumb.url, + "delete_type" => "DELETE" + } +end end diff --git a/app/models/calentry.rb b/app/models/calentry.rb index ae1aae9..1689d1d 100644 --- a/app/models/calentry.rb +++ b/app/models/calentry.rb @@ -21,7 +21,8 @@ class Calentry < ActiveRecord::Base validates :typ, :presence => true before_save :get_public belongs_to :object, polymorphic: true # Objekt zu dem der Calentry gehört (derzeit ein Newsartikel) - + scope :upcoming, ->{ where("start >= ?", Time.now).order(:start)} + scope :recent,-> { where("start <= ?", Time.now).order(:start).reverse_order} validate do |entry| if entry.ende.nil? errors.add(:ende, "Es muss ein Endzeitpunkt vorhanden sein") @@ -61,5 +62,5 @@ def text I18n.l(self.start) +" bis "+ I18n.l(self.ende) end scope :public, -> { where(:public => :true) } - scope :upcoming, -> { where("start >= ?" , Time.now).where("start <= ?", 28.days.from_now) } + # scope :upcoming, -> { where("start >= ?" , Time.now).where("start <= ?", 28.days.from_now) } end diff --git a/app/views/attachments/_rform.html.erb b/app/views/attachments/_rform.html.erb new file mode 100644 index 0000000..066e87d --- /dev/null +++ b/app/views/attachments/_rform.html.erb @@ -0,0 +1,12 @@ +<%= semantic_form_for [@thema,@attachment], :remote=>true do |f| %> + <%= f.inputs do %> + <%= f.input :name %> + +<%= token_tag form_authenticity_token %> + <%= f.input :datei, :as => :file %> + <% end %> + + <%= f.actions do %> + <%= f.action :submit, :as => :input %> + <% end %> +<% end %> diff --git a/app/views/attachments/create.js.erb b/app/views/attachments/create.js.erb new file mode 100644 index 0000000..9c2920e --- /dev/null +++ b/app/views/attachments/create.js.erb @@ -0,0 +1,2 @@ +alert('create_attachment'); +$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )%>"); diff --git a/app/views/attachments/new.js.erb b/app/views/attachments/new.js.erb new file mode 100644 index 0000000..9145620 --- /dev/null +++ b/app/views/attachments/new.js.erb @@ -0,0 +1,4 @@ +alert('new.js.erb') +$("#attachmentform").html("<%=escape_javascript( render :partial=>'attachments/rform' )+ @action.to_s%>"); +$('document').trigger('ready'); +alert('ready') \ No newline at end of file diff --git a/app/views/beispiele/_form_bulk.html.erb b/app/views/beispiele/_form_bulk.html.erb index 955ea51..5ab9ca9 100644 --- a/app/views/beispiele/_form_bulk.html.erb +++ b/app/views/beispiele/_form_bulk.html.erb @@ -1,5 +1,6 @@ +