many tiny changes

This commit is contained in:
jomo
2013-06-25 02:53:12 +02:00
parent c5dfdbeb8f
commit ceb39bf0c3
22 changed files with 209 additions and 80 deletions

View File

@@ -13,3 +13,5 @@
//= #require jquery
//= #require jquery_ujs
//= #require_tree .
//= require jquery
//= require confirm

View File

@@ -1,3 +0,0 @@
# 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/

View File

@@ -1,3 +0,0 @@
# 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/

View File

@@ -0,0 +1,6 @@
$(function(){
$('[data-confirm]').click(function(){
var c = confirm($(this).attr('data-confirm'));
if (!c) return false;
})
})

6
app/assets/javascripts/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +0,0 @@
# 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/

View File

@@ -173,6 +173,9 @@ and (min-width: 1000px)
#post-content {
margin-top: 10px;
clear: both;
img {
max-width: 100%;
}
}
#comments {
@@ -181,10 +184,18 @@ and (min-width: 1000px)
margin-bottom: 12px;
padding: 15px;
box-shadow: 0 0 10px #bbb inset;
&:hover .editlink {
opacity: 1;
margin-right: 0;
}
&.author {
background: #dadada;
box-shadow: 0 0 10px #a7a7a7 inset;
}
.comment-content {
word-wrap: break-word;
overflow: hidden;
}
}
textarea {
width: 480px;
@@ -296,7 +307,24 @@ and (min-width: 1000px)
}
}
.editlink {
float: right;
opacity: 0;
margin-right: -10px;
transition: opacity 0.3s, margin 0.3s;
}
#edit_create_post {
float: left;
}
#delete_post {
float: right;
}
#blogpost_text {
width: 100%;
}

View File

@@ -64,6 +64,6 @@ class BlogpostsController < ApplicationController
else
flash[:alert] = "You are not allowed to delete this Post"
end
redirect_to blogpots_path
redirect_to blogposts_path
end
end

View File

@@ -3,7 +3,6 @@ class CommentsController < ApplicationController
def edit
@comment = Comment.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @comment.user.rank.to_i) || (current_user == @comment.user))
@comment = Comment.find(params[:id])
session[:return_to] = blogpost_path(@comment.blogpost)
else
flash[:alert] = "You are not allowed to edit this comment"
@@ -19,7 +18,7 @@ class CommentsController < ApplicationController
if @comment.save
redirect_to @comment.blogpost, notice: 'Comment created!'
else
flash[:alert] = "There was a problem while saving your comment"
flash[:alert] = @comment.errors.full_messages.first
redirect_to blogpost_path(params[:blogpost_id])
end
end

View File

@@ -8,56 +8,70 @@ class UsersController < ApplicationController
@user = User.find(params[:id])
end
# GET /users/new
# GET /users/new.json
# REGISTER
def new
if current_user
flash[:alert] = "You are already registered!"
flash[:notice] = "You are already registered!"
redirect_to user_path(current_user.id)
else
@user = User.new
end
end
# GET /users/1/edit
def edit
if current_user && (current_user.id = params[:id] || current_user.rank >= rank_to_int("mod"))
@user = User.find(params[:id])
else
@user = User.find(params[:id])
unless current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @user.rank.to_i) || (current_user == @user) && @user.id != 1 )
flash[:alert] = "You are not allowed to edit this user"
redirect_to user_path(params[:id])
redirect_to user_path(@user)
end
end
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
@user.last_ip = request.remote_ip
if @user.save
redirect_to @user, notice: 'User was successfully created.'
if current_user
flash[:notice] = "You are already registered!"
redirect_to current_user
else
flash[:alert] = "Something went wrong"
render action: "new"
@user = User.new(params[:user])
@user.last_ip = request.remote_ip
if @user.save
session[:user_id] = @user.id
redirect_to @user, notice: 'Successfully registered!'
else
flash[:alert] = "Something went wrong"
render action: "new"
end
end
end
# PUT /users/1
# PUT /users/1.json
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
redirect_to @user, notice: 'User was successfully updated.'
if (current_user && @user.id != 1) && ( (current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @user.rank.to_i) || current_user == @user)
if @user.update_attributes(params[:user])
redirect_to @user, notice: 'User was successfully updated.'
else
flash[:alert] = "There was a problem while updating this user"
render action: "edit"
end
else
render action: "edit"
flash[:alert] = "You are not allowed to edit this user"
redirect_to @user
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user = User.find(params[:id])
@user.destroy
redirect_to users_url
if (current_user && @user.id != 1) && (current_user.rank >= rank_to_int("superadmin") && current_user.rank.to_i >= @user.rank.to_i)
if @user.destroy
flash[:notice] = "User deleted forever."
redirect_to users_url
else
flash[:alert] = "Problem while deleting user"
redirect_to @user
end
else
flash[:alert] = "You are not allowed to delete this user"
redirect_to @user
end
end
end

View File

@@ -4,4 +4,12 @@ class Blogpost < ActiveRecord::Base
belongs_to :user
has_many :comments
accepts_nested_attributes_for :comments
def author
@author ||= if user.present?
user
else
User.find_by_name("Deleted user")
end
end
end

View File

@@ -1,6 +1,10 @@
class Comment < ActiveRecord::Base
attr_accessible :text, :user, :blogpost, :post
validates_presence_of :text, :user, :blogpost
validates_length_of :text, :in => 4..1000
belongs_to :blogpost
belongs_to :user
end

View File

@@ -1,5 +0,0 @@
<%= simple_form_for @post do |f|%>
<%= f.input :title, :label => false %>
<%= f.input :text, :label => false %>
<%= f.submit "Create Post" %>
<% end %>

View File

@@ -1,6 +1,10 @@
<h1>Editing blogpost</h1>
<h1>Edit post</h1>
<%= render 'form' %>
<%= link_to 'Show', @blogpost %> |
<%= link_to 'Back', blogposts_path %>
<%= simple_form_for @post do |f|%>
<%= f.input :title, :label => false %>
<%= f.input :text, :label => false %>
<%= f.submit "Update Post", :id => "edit_create_post" %>
<% end %>
<div id="delete_post">
<%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post forever?" %>
</div>

View File

@@ -1,3 +1,6 @@
<h1>New Post</h1>
<%= render 'form' %>
<%= simple_form_for @post do |f|%>
<%= f.input :title, :label => false %>
<%= f.input :text, :label => false'%>
<%= f.submit "Update Post", :id => "edit_create_post" %>
<% end %>

View File

@@ -1,5 +1,5 @@
<h1><%= @post.title %></h1>
<span class="post-info"><%= link_to @post.user.name, @post.user %> on <%= @post.created_at.strftime("%e. %b %Y") %>
<span class="post-info"><%= link_to @post.author.name, @post.author %> on <%= @post.created_at.strftime("%e. %b %Y") %>
<% if current_user && current_user.rank >= rank_to_int("mod") %>
- <%= link_to "edit", edit_blogpost_path(@post.id) %>
<% end %>
@@ -9,20 +9,7 @@
</div>
<div id="comments">
<% @post.comments.each do |c| %>
<div class="comment <%= "author" if c.user == @post.user %>">
<span class="comment-info"><%= link_to c.user.name, c.user %> on <%= c.created_at.strftime("%e. %b %Y") %>
<% if current_user && current_user.rank >= rank_to_int("mod") %>
- <%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c) %>
<% end %>
</span>
<div class="comment-content"><%= c.text %></div>
</div>
<% end %>
<% if current_user %>
<h3>New comment</h3>
<%= simple_form_for [@post, @comment] do |f| %>
<%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %>
<%= f.submit %>
<% end %>
<%= render "comments/comment", :c => c %>
<% end %>
<%= render "comments/new" %>
</div>

View File

@@ -0,0 +1,8 @@
<div class="comment <%= "author" if c.user == @post.user %>">
<span class="comment-info"><%= link_to c.user.name, c.user %> <%= c.created_at.strftime("%e. %b %Y, %H:%m") %>
<% if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= c.user.rank.to_i) || (current_user == c.user)) %>
<div class="editlink"><%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c) %></div>
<% end %>
</span>
<div class="comment-content"><%= c.text %></div>
</div>

View File

@@ -0,0 +1,7 @@
<% if current_user %>
<h3>New comment</h3>
<%= simple_form_for [@post, @comment] do |f| %>
<%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %>
<%= f.submit %>
<% end %>
<% end %>

View File

@@ -5,6 +5,7 @@
<%= stylesheet_link_tag "application", :media => "all" %>
<%= csrf_meta_tags %>
<%= favicon_link_tag "favicon.ico" %>
<%= javascript_include_tag "application" %>
</head>
<body>
<%= render "/layouts/head" %>