Ray's modifications

This commit is contained in:
chris2tof committed 2011-11-18 16:43:14 +08:00
1 parent 861237d65b
commit 65349796d0
105 files changed
+1663 -369

No files matched your search

Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,7 @@
/*
*This is a manifest file that'll automatically include all the stylesheets available in this directory
*and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
*the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree .
*/
@@ -0,0 +1,21 @@
.preview h2 {
font-size: large;
background-color: red;
}
.production h2 {
font-size: large;
background-color: green;
}
.widget_index {
width: 200px;
height: 120px;
border: solid;
}
.widget_latest_post{
width: 200px;
height: 120px;
border: solid;
}
View File
Whitespace-only changes.
@@ -0,0 +1,23 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
# Set I18n.locale
def set_locale
# update session if passed
session[:locale] = params[:locale] if params[:locale]
# set locale based on session or default
begin
# check if locale is valid for non site pages
if !VALID_LOCALES.include?(session[:locale])
I18n.locale = I18n.default_locale
else
I18n.locale = session[:locale]
end
rescue
I18n.locale = I18n.default_locale
end
end
end
@@ -0,0 +1,7 @@
class Panel::Blog::CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(params[:comment])
redirect_to panel_blog_post_url(@post)
end
end
@@ -0,0 +1,111 @@
class Panel::Blog::PostsController < ApplicationController
layout 'admin'
# GET /posts
# GET /posts.xml
def widget_index
@posts = Post.all
widget_default_layout
end
def widget_latest_post
@post = Post.all.last
widget_default_layout
end
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
# POST /posts.xml
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to(panel_blog_post_url(@post), :notice => t('blog.create_post_success')) }
format.xml { render :xml => @post, :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to(panel_blog_post_url(@post), :notice => t('blog.update_post_success')) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.xml
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to(panel_blog_posts_url) }
format.xml { head :ok }
end
end
end
def widget_default_layout
respond_to do |format|
format.html {
if params[:edit_view]
#in the case of editing,should be displayed in modal window and
#be restricted by the border developer sat.
render :layout => 'admin'
else
#in the case of fetching data for ajax display,should
render :layout => 'production'
end
}
format.xml { render :xml => @posts }
end
end
View File
Whitespace-only changes.
@@ -0,0 +1,2 @@
module ApplicationHelper
end
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+7
View File
@@ -0,0 +1,7 @@
class Comment
include Mongoid::Document
include Mongoid::Timestamps
field :name, :type => String
field :body, :type => String
embedded_in :post, :inverse_of => :comments
end
+8
View File
@@ -0,0 +1,8 @@
class Post
include Mongoid::Document
include Mongoid::Timestamps
field :title, :type => String
field :body, :type => String
embeds_many :comments
validates_presence_of :title, :body
end
View File
Whitespace-only changes.
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body class="edit preview">
<div class="wapper">
<%= yield %>
</div>
</body>
</html>
@@ -0,0 +1,3 @@
<div class="production">
<%= yield %>
</div>
@@ -0,0 +1,14 @@
<%= f.error_messages %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :body %><br />
<%= f.text_area :body %>
</div>
<div class="actions">
<%= f.submit %>
</div>
@@ -0,0 +1,8 @@
<h1><%= t('blog.editing_post') %></h1>
<%= form_for @post, :url => panel_blog_post_path(@post) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
<%= link_to t('blog.show'), panel_blog_post_path(@post) %> |
<%= link_back %>
@@ -0,0 +1,25 @@
<h1><%= t('blog.list_post') %></h1>
<table>
<tr>
<th><%= t('blog.title') %></th>
<th><%= t('blog.body') %></th>
<th></th>
<th></th>
<th></th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.body %></td>
<td><%= link_to t('blog.show'), panel_blog_post_path(post) %></td>
<td><%= link_to t('blog.edit'), edit_panel_blog_post_path(post) %></td>
<td><%= link_to t('blog.delete'), panel_blog_post_path(post), :confirm => t('blog.sure?'), :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to t('blog.new_post'), new_panel_blog_post_path %>
@@ -0,0 +1,5 @@
<%=stylesheet_link_tag "NewBlog/application"%>
<h2><%=@post.title%></h2>
<p>
<%= @post.body%>
</p>
@@ -0,0 +1,6 @@
<h1><%= t('blog.new_post') %></h1>
<%= form_for @post, :url => panel_blog_posts_path do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
<%= link_back %>
@@ -0,0 +1,38 @@
<p id="notice"><%= flash_messages %></p>
<p>
<b><%= t('blog.body') %></b>
<%=h @post.body %>
</p>
<h2><%= t('blog.comments') %></h2>
<% @post.comments.each do |c| %>
<p>
<b><%=h c.name %> said:</b><br />
<%= time_ago_in_words(c.created_at) %> ago
</p>
<p>
<%=h c.body %>
</p>
<% end %>
<%= form_for Comment.new, :url => panel_blog_comments_path do |f| %>
<p>
<%= f.label :name, "Author" %><br />
<%= f.text_field :name %><br />
<%= f.label :body, "Comment Description" %><br />
<%= f.text_area :body %>
<%= hidden_field_tag :post_id, @post.id %>
</p>
<p>
<%= f.submit "Add Comment" %>
</p>
<% end %>
<%= link_to t('blog.edit'), edit_panel_blog_post_path(@post) %> |
<%= link_back %>
@@ -0,0 +1,16 @@
<%=stylesheet_link_tag "NewBlog/application"%>
<div class="widget_index">
<table>
<tr>
<th><%= t('blog.title') %></th>
<th><%= t('blog.body') %></th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= link_to post.title,panel_blog_post_path(post) %></td>
<td><%= post.body.truncate(14) %></td>
</tr>
<% end %>
</table>
</div>
@@ -0,0 +1,7 @@
<%=stylesheet_link_tag "NewBlog/application"%>
<div class="widget_latest_post">
<h2><%= @post.title %> </h2>
<p>
<%= @post.body %>
</p>
</div>