Merge branch 'nccu_0509' of https://github.com/Rulingcom/orbit into nccu_0509

This commit is contained in:
Matthew K. Fu JuYuan 2012-05-18 10:52:16 +08:00
commit 1d9fc7eb75
14 changed files with 145 additions and 50 deletions

View File

@ -62,14 +62,16 @@ function myFileBrowser(field_name, url, type, win) {
tinyMCE.activeEditor.windowManager.open({ tinyMCE.activeEditor.windowManager.open({
file : cmsURL, file : cmsURL,
title : 'File Browser', title : 'File Browser',
width : 850, // Your dimensions may differ - toy around with them! width : 530, // Your dimensions may differ - toy around with them!
height : 455, height : 350,
resizable : "no", resizable : "no",
inline : "no", // This parameter only has an effect if you use the inlinepopups plugin! inline : "no", // This parameter only has an effect if you use the inlinepopups plugin!
close_previous : "no" close_previous : "no"
}, { }, {
window : win, window : win,
input : field_name, input : field_name,
alt : "alt",
title : "title"
}); });
return false; return false;
} }

View File

@ -1,7 +1,7 @@
/*message*/ /*message*/
.error{ .error{
color:red; color: #B94A48;
} }
.notice, .message{ .notice, .message{

View File

@ -30,7 +30,7 @@ class Admin::AssetsController < OrbitBackendController
def create def create
@asset = Asset.new(params[:asset]) @asset = Asset.new(params[:asset])
@asset.filename = @asset.i18n_variable[I18n.locale] rescue nil @asset.filename = @asset.title[I18n.locale] rescue nil
if @asset.filename && @asset.save if @asset.filename && @asset.save
respond_to do |format| respond_to do |format|
format.js { format.js {

View File

@ -0,0 +1,11 @@
module Admin::AssetHelper
def show_all_fields(asset, field)
a = []
@site_valid_locales.each do |locale|
a << asset.send(field)[locale] rescue nil
end
a.join(' - ')
end
end

View File

@ -3,21 +3,43 @@ class Asset
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
mount_uploader :data, AssetUploader mount_uploader :data, FileAssetUploader
field :filename field :filename
field :description field :description
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :description, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy validates_presence_of :title, :data, :description
validates_presence_of :filename, :data
belongs_to :asset_category belongs_to :asset_category
belongs_to :assetable, polymorphic: true belongs_to :assetable, polymorphic: true
has_and_belongs_to_many :tags, :class_name => "AssetTag" has_and_belongs_to_many :tags, :class_name => "AssetTag"
before_save :set_key
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def description
@description ||= I18nVariable.first(:conditions => {:key => 'description', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def sorted_tags def sorted_tags
tags.order_by(I18n.locale, :asc) tags.order_by(I18n.locale, :asc)
end end
protected
def set_key
if title.new_record?
title.key = 'title'
end
if description.new_record?
description.key = 'description'
end
end
end end

View File

@ -48,8 +48,8 @@ class AssetUploader < CarrierWave::Uploader::Base
# end # end
# Override the filename of the uploaded files: # Override the filename of the uploaded files:
def filename # def filename
model.filename # model.filename
end # end
end end

View File

@ -0,0 +1,55 @@
# encoding: utf-8
class FileAssetUploader < CarrierWave::Uploader::Base
require 'mime/types'
process :set_content_type
def set_content_type(*args)
content_type = file.content_type == ('binary/octet-stream' || 'application/octet-stream') || file.content_type.blank? ? MIME::Types.type_for(original_filename).first.to_s : file.content_type
self.file.instance_variable_set(:@content_type, content_type)
end
# 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.force_encoding("UTF-8")
# end
end

View File

@ -1,6 +1,6 @@
<tr id="asset_<%= asset.id %>" class="with_action"> <tr id="asset_<%= asset.id %>" class="with_action">
<td><%= check_box_tag 'to_delete[]', asset.id, false, :class => "checkbox_in_list" %></td> <td><%= check_box_tag 'to_delete[]', asset.id, false, :class => "checkbox_in_list" %></td>
<td><%= asset.i18n_variable[I18n.locale] rescue nil %></td> <td><%= asset.title.i18n_variable[I18n.locale] rescue nil %></td>
<td> <td>
<i class="icons-picture img-peview" rel="popover" data-content="<img src='<%= asset.data.url %>' />" data-original-title="<%= asset.data.filename %>"></i> <i class="icons-picture img-peview" rel="popover" data-content="<img src='<%= asset.data.url %>' />" data-original-title="<%= asset.data.filename %>"></i>
<div class="quick-edit"> <div class="quick-edit">
@ -12,7 +12,7 @@
</td> </td>
<td><%= asset.data.file.content_type %></td> <td><%= asset.data.file.content_type %></td>
<td><%= number_to_human_size(asset.data.file.file_length) %></td> <td><%= number_to_human_size(asset.data.file.file_length) %></td>
<td><%= asset.category.i18n_variable[I18n.locale] rescue nil %></td> <td><%= asset.description.i18n_variable[I18n.locale] rescue nil %></td>
<td> <td>
<div class="label-group"> <div class="label-group">
<div class="label-td"> <div class="label-td">

View File

@ -2,5 +2,5 @@
['description', 'description', 'span1-2', 'admin.data'], ['description', 'description', 'span1-2', 'admin.data'],
['intro', 'intro', 'span1-2', 'admin.file_type'], ['intro', 'intro', 'span1-2', 'admin.file_type'],
['intro', 'intro', 'span1-2', 'admin.file_length'], ['intro', 'intro', 'span1-2', 'admin.file_length'],
['intro', 'intro', 'span1-2', 'admin.category'], ['intro', 'intro', 'span1-2', 'admin.description'],
['intro', 'intro', 'span1-2', 'admin.tags']).html_safe %> ['intro', 'intro', 'span1-2', 'admin.tags']).html_safe %>

File diff suppressed because one or more lines are too long

View File

@ -9,39 +9,41 @@
</div> </div>
<div class="modal-body form-horizontal"> <div class="modal-body form-horizontal">
<div class="control-group"> <div class="control-group">
<label for="title" class="control-label"><%= t 'admin.title' %></label> <label for="title" class="control-label error"><%= t 'admin.title' %></label>
<div class="controls"> <div class="controls">
<%= f.fields_for :i18n_variable, (@asset.new_record? ? @asset.build_i18n_variable : @asset.i18n_variable) do |f| %> <%= f.fields_for :title, (@asset.new_record? ? @asset.build_title : @asset.title) do |f| %>
<% @site_valid_locales.each do |locale| %> <div>
<%= content_tag :label do -%> <% @site_valid_locales.each do |locale| %>
<div> <%= content_tag :label do -%>
<%= I18nVariable.from_locale(locale) %> <div>
<%= f.text_field locale, :class => "input-large" %> <%= I18nVariable.from_locale(locale) %>
</div> <%= f.text_field locale, :class => "input-large" %>
<% end %> </div>
<% end %> <% end %>
<% end %>
</div>
<% end %> <% end %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label"><%= f.label :category, t('admin.category') %></label> <label for="description" class="control-label error"><%= t 'admin.description' %></label>
<div class="controls"> <div class="controls">
<%= f.select :asset_category_id, @asset_categories.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-large" %> <%= f.fields_for :description, (@asset.new_record? ? @asset.build_description : @asset.description) do |f| %>
</div> <div>
</div> <% @site_valid_locales.each do |locale| %>
<div class="control-group"> <%= content_tag :label do -%>
<label class="control-label"><%= t 'admin.tags' %></label> <div>
<div class="controls"> <%= I18nVariable.from_locale(locale) %>
<% @tags.each do |tag| %> <%= f.text_field locale, :class => "input-large" %>
<%= content_tag :label, :class => "checkbox inline" do -%> </div>
<%= check_box_tag 'asset[tag_ids][]', tag.id, @asset.tag_ids.include?(tag.id) %> <% end %>
<%= tag[I18n.locale] %> <% end %>
<% end %> </div>
<% end %> <% end %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label"><%= f.label :data, t('admin.data') %></label> <%= f.label :data, t('admin.data'), :class => "control-label" %>
<div class="controls"> <div class="controls">
<%= f.file_field :data, :class => 'upload' %> <%= f.file_field :data, :class => 'upload' %>
</div> </div>

View File

@ -71,11 +71,11 @@
<% end -%> <% end -%>
<% end -%> <% end -%>
<%= content_tag :li, :class => active_for_controllers('assets', '/admin/asset_tags', 'asset_categories') do -%> <%#= content_tag :li, :class => active_for_controllers('assets', '/admin/asset_tags', 'asset_categories') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.asset'), admin_assets_path %> <%#= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.asset'), admin_assets_path %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('assets', '/admin/asset_tags', 'asset_categories')) do -%> <%#= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('assets', '/admin/asset_tags', 'asset_categories')) do -%>
<%= content_tag :li, link_to(t('admin.all_assets'), admin_assets_path), :class => active_for_action('assets', 'index') %> <%#= content_tag :li, link_to(t('admin.all_assets'), admin_assets_path), :class => active_for_action('assets', 'index') %>
<%= content_tag :li, link_to(t('admin.categories'), admin_asset_categories_path), :class => active_for_action('asset_categories', 'index') %> <%#= content_tag :li, link_to(t('admin.categories'), admin_asset_categories_path), :class => active_for_action('asset_categories', 'index') %>
<%= content_tag :li, link_to(t('admin.tags'), admin_asset_tags_path), :class => active_for_action('/admin/asset_tags', 'index') %> <%#= content_tag :li, link_to(t('admin.tags'), admin_asset_tags_path), :class => active_for_action('/admin/asset_tags', 'index') %>
<% end -%> <%# end -%>
<% end -%> <%# end -%>

View File

@ -13,8 +13,8 @@ class Bulletin
has_one :text, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_one :text, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_and_belongs_to_many :tags, :class_name => "AnnouncementTag" has_and_belongs_to_many :tags, :class_name => "AnnouncementTag"
field :postdate , :type => Date field :postdate , :type => DateTime
field :deadline , :type => Date field :deadline , :type => DateTime
# field :url # field :url
field :create_user_id field :create_user_id
field :update_user_id, :class_name => "User" field :update_user_id, :class_name => "User"

View File

@ -13,8 +13,8 @@ class NewsBulletin
has_one :text, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_one :text, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_and_belongs_to_many :tags, :class_name => "NewsTag" has_and_belongs_to_many :tags, :class_name => "NewsTag"
field :postdate , :type => Date field :postdate , :type => DateTime
field :deadline , :type => Date field :deadline , :type => DateTime
# field :url # field :url
field :create_user_id field :create_user_id
field :update_user_id, :class_name => "User" field :update_user_id, :class_name => "User"