Permalink
Browse files

Add chosen;

Add @ reply feature.
More style improve.
Version 0.0.4.
  • Loading branch information...
1 parent 6af83c4 commit eb059ea5bac7f42edf19c86a3a73a55a53b46b00 @huacnlee huacnlee committed Apr 19, 2012
@@ -1,5 +1,7 @@
#= require jquery.hotkeys
#= require jquery.timeago
+#= require jquery.atwho
+#= require jquery.chosen
#= require_self
# TopicsController 下所有页面的 JS 功能
window.Topics =
@@ -42,6 +44,7 @@ window.Topics =
# Page.ready
$(document).ready ->
$("abbr.timeago").timeago()
+ $("select").chosen()
$("textarea").bind "keydown","ctrl+return",(el) ->
if $(el.target).val().trim().length > 0
$("#reply form").submit()
@@ -1,3 +1,8 @@
+/*
+ *= require jquery.atwho
+ *= require jquery.chosen
+ */
+ .bbs_name { text-align:right; font-size:18px;}
.topics .topic .title a:link,
.topics .topic .title a:visited,
.node_topics .title a:link,
@@ -7,6 +12,21 @@
.sidebar p { margin-bottom:8px;}
+#sections {
+ ul {
+ margin:0; list-style:none;
+ li {
+ margin-bottom:10px;
+ position:relative;
+ min-height:20px;
+ label { display:block; width:80px; text-align:right; color:#999; padding-right:10px; position:absolute; left:0; top:0; }
+ a { display:inline-block; margin-right:8px; }
+ .items { padding-left:90px; }
+ }
+
+ }
+}
+
.topics { }
.topics .topic { }
.topics .topic_line {border-top:1px solid #DDD; padding:10px 0; margin:0 -10px; vertical-align:top; }
@@ -24,19 +44,14 @@
.topics .tools { text-align:right; }
.topics .tools a {margin-left:6px;}
.topics .topic .replies { width:70px; margin-right:10px; text-align:right; vertical-align:middle; }
-.topics .topic .replies a.count,
-.topics .topic .replies a.count:visited { line-height: 12px; font-weight: bold; color: white;
+.topics .topic .replies a.count:link { line-height: 12px; font-weight: bold; color: white;
background-color: #1c7fdb; display: inline-block;
padding: 2px 10px 2px 10px;
-moz-border-radius: 12px; -webkit-border-radius: 12px;
margin: 18px 12px 0px 0px; text-decoration: none; }
+.topics .topic .replies a.count:visited { background:#ddd; color:#aaa;}
.topics .topic .replies a.count:hover { color:write; background-color:#1F8AEE; }
-.topics .topic .replies a.state0:link,
-.topics .topic .replies a.state0:visited { background:#DDD; }
-.topics .topic .replies a.state0:hover { background:#1dc115;}
-.topics .topic .replies a.state2:link,
-.topics .topic .replies a.state2:visited { background:#22D419; }
-.topics .topic .replies a.state2:hover {background:#1dc115; }
+
.topics tr.topic td.replies { text-align:right; width:50px; font-size:14px; color:green;font-weight:bold; }
.more { padding:8px; border-top:1px solid #DDD; font-size:14px; text-align:right; }
@@ -11,7 +11,7 @@ def update
@reply = current_user.replies.find(params[:id])
if @reply.update_attributes(params[:reply])
- redirect_to(topic_path(@reply.topic_id), :notice => '回帖删除成功.')
+ redirect_to(topic_path(@reply.topic_id,:anchor => "reply#{@reply.topic.replies_count}"), :notice => '回帖更新成功.')
else
render :action => "edit"
end
@@ -60,8 +60,13 @@ def show
# GET /topics/new.xml
def new
@topic = Topic.new
- @topic.node_id = params[:node]
- @node = Node.find(params[:node])
+ if !params[:node].blank?
+ @topic.node_id = params[:node]
+ @node = Node.find_by_id(params[:node])
+ if @node.blank?
+ render_404
+ end
+ end
end
def reply
@@ -73,7 +78,7 @@ def reply
else
flash[:notice] = @reply.errors.full_messages.join("<br />")
end
- redirect_to topic_path(params[:id],:anchor => 'reply')
+ redirect_to topic_path(params[:id],:anchor => "reply")
end
# GET /topics/1/edit
@@ -4,5 +4,10 @@ module TopicsHelper
def format_topic_body(text,title = "",allow_image = true)
auto_link(simple_format(text),:all, :target => '_blank', :rel => "nofollow")
end
+
+ def render_topic_node_select_tag(topic, opts = {})
+ return "" if topic.blank?
+ grouped_collection_select(:topic, :node_id, Section.all,:sorted_nodes, :name, :id, :name, {:value => topic.node_id, :include_blank => false}, opts)
+ end
end
end
@@ -20,5 +20,12 @@ class Node
scope :hots, desc(:topics_count)
scope :sorted, desc(:sort)
+
+ # 热门节电给 select 用的
+ def self.node_collection
+ Rails.cache.fetch("node:node_collection:#{CacheVersion.section_node_updated_at}") do
+ Node.all.collect { |n| [n.name,n.id] }
+ end
+ end
end
end
@@ -13,5 +13,9 @@ class Section
default_scope desc(:sort)
+
+ def sorted_nodes
+ self.nodes.sorted
+ end
end
end
@@ -6,7 +6,10 @@
<div class="clearfix">
<%= f.label :title %>
<div class="input">
- <%= f.text_field :title, :class => "span7" %>
+ <span class="span2" style="margin-left:0px;margin-right:10px;">
+ <%= render_topic_node_select_tag(@topic, :style => "width:140px;") %>
+ </span>
+ <%= f.text_field :title, :class => "span6" %>
</div>
</div>
<div class="clearfix">
@@ -16,7 +19,7 @@
</div>
</div>
<div class="actions">
- <input type="submit" value="保存" class="btn primary">
+ <input type="submit" value="保存" class="btn btn-primary">
<a href="<%= @topic.id.blank? ? topics_path : topic_path(@topic) %>" class="btn">取消</a>
</div>
</fieldset>
@@ -1,65 +1,49 @@
<div class="sidebar">
-<% if ["show","new","edit","node"].index(params[:action]) %>
- <div class="box">
- <h2><a href="<%= node_topics_path(@node.id) %>"><%= @node.name %></a></h2>
- <% if ["new"].index params[:action] %>
- <p class="sumamry">
- <%= @node.summary %>
- </p>
- <% end %>
- <div class="content">
- <a class="btn success" href="<%= new_topic_path(:node => @node.id) %>">发布新帖</a>
+
+ <% if params[:action] == "index" %>
+ <div class="box">
+ <h2>社区论坛</h2>
+ <div class="content">
+ <a class="btn btn-success" href="<%= new_topic_path %>">发布新帖</a>
+ </div>
+ <div style="text-align:center;">
+ <a href="<%= homeland.feed_topics_url %>" title="用RSS阅读器订阅<%= Setting.app_name %>论坛新贴">
+ <%= image_tag('feed.png', :alt => "订阅#{Setting.app_name}论坛新贴") %></a>
+ </div>
</div>
- </div>
-<% elsif params[:action] == "index" %>
- <div class="box">
- <h2>社区论坛</h2>
- <p>
- 发贴请先进入一个节点以后点击“发布新帖”。
- </p>
- <p style="text-align:center;">
- <a href="<%= homeland.feed_topics_url %>" title="用RSS阅读器订阅<%= Setting.app_name %>论坛新贴">
- <%= image_tag('feed.png', :alt => "订阅#{Setting.app_name}论坛新贴") %></a>
- </p>
- </div>
-<% end %>
-<%= cache("topic/init_list_sidebar/hot_nodes",:expires_in => 30.minutes) do %>
- <% if not @hot_nodes.blank? %>
- <div class="hot_nodes nodes box">
- <h2>热门节点</h2>
- <p>
- <% @hot_nodes.each do |node| %>
- <a href="<%= node_topics_path(:id => node.id) %>"><%= node.name %></a>
+ <% end %>
+
+ <% if ["show","new","edit","node"].index(params[:action]) and !@node.blank? %>
+ <div class="box">
+ <h2><a href="<%= node_topics_path(@node.id) %>"><%= @node.name %></a></h2>
+ <% if ["new"].index params[:action] %>
+ <p class="sumamry">
+ <%= @node.summary %>
+ </p>
<% end %>
- </p>
- </div>
+ <div class="content">
+ <a class="btn btn-success" href="<%= new_topic_path(:node => @node.id) %>">发布新帖</a>
+ </div>
+ </div>
<% end %>
-<% end %>
-<% if current_user and (not @user_last_nodes.blank?) %>
-<div class="user_last_nodes nodes box">
- <h2>最近访问节点</h2>
- <p>
- <% @user_last_nodes.each do |node| %>
- <a href="<%= node_topics_path(:id => node.id) %>"><%= node.name %></a>
- <% end %>
- </p>
-</div>
-<% end %>
-<% if ["new"].index(params[:action]) %>
- <div id="topic_new_tip" class="box">
- <h2>发贴说明</h2>
- <ol>
- <li>发布后正文排版会自动安你在文本框里面输入的样子排列.如果里面带有 URL地址,将会自动转变为超级链接。</li>
- </ol>
- </div>
-<% end %>
-<% if params[:action] == "index" %>
-<div class="totals box">
- <h2>统计信息</h2>
- <ul>
- <li>贴子数: <%= Homeland::Topic.count %> 篇</li>
- <li>回贴数: <%= Homeland::Reply.count %> 条</li>
- </ul>
-</div>
-<% end %>
+
+ <% if ["new"].index(params[:action]) %>
+ <div id="topic_new_tip" class="box">
+ <h2>发贴说明</h2>
+ <ol>
+ <li>发布后正文排版会自动安你在文本框里面输入的样子排列.如果里面带有 URL地址,将会自动转变为超级链接。</li>
+ </ol>
+ </div>
+ <% end %>
+
+ <% if params[:action] == "index" %>
+ <div class="totals box">
+ <h2>统计信息</h2>
+ <ul>
+ <li>贴子数: <%= Homeland::Topic.count %> 篇</li>
+ <li>回贴数: <%= Homeland::Reply.count %> 条</li>
+ </ul>
+ </div>
+ <% end %>
+
</div>
@@ -9,7 +9,7 @@
</a>
</div>
<div class="infos">
- <div class="title"><a href="<%= topic_path(topic) %>" title="<%= topic.title %>"><%= truncate(topic.title, :length => 100) %></a></div>
+ <div class="title"><a href="<%= topic_path(topic) %>#reply<%= topic.replies_count %>" title="<%= topic.title %>"><%= truncate(topic.title, :length => 100) %></a></div>
<div class="info leader">
<%= user_name_tag(topic.user) %>
在 <a href="<%= node_topics_path(topic.node_id) %>"><%= topic.node.name %></a> 中发起
@@ -18,7 +18,7 @@
</p>
</div>
<% else %>
- <h1><%= Setting.app_name %></h1>
+ <h1 class="bbs_name"><%= Setting.app_name %></h1>
<% end %>
<div class="topics">
<%= render :partial => "topic", :collection => @topics %>
@@ -39,9 +39,11 @@
<% @sections.each do |section| %>
<li>
<label><%= section.name %></label>
- <% section.nodes.each do |node| %>
- <a href="<%= node_topics_path(node.id) %>" title="<%= node.name %>"><%= node.name %></a>
- <% end %>
+ <div class="items">
+ <% section.nodes.each do |node| %>
+ <a href="<%= node_topics_path(node.id) %>" title="<%= node.name %>"><%= node.name %></a>
+ <% end %>
+ </div>
</li>
<% end %>
</ul>
@@ -62,14 +62,21 @@
</div>
</div>
<% end %>
+ <script type="text/javascript">
+ $(document).ready(function(){
+ atDatas = []
+ $(".reply .name a").text(function(idx,text) { atDatas.push(text) });
+ $('#reply_body').atWho("@",{'data':atDatas});
+ })
+ </script>
</div>
<% end %>
<% if current_user %>
<div id="reply" class="form box">
<h4>回复</h4>
<%= form_for(Homeland::Reply.new,:url => reply_topic_path(params[:id])) do |f| %>
<div class="pull-right">
- <button type="submit" class="btn primary">提交回复</button><br />
+ <button type="submit" class="btn btn-primary">提交回复</button><br />
<span class="help-inline">Ctrl+Enter</span>
</div>
<div class="clearfix">
@@ -81,7 +88,7 @@
<% else %>
<div id="reply" class="form box">
<div style="padding:20px;">
- 需要 <a href='/account/sign_in' class="btn primary">登录</a> 后回复方可回复, 如果你还没有账号 <a href="/account/sign_up" class="btn danger"> 点击这里注册</a>。
+ 需要 <a href='/account/sign_in' class="btn btn-primary">登录</a> 后回复方可回复, 如果你还没有账号 <a href="/account/sign_up" class="btn btn-success"> 点击这里注册</a>。
</div>
</div>
<% end %>
View
@@ -1,7 +1,7 @@
# coding: utf-8
Gem::Specification.new do |s|
s.name = "homeland"
- s.version = "0.0.3"
+ s.version = "0.0.4"
s.platform = Gem::Platform::RUBY
s.authors = ["Jason Lee"]
s.email = ["huacnlee@gmail.com"]
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.add_dependency("rails", "> 3.1.0")
+ s.add_dependency("jquery-atwho-rails", "~> 0.1.5")
s.files = Dir.glob("lib/**/*") + Dir.glob("app/**/*") + Dir.glob("config/**/*") + %w(README.markdown)
s.require_path = 'lib'
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit eb059ea

Please sign in to comment.