Update Announcement module

This commit is contained in:
manson 2014-05-01 16:44:01 +08:00
parent 824b484e67
commit c627429b92
38 changed files with 563 additions and 12 deletions

View File

@ -22,7 +22,7 @@ gem 'active_model_serializers'
#parser
gem 'nokogiri'
gem 'ckeditor'
#database
gem 'mongoid', github: "mongoid/mongoid"
@ -31,7 +31,10 @@ gem "mini_magick", github: 'minimagick/minimagick'
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
gem 'kaminari'
gem "impressionist"
gem 'ckeditor'
#built in modules
eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))

View File

@ -8,3 +8,4 @@
//= require basic/jquery.nanoscroller.js
//= require basic/jquery.easing.1.3.js
//= require ckeditor/init

View File

@ -125,8 +125,8 @@
top: 14px;
}
#orbit-bar #search .icon-search {
left: 20px;
top: 12px;
left: 16px;
top: 16px;
font-size: 1.2em;
}
#orbit-bar #search .search-clear {

View File

@ -1,6 +1,4 @@
class Admin::DashboardsController < OrbitAdminController
layout "back_end"
def index
end
end

View File

@ -2,6 +2,8 @@ class OrbitAdminController < ApplicationController
include OrbitCoreLib::Authorize
include OrbitCoreLib::PermissionUtility
include Authorize
include OrbitBackendHelper
before_action :authenticate_user
layout "back_end"
end

View File

@ -0,0 +1,87 @@
module OrbitBackendHelper
def self.included(base)
ActionView::Helpers::FormBuilder.send(:include, Orbit::FormBuilder)
end
def thead(field)
active = params[:sort].eql? field.to_s
order = active ? (["asc", "desc"]-[params[:order]]).first : "asc"
arrow = (order.eql? "desc") ? "<b class='icons-arrow-up-3'></b>" : "<b class='icons-arrow-down-4'></b>"
"<th class='#{active ? "active" : ""}'><a href='?sort=#{field}&order=#{order}''>#{t(field.to_sym)} #{active ? arrow : ""}</a></th>".html_safe
end
def datetime_picker(object_name, method, options = {})
options[:icon_time] ||= 'icons-clock'
options[:icon_date] ||= 'icons-calendar'
options[:icon_clear] ||= 'icons-cross-3'
options[:input_class] ||= 'input-large'
options[:value] ||= options[:object].send(method) if options[:object] && options[:object][method]
case options[:picker_type]
when 'date'
content_tag :div, :id => options[:id], :class => options[:class] do
date_picker(object_name, method, options)
end
when 'time'
content_tag :div, :id => options[:id], :class => options[:class] do
time_picker(object_name, method, options)
end
when 'separated'
options[:label] ||= I18n.t('datetime_picker.separated.label')
content_tag :div, :id => options[:id], :class => "separated_picker #{options[:class]}" do
concat label_tag options[:label] unless options[:no_label]
concat hidden_field(object_name, method, :value => options[:value])
concat separated_picker(object_name, method, options)
end
else
content_tag :div, :id => options[:id], :class => options[:class] do
default_picker(object_name, method, options)
end
end
end
def default_picker(object_name, method, options)
custom = {}
custom[:format] = options[:format] || 'yyyy/MM/dd hh:mm'
custom[:value] = format_value(options[:value], custom[:format]) if options[:value]
custom[:picker_class] = 'default_picker'
custom[:label] = options[:label] || I18n.t('datetime_picker.default.label')
custom[:placeholder] = options[:placeholder] || I18n.t('datetime_picker.default.placeholder')
picker(object_name, method, options.merge(custom))
end
def picker(object_name, method, options)
content_tag :div, :class => "#{options[:picker_class]} input-append", :style => "#{(options[:picker_class].eql?('time_picker') && options[:value].blank? && options[:separated]) ? 'pointer-events:none' : nil}" do
concat label_tag options[:label] unless options[:no_label]
concat text_field object_name, method, :placeholder => options[:placeholder], :class => options[:input_class], 'data-format' => options[:format], :value => options[:value]
concat (content_tag :span, :class => 'add-on clearDate' do
content_tag :i, nil, :class => options[:icon_clear]
end)
concat (content_tag :span, :class => 'add-on iconbtn' do
content_tag :i, nil, 'data-time-icon' => options[:icon_time], 'data-date-icon' => options[:icon_date]
end)
end
end
def format_value(value, format = 'yyyy-MM-dd hh:mm')
value.strftime(format.gsub('yyyy', '%Y').gsub('MM', '%m').gsub('dd', '%d').gsub('hh', '%H').gsub('mm', '%M')) rescue ""
end
def add_attribute(partial, f, attribute)
new_object = f.object.send(attribute).build
fields = f.fields_for(attribute, new_object, :child_index => "new_#{attribute}") do |f|
render :partial => partial, :object => new_object, :locals => {:f => f}
end
end
def is_filter_active?(field, value)
params[:filters][field].include?(value.to_s) ? "active" : "" rescue ""
end
end
module Orbit::FormBuilder
def datetime_picker(method, options = {})
@template.datetime_picker(@object_name, method, objectify_options(options))
end
end

View File

@ -0,0 +1,7 @@
class Ckeditor::Asset
include Ckeditor::Orm::Mongoid::AssetBase
delegate :url, :current_path, :size, :content_type, :filename, :to => :data
validates_presence_of :data
end

View File

@ -0,0 +1,7 @@
class Ckeditor::AttachmentFile < Ckeditor::Asset
mount_uploader :data, CkeditorAttachmentFileUploader, :mount_on => :data_file_name
def url_thumb
@url_thumb ||= Ckeditor::Utils.filethumb(filename)
end
end

View File

@ -0,0 +1,7 @@
class Ckeditor::Picture < Ckeditor::Asset
mount_uploader :data, CkeditorPictureUploader, :mount_on => :data_file_name
def url_content
url(:content)
end
end

View File

@ -2,6 +2,8 @@
extend ActiveSupport::Concern
included do
field :uid, type: String
index({ uid: 1}, { unique: true })
validates_uniqueness_of :uid

View File

@ -0,0 +1,56 @@
# encoding: utf-8
require 'carrierwave/processing/mime_types'
class AssetUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
process :set_content_type
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
# storage :file
# storage :s3
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"assets/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# def filename
# model.filename
# end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end

View File

@ -0,0 +1,36 @@
# encoding: utf-8
class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/ckeditor/attachments/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
Ckeditor.attachment_file_types
end
end

View File

@ -0,0 +1,47 @@
# encoding: utf-8
class CkeditorPictureUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/ckeditor/pictures/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
process :read_dimensions
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [118, 100]
end
version :content do
process :resize_to_limit => [800, 800]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
Ckeditor.image_file_types
end
end

View File

@ -0,0 +1,4 @@
<% content_for :right_nav do %>
<% end %>

View File

@ -3,7 +3,7 @@
<div class="action pull-right">
<button id="selectAllTags" class="btn"><%= t(:select_all) %></button>
<button id="deselect" class="btn btn-inverse toggable hide"><%= t(:deselect_all) %></button>
<%= link_to t(:delete), '#', id: "deleteTags", class: "btn btn-danger toggable hide", rel: '' %>
<%= link_to t(:delete_), '#', id: "deleteTags", class: "btn btn-danger toggable hide", rel: '' %>
<%= link_to t(:merge), '#', id: "mergerTags", class: "btn btn-success toggable hide", rel: merge_admin_tags_path %>
<%= link_to t(:add_to_default), add_to_default_admin_tags_path, id: "addDefault", class: "btn btn-info toggable hide", method: :post, remote: true %>
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), '#', class: "btn btn-primary open-slide", data: {title: t('new.tag'), id: 'new'} %>

View File

@ -0,0 +1,11 @@
<%# Link to the "First" page
- available local variables
url: url to the first page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="first">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
</li>

View File

@ -0,0 +1,11 @@
<%# Link to the "First" page
- available local variables
url: url to the first page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="first">
<%= link_to_unless current_page.first?, "«", url, :remote => remote %>
</li>

View File

@ -0,0 +1,8 @@
<%# Non-link tag that stands for skipped pages...
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<!-- <li class="page gap"><%= raw(t 'views.pagination.truncate') %></li> -->

View File

@ -0,0 +1,8 @@
<%# Non-link tag that stands for skipped pages...
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<!-- <li class="page gap"><%= raw(t 'views.pagination.truncate') %></li> -->

View File

@ -0,0 +1,11 @@
<%# Link to the "Last" page
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="last">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
</li>

View File

@ -0,0 +1,11 @@
<%# Link to the "Last" page
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="last">
<%= link_to_unless current_page.last?, "»", url, {:remote => remote} %>
</li>

View File

@ -0,0 +1,11 @@
<%# Link to the "Next" page
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="next">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
</li>

View File

@ -0,0 +1,11 @@
<%# Link to the "Next" page
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="next">
<%= link_to_unless current_page.last?, '', url, :rel => 'next', :remote => remote %>
</li>

View File

@ -0,0 +1,16 @@
<%# Link showing page number
- available local variables
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="page<%= ' active' if page.current? %>">
<% if page.current? %>
<a><%= page %></a>
<% else %>
<%= link_to page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
<% end %>
</li>

View File

@ -0,0 +1,16 @@
<%# Link showing page number
- available local variables
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="page<%= ' active' if page.current? %>">
<% if page.current? %>
<a><%= page %></a>
<% else %>
<%= link_to page, url, opts = {:remote => remote, :rel => page.next? ? '' : page.prev? ? '' : nil} %>
<% end %>
</li>

View File

@ -0,0 +1,25 @@
<%# The container tag
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside
-%>
<%= paginator.render do -%>
<div class="pagination">
<ul>
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
</div>
<% end -%>

View File

@ -0,0 +1,25 @@
<%# The container tag
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside
-%>
<%= paginator.render do -%>
<div class="pagination">
<ul>
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| -%>
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end -%>
<% end -%>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
</div>
<% end -%>

View File

@ -0,0 +1,11 @@
<%# Link to the "Previous" page
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="prev">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
</li>

View File

@ -0,0 +1,11 @@
<%# Link to the "Previous" page
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
num_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<li class="prev">
<%= link_to_unless current_page.first?, '', url, :rel => 'prev', :remote => remote %>
</li>

View File

@ -0,0 +1,13 @@
<div id="dialog" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete_modal" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3><%= (delete_options[:title] rescue nil) || t(:delete_) %></h3>
</div>
<div class="modal-body">
<span class="text-warning text-center"><%= (delete_options[:warning] rescue nil) || t(:delete_warning) %></span>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><%= (delete_options[:cancel] rescue nil) || t(:close) %></button>
<%= link_to ((delete_options[:submit] rescue nil) || t(:delete_)), nil, class: "delete-item btn btn-danger", method: :delete, remote: (delete_options[:remote] rescue false) || false %>
</div>
</div>

View File

@ -5,15 +5,17 @@
<%= render 'shared/meta' %>
<%= render 'shared/google_font' %>
<%= stylesheet_link_tag "back_end", media: "all", "data-turbolinks-track" => true %>
<%= stylesheet_link_tag params[:controller] if Rails.application.assets.find_asset "#{params[:controller]}.css" %>
<%= yield :page_specific_css %>
<%= javascript_include_tag "back_end" %>
<%= render 'shared/ie_html5_fix' %>
<%= javascript_include_tag params[:controller] if Rails.application.assets.find_asset "#{params[:controller]}.js" %>
<%= yield :page_specific_javascript %>
<%= csrf_meta_tags %>
</head>
<body id="dashboards">
<%= render 'layouts/orbit_bar_backend' %>
<%= render 'shared/side_bar' %>
<%= render 'layouts/side_bar' %>
<section id="main-wrap">
<div class="wrap-inner">
<div id="filter" class="topnav clearfix">

View File

@ -36,6 +36,9 @@ module Orbit
config.assets.paths << "#{path}/assets/fonts"
end
# Ckeditor
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
# tell the I18n library where to find your translations
I18n.load_path += Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]
@ -47,7 +50,7 @@ module Orbit
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
config.time_zone = 'Asia/Taipei'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]

View File

@ -6,7 +6,7 @@ Orbit::Application.initialize!
if Site.count == 0
site = Site.new
site.title = "Orbit"
site.title_translations = {:en=>"Orbit",:zh_tw=>"Orbit"}
site.valid_locales = [:en, :zh_tw]
site.in_use_locales = site.valid_locales
site.save
@ -15,7 +15,7 @@ end
if Page.count == 0
home = Page.new
home.name_translations = {:en=>"home",:zh_tw=>"首頁"}
home.url = ""
home.url = "/"
home.save
end

View File

@ -0,0 +1,34 @@
# Use this hook to configure ckeditor
Ckeditor.setup do |config|
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default), :mongo_mapper and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require "ckeditor/orm/mongoid"
# Allowed image file types for upload.
# Set to nil or [] (empty array) for all file types
# By default: %w(jpg jpeg png gif tiff)
# config.image_file_types = ["jpg", "jpeg", "png", "gif", "tiff"]
# Allowed attachment file types for upload.
# Set to nil or [] (empty array) for all file types
# By default: %w(doc docx xls odt ods pdf rar zip tar tar.gz swf)
# config.attachment_file_types = ["doc", "docx", "xls", "odt", "ods", "pdf", "rar", "zip", "tar", "swf"]
# Setup authorization to be run as a before filter
# By default: there is no authorization.
# config.authorize_with :cancan
# Asset model classes
# config.picture_model { Ckeditor::Picture }
# config.attachment_file_model { Ckeditor::AttachmentFile }
# Paginate assets
# By default: 24
# config.default_per_page = 24
# Customize ckeditor assets path
# By default: nil
# config.asset_path = "http://www.example.com/assets/ckeditor/"
end

View File

@ -20,10 +20,10 @@
# available at http://guides.rubyonrails.org/i18n.html.
en:
alternative: Alternative
en: English
zh_tw: Chinese
_locale: English
access:
denied:
ajax_401_error: "User session has been expired,please login again."
@ -443,6 +443,7 @@ en:
app_page_noname:
module_app_noname:
save_and_close: Save and close
more: "More"
search:
domains: Google Search Domains
not_found: "NOT FOUND"
@ -659,3 +660,24 @@ en:
visitors_this_year: This year's visitors
visitors_today: Today's visitors
yes_: "Yes"
dots: ●●●●●●
register: Register
registered: Registered
url: URL
url_alt: Alternative text
module_name:
tag: Tag
datetime_picker:
date:
label: Date
placeholder: "YYYY/MM/DD"
default:
label: Date and time
placeholder: "YYYY/MM/DD HH:MM"
separated:
label: Date and time
time:
label: Time
placeholder: "HH:MM"

View File

@ -1,5 +1,7 @@
Orbit::Application.routes.draw do
mount Ckeditor::Engine => '/ckeditor'
resources :sessions
get "logout", to: "sessions#destroy", as: "logout"

32
lib/orbit_model/status.rb Normal file
View File

@ -0,0 +1,32 @@
module OrbitModel
module Status
def self.included(base)
base.field :is_top, :type => Boolean, :default => false
base.field :is_hot, :type => Boolean, :default => false
base.field :is_hidden, :type => Boolean, :default => false
def is_top?
self.is_top
end
def is_hot?
self.is_hot
end
def is_hidden?
self.is_hidden
end
def status_for_table
status = ""
status << "<span class='label label-success'>#{I18n.t(:top)}</span> " if self.is_top
status << "<span class='label label-important'>#{I18n.t(:hot)}</span> " if self.is_hot
status << "<span class='label'>#{I18n.t(:hidden)}</span>"if self.is_hidden
status.html_safe
end
end
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB