Add Memorabilia Model & CRUD
This commit is contained in:
parent
4380966ab8
commit
05cfa10a8e
|
@ -0,0 +1,61 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::VenueManagementMemorabiliasController < OrbitAdminController
|
||||
include Admin::VenueManagementsHelper
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
before_action :set_venue_management_memorabilia, only: [:edit, :update, :destroy]
|
||||
|
||||
def initialize
|
||||
super
|
||||
@app_title = 'venue_management'
|
||||
end
|
||||
|
||||
def index
|
||||
@table_fields = [
|
||||
'venue_management.title',
|
||||
'vm_memorabilia.case_no',
|
||||
'vm_memorabilia.event_date',
|
||||
'vm_memorabilia.details',
|
||||
]
|
||||
@memorabilias = VenueManagementMemorabilia.order(updated_at: :desc).page(params[:page]).per(10)
|
||||
end
|
||||
|
||||
def new
|
||||
@venue_management = VenueManagementMain.find(params[:id])
|
||||
@venue_management_memorabilia = @venue_management.venue_management_memorabilias.build
|
||||
end
|
||||
|
||||
def create
|
||||
@venue_management_memorabilia = VenueManagementMemorabilia.new(venue_management_memorabilia_params)
|
||||
@venue_management_memorabilia.save
|
||||
|
||||
redirect_to params['referer_url']
|
||||
end
|
||||
|
||||
def edit
|
||||
@venue_management = VenueManagementMain.find(@venue_management_memorabilia.venue_management_main_id)
|
||||
end
|
||||
|
||||
def update
|
||||
@venue_management_memorabilia.update_attributes(venue_management_memorabilia_params)
|
||||
|
||||
redirect_to venue_management_memorabilias_admin_venue_management_path(@venue_management_memorabilia.venue_management_main_id)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@venue_management_main_id = @venue_management_memorabilia.venue_management_main_id
|
||||
@venue_management_memorabilia.destroy
|
||||
|
||||
redirect_to venue_management_memorabilias_admin_venue_management_path(@venue_management_main_id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_venue_management_memorabilia
|
||||
@venue_management_memorabilia = VenueManagementMemorabilia.find(params[:id])
|
||||
end
|
||||
|
||||
def venue_management_memorabilia_params
|
||||
params.require(:venue_management_memorabilia).permit!
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ class Admin::VenueManagementsController < OrbitAdminController
|
|||
require 'axlsx'
|
||||
helper Admin::VenueManagementsFieldHelper
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings]
|
||||
before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings, :venue_management_memorabilias]
|
||||
|
||||
def initialize
|
||||
super
|
||||
|
@ -254,6 +254,15 @@ class Admin::VenueManagementsController < OrbitAdminController
|
|||
@invitings = @venue_management.venue_management_invitings.page(params[:page]).per(10)
|
||||
end
|
||||
|
||||
def venue_management_memorabilias
|
||||
@table_fields = [
|
||||
'vm_memorabilia.case_no',
|
||||
'vm_memorabilia.event_date',
|
||||
'vm_memorabilia.details',
|
||||
]
|
||||
@memorabilias = @venue_management.venue_management_memorabilias.page(params[:page]).per(10)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_venue_management
|
||||
|
|
|
@ -37,6 +37,7 @@ class VenueManagementMain
|
|||
|
||||
has_many :venue_management_links, :autosave => true, :dependent => :destroy
|
||||
has_many :venue_management_invitings, :autosave => true, :dependent => :destroy
|
||||
has_many :venue_management_memorabilias, :autosave => true, :dependent => :destroy
|
||||
has_many :venue_management_files, :autosave => true, :dependent => :destroy
|
||||
has_many :venue_management_item_contents, :autosave => true, :dependent => :destroy
|
||||
has_many :venue_management_signups, :autosave => true, :dependent => :destroy
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'orbit_form_helper'
|
||||
|
||||
class VenueManagementMemorabilia
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::Enum
|
||||
|
||||
field :event_date, type: Date, default: Time.now
|
||||
field :case_no, type: String
|
||||
field :details, localize: true
|
||||
|
||||
belongs_to :venue_management_main
|
||||
has_many :venue_management_links, :as => :venue_object, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :venue_management_links, :allow_destroy => true
|
||||
|
||||
end
|
|
@ -0,0 +1,103 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<%= stylesheet_link_tag "lib/fileupload" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
||||
<%= javascript_include_tag "lib/file-type" %>
|
||||
<%= javascript_include_tag "lib/module-area" %>
|
||||
<% end %>
|
||||
<!-- Input Area -->
|
||||
<div class="input-area">
|
||||
|
||||
<!-- Module -->
|
||||
<div class="tab-content module-area">
|
||||
<!-- Basic Module -->
|
||||
<div class="tab-pane fade in active" id="basic">
|
||||
<%= f.hidden_field :venue_management_main_id %>
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t('vm_memorabilia.case_no') %></label>
|
||||
<div class="controls">
|
||||
<%= f.text_field :case_no %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t('vm_memorabilia.event_date') %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :event_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_memorabilia.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Language Tabs -->
|
||||
<div class="nav-name"><strong><%= t(:language) %></strong></div>
|
||||
<ul class="nav nav-pills language-nav">
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
<li class="<%= 'active' if i == 0 %>">
|
||||
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<!-- Language -->
|
||||
<div class="tab-content language-area">
|
||||
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
|
||||
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
|
||||
|
||||
<!-- Content -->
|
||||
<div class="control-group input-content">
|
||||
<label class="control-label muted"><%= t('vm_memorabilia.details') %></label>
|
||||
<div class="controls">
|
||||
<div class="textarea">
|
||||
<%= f.fields_for :details_translations do |f| %>
|
||||
<%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@venue_management_memorabilia.details_translations[locale] rescue nil) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<!-- Link -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:link) %></label>
|
||||
<div class="controls add-input">
|
||||
|
||||
<!-- Exist -->
|
||||
<% if @venue_management_memorabilia && !@venue_management_memorabilia.venue_management_links.blank? %>
|
||||
<div class="exist">
|
||||
<% @venue_management_memorabilia.venue_management_links.each_with_index do |venue_management_link, i| %>
|
||||
<%= f.fields_for :venue_management_links, venue_management_link do |f| %>
|
||||
<%= render :partial => 'form_link', :object => venue_management_link, :locals => {:f => f, :i => i} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<hr>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<!-- Add -->
|
||||
<div class="add-target">
|
||||
</div>
|
||||
<p class="add-btn">
|
||||
<%= hidden_field_tag 'venue_management_link_field_count', @venue_management_memorabilia.venue_management_links.count %>
|
||||
<a id="add_link" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Form Actions -->
|
||||
<div class="form-actions">
|
||||
<%= get_referer_url[:venue_managemention] rescue "" %>
|
||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||
<input type="hidden" name="referer_url" value="<%= get_referer_url %>">
|
||||
<%= link_to t('cancel'), venue_management_memorabilias_admin_venue_management_path(id: @venue_management.id), :class=>"btn" %>
|
||||
</div>
|
|
@ -0,0 +1,52 @@
|
|||
<script>
|
||||
if(document.querySelectorAll("#orbit-bar").length==0) location.reload();
|
||||
</script>
|
||||
<% if 'venue_management_memorabilias' == params[:action] %>
|
||||
<h4><%= @venue_management.title %></h4>
|
||||
<% end %>
|
||||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<% @table_fields.each do |f| %>
|
||||
<%= thead(f) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @memorabilias.each do |memorabilia| %>
|
||||
<tr>
|
||||
<% if 'venue_management_memorabilias' != params[:action] %>
|
||||
<td><%= memorabilia.venue_management_main.title %></td>
|
||||
<% end %>
|
||||
<td>
|
||||
<%= link_to memorabilia.case_no, admin_venue_management_memorabilia_path(memorabilia.id), :target => '_blank' %>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
<% if can_edit_or_delete?(memorabilia) %>
|
||||
<li><%= link_to t(:edit), edit_admin_venue_management_memorabilia_path(memorabilia.id) %></li>
|
||||
<li><a href="#" class="delete text-error" rel="/admin/venue_management_memorabilias/<%=memorabilia.id.to_s%>"><%= t(:delete_) %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td><%= memorabilia.event_date %></td>
|
||||
<td><%= memorabilia.details %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%=
|
||||
content_tag :div, class: "bottomnav clearfix" do
|
||||
content_tag :div, paginate(@memorabilias), class: "pagination pagination-centered"
|
||||
end
|
||||
%>
|
||||
<% if @venue_management.present? %>
|
||||
<!-- footer -->
|
||||
<div class="bottomnav clearfix">
|
||||
<div class="action pull-right">
|
||||
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_memorabilia_path(id: @venue_management.id), class: "btn btn-primary" %>
|
||||
</div>
|
||||
</div>
|
||||
<!-- footer:end -->
|
||||
<% end %>
|
|
@ -0,0 +1,5 @@
|
|||
<%= form_for @venue_management_memorabilia, url: admin_venue_management_memorabilia_path(@venue_management_memorabilia), html: {class: "form-horizontal main-forms"} do |f| %>
|
||||
<fieldset>
|
||||
<%= render :partial => 'form', locals: {f: f} %>
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -0,0 +1,4 @@
|
|||
<span id="index_table">
|
||||
<%= render 'index' %>
|
||||
</span>
|
||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
|
@ -0,0 +1,5 @@
|
|||
<%= form_for @venue_management_memorabilia, url: admin_venue_management_memorabilias_path, html: {class: "form-horizontal main-forms"} do |f| %>
|
||||
<fieldset>
|
||||
<%= render :partial => 'form', locals: {f: f} %>
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -38,7 +38,9 @@
|
|||
<td>
|
||||
<%= link_to venue_management.venue_management_invitings.count, venue_management_invitings_admin_venue_management_path(venue_management.id) %>
|
||||
</td>
|
||||
<td><a href="#">0</a></td>
|
||||
<td>
|
||||
<%= link_to venue_management.venue_management_memorabilias.count, venue_management_memorabilias_admin_venue_management_path(venue_management.id) %>
|
||||
</td>
|
||||
<td><a href="/admin/venue_managements/<%=venue_management.id.to_s%>/export?format=xlsx" target="_blank"><%= t('venue_management.export') %></a></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<span id="index_table">
|
||||
<%= render 'admin/venue_management_memorabilias/index' %>
|
||||
</span>
|
||||
|
||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
|
@ -161,3 +161,7 @@ en:
|
|||
failure: Failure
|
||||
abandoned: Abandoned
|
||||
qualified: Qualified
|
||||
vm_memorabilia:
|
||||
case_no: 'Case No.'
|
||||
event_date: Event Date
|
||||
details: Details
|
||||
|
|
|
@ -164,3 +164,7 @@ zh_tw:
|
|||
failure: 流標
|
||||
abandoned: 廢標
|
||||
qualified: 合格續行評審
|
||||
vm_memorabilia:
|
||||
case_no: 相關案號
|
||||
event_date: 事件日期
|
||||
details: 事件內容
|
||||
|
|
|
@ -13,6 +13,7 @@ Rails.application.routes.draw do
|
|||
get 'venue_management_signup_field'
|
||||
get 'venue_management_submission_field'
|
||||
get 'venue_management_invitings'
|
||||
get 'venue_management_memorabilias'
|
||||
end
|
||||
end
|
||||
resources :venue_management_items do
|
||||
|
@ -24,6 +25,7 @@ Rails.application.routes.draw do
|
|||
resources :venue_management_signups
|
||||
resources :venue_management_item_contents
|
||||
resources :venue_management_invitings
|
||||
resources :venue_management_memorabilias
|
||||
end
|
||||
|
||||
resources :venue_managements do
|
||||
|
|
|
@ -47,6 +47,11 @@ module VenueManagement
|
|||
:priority => 3,
|
||||
:active_for_action => { 'admin/venue_managements' => 'venue_management_invitings' },
|
||||
:available_for => 'managers'
|
||||
context_link 'venue_management.set_venue_management_memorabilias',
|
||||
:link_path => 'admin_venue_management_memorabilias_path',
|
||||
:priority => 3,
|
||||
:active_for_action => { 'admin/venue_managements' => 'venue_management_memorabilias' },
|
||||
:available_for => 'managers'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue