added news updates ui
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
(function() {
|
||||
Danbooru.News = {};
|
||||
Danbooru.NewsUpdate = {};
|
||||
|
||||
Danbooru.News.initialize = function() {
|
||||
var key = $("#news-ticker").data("updated-at");
|
||||
Danbooru.NewsUpdate.initialize = function() {
|
||||
var key = $("#news-updates").data("updated-at");
|
||||
|
||||
if (Danbooru.Cookie.get("news-ticker") === key) {
|
||||
$("#news-ticker").hide();
|
||||
$("#news-updates").hide();
|
||||
} else {
|
||||
$("#close-news-ticker-link").click(function(e) {
|
||||
$("#news-ticker").hide();
|
||||
$("#news-updates").hide();
|
||||
Danbooru.Cookie.put("news-ticker", key);
|
||||
|
||||
// need to reset the more link
|
||||
@@ -20,6 +20,6 @@
|
||||
}
|
||||
|
||||
$(function() {
|
||||
Danbooru.News.initialize();
|
||||
Danbooru.NewsUpdate.initialize();
|
||||
});
|
||||
})();
|
||||
@@ -1,4 +1,4 @@
|
||||
div#news-ticker {
|
||||
div#news-updates {
|
||||
padding: 5px;
|
||||
background: #EEE;
|
||||
border-bottom: 2px solid #666;
|
||||
|
||||
4
app/assets/stylesheets/news_updates.css
Normal file
4
app/assets/stylesheets/news_updates.css
Normal file
@@ -0,0 +1,4 @@
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
38
app/controllers/news_updates_controller.rb
Normal file
38
app/controllers/news_updates_controller.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
class NewsUpdatesController < ApplicationController
|
||||
before_filter :admin_only
|
||||
respond_to :html
|
||||
|
||||
def index
|
||||
@news_updates = NewsUpdate.paginate(params[:page])
|
||||
respond_with(@news_updates)
|
||||
end
|
||||
|
||||
def edit
|
||||
@news_update = NewsUpdate.find(params[:id])
|
||||
respond_with(@news_update)
|
||||
end
|
||||
|
||||
def update
|
||||
@news_update = NewsUpdate.find(params[:id])
|
||||
@news_update.update_attributes(params[:news_update])
|
||||
respond_with(@news_update, :location => news_updates_path)
|
||||
end
|
||||
|
||||
def new
|
||||
@news_update = NewsUpdate.new
|
||||
respond_with(@news_update)
|
||||
end
|
||||
|
||||
def create
|
||||
@news_update = NewsUpdate.create(params[:news_update])
|
||||
respond_with(@news_update, :location => news_updates_path)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@news_update = NewsUpdate.find(params[:id])
|
||||
@news_update.destroy
|
||||
respond_with(@news_update) do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/news_updates_helper.rb
Normal file
2
app/helpers/news_updates_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module NewsUpdatesHelper
|
||||
end
|
||||
15
app/models/news_update.rb
Normal file
15
app/models/news_update.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class NewsUpdate < ActiveRecord::Base
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :udpater, :class_name => "User"
|
||||
scope :recent, order("created_at desc").limit(5)
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
end
|
||||
end
|
||||
@@ -23,7 +23,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<header id="top">
|
||||
<%= render "news/listing" %>
|
||||
<%= render "news_updates/listing" %>
|
||||
|
||||
<h1><%= link_to Danbooru.config.app_name, "/" %></h1>
|
||||
<nav>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<% unless cookies["news-ticker"] == "2011-09-01" %>
|
||||
<div id="news-ticker" data-updated-at="2011-09-01">
|
||||
<ul>
|
||||
<li>10/22: Database has been reset</li>
|
||||
<li>Report issues on <a href="https://github.com/r888888888/danbooru/issues/new">Github</a> or the <a href="http://danbooru.donmai.us/forum/show/65870">forum</a></li>
|
||||
</ul>
|
||||
|
||||
<a href="#" id="close-news-ticker-link">close</a>
|
||||
</div>
|
||||
<% end %>
|
||||
11
app/views/news_updates/_listing.html.erb
Normal file
11
app/views/news_updates/_listing.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<% cache("news-updates", :expires_in => 1.hour) do %>
|
||||
<div id="news-updates" data-updated-at="<%= NewsUpdate.recent.first.try(:created_at).try(:strftime, "%m/%d/%Y") %>">
|
||||
<ul>
|
||||
<% NewsUpdate.recent.each do |news_update| %>
|
||||
<li><%= news_update.created_at.strftime("%m/%d") %>: <%= news_update.message.html_safe %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<a href="#" id="close-news-ticker-link">close</a>
|
||||
</div>
|
||||
<% end %>
|
||||
6
app/views/news_updates/_secondary_links.html.erb
Normal file
6
app/views/news_updates/_secondary_links.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<menu>
|
||||
<li><%= link_to "Listing", news_updates_path %></li>
|
||||
<li><%= link_to "New", new_news_update_path %></li>
|
||||
</menu>
|
||||
<% end %>
|
||||
1
app/views/news_updates/destroy.js.erb
Normal file
1
app/views/news_updates/destroy.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#news-update-<%= @news_update.id %>").remove();
|
||||
16
app/views/news_updates/edit.html.erb
Normal file
16
app/views/news_updates/edit.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<div id="c-news-updates">
|
||||
<div id="a-new">
|
||||
<h1>Edit Update</h1>
|
||||
|
||||
<%= simple_form_for(@news_update) do |f| %>
|
||||
<%= f.input :message, :hint => "Use HTML for formatting", :input_html => {:size => "30x5"} %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Edit Update - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
32
app/views/news_updates/index.html.erb
Normal file
32
app/views/news_updates/index.html.erb
Normal file
@@ -0,0 +1,32 @@
|
||||
<div id="c-news-updates">
|
||||
<div id="a-index">
|
||||
<h1>News Updates</h1>
|
||||
|
||||
<table class="striped" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Creator</th>
|
||||
<th>Message</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @news_updates.each do |news_update| %>
|
||||
<tr id="news-update-<%= news_update.id %>">
|
||||
<td><%= news_update.creator.name %></td>
|
||||
<td><%= news_update.message %></td>
|
||||
<td><%= link_to "Edit", edit_news_update_path(news_update) %> | <%= link_to "Delete", news_update_path(news_update), :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= numbered_paginator(@news_updates) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
News Updates - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
16
app/views/news_updates/new.html.erb
Normal file
16
app/views/news_updates/new.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<div id="c-news-updates">
|
||||
<div id="a-new">
|
||||
<h1>New Update</h1>
|
||||
|
||||
<%= simple_form_for(@news_update) do |f| %>
|
||||
<%= f.input :message, :hint => "Use HTML for formatting", :input_html => {:size => "30x5"} %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
New Update - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user