fix style error for show page and add setting for default field
This commit is contained in:
parent
c39be9a84a
commit
f2215be917
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
@ -455,6 +455,22 @@ class Admin::EventNewsController < OrbitAdminController
|
|||
end
|
||||
end
|
||||
|
||||
def custom_fields_title
|
||||
@event_news_custom_titles = EventNewsCustomTitle.get_map
|
||||
end
|
||||
|
||||
def update_custom_title
|
||||
event_news_custom_title_params = params.require(:event_news_custom_title).permit!
|
||||
event_news_custom_title_params.each do |k,event_news_custom_title_param|
|
||||
EventNewsCustomTitle.find(event_news_custom_title_param['id']).update_attributes(event_news_custom_title_param)
|
||||
end
|
||||
Thread.new do
|
||||
content = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s USR2 $UNICORN_PID ; n=20; while (kill -0 $UNICORN_PID > /dev/null 2>&1) && test $n -ge 0; do printf '.' && sleep 1 && n=$(( $n - 1 )); done ; if test $n -lt 0; then kill -s TERM $UNICORN_PID; sleep 3; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{Rails.env}; else kill -s QUIT $UNICORN_PID; fi"
|
||||
system(content)
|
||||
end
|
||||
redirect_to action: :index
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_settings
|
||||
|
|
|
@ -68,11 +68,11 @@ class EventNewsController < ApplicationController
|
|||
"extras" => {
|
||||
"widget-title" =>t('event_news.event_news'),
|
||||
"title-head" => t('event_news.table.title'),
|
||||
"speaker-head" => t('event_news.speaker'),
|
||||
"place-head" => t('event_news.place'),
|
||||
"host-head" => t('event_news.host'),
|
||||
"speaker-head" => EventNewsCustomTitle.get_trans('speaker'),
|
||||
"place-head" => EventNewsCustomTitle.get_trans('place'),
|
||||
"host-head" => EventNewsCustomTitle.get_trans('host'),
|
||||
"notes-head" => t('event_news.notes'),
|
||||
"event_date-head" => t('date_'),
|
||||
"event_date-head" => EventNewsCustomTitle.get_trans('event_date'),
|
||||
"date-head" => t('event_news.table.date'),
|
||||
"status-head" => t('event_news.table.status'),
|
||||
"author-head" => t('event_news.table.author'),
|
||||
|
@ -415,11 +415,11 @@ class EventNewsController < ApplicationController
|
|||
"main_picture" => mp,
|
||||
"main_picture_description" => mpd,
|
||||
"title-head" => t('event_news.table.title'),
|
||||
"speaker-head" => t('event_news.speaker'),
|
||||
"place-head" => t('event_news.place'),
|
||||
"host-head" => t('event_news.host'),
|
||||
"speaker-head" => EventNewsCustomTitle.get_trans('speaker'),
|
||||
"place-head" => EventNewsCustomTitle.get_trans('place'),
|
||||
"host-head" => EventNewsCustomTitle.get_trans('host'),
|
||||
"notes-head" => t('event_news.notes'),
|
||||
"event_date-head" => t('date_'),
|
||||
"event_date-head" => EventNewsCustomTitle.get_trans('event_date'),
|
||||
"date-head" => t('event_news.table.date'),
|
||||
"author-head" => t('event_news.table.author'),
|
||||
"status-head" => t('event_news.table.status'),
|
||||
|
@ -561,10 +561,11 @@ class EventNewsController < ApplicationController
|
|||
"event_news_links" => links,
|
||||
"event_carousel_images" => event_carousel_images,
|
||||
"data" => {
|
||||
"speaker-head" => t('event_news.speaker'),
|
||||
"host-head" => t('event_news.host'),
|
||||
"speaker-head" => EventNewsCustomTitle.get_trans('speaker'),
|
||||
"host-head" => EventNewsCustomTitle.get_trans('host'),
|
||||
"notes-head" => t('event_news.notes'),
|
||||
"speaker" => event_news.speaker,
|
||||
"speaker-css" => (event_news.speaker.blank? ? "display: none;" : "display: inline-block;"),
|
||||
"host" => event_news.host,
|
||||
"notes" => event_news.notes,
|
||||
"title" => event_news.title,
|
||||
|
@ -583,7 +584,7 @@ class EventNewsController < ApplicationController
|
|||
"next_btn_title" => next_btn_title,
|
||||
"carousel_display_style" => (event_carousel_images.count == 0 ? 'display: none' : "width: #{event_news.carousel_image_width};margin: auto;"),
|
||||
"carousel_count" => event_carousel_images.count,
|
||||
"place_text" => (event_news.place.present? rescue false) ? "#{I18n.t("event_news.place")}: #{event_news.place}" : ""
|
||||
"place_text" => (event_news.place.present? rescue false) ? "#{EventNewsCustomTitle.get_trans("place")}: #{event_news.place}" : ""
|
||||
},
|
||||
"impressionist" => (event_news.is_preview ? nil : event_news),
|
||||
"url_to_edit"=>url_to_edit
|
||||
|
@ -658,10 +659,10 @@ class EventNewsController < ApplicationController
|
|||
"update_user" => update_user,
|
||||
"updated_at" => event_time,
|
||||
"body" => event_news["text_translations"][locale],
|
||||
"speaker-head" => t('event_news.speaker'),
|
||||
"host-head" => t('event_news.host'),
|
||||
"speaker-head" => EventNewsCustomTitle.get_trans('speaker'),
|
||||
"host-head" => EventNewsCustomTitle.get_trans('host'),
|
||||
"notes-head" => t('event_news.notes'),
|
||||
"event_date-head" => t('date_'),
|
||||
"event_date-head" => EventNewsCustomTitle.get_trans('event_date'),
|
||||
"speaker" => (event_news["speaker_translations"][locale].to_s rescue ""),
|
||||
"host" => (event_news["host_translations"][locale].to_s rescue ""),
|
||||
"notes" => (event_news["notes_translations"][locale].to_s rescue ""),
|
||||
|
@ -777,10 +778,10 @@ class EventNewsController < ApplicationController
|
|||
"extras" => {
|
||||
"widget-title" =>t('event_news.event_news'),
|
||||
"title-head" => t('event_news.table.title'),
|
||||
"speaker-head" => t('event_news.speaker'),
|
||||
"host-head" => t('event_news.host'),
|
||||
"speaker-head" => EventNewsCustomTitle.get_trans('speaker'),
|
||||
"host-head" => EventNewsCustomTitle.get_trans('host'),
|
||||
"notes-head" => t('event_news.notes'),
|
||||
"event_date-head" => t('date_'),
|
||||
"event_date-head" => EventNewsCustomTitle.get_trans('event_date'),
|
||||
"date-head" => t('event_news.table.date'),
|
||||
"status-head" => t('event_news.table.status'),
|
||||
"author-head" => t('event_news.table.author'),
|
||||
|
|
|
@ -3,6 +3,84 @@ require "uri"
|
|||
require 'json'
|
||||
|
||||
module Admin::EventNewsHelper
|
||||
module FormHelper
|
||||
extend self
|
||||
extend ActionView::Helpers::FormTagHelper
|
||||
extend ActionView::Helpers::FormOptionsHelper
|
||||
extend ActionView::Helpers::DateHelper
|
||||
extend ActionView::Helpers::TagHelper
|
||||
extend ActionView::Helpers::RenderingHelper
|
||||
extend ActionView::Context
|
||||
extend OrbitBasis::RenderAnywhere
|
||||
extend ActionView::Helpers::UrlHelper
|
||||
extend OrbitFormHelper
|
||||
extend Ckeditor::Helpers::FormHelper
|
||||
def available_locales
|
||||
@available_locales = @available_locales || Site.first.in_use_locales || I18n.available_locales
|
||||
end
|
||||
def set_input_name(input_name)
|
||||
@input_name = input_name
|
||||
end
|
||||
|
||||
def get_input_name
|
||||
@input_name.to_s
|
||||
end
|
||||
def create_lang_panel(field)
|
||||
tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do
|
||||
available_locales.collect do |key|
|
||||
link_entry_ary = ["##{field}","_#{key}"]
|
||||
link_entry = link_entry_ary.join
|
||||
link_to(I18n.t(key),link_entry,:data=>{:toggle=>"tab"},:class=>"btn #{(key == I18n.locale ? "active" : nil)}",:for=>key)
|
||||
end.join.html_safe
|
||||
end
|
||||
end
|
||||
def multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},sortable=false)
|
||||
if !index1.nil?
|
||||
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
|
||||
else
|
||||
all_field = (get_input_name + "[#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
|
||||
end
|
||||
tmp = (available_locales.collect do |locale|
|
||||
active_flag = ((locale == I18n.locale) ? ' in active' : '')
|
||||
content_tag(:div,:class => "tab-content fade#{active_flag}",:id=>"#{all_field}_#{locale}") do
|
||||
value_locale = value[locale.to_s] rescue nil
|
||||
if !index1.nil?
|
||||
self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{index1}][#{field}][#{locale}]",value_locale,custom_options)
|
||||
else
|
||||
self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{field}][#{locale}]",value_locale,custom_options)
|
||||
end
|
||||
end
|
||||
end.join + create_lang_panel(all_field)).html_safe + combine_element
|
||||
|
||||
if sortable
|
||||
if exteral_options['style'].nil?
|
||||
exteral_options['style'] = 'display: flex;align-items: center;flex-wrap: nowrap;'
|
||||
else
|
||||
exteral_options['style'] = exteral_options['style'] + 'display: flex;align-items: center;flex-wrap: nowrap;'
|
||||
end
|
||||
content_tag(:div,{:class => "tab-panel border"}.merge(exteral_options)) do
|
||||
("<i class=\"icons-list-2\" style=\"cursor: grab;font-size: x-large;\"></i>" +content_tag(:div) do
|
||||
tmp
|
||||
end).html_safe
|
||||
end
|
||||
else
|
||||
content_tag(:div,{:class => "tab-panel"}.merge(exteral_options)) do
|
||||
tmp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.thead(field,center=false,enable_sort=true)
|
||||
sort = field.to_s.include?('.') ? field.to_s.split('.')[1] : field.to_s
|
||||
active = OrbitHelper.params[:sort].eql? sort
|
||||
order = active ? (["asc", "desc"]-[OrbitHelper.params[:order]]).first : "asc"
|
||||
arrow = (order.eql? "desc") ? "<b class='icons-arrow-up-3'></b>" : "<b class='icons-arrow-down-4'></b>"
|
||||
klass = field.eql?(:title) ? "span5" : "span2"
|
||||
th_data = (sort=="preview" || !enable_sort) ? EventNewsCustomTitle.get_trans(field) : "<a href='?sort=#{sort}&order=#{order}'>#{EventNewsCustomTitle.get_trans(field)} #{active ? arrow : ""}</a>"
|
||||
"<th class='#{klass} #{active ? "active" : ""}' style='#{center ? "text-align:center" : ""}'>#{th_data}</th>".html_safe
|
||||
end
|
||||
|
||||
def page_for_event_news(event_news)
|
||||
ann_page = nil
|
||||
pages = Page.where(:module=>'event_news')
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
class EventNewsCustomTitle
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
field :key
|
||||
field :title, type: String, localize: true
|
||||
KEYS = ['event_date','speaker','place','host']
|
||||
def self.get_map
|
||||
KEYS.map{|k| self.where(key: k).first || self.create(key: k,title_translations: I18n.available_locales.map{|l| [l,I18n.with_locale(l){I18n.t("event_news.#{k}")}]}.to_h)}
|
||||
end
|
||||
def default_title
|
||||
I18n.t("event_news.#{self.key}")
|
||||
end
|
||||
def self.get_trans(key)
|
||||
TitleMap[key][I18n.locale] rescue I18n.t("event_news.#{key}")
|
||||
end
|
||||
TitleMap = self.get_map.map{|v| [v.key,v.title_translations]}.to_h
|
||||
end
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
<!-- Date Time Picker -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("event_news.event_date") %></label>
|
||||
<label class="control-label muted"><%= EventNewsCustomTitle.get_trans('event_date') %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :event_date, :no_label => true, :new_record => @event_news.new_record?, :data=>{"picker-type" => "range", "range" => "start"} %>
|
||||
</div>
|
||||
|
@ -382,7 +382,7 @@
|
|||
</div>
|
||||
<!-- Speaker-->
|
||||
<div class="control-group input-speaker">
|
||||
<label class="control-label muted"><%= t("event_news.speaker") %></label>
|
||||
<label class="control-label muted"><%= EventNewsCustomTitle.get_trans('speaker') %></label>
|
||||
<div class="controls">
|
||||
<%= f.fields_for :speaker_translations do |f| %>
|
||||
<%= f.text_field locale, class: "input-block-level", placeholder: t("event_news.speaker"), value: (@event_news.speaker_translations[locale] rescue nil) %>
|
||||
|
@ -391,7 +391,7 @@
|
|||
</div>
|
||||
<!-- Place-->
|
||||
<div class="control-group input-speaker">
|
||||
<label class="control-label muted"><%= t("event_news.place") %></label>
|
||||
<label class="control-label muted"><%= EventNewsCustomTitle.get_trans('place') %></label>
|
||||
<div class="controls">
|
||||
<%= f.fields_for :place_translations do |f| %>
|
||||
<%= f.text_field locale, class: "input-block-level", placeholder: t("event_news.place"), value: (@event_news.place_translations[locale] rescue nil) %>
|
||||
|
@ -400,7 +400,7 @@
|
|||
</div>
|
||||
<!-- Host-->
|
||||
<div class="control-group input-host">
|
||||
<label class="control-label muted"><%= t("event_news.host") %></label>
|
||||
<label class="control-label muted"><%= EventNewsCustomTitle.get_trans('host') %></label>
|
||||
<div class="controls">
|
||||
<%= f.fields_for :host_translations do |f| %>
|
||||
<%= f.text_field locale, class: "input-block-level", placeholder: t("event_news.host"), value: (@event_news.host_translations[locale] rescue nil) %>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<thead>
|
||||
<tr class="sort-header">
|
||||
<% @table_fields.each do |f| %>
|
||||
<%= thead(f) %>
|
||||
<%= tmp = f.to_s.split('.')[-1]; EventNewsCustomTitle::KEYS.include?(tmp) ? Admin::EventNewsHelper.thead(tmp): thead(f) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<style type="text/css">
|
||||
.tab-panel .tab-content{
|
||||
display: none;
|
||||
}
|
||||
.tab-panel .tab-content.active{
|
||||
display: block;
|
||||
}
|
||||
.tab-panel .tab-content,.tab-panel .btn-group{
|
||||
float: left;
|
||||
}
|
||||
</style>
|
||||
<%= form_tag({action: 'update_custom_title',method: 'post'}, {class: "form-horizontal main-forms previewable"}) do %>
|
||||
<% Admin::EventNewsHelper::FormHelper.set_input_name("event_news_custom_title") %>
|
||||
<% @event_news_custom_titles.each_with_index do |v,i| %>
|
||||
<div class="control-group">
|
||||
<%= label_tag :title , v.default_title, :class=>"control-label muted" %>
|
||||
<div class="controls">
|
||||
<%= hidden_field_tag "event_news_custom_title[#{i}][id]", v.id %>
|
||||
<%= Admin::EventNewsHelper::FormHelper.multiple_lang_tag(i,'text_field','title_translations',v.title_translations,{placeholder: v.default_title}) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-actions">
|
||||
<%= submit_tag t(:submit),class: 'btn btn-primary' %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -2,6 +2,7 @@ en:
|
|||
module_name:
|
||||
event_news: Event News
|
||||
event_news:
|
||||
custom_fields_title: Custom Fields Title
|
||||
custom_carousel_image_width_hint: "If blank, width will be default value."
|
||||
carousel_image_width: Carousel Image Width
|
||||
default_carousel_image_width: Default Carousel Image Width
|
||||
|
|
|
@ -2,6 +2,7 @@ zh_tw:
|
|||
module_name:
|
||||
event_news: 活動公告
|
||||
event_news:
|
||||
custom_fields_title: 欄位名稱設定
|
||||
custom_carousel_image_width_hint: "未填寫,則使用預設寬度"
|
||||
carousel_image_width: 輪播圖片寬度
|
||||
default_carousel_image_width: 預設輪播圖片寬度
|
||||
|
|
|
@ -22,7 +22,12 @@ Rails.application.routes.draw do
|
|||
patch 'event_news/updatesettings', to: 'event_news#updatesettings'
|
||||
post 'event_news/import_from_wp', to: 'event_news#import_from_wp'
|
||||
post 'event_news/generate_iframe_url' => 'event_news#generate_iframe_url'
|
||||
resources :event_news
|
||||
resources :event_news do
|
||||
collection do
|
||||
get 'custom_fields_title'
|
||||
post 'update_custom_title'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
resources :event_news do
|
||||
|
|
|
@ -14,6 +14,7 @@ if bundle_update_flag
|
|||
if !folder.include?('mobile')
|
||||
info_json_file = "#{folder}modules/event_news/info.json"
|
||||
if File.exist?(info_json_file)
|
||||
Bundler.with_clean_env{system ('cp -f '+ app_path + '/modules/event_news/show.html.erb ' + "#{folder}modules/event_news/.")}
|
||||
begin
|
||||
file_text = File.read(info_json_file) rescue ""
|
||||
encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
|
||||
|
|
|
@ -75,6 +75,10 @@ module EventNewsMod
|
|||
if defined? EventNewsCache
|
||||
EventNewsCache.destroy_all
|
||||
end
|
||||
require File.expand_path('../../../app/models/event_news_custom_title', __FILE__)
|
||||
if defined? EventNewsCustomTitle
|
||||
EventNewsCustomTitle.get_map
|
||||
end
|
||||
rescue => e
|
||||
puts ['error in event_news',e]
|
||||
end
|
||||
|
@ -125,19 +129,25 @@ module EventNewsMod
|
|||
:active_for_action=>{'admin/event_news'=>'tags'},
|
||||
:active_for_tag => 'EventNewsModule',
|
||||
:available_for => 'managers'
|
||||
context_link 'event_news.custom_fields_title',
|
||||
:link_path=>"custom_fields_title_admin_event_news_index_path" ,
|
||||
:priority=>5,
|
||||
:active_for_action=>{'admin/event_news'=>'custom_fields_title'},
|
||||
:available_for => 'managers'
|
||||
|
||||
context_link 'event_news.feed_list',
|
||||
:link_path=>"admin_event_news_feed_path" ,
|
||||
:priority=>5,
|
||||
:priority=>6,
|
||||
:active_for_action=>{'admin/event_news'=>'feed'},
|
||||
:available_for => 'managers'
|
||||
context_link 'event_news.import',
|
||||
context_link 'event_news.import',
|
||||
:link_path=>"admin_event_news_import_path" ,
|
||||
:priority=>6,
|
||||
:priority=>7,
|
||||
:active_for_action=>{'admin/event_news'=>'import'},
|
||||
:available_for => 'managers'
|
||||
context_link 'event_news.settings',
|
||||
:link_path=>"admin_event_news_settings_path" ,
|
||||
:priority=>6,
|
||||
:priority=>8,
|
||||
:active_for_action=>{'admin/event_news'=>'settings'},
|
||||
:available_for => 'managers'
|
||||
end
|
||||
|
|
|
@ -157,7 +157,7 @@
|
|||
</span>
|
||||
</li>
|
||||
<li class="s-annc__extra_info-wrap s-annc__meta--item ">
|
||||
<span style="display: inline-block;">
|
||||
<span style="{{speaker-css}}">
|
||||
<span>{{speaker-head}}:</span>
|
||||
<span>{{speaker}}</span>
|
||||
</span>
|
||||
|
|
Loading…
Reference in New Issue