diff --git a/Gemfile b/Gemfile index 2ab6deb..fd80595 100755 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,9 @@ gem 'jquery-rails' # Formbuilder for easier form generation gem 'formtastic', '~>2.2.1' -gem 'formtastic-bootstrap', '~>2.1.3' #, :git => "git://github.com/mjbellantoni/formtastic-bootstrap.git" + +# gem 'formtastic-bootstrap', '~>2.1.3' #, :git => "git://github.com/mjbellantoni/formtastic-bootstrap.git" +gem 'formtastic-bootstrap', '~>3.0.0' #, :git => "git://github.com/mjbellantoni/formtastic-bootstrap.git" # TinyMCE gem "tinymce-rails" , '~>4.1.0' diff --git a/Gemfile.lock b/Gemfile.lock index ac311a3..b4e46ea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,7 @@ GEM activesupport (3.2.13) i18n (= 0.6.1) multi_json (~> 1.0) + acts_as_votable (0.10.0) annotate (2.6.1) activerecord (>= 2.3.0) rake (>= 0.8.7) @@ -225,6 +226,7 @@ GEM rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) rubyntlm (0.1.1) + rubyzip (1.1.6) sanitize (2.0.6) nokogiri (>= 1.4.4) sass (3.2.13) @@ -271,6 +273,7 @@ PLATFORMS DEPENDENCIES RedCloth + acts_as_votable annotate (>= 2.5.0) awesome_nested_set bootstrap-addons-rails @@ -304,6 +307,7 @@ DEPENDENCIES rmagick rolify rspec-rails + rubyzip sanitize sass-rails (~> 3.2) seed_dump (~> 0.5.3) diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/comments.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/themes/blue1/application.css.scss b/app/assets/stylesheets/themes/blue1/application.css.scss index a24cf52..28f08bb 100755 --- a/app/assets/stylesheets/themes/blue1/application.css.scss +++ b/app/assets/stylesheets/themes/blue1/application.css.scss @@ -115,3 +115,4 @@ $box-background: white; @import 'layout'; @import 'calendars'; +@import 'formtastic-bootstrap' \ No newline at end of file diff --git a/app/controllers/beispiele_controller.rb b/app/controllers/beispiele_controller.rb index 647c45f..1917613 100755 --- a/app/controllers/beispiele_controller.rb +++ b/app/controllers/beispiele_controller.rb @@ -17,7 +17,10 @@ class BeispieleController < ApplicationController def show # @lva = params([:lva]) unless params([:lva]).nil? @beispiel = Beispiel.find(params[:id]) - redirect_to @beispiel.lva + respond_to do |format| + format.html { redirect_to @beispiel.lva } + format.js + end end # GET /beispiele/new diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..7501c65 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,83 @@ +class CommentsController < ApplicationController + def index + @comments=Comment.all + end + def show + @comment = Comment.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @comment } + end + end + def new + @comment = Comment.new + @comment.commentable=params[:commentable_type].constantize.find(params[:commentable_id]) unless params[:commentable_type].nil? or params[:commentable_id].nil? + respond_to do |format| + format.html # new.html.erb + format.json { render json: @comment } + format.js + end + end + + # GET /comments/1/edit + def edit + @comment = Comment.find(params[:id]) + end + + # POST /comments + # POST /comments.json + def create + params_new= params[:comment].select {|i| !["commentable_id", "commentable_type"].include?(i)} + + c = params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil? + + @comment = Comment.build_for(c, current_user,"", params_new) + #raise @comment.to_yaml.to_s + # @comment.commentable= c + + + + + respond_to do |format| + if @comment + format.html { redirect_to @comment.commentable, notice: 'Comment was successfully created.' } + format.json { render json: @comment, status: :created, location: @comment } + else + format.html { render action: "new" } + format.json { render json: @comment.errors, status: :unprocessable_entity } + end + end + end + + # PUT /comments/1 + # PUT /comments/1.json + def update + + params[:comment].select! {|i| !["commentable_id", "commentable_type"].include?(i)} + @comment = Comment.find(params[:id]) + @comment.commentable=params[:comment][:commentable_type].constantize.find(params[:comment][:commentable_id]) unless params[:comment][:commentable_type].nil? or params[:comment][:commentable_id].nil? + respond_to do |format| + + if @comment.update_attributes(params[:comment]) + format.html { redirect_to @comment.commentable, notice: 'Comment was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @comment.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /comments/1 + # DELETE /comments/1.json + def destroy + @comment = Comment.find(params[:id]) + @comment.destroy + + respond_to do |format| + format.html { redirect_to comments_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/config_controller.rb b/app/controllers/config_controller.rb index 5caffd0..53cb795 100755 --- a/app/controllers/config_controller.rb +++ b/app/controllers/config_controller.rb @@ -4,4 +4,6 @@ class ConfigController < ApplicationController end + def choose_contact_topics + end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 516cabb..df28c51 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -8,6 +8,8 @@ class HomeController < ApplicationController end def kontakt + t=YAML.load_file("#{::Rails.root.to_s}/config/contact_topic.yml") + @themen = Thema.where(:id=>t) end def intern authorize! :seeintern, User @@ -51,4 +53,9 @@ class HomeController < ApplicationController format.js end end + def choose_contact_topics +File.open("config/contact_topic.yml",'w'){|f| f.write(params[:themen].to_yaml)} + redirect_to admin_home_index_path + end + end diff --git a/app/controllers/lvas_controller.rb b/app/controllers/lvas_controller.rb index 5423e28..ee2732c 100755 --- a/app/controllers/lvas_controller.rb +++ b/app/controllers/lvas_controller.rb @@ -1,7 +1,7 @@ class LvasController < ApplicationController # GET /lvas require 'zip' - before_filter :load_toolbar, :only => [:show] + before_filter :load_toolbar, :only => [:verwalten] load_and_authorize_resource def index @lvas = Lva.all @@ -43,6 +43,15 @@ class LvasController < ApplicationController def show @lva = Lva.find_by_id(params[:id]) @beispiel=Beispiel.new + @toolbar_elements =[] + @toolbar_elements<<{:hicon=>'icon-pencil', :icon=>:pencil,:text =>I18n.t('common.manage'),:path => verwalten_lva_path(@lva)} if can? :verwalten, @lva + + end + def verwalten + @lva = Lva.find_by_id(params[:id]) + @beispiel=Beispiel.new + + render :show end # GET /lvas/new diff --git a/app/controllers/neuigkeiten_controller.rb b/app/controllers/neuigkeiten_controller.rb index 0af5eac..29a54b9 100755 --- a/app/controllers/neuigkeiten_controller.rb +++ b/app/controllers/neuigkeiten_controller.rb @@ -69,7 +69,7 @@ class NeuigkeitenController < ApplicationController unless @neuigkeit.published? redirect_to [@neuigkeit.rubrik,@neuigkeit], notice: 'Neuigkeit muss veröffentlicht sein um sie auf Facebook zu posten.' else - page=YAML.load_file("#{::Rails.root.to_s}/tmp/page.yml") + page=YAML.load_file("#{::Rails.root.to_s}/config/page.yml") page.feed!(:access_token=>page.access_token, :message=>@neuigkeit.text_first_words, :name=>@neuigkeit.title, :link=>rubrik_neuigkeit_url(@neuigkeit.rubrik, @neuigkeit)+".html", :picture=>@neuigkeit.picture.url) redirect_to [@neuigkeit.rubrik,@neuigkeit], notice: 'Neuigkeit auf Facebook gepostet' @@ -113,9 +113,14 @@ class NeuigkeitenController < ApplicationController render action:"show" end def create_link - Nlink.create(:link=>params[:link_type].constantize.find(params[:link_id]),:neuigkeit=>Neuigkeit.find(params[:id])) + @neuigkeit = Neuigkeit.find(params[:id]) - redirect_to action:"show" + Nlink.create(:link=>params[:link_type].constantize.find(params[:link_id]),:neuigkeit=>Neuigkeit.find(params[:id])) + @nlinks=@neuigkeit.nlinks + respond_to do |format| + format.html { edirect_to action:"show" } + format.js + end end def create @@ -159,21 +164,23 @@ private def load_toolbar_elements @neuigkeit=Neuigkeit.find(params[:id]) @toolbar_elements=[] - @toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('neuigkeit.publish'),:path => publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=> I18n.t('neuigkeit.publish_sure') } if can?(:publish, @neuigkeit) && !@neuigkeit.published? - @toolbar_elements << {:hicon=>'icon-facebook', :text=> I18n.t('neuigkeit.publishfb'),:path => publish_to_facebook_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>I18n.t('neuigkeit.publishfb_sure') } if can?(:publish, @neuigkeit) && @neuigkeit.published? + actions=[] + actions << {:hicon=>'icon-plus', :text=> I18n.t('neuigkeit.publish'),:path => publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=> I18n.t('neuigkeit.publish_sure') } if can?(:publish, @neuigkeit) && !@neuigkeit.published? + actions << {:hicon=>'ffi1-facebook1', :text=> I18n.t('neuigkeit.publishfb'),:path => publish_to_facebook_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>I18n.t('neuigkeit.publishfb_sure') } if can?(:publish, @neuigkeit) && @neuigkeit.published? -@toolbar_elements << {:hicon=>'icon-facebook', :text=> I18n.t('neuigkeit.publishfetmail'),:path => mail_to_fet_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>I18n.t('neuigkeit.publishfetmail_sure') } if can?(:publish, @neuigkeit) && @neuigkeit.published? +actions << {:hicon=>'icon-facebook', :text=> I18n.t('neuigkeit.publishfetmail'),:path => mail_to_fet_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>I18n.t('neuigkeit.publishfetmail_sure') } if can?(:publish, @neuigkeit) && @neuigkeit.published? - @toolbar_elements << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=> I18n.t('neuigkeit.unpublish_sure') } if can?(:unpublish, @neuigkeit) && @neuigkeit.published? + actions << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=> I18n.t('neuigkeit.unpublish_sure') } if can?(:unpublish, @neuigkeit) && @neuigkeit.published? + @toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:icon=>:pencil} if can? :edit, @neuigkeit.rubrik @versions= @neuigkeit.translation.versions.select([:created_at]).reverse @toolbar_elements <<{:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:method=>:versions,:versions=>@versions} - @toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :method=> :delete,:confirm=>'Sure?' } if can? :delete, @neuigkeit - + actions << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :method=> :delete,:confirm=>'Sure?' } if can? :delete, @neuigkeit + @toolbar_elements << {:text => "action", :method => :dropdown, :elements=> actions} end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f5a0334..35a3051 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -17,7 +17,7 @@ class UsersController < ApplicationController redirect_to intern_home_index_path else @fbu=FbGraph::User.new(current_user.uid.to_s).fetch(:access_token=>session["fbuser_access_token"]) - File.open("tmp/page.yml",'w'){|f| f.write(@fbu.accounts(:access_token=>session["fbuser_access_token"]).select { |p| p.name == params["page"] }.first.to_yaml)} + File.open("config/page.yml",'w'){|f| f.write(@fbu.accounts(:access_token=>session["fbuser_access_token"]).select { |p| p.name == params["page"] }.first.to_yaml)} logger.debug @fbu.to_s redirect_to admin_home_index_path end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..0ec9ca5 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb index 616979b..3a6397c 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -4,12 +4,14 @@ class Ability def initialize(user) loggedin=!(user.nil?) user ||= User.new # guest user (not logged in) + + can :manage, Comment #----------------------------------------------------- # Rechteverwaltung fuer Studien Modul can [:show, :index], Studium can [:show, :index], Modulgruppe can [:show, :index], Modul - can [:show, :index], Lva + can [:show, :index, :beispiel_sammlung], Lva can [:create, :show], Beispiel if loggedin can :like, Beispiel @@ -20,6 +22,7 @@ class Ability can :manage, Modul can :manage, Lva can :manage, Studium + can :manage, Beispiel end unless user.has_role?("fetadmin") cannot :delete, Studium @@ -40,6 +43,7 @@ class Ability can :showintern, Thema can :manage, Thema can :manage, Themengruppe + can :manage, Attachment end unless user.has_role?("fetadmin") cannot :delete, Themengruppe @@ -95,6 +99,8 @@ class Ability if user.has_role?("fetadmin") can :addfetuser, User can :addfetadmin, User + can :edit, User + can :manage, User end if user.has_role?("newsadmin") || user.has_role?( "fetadmin") || user.has_role?( "fetuser") diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c61214f..3301381 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -18,6 +18,13 @@ class Attachment < ActiveRecord::Base validates :thema, :presence => true validates :name, :presence => true + def image? + + # data_ext = datei.file.extension.downcase + # %w(jpg png jpeg).include?(data_ext) + datei.image?(datei.file) + end + def to_jq_upload { "id" => read_attribute(:id), diff --git a/app/models/beispiel.rb b/app/models/beispiel.rb index 8e0ba3c..9d94c06 100755 --- a/app/models/beispiel.rb +++ b/app/models/beispiel.rb @@ -16,7 +16,7 @@ class Beispiel < ActiveRecord::Base attr_accessible :desc, :name, :lva_id, :beispieldatei, :beispieldatei_cache, :datum acts_as_votable belongs_to :lva - + include IsCommentable mount_uploader :beispieldatei, AttachmentUploader validates :beispieldatei, :presence => true validates :name, :presence => true @@ -35,4 +35,7 @@ class Beispiel < ActiveRecord::Base "delete_type" => "DELETE" } end + def divid + "beispiel_"+id.to_s + end end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..a074fd7 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,44 @@ +class Comment < ActiveRecord::Base + attr_accessible :text,:anonym, :intern, :hidden + # commentable depth, official, intern, anonym + acts_as_votable + acts_as_nested_set :scope => [:commentable_id, :commentable_type] + belongs_to :commentable, :polymorphic=> true + belongs_to :user + validate :text, :presence=>true + validate :user, :presence=>true + validate :commentable, :presence=>true + include IsCommentable + + def self.build_for(set_commentable, user, text,attr={}) + c = new + raise "Tried to build comment for non commentable" unless set_commentable.try(:is_commentable?) + c.user=user + c.text=text + c.assign_attributes(attr) + + unless set_commentable.class.to_s == "Comment" + c.commentable=set_commentable + c.save + else + + c.commentable=set_commentable.commentable + c.save + c.move_to_child_of(set_commentable) + end + c + end + def thumb_url + t_url= user.fetprofile.picture.thumb.url unless user.nil? or user.fetprofile.nil? + t_url + end + def divid + "comment_" + id.to_s + end + def formid +"comment_form_" + commentable_type + "_" + commentable_id.to_s + end + def self.formid_for(c) + "comment_form_" + c.class.to_s + "_" + c.id.to_s + end +end diff --git a/app/models/fetprofile.rb b/app/models/fetprofile.rb index bf367bf..1731382 100644 --- a/app/models/fetprofile.rb +++ b/app/models/fetprofile.rb @@ -16,7 +16,7 @@ class Fetprofile < ActiveRecord::Base attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname, :memberships_attributes, :remove_picture, :picture_cache, :plz, :street, :city, :instant,:skype, :telnr, :hdynr, :birth_day, :birth_month, :birth_year,:geschlecht - has_many :memberships, dependent: :delete_all + has_many :memberships, dependent: :destroy has_many :gremien, :through=> :membership mount_uploader :picture, PictureUploader has_paper_trail diff --git a/app/models/thema.rb b/app/models/thema.rb index 3f73b38..d61bf46 100644 --- a/app/models/thema.rb +++ b/app/models/thema.rb @@ -49,7 +49,9 @@ include Rails.application.routes.url_helpers def fix_links(host) full_url= URI.parse(root_url(:host=>host)) - self.text.gsub!(/src="[^"]*attachment\/datei\/(\d+)[^"]*"/){|s| full_url.path=Attachment.find($1.to_i).datei.url; 'src="'+full_url.to_s+'"'} + self.text.gsub!(/src="[\.\/]*uploads\/attachment\/datei\/(\d+)\/thumb_big[^"]*"/){|s| full_url.path=Attachment.find($1.to_i).datei.thumb_big.url; 'src="'+full_url.to_s+'"'} + self.text.gsub!(/src="[\.\/^"]*uploads\/attachment\/datei\/(\d+)\/[^"]*"/){|s| full_url.path=Attachment.find($1.to_i).datei.url; 'src="'+full_url.to_s+'"'} + self.text.gsub!(/href="[^"]*themen\/(\d+)[^"]*"/){|s| full_url.path=thema_path(Thema.find($1.to_i)); 'href="'+full_url.to_s+'"'} end diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb index c7d10a4..d08f8cd 100644 --- a/app/uploaders/attachment_uploader.rb +++ b/app/uploaders/attachment_uploader.rb @@ -89,8 +89,11 @@ end # def filename # "something.jpg" if original_filename # end -protected - def image?(file) - %w(jpg png jpeg).include?(File.extname(full_filename(file))) + def extention + File.extname(full_filename(file.file)).downcase + end + + def image?(for_file) + %w(.jpg .png .jpeg).include?(File.extname(full_filename(for_file.file)).downcase) end end diff --git a/app/views/beispiele/_beispiel.html.erb b/app/views/beispiele/_beispiel.html.erb index b44dde7..d7b9290 100644 --- a/app/views/beispiele/_beispiel.html.erb +++ b/app/views/beispiele/_beispiel.html.erb @@ -1,13 +1,13 @@ - -
<%= comment.text %>
+<% if can?(:comment, comment.commentable) %>
+
<%= link_to "comment" , new_comment_path( commentable_type: "Comment", commentable_id: comment.id), remote:true %>
+<% end %>
+
| + | + | + |
|---|---|---|
| <%= link_to 'Show', comment %> | +<%= link_to 'Edit', edit_comment_path(comment) %> | +<%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ +<%= render @comment %> + +<%= link_to 'Edit', edit_comment_path(@comment) %> | +<%= link_to 'Back', comments_path %> diff --git a/app/views/fetprofiles/_interninfo.html.erb b/app/views/fetprofiles/_interninfo.html.erb index bd5fc1f..4ea0119 100644 --- a/app/views/fetprofiles/_interninfo.html.erb +++ b/app/views/fetprofiles/_interninfo.html.erb @@ -1,5 +1,5 @@-Geburtstag <%= %> +Geburtstag <%= I18n.l(interninfo.birthday,format: :short) %>
Adresse: diff --git a/app/views/home/admin.html.erb b/app/views/home/admin.html.erb index 55cc15d..1c65a34 100644 --- a/app/views/home/admin.html.erb +++ b/app/views/home/admin.html.erb @@ -9,4 +9,12 @@ <%= semantic_form_for :set_page, url: fb_set_default_publish_page_user_path(current_user), html:{method: :get} do |f| %> <%= f.input :page , :input_html => { :name => 'page' }%> <% end %> + +<%= semantic_form_for :set_thema, url: choose_contact_topics_home_index_path, html:{method: :get} do |f| %> +<%= f.input :themen, :input_html=> {:name=>'themen'}, :as=>:select ,:multiple=>true,:collection =>Thema.all%> + + <%= f.actions do %> + <%= f.action :submit, :as => :button, :label=> I18n.t("common.save" ) %> +<% end %> +<% end %>
diff --git a/app/views/home/kontakt.html.erb b/app/views/home/kontakt.html.erb index f2d4a8b..68ff483 100644 --- a/app/views/home/kontakt.html.erb +++ b/app/views/home/kontakt.html.erb @@ -1,12 +1,10 @@- <%= I18n.t "kontakt.text" %> -
-<%= raw(I18n.t("kontakt.adresse_text")) %>
-<%= raw(I18n.t ("kontakt.telefon_text")) %>
+<% @themen.each do |th| %> +<%= render partial: "themen/small", object: th %> +<% end %> + + +