Add site_info

This commit is contained in:
Christophe Vilayphiou 2012-05-07 00:54:18 +08:00
parent 48f8fbde7f
commit 1fb6c20b86
13 changed files with 147 additions and 32 deletions

View File

@ -1,16 +1,48 @@
class Admin::SitesController < ApplicationController
layout "admin"
layout "new_admin"
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :get_site
def index
@site = Site.first
redirect_to :action => :new unless @site
# def index
# @site = Site.first
# # redirect_to :action => :new unless @site
# end
# def new
# @site = Site.new
# end
def update
@site.update_attributes(params[:site])
redirect_to :back
end
def new
@site = Site.new
def site_info
end
def system_info
end
def language
end
def mail_setting
end
def ui_theme
end
private
def get_site
@site ||= Site.first
end
end

View File

@ -95,12 +95,20 @@ module ApplicationHelper
end
def page_metas(page)
tmp_meta = {}
metas = ''
@site.page_metas.each do |meta|
@site.site_metas.each do |meta|
name, content = meta.get_name_content
metas << "<meta name=#{name} content=#{content} />\n"
tmp_meta.merge!(name => content)
end rescue nil
return metas
page.page_metas.each do |meta|
name, content = meta.get_name_content
tmp_meta.merge!(name => content)
end rescue nil
tmp_meta.each_pair{|name, content|
metas << "<meta name='#{name}' content='#{content}' />\n"
} if !tmp_meta.blank?
metas
end
def page_title(page)

View File

@ -1,15 +0,0 @@
class Meta
include Mongoid::Document
include Mongoid::Timestamps
field :key
field :value, :default => nil
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
def get_name_content
[self.key, self.value ? self.value : self.i18n_variable[I18n.locale]]
end
end

View File

@ -7,5 +7,13 @@ class Meta
field :value, :default => nil
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
def get_name_content
[self.key, get_content]
end
def get_content
self.value ? self.value : self.i18n_variable[I18n.locale]
end
end

View File

@ -1,5 +1,7 @@
class Site
METAS = ['description', 'keywords']
include Mongoid::Document
include Mongoid::Timestamps
@ -13,8 +15,11 @@ class Site
field :school
field :department
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
has_many :site_metas, :autosave => true, :dependent => :destroy
before_save :set_key
def generate_keys
private_key = OpenSSL::PKey::RSA.generate(2048)
self.public_key = private_key.public_key.to_s
@ -30,5 +35,30 @@ class Site
res = res.split('rails_3_1').pop.gsub('(', '').gsub(')','').strip rescue nil
res.eql?('local out of date') ? false : true
end
def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
METAS.each do |meta|
define_method meta do
fetch_meta = self.site_metas.where(key: meta).limit(1)
fetch_meta.blank? ? nil : fetch_meta[0].i18n_variable
end
define_method "#{meta}=" do |values|
if a = self.send(meta)
a.update_attributes(values)
else
a = self.site_metas.build(key: meta)
a.build_i18n_variable(values)
end
end
end
protected
def set_key
title.key = 'title' if title
end
end

View File

@ -0,0 +1 @@
language.html.erb

View File

@ -0,0 +1 @@
mail_setting.html.erb

View File

@ -0,0 +1,36 @@
<%= form_for @site, :url => admin_site_path(@site) do |f| %>
<div id="post-body">
<div id="post-body-content" class="clear">
<ul class="nav nav-tabs">
<% @site_valid_locales.each do |locale|%>
<%#= raise @site_valid_locales.inspect %>
<%= content_tag :li, link_to(I18nVariable.from_locale(locale), "##{locale}", :data => {:toggle => "tab"}), :class => (active_when_current_locale_eq locale) %>
<% end %>
<li>
<%= f.submit t("submit"), :class => "btn btn-primary" %>
<%= f.submit t("cancel"), :class => "btn ", :type => 'reset' %>
</li>
</ul>
<div class="tab-content">
<% @site_valid_locales.each do |locale|%>
<%= content_tag :div, :class => "tab-pane #{active_when_current_locale_eq locale}", :id => "#{locale}" do %>
<%= t :title %>
<%= f.fields_for :title, @site.title do |f| %>
<%= f.text_field locale %>
<% end %>
<%= t :keywords %>
<%= f.fields_for :keywords, @site.keywords do |f| %>
<%= f.text_field locale %>
<% end %>
<%= t :description %>
<%= f.fields_for :description, @site.description do |f| %>
<%= f.text_field locale %>
<% end %>
<% end %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>

View File

@ -0,0 +1 @@
system_info.html.erb

View File

@ -0,0 +1 @@
ui_theme.html.erb

View File

@ -7,7 +7,7 @@
<%= content_tag :li, :class => active_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals') || active_sys_call_for_app('module_apps','edit','Announcement') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-announcement') + t('admin.announcement'), panel_announcement_back_end_bulletins_path %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')) do -%>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')) do -%>
<%= content_tag :li, link_to(t('announcement.all_articles'), panel_announcement_back_end_bulletins_path), :class => active_for_action('bulletins', 'index') %>
<%= content_tag :li, link_to(t('announcement.add_new'), new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') %>
<%= content_tag :li, link_to(t('announcement.categories'), panel_announcement_back_end_bulletin_categorys_path), :class => active_for_action('bulletin_categorys', 'index') %>
@ -21,7 +21,7 @@
<%= content_tag :li, :class => active_for_controllers('news_bulletins', '/panel/news/back_end/tags', 'news_bulletin_categorys', 'news_approvals') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-announcement') + t('admin.news'), panel_news_back_end_news_bulletins_path %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('news_bulletins', '/panel/news/back_end/tags', 'news_bulletin_categorys', 'news_approvals')) do -%>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('news_bulletins', '/panel/news/back_end/tags', 'news_bulletin_categorys', 'news_approvals')) do -%>
<%= content_tag :li, link_to(t('announcement.all_articles'), panel_news_back_end_news_bulletins_path), :class => active_for_action('news_bulletins', 'index') %>
<%= content_tag :li, link_to(t('announcement.add_new'), new_panel_news_back_end_news_bulletin_path), :class => active_for_action('news_bulletins', 'new') %>
<%= content_tag :li, link_to(t('announcement.categories'), panel_news_back_end_news_bulletin_categorys_path), :class => active_for_action('news_bulletin_categorys', 'index') %>
@ -59,7 +59,7 @@
<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.link'), panel_web_resource_back_end_web_links_path %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%>
<%= content_tag :li, link_to(t('admin.all_articles'), panel_web_resource_back_end_web_links_path), :class => active_for_action('web_links', 'index') %>
<%= content_tag :li, link_to(t('announcement.add_new'), new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_links', 'new') %>
<%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => active_for_action('web_link_categorys', 'index') %>
@ -67,6 +67,13 @@
<% end -%>
<% end -%>
<%= content_tag :li, :class => active_for_controllers(nil) do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), nil %>
<%= content_tag :li, :class => active_for_controllers('sites') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('sites')) do -%>
<%= content_tag :li, link_to(t('admin.site_info'), admin_site_site_info_path(@site)), :class => active_for_action('sites', 'site_info') %>
<%= content_tag :li, link_to(t('admin.system_info'), admin_site_system_info_path(@site)), :class => active_for_action('sites', 'system_info') %>
<%= content_tag :li, link_to(t('admin.language'), admin_site_language_path(@site)), :class => active_for_action('sites', 'language') %>
<%= content_tag :li, link_to(t('admin.mail_setting'), admin_site_mail_setting_path(@site)), :class => active_for_action('sites', 'mail_setting') %>
<%= content_tag :li, link_to(t('admin.ui_theme'), admin_site_ui_theme_path(@site)), :class => active_for_action('sites', 'ui_theme') %>
<% end -%>
<% end -%>

View File

@ -4,7 +4,6 @@
<meta charset="utf-8">
<%= page_title(@item).html_safe %>
<%= page_metas(@item).html_safe %>
<%= @metas %>
<!--[if lt IE 9]>
<%= javascript_include_tag "html5" %>
<![endif]-->

View File

@ -93,7 +93,13 @@ Orbit::Application.routes.draw do
get 'add_sub_role'
get 'add_attribute_field'
end
resources :sites
resources :sites do
get 'site_info'
get 'system_info'
get 'language'
get 'mail_setting'
get 'ui_theme'
end
resources :snippets
resources :tags
resources :translations