enju_event 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +36 -0
- data/app/controllers/calendar_controller.rb +34 -0
- data/app/controllers/event_categories_controller.rb +18 -0
- data/app/controllers/event_import_files_controller.rb +95 -0
- data/app/controllers/event_import_results_controller.rb +15 -0
- data/app/controllers/events_controller.rb +152 -0
- data/app/controllers/participates_controller.rb +81 -0
- data/app/helpers/calendar_helper.rb +31 -0
- data/app/models/event.rb +87 -0
- data/app/models/event_category.rb +23 -0
- data/app/models/event_import_file.rb +166 -0
- data/app/models/event_import_result.rb +23 -0
- data/app/models/participate.rb +25 -0
- data/app/views/calendar/index.html.erb +45 -0
- data/app/views/event_categories/_form.html.erb +19 -0
- data/app/views/event_categories/edit.html.erb +13 -0
- data/app/views/event_categories/index.html.erb +46 -0
- data/app/views/event_categories/new.html.erb +12 -0
- data/app/views/event_categories/show.html.erb +29 -0
- data/app/views/event_import_files/edit.html.erb +25 -0
- data/app/views/event_import_files/index.html.erb +40 -0
- data/app/views/event_import_files/new.html.erb +37 -0
- data/app/views/event_import_files/show.html.erb +64 -0
- data/app/views/event_import_results/index.csv.erb +3 -0
- data/app/views/event_import_results/index.html.erb +50 -0
- data/app/views/event_import_results/show.html.erb +33 -0
- data/app/views/events/_all_day.html.erb +24 -0
- data/app/views/events/_form.html.erb +44 -0
- data/app/views/events/edit.html.erb +14 -0
- data/app/views/events/index.atom.builder +10 -0
- data/app/views/events/index.csv.erb +4 -0
- data/app/views/events/index.html.erb +105 -0
- data/app/views/events/index.ics.erb +13 -0
- data/app/views/events/index.mobile.erb +49 -0
- data/app/views/events/index.rss.builder +34 -0
- data/app/views/events/new.html.erb +17 -0
- data/app/views/events/show.html.erb +50 -0
- data/app/views/events/show.mobile.erb +42 -0
- data/app/views/participates/edit.html.erb +28 -0
- data/app/views/participates/index.html.erb +30 -0
- data/app/views/participates/new.html.erb +27 -0
- data/app/views/participates/show.html.erb +24 -0
- data/config/routes.rb +10 -0
- data/db/fixtures/event_categories.yml +13 -0
- data/db/migrate/113_create_events.rb +23 -0
- data/db/migrate/114_create_event_categories.rb +16 -0
- data/db/migrate/20081028093607_create_event_import_files.rb +29 -0
- data/db/migrate/20090519203307_create_participates.rb +17 -0
- data/db/migrate/20100925074639_create_event_import_results.rb +15 -0
- data/lib/enju_event.rb +5 -0
- data/lib/enju_event/engine.rb +18 -0
- data/lib/enju_event/version.rb +3 -0
- data/lib/tasks/enju_event_tasks.rake +5 -0
- data/spec/controllers/event_categories_controller_spec.rb +483 -0
- data/spec/controllers/event_import_files_controller_spec.rb +321 -0
- data/spec/controllers/events_controller_spec.rb +506 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +99 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/notifier.rb +28 -0
- data/spec/dummy/app/models/ability.rb +39 -0
- data/spec/dummy/app/models/language.rb +4 -0
- data/spec/dummy/app/models/library.rb +128 -0
- data/spec/dummy/app/models/library_group.rb +86 -0
- data/spec/dummy/app/models/patron.rb +163 -0
- data/spec/dummy/app/models/patron_type.rb +19 -0
- data/spec/dummy/app/models/role.rb +8 -0
- data/spec/dummy/app/models/shelf.rb +54 -0
- data/spec/dummy/app/models/user.rb +43 -0
- data/spec/dummy/app/models/user_group.rb +2 -0
- data/spec/dummy/app/models/user_has_role.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/page/403.html.erb +9 -0
- data/spec/dummy/app/views/page/403.mobile.erb +5 -0
- data/spec/dummy/app/views/page/403.xml.erb +4 -0
- data/spec/dummy/app/views/page/404.html.erb +9 -0
- data/spec/dummy/app/views/page/404.mobile.erb +5 -0
- data/spec/dummy/app/views/page/404.xml.erb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +209 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +7 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/db/migrate/001_create_patrons.rb +62 -0
- data/spec/dummy/db/migrate/059_create_libraries.rb +34 -0
- data/spec/dummy/db/migrate/069_create_shelves.rb +19 -0
- data/spec/dummy/db/migrate/080_create_library_groups.rb +25 -0
- data/spec/dummy/db/migrate/20080905191442_create_patron_types.rb +16 -0
- data/spec/dummy/db/migrate/20081025083905_create_languages.rb +27 -0
- data/spec/dummy/db/migrate/20100211105551_add_admin_networks_to_library_group.rb +9 -0
- data/spec/dummy/db/migrate/20100222124420_add_allow_bookmark_external_url_to_library_group.rb +9 -0
- data/spec/dummy/db/migrate/20100527113752_create_delayed_jobs.rb +21 -0
- data/spec/dummy/db/migrate/20110115022329_add_position_to_library_group.rb +9 -0
- data/spec/dummy/db/migrate/20110222073537_add_url_to_library_group.rb +9 -0
- data/spec/dummy/db/migrate/20111020063828_remove_dsbl_from_library_group.rb +11 -0
- data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
- data/spec/dummy/db/migrate/20111201155456_create_users.rb +14 -0
- data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +31 -0
- data/spec/dummy/db/migrate/20111201163342_create_user_groups.rb +12 -0
- data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
- data/spec/dummy/db/schema.rb +293 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/enju_leaf.rb +4 -0
- data/spec/dummy/lib/enju_leaf/import_file.rb +13 -0
- data/spec/dummy/lib/enju_leaf/localized_name.rb +13 -0
- data/spec/dummy/lib/enju_leaf/master_model.rb +41 -0
- data/spec/dummy/lib/enju_leaf/url_validator.rb +10 -0
- data/spec/dummy/log/sunspot-solr-test.log +222 -0
- data/spec/dummy/log/test.log +145759 -0
- data/spec/dummy/private/system/event_imports/4/original/event_import_file_sample1.tsv +5 -0
- data/spec/dummy/private/system/event_imports/4/original/event_import_file_sample2.tsv +3 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/solr/conf/admin-extra.html +31 -0
- data/spec/dummy/solr/conf/elevate.xml +36 -0
- data/spec/dummy/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/spec/dummy/solr/conf/protwords.txt +21 -0
- data/spec/dummy/solr/conf/schema.xml +238 -0
- data/spec/dummy/solr/conf/scripts.conf +24 -0
- data/spec/dummy/solr/conf/solrconfig.xml +934 -0
- data/spec/dummy/solr/conf/spellings.txt +2 -0
- data/spec/dummy/solr/conf/stopwords.txt +58 -0
- data/spec/dummy/solr/conf/synonyms.txt +31 -0
- data/spec/dummy/solr/data/test/index/segments.gen +0 -0
- data/spec/dummy/solr/data/test/index/segments_1 +0 -0
- data/spec/dummy/solr/data/test/spellchecker/segments.gen +0 -0
- data/spec/dummy/solr/data/test/spellchecker/segments_1 +0 -0
- data/spec/factories/event.rb +7 -0
- data/spec/factories/event_category.rb +5 -0
- data/spec/factories/library.rb +13 -0
- data/spec/factories/user.rb +34 -0
- data/spec/fixtures/event_categories.yml +55 -0
- data/spec/fixtures/event_import_files.yml +49 -0
- data/spec/fixtures/event_import_results.yml +24 -0
- data/spec/fixtures/events.yml +142 -0
- data/spec/fixtures/languages.yml +1901 -0
- data/spec/fixtures/libraries.yml +108 -0
- data/spec/fixtures/library_groups.yml +34 -0
- data/spec/fixtures/patron_types.yml +35 -0
- data/spec/fixtures/patrons.yml +338 -0
- data/spec/fixtures/roles.yml +21 -0
- data/spec/fixtures/shelves.yml +46 -0
- data/spec/fixtures/user_groups.yml +25 -0
- data/spec/fixtures/user_has_roles.yml +41 -0
- data/spec/fixtures/users.yml +69 -0
- data/spec/models/event_category_spec.rb +21 -0
- data/spec/models/event_import_file_spec.rb +62 -0
- data/spec/models/event_import_result_spec.rb +20 -0
- data/spec/models/event_spec.rb +39 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/support/controller_macros.rb +48 -0
- data/spec/support/devise.rb +4 -0
- metadata +541 -0
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
4
|
+
|
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
|
6
|
+
|
|
7
|
+
Dummy::Application.load_tasks
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
|
+
// the compiled file.
|
|
6
|
+
//
|
|
7
|
+
//= require jquery
|
|
8
|
+
//= require jquery_ujs
|
|
9
|
+
//= require_tree .
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
|
5
|
+
*= require_self
|
|
6
|
+
*= require_tree .
|
|
7
|
+
*/
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
class ApplicationController < ActionController::Base
|
|
2
|
+
protect_from_forgery
|
|
3
|
+
|
|
4
|
+
rescue_from CanCan::AccessDenied, :with => :render_403
|
|
5
|
+
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
|
|
6
|
+
|
|
7
|
+
before_filter :set_locale
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
def render_403
|
|
11
|
+
return if performed?
|
|
12
|
+
if user_signed_in?
|
|
13
|
+
respond_to do |format|
|
|
14
|
+
format.html {render :template => 'page/403', :status => 403}
|
|
15
|
+
format.mobile {render :template => 'page/403', :status => 403}
|
|
16
|
+
format.xml {render :template => 'page/403', :status => 403}
|
|
17
|
+
format.json
|
|
18
|
+
end
|
|
19
|
+
else
|
|
20
|
+
respond_to do |format|
|
|
21
|
+
format.html {redirect_to new_user_session_url}
|
|
22
|
+
format.mobile {redirect_to new_user_session_url}
|
|
23
|
+
format.xml {render :template => 'page/403', :status => 403}
|
|
24
|
+
format.json
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def render_404
|
|
30
|
+
return if performed?
|
|
31
|
+
respond_to do |format|
|
|
32
|
+
format.html {render :template => 'page/404', :status => 404}
|
|
33
|
+
format.mobile {render :template => 'page/404', :status => 404}
|
|
34
|
+
format.xml {render :template => 'page/404', :status => 404}
|
|
35
|
+
format.json
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get_patron
|
|
40
|
+
@patron = Patron.find(params[:patron_id]) if params[:patron_id]
|
|
41
|
+
authorize! :show, @patron if @patron
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_library
|
|
45
|
+
@library = Library.find(params[:library_id]) if params[:library_id]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def get_libraries
|
|
49
|
+
@libraries = Library.all_cache
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def set_locale
|
|
53
|
+
if params[:locale]
|
|
54
|
+
unless I18n.available_locales.include?(params[:locale].to_s.intern)
|
|
55
|
+
raise InvalidLocaleError
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
if user_signed_in?
|
|
59
|
+
locale = params[:locale] || session[:locale] || current_user.locale.try(:to_sym)
|
|
60
|
+
else
|
|
61
|
+
locale = params[:locale] || session[:locale]
|
|
62
|
+
end
|
|
63
|
+
if locale
|
|
64
|
+
I18n.locale = @locale = session[:locale] = locale.to_sym
|
|
65
|
+
else
|
|
66
|
+
I18n.locale = @locale = session[:locale] = I18n.default_locale
|
|
67
|
+
end
|
|
68
|
+
rescue InvalidLocaleError
|
|
69
|
+
@locale = I18n.default_locale
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def solr_commit
|
|
73
|
+
Sunspot.commit
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def convert_charset
|
|
77
|
+
case params[:format]
|
|
78
|
+
when 'csv'
|
|
79
|
+
return unless configatron.csv_charset_conversion
|
|
80
|
+
# TODO: 他の言語
|
|
81
|
+
if @locale.to_sym == :ja
|
|
82
|
+
headers["Content-Type"] = "text/csv; charset=Shift_JIS"
|
|
83
|
+
response.body = NKF::nkf('-Ws', response.body)
|
|
84
|
+
end
|
|
85
|
+
when 'xml'
|
|
86
|
+
if @locale.to_sym == :ja
|
|
87
|
+
headers["Content-Type"] = "application/xml; charset=Shift_JIS"
|
|
88
|
+
response.body = NKF::nkf('-Ws', response.body)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def store_page
|
|
94
|
+
flash[:page] = params[:page] if params[:page].to_i > 0
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class InvalidLocaleError < StandardError
|
|
99
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Notifier < ActionMailer::Base
|
|
2
|
+
if LibraryGroup.site_config.try(:url)
|
|
3
|
+
uri = Addressable::URI.parse(LibraryGroup.site_config.url)
|
|
4
|
+
default_url_options[:host] = uri.host
|
|
5
|
+
default_url_options[:port] = uri.port if configatron.enju.web_port_number != 80
|
|
6
|
+
else
|
|
7
|
+
default_url_options[:host] = configatron.enju.web_hostname
|
|
8
|
+
default_url_options[:port] = configatron.enju.web_port_number if configatron.enju.web_port_number != 80
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def message_notification(message)
|
|
12
|
+
I18n.locale = message.receiver.locale.to_sym
|
|
13
|
+
from = "#{LibraryGroup.system_name(message.receiver.locale)} <#{LibraryGroup.site_config.email}>"
|
|
14
|
+
if message.subject
|
|
15
|
+
subject = message.subject
|
|
16
|
+
else
|
|
17
|
+
subject = I18n.t('message.new_message_from_library', :library => LibraryGroup.system_name(message.receiver.user.locale))
|
|
18
|
+
end
|
|
19
|
+
if message.sender
|
|
20
|
+
@sender_name = message.sender.patron.full_name
|
|
21
|
+
else
|
|
22
|
+
@sender_name = LibraryGroup.system_name(message.receiver.locale)
|
|
23
|
+
end
|
|
24
|
+
@message = message
|
|
25
|
+
@locale = message.receiver.locale
|
|
26
|
+
mail(:from => from, :to => message.receiver.email, :subject => subject)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Ability
|
|
2
|
+
include CanCan::Ability
|
|
3
|
+
|
|
4
|
+
def initialize(user)
|
|
5
|
+
case user.try(:role).try(:name)
|
|
6
|
+
when 'Administrator'
|
|
7
|
+
can [:read, :create], EventCategory
|
|
8
|
+
can [:update, :destroy], EventCategory do |event_category|
|
|
9
|
+
!['unknown', 'closed'].include?(event_category.name)
|
|
10
|
+
end
|
|
11
|
+
can :manage, [
|
|
12
|
+
Event,
|
|
13
|
+
EventImportFile,
|
|
14
|
+
Participate
|
|
15
|
+
]
|
|
16
|
+
can :read, EventImportResult
|
|
17
|
+
when 'Librarian'
|
|
18
|
+
can :manage, [
|
|
19
|
+
Event,
|
|
20
|
+
EventImportFile,
|
|
21
|
+
Participate
|
|
22
|
+
]
|
|
23
|
+
can :read, [
|
|
24
|
+
EventCategory,
|
|
25
|
+
EventImportResult
|
|
26
|
+
]
|
|
27
|
+
when 'User'
|
|
28
|
+
can :read, [
|
|
29
|
+
Event,
|
|
30
|
+
EventCategory
|
|
31
|
+
]
|
|
32
|
+
else
|
|
33
|
+
can :read, [
|
|
34
|
+
Event,
|
|
35
|
+
EventCategory
|
|
36
|
+
]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
class Library < ActiveRecord::Base
|
|
3
|
+
include MasterModel
|
|
4
|
+
default_scope :order => 'libraries.position'
|
|
5
|
+
scope :real, where('id != 1')
|
|
6
|
+
has_many :shelves, :order => 'shelves.position'
|
|
7
|
+
belongs_to :library_group, :validate => true
|
|
8
|
+
has_many :events, :include => :event_category
|
|
9
|
+
#belongs_to :holding_patron, :polymorphic => true, :validate => true
|
|
10
|
+
belongs_to :patron #, :validate => true
|
|
11
|
+
has_many :inter_library_loans, :foreign_key => 'borrowing_library_id'
|
|
12
|
+
has_many :users
|
|
13
|
+
belongs_to :country
|
|
14
|
+
|
|
15
|
+
extend FriendlyId
|
|
16
|
+
friendly_id :name
|
|
17
|
+
#geocoded_by :address
|
|
18
|
+
|
|
19
|
+
searchable do
|
|
20
|
+
text :name, :display_name, :note, :address
|
|
21
|
+
time :created_at
|
|
22
|
+
time :updated_at
|
|
23
|
+
integer :position
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#validates_associated :library_group, :holding_patron
|
|
27
|
+
validates_associated :library_group, :patron
|
|
28
|
+
validates_presence_of :short_display_name, :library_group, :patron
|
|
29
|
+
validates_uniqueness_of :short_display_name, :case_sensitive => false
|
|
30
|
+
validates :display_name, :uniqueness => true
|
|
31
|
+
validates :name, :format => {:with => /^[a-z][0-9a-z]{2,254}$/}
|
|
32
|
+
before_validation :set_patron, :on => :create
|
|
33
|
+
#before_save :set_calil_neighborhood_library
|
|
34
|
+
after_validation :geocode, :if => :address_changed?
|
|
35
|
+
after_create :create_shelf
|
|
36
|
+
after_save :clear_all_cache
|
|
37
|
+
after_destroy :clear_all_cache
|
|
38
|
+
|
|
39
|
+
def self.per_page
|
|
40
|
+
10
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.all_cache
|
|
44
|
+
if Rails.env == 'production'
|
|
45
|
+
Rails.cache.fetch('library_all'){Library.all}
|
|
46
|
+
else
|
|
47
|
+
Library.all
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def clear_all_cache
|
|
52
|
+
Rails.cache.delete('library_all')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def set_patron
|
|
56
|
+
self.patron = Patron.new(
|
|
57
|
+
:full_name => self.name
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def create_shelf
|
|
62
|
+
Shelf.create!(:name => "#{self.name}_default", :library => self)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def closed?(date)
|
|
66
|
+
events.closing_days.collect{|c| c.start_at.beginning_of_day}.include?(date.beginning_of_day)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def web?
|
|
70
|
+
return true if self.id == 1
|
|
71
|
+
false
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.web
|
|
75
|
+
Library.find(1)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def address(locale = I18n.locale)
|
|
79
|
+
case locale.to_sym
|
|
80
|
+
when :ja
|
|
81
|
+
"#{self.region.to_s.localize(locale)}#{self.locality.to_s.localize(locale)}#{self.street.to_s.localize(locale)}"
|
|
82
|
+
else
|
|
83
|
+
"#{self.street.to_s.localize(locale)} #{self.locality.to_s.localize(locale)} #{self.region.to_s.localize(locale)}"
|
|
84
|
+
end
|
|
85
|
+
rescue
|
|
86
|
+
nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def address_changed?
|
|
90
|
+
return true if region_changed? or locality_changed? or street_changed?
|
|
91
|
+
false
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# == Schema Information
|
|
96
|
+
#
|
|
97
|
+
# Table name: libraries
|
|
98
|
+
#
|
|
99
|
+
# id :integer not null, primary key
|
|
100
|
+
# patron_id :integer
|
|
101
|
+
# patron_type :string(255)
|
|
102
|
+
# name :string(255) not null
|
|
103
|
+
# display_name :text
|
|
104
|
+
# short_display_name :string(255) not null
|
|
105
|
+
# zip_code :string(255)
|
|
106
|
+
# street :text
|
|
107
|
+
# locality :text
|
|
108
|
+
# region :text
|
|
109
|
+
# telephone_number_1 :string(255)
|
|
110
|
+
# telephone_number_2 :string(255)
|
|
111
|
+
# fax_number :string(255)
|
|
112
|
+
# note :text
|
|
113
|
+
# call_number_rows :integer default(1), not null
|
|
114
|
+
# call_number_delimiter :string(255) default("|"), not null
|
|
115
|
+
# library_group_id :integer default(1), not null
|
|
116
|
+
# users_count :integer default(0), not null
|
|
117
|
+
# position :integer
|
|
118
|
+
# country_id :integer
|
|
119
|
+
# created_at :datetime
|
|
120
|
+
# updated_at :datetime
|
|
121
|
+
# deleted_at :datetime
|
|
122
|
+
# opening_hour :text
|
|
123
|
+
# latitude :float
|
|
124
|
+
# longitude :float
|
|
125
|
+
# calil_systemid :string(255)
|
|
126
|
+
# calil_neighborhood_systemid :text
|
|
127
|
+
#
|
|
128
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
class LibraryGroup < ActiveRecord::Base
|
|
3
|
+
#include Singleton
|
|
4
|
+
#include Configurator
|
|
5
|
+
include MasterModel
|
|
6
|
+
|
|
7
|
+
has_many :libraries
|
|
8
|
+
has_many :search_engines
|
|
9
|
+
#has_many :news_feeds
|
|
10
|
+
belongs_to :country
|
|
11
|
+
|
|
12
|
+
validates :email, :format => {:with => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i}, :presence => true
|
|
13
|
+
validates :url, :presence => true, :url => true
|
|
14
|
+
after_save :clear_site_config_cache
|
|
15
|
+
|
|
16
|
+
def clear_site_config_cache
|
|
17
|
+
Rails.cache.delete('library_site_config')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.site_config
|
|
21
|
+
#if Rails.env == 'production'
|
|
22
|
+
# Rails.cache.fetch('library_site_config'){LibraryGroup.find(1)}
|
|
23
|
+
#else
|
|
24
|
+
LibraryGroup.find(1)
|
|
25
|
+
#end
|
|
26
|
+
rescue
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.system_name(locale = I18n.locale)
|
|
31
|
+
LibraryGroup.site_config.display_name.localize(locale)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def config?
|
|
35
|
+
true if self == LibraryGroup.site_config
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def real_libraries
|
|
39
|
+
# 物理的な図書館 = IDが1以外
|
|
40
|
+
libraries.where('id != 1').all
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def network_access_allowed?(ip_address, options = {})
|
|
44
|
+
options = {:network_type => :lan}.merge(options)
|
|
45
|
+
client_ip = IPAddr.new(ip_address)
|
|
46
|
+
case options[:network_type]
|
|
47
|
+
when :admin
|
|
48
|
+
allowed_networks = self.admin_networks.to_s.split
|
|
49
|
+
else
|
|
50
|
+
allowed_networks = self.my_networks.to_s.split
|
|
51
|
+
end
|
|
52
|
+
allowed_networks.each do |allowed_network|
|
|
53
|
+
begin
|
|
54
|
+
network = IPAddr.new(allowed_network)
|
|
55
|
+
return true if network.include?(client_ip)
|
|
56
|
+
rescue ArgumentError
|
|
57
|
+
nil
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
return false
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# == Schema Information
|
|
66
|
+
#
|
|
67
|
+
# Table name: library_groups
|
|
68
|
+
#
|
|
69
|
+
# id :integer not null, primary key
|
|
70
|
+
# name :string(255) not null
|
|
71
|
+
# display_name :text
|
|
72
|
+
# short_name :string(255) not null
|
|
73
|
+
# email :string(255)
|
|
74
|
+
# my_networks :text
|
|
75
|
+
# login_banner :text
|
|
76
|
+
# note :text
|
|
77
|
+
# post_to_union_catalog :boolean default(FALSE), not null
|
|
78
|
+
# country_id :integer
|
|
79
|
+
# created_at :datetime
|
|
80
|
+
# updated_at :datetime
|
|
81
|
+
# admin_networks :text
|
|
82
|
+
# allow_bookmark_external_url :boolean default(FALSE), not null
|
|
83
|
+
# position :integer
|
|
84
|
+
# url :string(255) default("http://localhost:3000/")
|
|
85
|
+
#
|
|
86
|
+
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
class Patron < ActiveRecord::Base
|
|
3
|
+
scope :readable_by, lambda{|user| {:conditions => ['required_role_id <= ?', user.try(:user_has_role).try(:role_id) || Role.where(:name => 'Guest').select(:id).first.id]}}
|
|
4
|
+
belongs_to :user
|
|
5
|
+
belongs_to :patron_type
|
|
6
|
+
belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id', :validate => true
|
|
7
|
+
belongs_to :language
|
|
8
|
+
|
|
9
|
+
validates_presence_of :language, :patron_type
|
|
10
|
+
validates_associated :language, :patron_type
|
|
11
|
+
validates :full_name, :presence => true, :length => {:maximum => 255}
|
|
12
|
+
validates :user_id, :uniqueness => true, :allow_nil => true
|
|
13
|
+
validates :email, :format => {:with => /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i}, :allow_blank => true
|
|
14
|
+
before_validation :set_role_and_name, :on => :create
|
|
15
|
+
|
|
16
|
+
#has_paper_trail
|
|
17
|
+
attr_accessor :user_username
|
|
18
|
+
#[:address_1, :address_2].each do |column|
|
|
19
|
+
# encrypt_with_public_key column,
|
|
20
|
+
# :key_pair => File.join(Rails.root.to_s,'config','keypair.pem'),
|
|
21
|
+
# :base64 => true
|
|
22
|
+
#end
|
|
23
|
+
|
|
24
|
+
searchable do
|
|
25
|
+
text :name, :place, :address_1, :address_2, :other_designation, :note
|
|
26
|
+
string :zip_code_1
|
|
27
|
+
string :zip_code_2
|
|
28
|
+
string :username do
|
|
29
|
+
user.username if user
|
|
30
|
+
end
|
|
31
|
+
time :created_at
|
|
32
|
+
time :updated_at
|
|
33
|
+
string :user
|
|
34
|
+
integer :required_role_id
|
|
35
|
+
integer :patron_type_id
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.per_page
|
|
39
|
+
10
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def full_name_without_space
|
|
43
|
+
full_name.gsub(/\s/, "")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def set_role_and_name
|
|
47
|
+
self.required_role = Role.where(:name => 'Librarian').first if self.required_role_id.nil?
|
|
48
|
+
set_full_name
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def set_full_name
|
|
52
|
+
if self.full_name.blank?
|
|
53
|
+
if self.last_name.to_s.strip and self.first_name.to_s.strip and configatron.family_name_first == true
|
|
54
|
+
self.full_name = [last_name, middle_name, first_name].compact.join(" ").to_s.strip
|
|
55
|
+
else
|
|
56
|
+
self.full_name = [first_name, last_name, middle_name].compact.join(" ").to_s.strip
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
if self.full_name_transcription.blank?
|
|
60
|
+
self.full_name_transcription = [last_name_transcription, middle_name_transcription, first_name_transcription].join(" ").to_s.strip
|
|
61
|
+
end
|
|
62
|
+
[self.full_name, self.full_name_transcription]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def full_name_without_space
|
|
66
|
+
full_name.gsub(/\s/, "")
|
|
67
|
+
# # TODO: 日本人以外は?
|
|
68
|
+
# name = []
|
|
69
|
+
# name << self.last_name.to_s.strip
|
|
70
|
+
# name << self.middle_name.to_s.strip
|
|
71
|
+
# name << self.first_name.to_s.strip
|
|
72
|
+
# name << self.corporate_name.to_s.strip
|
|
73
|
+
# name.join("").strip
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def full_name_transcription_without_space
|
|
77
|
+
full_name_transcription.to_s.gsub(/\s/, "")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def full_name_alternative_without_space
|
|
81
|
+
full_name_alternative.to_s.gsub(/\s/, "")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def name
|
|
85
|
+
name = []
|
|
86
|
+
name << full_name.to_s.strip
|
|
87
|
+
name << full_name_transcription.to_s.strip
|
|
88
|
+
name << full_name_alternative.to_s.strip
|
|
89
|
+
#name << full_name_without_space
|
|
90
|
+
#name << full_name_transcription_without_space
|
|
91
|
+
#name << full_name_alternative_without_space
|
|
92
|
+
#name << full_name.wakati rescue nil
|
|
93
|
+
#name << full_name_transcription.wakati rescue nil
|
|
94
|
+
#name << full_name_alternative.wakati rescue nil
|
|
95
|
+
name
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def date
|
|
99
|
+
if date_of_birth
|
|
100
|
+
if date_of_death
|
|
101
|
+
"#{date_of_birth} - #{date_of_death}"
|
|
102
|
+
else
|
|
103
|
+
"#{date_of_birth} -"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def creator?(resource)
|
|
109
|
+
resource.creators.include?(self)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def publisher?(resource)
|
|
113
|
+
resource.publishers.include?(self)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def check_required_role(user)
|
|
117
|
+
return true if self.user.blank?
|
|
118
|
+
return true if self.user.required_role.name == 'Guest'
|
|
119
|
+
return true if user == self.user
|
|
120
|
+
return true if user.has_role?(self.user.required_role.name)
|
|
121
|
+
false
|
|
122
|
+
rescue NoMethodError
|
|
123
|
+
false
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def created(work)
|
|
127
|
+
creates.where(:work_id => work.id).first
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def realized(expression)
|
|
131
|
+
realizes.where(:expression_id => expression.id).first
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def produced(manifestation)
|
|
135
|
+
produces.where(:manifestation_id => manifestation.id).first
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def owned(item)
|
|
139
|
+
owns.where(:item_id => item.id)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def self.import_patrons(patron_lists)
|
|
143
|
+
list = []
|
|
144
|
+
patron_lists.each do |patron_list|
|
|
145
|
+
patron = Patron.where(:full_name => patron_list[:full_name]).first
|
|
146
|
+
unless patron
|
|
147
|
+
patron = Patron.new(
|
|
148
|
+
:full_name => patron_list[:full_name],
|
|
149
|
+
:full_name_transcription => patron_list[:full_name_transcription],
|
|
150
|
+
:language_id => 1
|
|
151
|
+
)
|
|
152
|
+
patron.required_role = Role.where(:name => 'Guest').first
|
|
153
|
+
patron.save
|
|
154
|
+
end
|
|
155
|
+
list << patron
|
|
156
|
+
end
|
|
157
|
+
list
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def patrons
|
|
161
|
+
self.original_patrons + self.derived_patrons
|
|
162
|
+
end
|
|
163
|
+
end
|