cartoonist-announcements 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/admin/announcements.js.coffee +5 -0
- data/app/assets/javascripts/cartoonist-announcements.js.coffee +71 -0
- data/app/assets/stylesheets/admin/announcements.css.scss +3 -0
- data/app/controllers/admin/announcements_controller.rb +33 -0
- data/app/controllers/announcements_controller.rb +5 -0
- data/app/helpers/admin/announcements_helper.rb +5 -0
- data/app/models/announcement.rb +36 -10
- data/app/views/admin/announcements/edit.html.erb +43 -0
- data/app/views/admin/announcements/index.html.erb +9 -3
- data/app/views/admin/announcements/new.html.erb +31 -0
- data/app/views/layouts/admin/announcements.html.erb +1 -1
- data/config/locales/en.yml +17 -0
- data/db/migrate/20121219051501_add_locked_column_to_announcements.rb +7 -0
- data/db/migrate/20121227022810_remove_enabled_column_from_announcements.rb +9 -0
- data/lib/cartoonist-announcements/engine.rb +15 -2
- data/lib/cartoonist-announcements/version.rb +1 -1
- metadata +41 -36
- data/app/assets/javascripts/cartoonist-announcements.js +0 -4
@@ -0,0 +1,71 @@
|
|
1
|
+
do ($ = jQuery) ->
|
2
|
+
CLOSED_ANNOUNCEMENTS_COOKIE = "closedAnnouncements"
|
3
|
+
COOKIE_EXPIRATION = 5 * 365 * 24 * 60 * 60 * 1000
|
4
|
+
|
5
|
+
$.announcement = (announcement) ->
|
6
|
+
$.extend announcement,
|
7
|
+
append: () ->
|
8
|
+
return @appendedContent if @appendedContent
|
9
|
+
@appendedContent = $ @content
|
10
|
+
|
11
|
+
if @isSession()
|
12
|
+
button = $ """<button class="close-announcent">×</button>"""
|
13
|
+
button.click =>
|
14
|
+
@markCookie()
|
15
|
+
@appendedContent?.slideUp => @appendedContent.remove()
|
16
|
+
false
|
17
|
+
@appendedContent.append button
|
18
|
+
|
19
|
+
@appendedContent.addClass("announcement #{@location}-announcement").attr("id", "announcement-#{@id}").hide()
|
20
|
+
$(@target()).append @appendedContent
|
21
|
+
@appendedContent
|
22
|
+
|
23
|
+
getCookieValue: () ->
|
24
|
+
return [] unless document.cookie
|
25
|
+
cookies = document.cookie.split ";"
|
26
|
+
announcementCookie = null
|
27
|
+
|
28
|
+
$.each cookies, (_, cookie) ->
|
29
|
+
value = cookie.split "="
|
30
|
+
if $.trim(value[0]) == CLOSED_ANNOUNCEMENTS_COOKIE
|
31
|
+
announcementCookie = value
|
32
|
+
return false
|
33
|
+
|
34
|
+
return [] unless announcementCookie
|
35
|
+
|
36
|
+
$.map $.trim(announcementCookie[1]).split(","), (id, _) ->
|
37
|
+
parseInt id, 10
|
38
|
+
|
39
|
+
isSession: () ->
|
40
|
+
@location == "session"
|
41
|
+
|
42
|
+
isDisplayed: () ->
|
43
|
+
return true unless @isSession()
|
44
|
+
$.inArray(@id, @getCookieValue()) < 0
|
45
|
+
|
46
|
+
markCookie: () ->
|
47
|
+
expiration = new Date()
|
48
|
+
expiration.setTime(expiration.getTime() + COOKIE_EXPIRATION)
|
49
|
+
value = @getCookieValue()
|
50
|
+
value.push @id unless $.inArray(@id, value) >= 0
|
51
|
+
value = value.join ","
|
52
|
+
document.cookie = "#{CLOSED_ANNOUNCEMENTS_COOKIE}=#{value}; expires=#{expiration.toGMTString()}"
|
53
|
+
|
54
|
+
show: () ->
|
55
|
+
@append().slideDown() if @isDisplayed()
|
56
|
+
|
57
|
+
target: () ->
|
58
|
+
if @isSession()
|
59
|
+
$("body").prepend("""<div class="session-announcements-container" />""") unless $(".session-announcements-container").size() > 0
|
60
|
+
".session-announcements-container"
|
61
|
+
else
|
62
|
+
".header"
|
63
|
+
|
64
|
+
$ ->
|
65
|
+
$.ajax
|
66
|
+
url: "/announcements"
|
67
|
+
dataType: "json"
|
68
|
+
success: (data) ->
|
69
|
+
return unless data.announcements?.length > 0
|
70
|
+
$.each data.announcements, (_, announcement) ->
|
71
|
+
$.announcement(announcement).show()
|
@@ -1,7 +1,40 @@
|
|
1
1
|
class Admin::AnnouncementsController < AdminCartoonistController
|
2
|
+
def new
|
3
|
+
end
|
4
|
+
|
5
|
+
def create
|
6
|
+
announcement = Announcement.create_announcement params
|
7
|
+
redirect_to "/admin/announcements/#{announcement.id}/edit"
|
8
|
+
end
|
9
|
+
|
10
|
+
def edit
|
11
|
+
@announcement = Announcement.find params[:id].to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
announcement = Announcement.update_announcement params
|
16
|
+
redirect_to "/admin/announcements/#{announcement.id}/edit"
|
17
|
+
end
|
18
|
+
|
2
19
|
def index
|
3
20
|
@unposted = Announcement.future.all
|
4
21
|
@active = Announcement.active.all
|
5
22
|
@expired = Announcement.expired.all
|
6
23
|
end
|
24
|
+
|
25
|
+
def lock
|
26
|
+
announcement = Announcement.find params[:id].to_i
|
27
|
+
announcement.lock!
|
28
|
+
redirect_to "/admin/announcements/#{announcement.id}/edit"
|
29
|
+
end
|
30
|
+
|
31
|
+
def unlock
|
32
|
+
announcement = Announcement.find params[:id].to_i
|
33
|
+
announcement.unlock!
|
34
|
+
redirect_to "/admin/announcements/#{announcement.id}/edit"
|
35
|
+
end
|
36
|
+
|
37
|
+
def preview_content
|
38
|
+
render :text => Markdown.render(params[:content]), :layout => false
|
39
|
+
end
|
7
40
|
end
|
data/app/models/announcement.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# TODO: Make this searchable
|
1
2
|
class Announcement < ActiveRecord::Base
|
2
|
-
|
3
|
+
include Postable
|
4
|
+
include Expirable
|
5
|
+
include Lockable
|
6
|
+
attr_accessible :posted_at, :expired_at, :title, :content, :location
|
3
7
|
validate :posted_at_must_be_before_expired_at, :posted_at_must_exist_if_expired_at_exists
|
4
8
|
|
5
9
|
def posted_at_must_be_before_expired_at
|
@@ -14,25 +18,47 @@ class Announcement < ActiveRecord::Base
|
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
21
|
+
def as_hash
|
22
|
+
{
|
23
|
+
:id => id,
|
24
|
+
:title => title,
|
25
|
+
:content => Markdown.render(content),
|
26
|
+
:location => location
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
17
30
|
class << self
|
18
|
-
def
|
19
|
-
|
31
|
+
def create_announcement(params)
|
32
|
+
create :title => params[:title], :content => params[:content], :location => params[:location], :locked => true
|
20
33
|
end
|
21
34
|
|
22
|
-
def
|
23
|
-
|
35
|
+
def update_announcement(params)
|
36
|
+
announcement = find params[:id].to_i
|
37
|
+
announcement.ensure_unlocked!
|
38
|
+
announcement.title = params[:title]
|
39
|
+
announcement.location = params[:location]
|
40
|
+
announcement.content = params[:content]
|
41
|
+
announcement.post_from params
|
42
|
+
announcement.expire_from params
|
43
|
+
announcement.locked = true
|
44
|
+
announcement.save!
|
45
|
+
announcement
|
24
46
|
end
|
25
47
|
|
26
|
-
def
|
27
|
-
|
48
|
+
def actives_as_hash
|
49
|
+
active.creation_order.map &:as_hash
|
28
50
|
end
|
29
51
|
|
30
|
-
def
|
31
|
-
|
52
|
+
def creation_order
|
53
|
+
order :id
|
54
|
+
end
|
55
|
+
|
56
|
+
def active
|
57
|
+
posted.unexpired
|
32
58
|
end
|
33
59
|
|
34
60
|
def future
|
35
|
-
|
61
|
+
unposted
|
36
62
|
end
|
37
63
|
end
|
38
64
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<p>
|
2
|
+
<%= form_tag "/admin/announcements/#{@announcement.id}/#{@announcement.toggle_lock_target}", :method => :post do %>
|
3
|
+
<input type="submit" value="<%= @announcement.toggle_lock_target %>" />
|
4
|
+
<% end %>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<%= form_tag "/admin/announcements/#{@announcement.id}", :method => :put do %>
|
8
|
+
<p>
|
9
|
+
<%= partial "shared/post_date_time", :postable => @announcement %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<p>
|
13
|
+
<%= partial "shared/expire_date_time", :expirable => @announcement %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<label>
|
18
|
+
<%= t "admin.announcements.edit.title_label" %>
|
19
|
+
<input type="text" name="title" value="<%= @announcement.title %>" <%= lock_disabled %> />
|
20
|
+
</label>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p>
|
24
|
+
<label>
|
25
|
+
<%= t "admin.announcements.edit.location" %>
|
26
|
+
<select name="location" <%= lock_disabled %>>
|
27
|
+
<option value="session" <%= selected @announcement.location, "session" %>><%= t "admin.announcements.edit.location_option.session" %></option>
|
28
|
+
<option value="top" <%= selected @announcement.location, "top" %>><%= t "admin.announcements.edit.location_option.top" %></option>
|
29
|
+
</select>
|
30
|
+
</label>
|
31
|
+
</p>
|
32
|
+
|
33
|
+
<p>
|
34
|
+
<label>
|
35
|
+
<%= t "admin.announcements.edit.content" %><br />
|
36
|
+
<textarea name="content" rows="15" cols="100" <%= lock_disabled %>><%= @announcement.content %></textarea>
|
37
|
+
</label>
|
38
|
+
</p>
|
39
|
+
|
40
|
+
<p>
|
41
|
+
<input type="submit" value="<%= t "admin.announcements.edit.save" %>" <%= lock_disabled %> />
|
42
|
+
</p>
|
43
|
+
<% end %>
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
<ul>
|
4
4
|
<% @unposted.each do |announcement| %>
|
5
|
-
<li
|
5
|
+
<li>
|
6
|
+
<a href="/admin/announcements/<%= announcement.id %>/edit"><%= announcement.title %></a>
|
7
|
+
</li>
|
6
8
|
<% end %>
|
7
9
|
</ul>
|
8
10
|
|
@@ -10,7 +12,9 @@
|
|
10
12
|
|
11
13
|
<ul>
|
12
14
|
<% @active.each do |announcement| %>
|
13
|
-
<li
|
15
|
+
<li>
|
16
|
+
<a href="/admin/announcements/<%= announcement.id %>/edit"><%= announcement.title %></a>
|
17
|
+
</li>
|
14
18
|
<% end %>
|
15
19
|
</ul>
|
16
20
|
|
@@ -18,6 +22,8 @@
|
|
18
22
|
|
19
23
|
<ul>
|
20
24
|
<% @expired.each do |announcement| %>
|
21
|
-
<li
|
25
|
+
<li>
|
26
|
+
<a href="/admin/announcements/<%= announcement.id %>/edit"><%= announcement.title %></a>
|
27
|
+
</li>
|
22
28
|
<% end %>
|
23
29
|
</ul>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<% content_for :title, t("admin.announcements.new.title") %>
|
2
|
+
|
3
|
+
<%= form_tag "/admin/announcements", :method => :post do %>
|
4
|
+
<p>
|
5
|
+
<label>
|
6
|
+
<%= t "admin.announcements.new.title_label" %>
|
7
|
+
<input type="text" name="title" />
|
8
|
+
</label>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<label>
|
13
|
+
<%= t "admin.announcements.new.location" %>
|
14
|
+
<select name="location">
|
15
|
+
<option value="session"><%= t "admin.announcements.new.location_option.session" %></option>
|
16
|
+
<option value="top"><%= t "admin.announcements.new.location_option.top" %></option>
|
17
|
+
</select>
|
18
|
+
</label>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<label>
|
23
|
+
<%= t "admin.announcements.new.content" %><br />
|
24
|
+
<textarea name="content" rows="15" cols="100"></textarea>
|
25
|
+
</label>
|
26
|
+
</p>
|
27
|
+
|
28
|
+
<p>
|
29
|
+
<input type="submit" value="<%= t "admin.announcements.new.save" %>" />
|
30
|
+
</p>
|
31
|
+
<% end %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% content_for :subtabs do %>
|
2
2
|
<a class="subtab" href="/admin/announcements"><%= t "admin.announcements.layout.list" %></a>
|
3
|
-
<!-- Disable until they are ready.
|
4
3
|
<a class="subtab" href="/admin/announcements/new"><%= t "admin.announcements.layout.new" %></a>
|
4
|
+
<!-- Disable until they are ready.
|
5
5
|
<a class="subtab" href="/admin/announcements/preview"><%= t "admin.announcements.layout.preview" %></a>
|
6
6
|
-->
|
7
7
|
<% end %>
|
data/config/locales/en.yml
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
en:
|
2
2
|
admin:
|
3
3
|
announcements:
|
4
|
+
edit:
|
5
|
+
content: "Content:"
|
6
|
+
location: "Location:"
|
7
|
+
location_option:
|
8
|
+
session: Session
|
9
|
+
top: Top
|
10
|
+
save: Save
|
11
|
+
title_label: "Title:"
|
4
12
|
index:
|
5
13
|
active: Currently active
|
6
14
|
expired: Expired
|
@@ -10,6 +18,15 @@ en:
|
|
10
18
|
new: New Announcement
|
11
19
|
preview: Preview
|
12
20
|
section: Announcements
|
21
|
+
new:
|
22
|
+
content: "Content:"
|
23
|
+
location: "Location:"
|
24
|
+
location_option:
|
25
|
+
session: Session
|
26
|
+
top: Top
|
27
|
+
save: Save
|
28
|
+
title: New Announcement
|
29
|
+
title_label: "Title:"
|
13
30
|
layout:
|
14
31
|
tab:
|
15
32
|
announcements: Announcements
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class RemoveEnabledColumnFromAnnouncements < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
remove_index :announcements, [:posted_at, :expired_at, :enabled]
|
4
|
+
remove_index :announcements, [:expired_at, :enabled]
|
5
|
+
remove_column :announcements, :enabled
|
6
|
+
add_index :announcements, [:posted_at, :expired_at]
|
7
|
+
add_index :announcements, [:expired_at]
|
8
|
+
end
|
9
|
+
end
|
@@ -1,16 +1,29 @@
|
|
1
1
|
module CartoonistAnnouncements
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
Cartoonist::Admin::Tab.add :announcements, :url => "/admin/announcements"
|
4
|
+
Cartoonist::Asset.add "admin/announcements.css"
|
5
|
+
Cartoonist::Asset.add "admin/announcements.js"
|
4
6
|
Cartoonist::Asset.include_js "cartoonist-announcements.js"
|
5
7
|
Cartoonist::Migration.add_for self
|
8
|
+
|
6
9
|
Cartoonist::Backup.for :announcements do
|
7
10
|
Announcement.order(:id)
|
8
11
|
end
|
12
|
+
|
9
13
|
Cartoonist::Routes.add do
|
10
|
-
resources :announcements, :only => []
|
14
|
+
resources :announcements, :only => [:index]
|
11
15
|
|
12
16
|
namespace :admin do
|
13
|
-
resources :announcements, :only => [:index]
|
17
|
+
resources :announcements, :only => [:new, :create, :edit, :update, :index] do
|
18
|
+
member do
|
19
|
+
post "lock"
|
20
|
+
post "unlock"
|
21
|
+
end
|
22
|
+
|
23
|
+
collection do
|
24
|
+
post "preview_content"
|
25
|
+
end
|
26
|
+
end
|
14
27
|
end
|
15
28
|
end
|
16
29
|
end
|
metadata
CHANGED
@@ -1,75 +1,80 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cartoonist-announcements
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.17
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.16
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Mike Virata-Stone
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-02-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: cartoonist
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.17
|
24
22
|
type: :runtime
|
25
|
-
|
26
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.17
|
30
|
+
description: This plugin for Cartoonist adds announcements for things like announcing
|
31
|
+
a new website.
|
27
32
|
email: reasonnumber@gmail.com
|
28
33
|
executables: []
|
29
|
-
|
30
34
|
extensions: []
|
31
|
-
|
32
35
|
extra_rdoc_files: []
|
33
|
-
|
34
|
-
|
35
|
-
- app/assets/javascripts/cartoonist-announcements.js
|
36
|
+
files:
|
37
|
+
- app/assets/javascripts/admin/announcements.js.coffee
|
38
|
+
- app/assets/javascripts/cartoonist-announcements.js.coffee
|
39
|
+
- app/assets/stylesheets/admin/announcements.css.scss
|
36
40
|
- app/controllers/admin/announcements_controller.rb
|
37
41
|
- app/controllers/announcements_controller.rb
|
42
|
+
- app/helpers/admin/announcements_helper.rb
|
38
43
|
- app/models/announcement.rb
|
44
|
+
- app/views/admin/announcements/edit.html.erb
|
39
45
|
- app/views/admin/announcements/index.html.erb
|
46
|
+
- app/views/admin/announcements/new.html.erb
|
40
47
|
- app/views/layouts/admin/announcements.html.erb
|
41
48
|
- cartoonist-announcements.gemspec
|
42
49
|
- config/locales/en.yml
|
43
50
|
- db/migrate/20120412035009_create_announcements.rb
|
51
|
+
- db/migrate/20121219051501_add_locked_column_to_announcements.rb
|
52
|
+
- db/migrate/20121227022810_remove_enabled_column_from_announcements.rb
|
44
53
|
- lib/cartoonist-announcements.rb
|
45
54
|
- lib/cartoonist-announcements/engine.rb
|
46
55
|
- lib/cartoonist-announcements/version.rb
|
47
56
|
homepage: http://reasonnumber.com/cartoonist
|
48
57
|
licenses: []
|
49
|
-
|
50
58
|
post_install_message:
|
51
59
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
60
|
+
require_paths:
|
54
61
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
63
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
69
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
67
74
|
requirements: []
|
68
|
-
|
69
75
|
rubyforge_project:
|
70
76
|
rubygems_version: 1.8.24
|
71
77
|
signing_key:
|
72
78
|
specification_version: 3
|
73
79
|
summary: Cartoonist Announcements
|
74
80
|
test_files: []
|
75
|
-
|