best_boy 2.2.3 → 3.0.0
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.
- checksums.yaml +4 -4
- data/README.md +74 -110
- data/app/assets/javascripts/best_boy/best_boy.js +0 -1
- data/app/assets/stylesheets/best_boy/base.sass +21 -0
- data/app/assets/stylesheets/best_boy/best_boy.css +1 -3
- data/app/controllers/best_boy/{best_boy_events_controller.rb → events_controller.rb} +4 -4
- data/{lib/best_boy/models/active_record → app/models}/best_boy/day_report.rb +0 -0
- data/app/models/best_boy/event.rb +29 -0
- data/{lib/best_boy/models/active_record → app/models}/best_boy/month_report.rb +0 -0
- data/app/views/best_boy/events/_navigation.html.erb +11 -0
- data/app/views/best_boy/events/charts.html.erb +33 -0
- data/app/views/best_boy/events/details.html.erb +98 -0
- data/app/views/best_boy/events/details.xml.haml +22 -0
- data/app/views/best_boy/events/index.html.erb +8 -0
- data/app/views/best_boy/events/lists.html.erb +62 -0
- data/app/views/best_boy/events/lists.xml.haml +8 -0
- data/app/views/best_boy/events/monthly_details.html.erb +67 -0
- data/app/views/best_boy/events/monthly_details.xml.haml +15 -0
- data/app/views/best_boy/events/stats.html.erb +89 -0
- data/app/views/best_boy/events/stats.xml.haml +18 -0
- data/app/views/layouts/best_boy/best_boy.html.erb +43 -0
- data/config/routes.rb +13 -7
- data/db/migrate/20150610155237_create_best_boy_events.rb +17 -0
- data/db/migrate/20150610155251_create_best_boy_reports.rb +28 -0
- data/lib/best_boy.rb +8 -5
- data/lib/best_boy/{controllers/best_boy_controller.rb → controller.rb} +6 -3
- data/lib/best_boy/engine.rb +7 -27
- data/lib/best_boy/{models/active_record/best_boy/eventable.rb → eventable.rb} +7 -6
- data/lib/best_boy/{models/active_record/best_boy/obeys_test_mode.rb → obeys_test_mode.rb} +0 -0
- data/lib/best_boy/{models/active_record/best_boy/reporting.rb → reporting.rb} +0 -0
- data/lib/best_boy/version.rb +1 -1
- data/lib/generators/best_boy/install_generator.rb +11 -0
- data/lib/generators/{templates → best_boy/templates/config/initializers}/best_boy.rb +0 -6
- data/lib/tasks/recover_report_history.rake +7 -7
- metadata +64 -71
- data/app/assets/images/best_boy/glyphicons-halflings-white.png +0 -0
- data/app/assets/images/best_boy/glyphicons-halflings.png +0 -0
- data/app/assets/javascripts/best_boy/bootstrap_datepicker.js +0 -401
- data/app/assets/stylesheets/best_boy/bootstrap.scss +0 -4983
- data/app/assets/stylesheets/best_boy/bootstrap_datepicker.css +0 -156
- data/app/views/best_boy/best_boy_events/_navigation.html.erb +0 -9
- data/app/views/best_boy/best_boy_events/charts.html.erb +0 -25
- data/app/views/best_boy/best_boy_events/details.html.erb +0 -88
- data/app/views/best_boy/best_boy_events/index.html.erb +0 -6
- data/app/views/best_boy/best_boy_events/lists.html.erb +0 -45
- data/app/views/best_boy/best_boy_events/monthly_details.html.erb +0 -51
- data/app/views/best_boy/best_boy_events/stats.html.erb +0 -80
- data/app/views/layouts/best_boy_backend.html.erb +0 -70
- data/lib/best_boy/models/active_record/best_boy_event.rb +0 -21
- data/lib/generators/active_record/best_boy_generator.rb +0 -29
- data/lib/generators/active_record/templates/add_event_source_to_best_boy_events_table.rb +0 -11
- data/lib/generators/active_record/templates/create_best_boy_events_table.rb +0 -17
- data/lib/generators/active_record/templates/create_best_boy_reports.rb +0 -30
- data/lib/generators/best_boy_generator.rb +0 -23
- data/lib/generators/templates/bootstrap/bootstrap.css +0 -4983
- data/lib/generators/templates/bootstrap/bootstrap_datepicker.css +0 -156
- data/lib/generators/templates/bootstrap/bootstrap_datepicker.js +0 -401
- data/lib/generators/templates/bootstrap/glyphicons-halflings-white.png +0 -0
- data/lib/generators/templates/bootstrap/glyphicons-halflings.png +0 -0
data/lib/best_boy/engine.rb
CHANGED
@@ -1,39 +1,19 @@
|
|
1
|
-
require "best_boy"
|
2
|
-
require "rails"
|
3
|
-
require "google_visualr"
|
4
|
-
|
5
1
|
module BestBoy
|
6
2
|
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace BestBoy
|
7
4
|
|
8
|
-
initializer 'best_boy.assets', group: :all do |app|
|
9
|
-
|
10
|
-
require initializer_path if File.exist? initializer_path
|
11
|
-
|
12
|
-
if BestBoy.precompile_assets == true
|
13
|
-
Rails.application.config.assets.precompile += ['best_boy/best_boy.css', 'best_boy/best_boy.js']
|
14
|
-
end
|
5
|
+
initializer 'best_boy.assets.precompile', group: :all do |app|
|
6
|
+
Rails.application.config.assets.precompile += ['best_boy/best_boy.css', 'best_boy/best_boy.js']
|
15
7
|
end
|
16
8
|
|
17
9
|
initializer 'best_boy.model' do |app|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
require "best_boy/models/active_record/best_boy_event.rb"
|
22
|
-
require "best_boy/models/active_record/best_boy/eventable.rb"
|
23
|
-
require "best_boy/models/active_record/best_boy/day_report.rb"
|
24
|
-
require "best_boy/models/active_record/best_boy/month_report.rb"
|
25
|
-
ActiveRecord::Base.send(:include, BestBoy::Eventable)
|
26
|
-
else
|
27
|
-
raise "Sorry, best_boy actually only supports ActiveRecord ORM."
|
28
|
-
end
|
29
|
-
|
10
|
+
require "best_boy/obeys_test_mode.rb"
|
11
|
+
require "best_boy/reporting.rb"
|
12
|
+
require "best_boy/eventable.rb"
|
30
13
|
end
|
31
14
|
|
32
15
|
initializer 'best_boy.controller' do
|
33
|
-
require "best_boy/
|
34
|
-
ActiveSupport.on_load(:action_controller) do
|
35
|
-
include BestBoyController::InstanceMethods
|
36
|
-
end
|
16
|
+
require "best_boy/controller.rb"
|
37
17
|
end
|
38
18
|
end
|
39
19
|
end
|
@@ -14,13 +14,14 @@ module BestBoy
|
|
14
14
|
# associations
|
15
15
|
#
|
16
16
|
#
|
17
|
-
has_many :best_boy_events, as: :owner, dependent: :nullify
|
17
|
+
has_many :best_boy_events, as: :owner, class_name: "BestBoy::Event", dependent: :nullify
|
18
|
+
|
18
19
|
|
19
20
|
# callbacks
|
20
21
|
#
|
21
22
|
#
|
22
|
-
after_create :
|
23
|
-
after_destroy :
|
23
|
+
after_create :trigger_best_boy_create_event
|
24
|
+
after_destroy :trigger_best_boy_destroy_event
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -35,19 +36,19 @@ module BestBoy
|
|
35
36
|
|
36
37
|
private
|
37
38
|
|
38
|
-
def
|
39
|
+
def trigger_best_boy_create_event
|
39
40
|
return if self.class.best_boy_disable_callbacks
|
40
41
|
create_best_boy_event_with_type "create"
|
41
42
|
end
|
42
43
|
|
43
|
-
def
|
44
|
+
def trigger_best_boy_destroy_event
|
44
45
|
return if self.class.best_boy_disable_callbacks
|
45
46
|
create_best_boy_event_with_type "destroy"
|
46
47
|
end
|
47
48
|
|
48
49
|
def create_best_boy_event_with_type(type, source = nil)
|
49
50
|
raise "nil event is not allowed" if type.blank?
|
50
|
-
best_boy_event =
|
51
|
+
best_boy_event = BestBoy::Event.new do |bbe|
|
51
52
|
bbe.event = type
|
52
53
|
bbe.event_source = source
|
53
54
|
bbe.owner = self
|
File without changes
|
File without changes
|
data/lib/best_boy/version.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
BestBoy.setup do |config|
|
2
|
-
# if you want to use the asset-pipeline, set precompile_assets to true (default: false)
|
3
|
-
# config.precompile_assets = true
|
4
|
-
|
5
|
-
# Define ORM. Could be :active_record (default). Actually no other mapper is supported
|
6
|
-
#config.orm = :active_record
|
7
|
-
|
8
2
|
# Define base Controller (default ApplicationController)
|
9
3
|
#config.base_controller = "ApplicationController"
|
10
4
|
|
@@ -2,7 +2,7 @@ namespace :best_boy do
|
|
2
2
|
desc "Creates consistent structure of DayReports and MonthReports for a given set of events"
|
3
3
|
task :recover_report_history, [:date] => :environment do |t, args|
|
4
4
|
|
5
|
-
next unless
|
5
|
+
next unless BestBoy::Event.any?
|
6
6
|
|
7
7
|
# helper methods
|
8
8
|
#
|
@@ -48,17 +48,17 @@ namespace :best_boy do
|
|
48
48
|
puts "> Selected report data has been destroyed."
|
49
49
|
puts ""
|
50
50
|
|
51
|
-
owner_types =
|
51
|
+
owner_types = BestBoy::Event.order(:owner_type).uniq.pluck(:owner_type)
|
52
52
|
available_events = {}
|
53
53
|
available_event_sources = {}
|
54
54
|
|
55
55
|
owner_types.each do |owner_type|
|
56
|
-
available_events.merge!( { owner_type =>
|
57
|
-
available_event_sources.merge!( { owner_type =>
|
56
|
+
available_events.merge!( { owner_type => BestBoy::Event.where(owner_type: owner_type).order(:event).uniq.pluck(:event) } )
|
57
|
+
available_event_sources.merge!( { owner_type => BestBoy::Event.where(owner_type: owner_type).order(:event_source).uniq.pluck(:event_source) } ) # explicitly including nil
|
58
58
|
end
|
59
59
|
|
60
|
-
start =
|
61
|
-
days = (start..
|
60
|
+
start = BestBoy::Event.order('created_at ASC').first.created_at.to_date unless start.present?
|
61
|
+
days = (start..BestBoy::Event.order('created_at ASC').last.created_at.to_date)
|
62
62
|
|
63
63
|
puts ""
|
64
64
|
puts "> Start creating new reports for #{days.count} days ..."
|
@@ -69,7 +69,7 @@ namespace :best_boy do
|
|
69
69
|
available_events[owner_type].each do |event|
|
70
70
|
available_event_sources[owner_type].each do |source|
|
71
71
|
|
72
|
-
base_scope =
|
72
|
+
base_scope = BestBoy::Event.where(owner_type: owner_type, event: event, event_source: source).order('created_at DESC')
|
73
73
|
|
74
74
|
# Create MonthReports when...
|
75
75
|
# - diving into loop initially or
|
metadata
CHANGED
@@ -1,145 +1,145 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: best_boy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Seydel, Carsten Zimmermann, Robin Neumann, Daniel Schoppmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
20
|
-
- - <
|
19
|
+
version: 4.1.0
|
20
|
+
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 4.
|
30
|
-
- - <
|
29
|
+
version: 4.1.0
|
30
|
+
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: kaminari
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: 0.14.1
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.14.1
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: google_visualr
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: haml
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
|
-
type: :
|
68
|
+
type: :runtime
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: sqlite3
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- -
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: '0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: rspec-rails
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - ~>
|
93
|
+
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: 3.3.1
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - ~>
|
100
|
+
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
102
|
+
version: 3.3.1
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: shoulda
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
109
|
+
version: '3.5'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- -
|
114
|
+
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '3.5'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
118
|
+
name: appraisal
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- -
|
121
|
+
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
|
-
- -
|
128
|
+
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
132
|
name: sass-rails
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
|
-
- - ~>
|
135
|
+
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: 4.0.0
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
|
-
- - ~>
|
142
|
+
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: 4.0.0
|
145
145
|
description: Hybrid action logging, consisting of standard and custom logging.
|
@@ -151,46 +151,39 @@ extra_rdoc_files: []
|
|
151
151
|
files:
|
152
152
|
- README.md
|
153
153
|
- Rakefile
|
154
|
-
- app/assets/images/best_boy/glyphicons-halflings-white.png
|
155
|
-
- app/assets/images/best_boy/glyphicons-halflings.png
|
156
154
|
- app/assets/javascripts/best_boy/best_boy.js
|
157
|
-
- app/assets/
|
155
|
+
- app/assets/stylesheets/best_boy/base.sass
|
158
156
|
- app/assets/stylesheets/best_boy/best_boy.css
|
159
|
-
- app/
|
160
|
-
- app/assets/stylesheets/best_boy/bootstrap_datepicker.css
|
161
|
-
- app/controllers/best_boy/best_boy_events_controller.rb
|
157
|
+
- app/controllers/best_boy/events_controller.rb
|
162
158
|
- app/helpers/best_boy/best_boy_view_helper.rb
|
163
|
-
- app/
|
164
|
-
- app/
|
165
|
-
- app/
|
166
|
-
- app/views/best_boy/
|
167
|
-
- app/views/best_boy/
|
168
|
-
- app/views/best_boy/
|
169
|
-
- app/views/best_boy/
|
170
|
-
- app/views/
|
159
|
+
- app/models/best_boy/day_report.rb
|
160
|
+
- app/models/best_boy/event.rb
|
161
|
+
- app/models/best_boy/month_report.rb
|
162
|
+
- app/views/best_boy/events/_navigation.html.erb
|
163
|
+
- app/views/best_boy/events/charts.html.erb
|
164
|
+
- app/views/best_boy/events/details.html.erb
|
165
|
+
- app/views/best_boy/events/details.xml.haml
|
166
|
+
- app/views/best_boy/events/index.html.erb
|
167
|
+
- app/views/best_boy/events/lists.html.erb
|
168
|
+
- app/views/best_boy/events/lists.xml.haml
|
169
|
+
- app/views/best_boy/events/monthly_details.html.erb
|
170
|
+
- app/views/best_boy/events/monthly_details.xml.haml
|
171
|
+
- app/views/best_boy/events/stats.html.erb
|
172
|
+
- app/views/best_boy/events/stats.xml.haml
|
173
|
+
- app/views/layouts/best_boy/best_boy.html.erb
|
171
174
|
- config/initializers/will_paginate.rb
|
172
175
|
- config/routes.rb
|
176
|
+
- db/migrate/20150610155237_create_best_boy_events.rb
|
177
|
+
- db/migrate/20150610155251_create_best_boy_reports.rb
|
173
178
|
- lib/best_boy.rb
|
174
|
-
- lib/best_boy/
|
179
|
+
- lib/best_boy/controller.rb
|
175
180
|
- lib/best_boy/engine.rb
|
176
|
-
- lib/best_boy/
|
177
|
-
- lib/best_boy/
|
178
|
-
- lib/best_boy/
|
179
|
-
- lib/best_boy/models/active_record/best_boy/obeys_test_mode.rb
|
180
|
-
- lib/best_boy/models/active_record/best_boy/reporting.rb
|
181
|
-
- lib/best_boy/models/active_record/best_boy_event.rb
|
181
|
+
- lib/best_boy/eventable.rb
|
182
|
+
- lib/best_boy/obeys_test_mode.rb
|
183
|
+
- lib/best_boy/reporting.rb
|
182
184
|
- lib/best_boy/version.rb
|
183
|
-
- lib/generators/
|
184
|
-
- lib/generators/
|
185
|
-
- lib/generators/active_record/templates/create_best_boy_events_table.rb
|
186
|
-
- lib/generators/active_record/templates/create_best_boy_reports.rb
|
187
|
-
- lib/generators/best_boy_generator.rb
|
188
|
-
- lib/generators/templates/best_boy.rb
|
189
|
-
- lib/generators/templates/bootstrap/bootstrap.css
|
190
|
-
- lib/generators/templates/bootstrap/bootstrap_datepicker.css
|
191
|
-
- lib/generators/templates/bootstrap/bootstrap_datepicker.js
|
192
|
-
- lib/generators/templates/bootstrap/glyphicons-halflings-white.png
|
193
|
-
- lib/generators/templates/bootstrap/glyphicons-halflings.png
|
185
|
+
- lib/generators/best_boy/install_generator.rb
|
186
|
+
- lib/generators/best_boy/templates/config/initializers/best_boy.rb
|
194
187
|
- lib/tasks/recover_report_history.rake
|
195
188
|
homepage: https://github.com/absolventa/best_boy
|
196
189
|
licenses:
|
@@ -202,17 +195,17 @@ require_paths:
|
|
202
195
|
- lib
|
203
196
|
required_ruby_version: !ruby/object:Gem::Requirement
|
204
197
|
requirements:
|
205
|
-
- -
|
198
|
+
- - ">="
|
206
199
|
- !ruby/object:Gem::Version
|
207
200
|
version: '0'
|
208
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
202
|
requirements:
|
210
|
-
- -
|
203
|
+
- - ">="
|
211
204
|
- !ruby/object:Gem::Version
|
212
205
|
version: '0'
|
213
206
|
requirements: []
|
214
207
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.4.
|
208
|
+
rubygems_version: 2.4.7
|
216
209
|
signing_key:
|
217
210
|
specification_version: 4
|
218
211
|
summary: a simple event driven logging for models
|
Binary file
|
Binary file
|
@@ -1,401 +0,0 @@
|
|
1
|
-
/* =========================================================
|
2
|
-
* bootstrap-datepicker.js
|
3
|
-
* http://www.eyecon.ro/bootstrap-datepicker
|
4
|
-
* =========================================================
|
5
|
-
* Copyright 2012 Stefan Petre
|
6
|
-
*
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
* you may not use this file except in compliance with the License.
|
9
|
-
* You may obtain a copy of the License at
|
10
|
-
*
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
*
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
* See the License for the specific language governing permissions and
|
17
|
-
* limitations under the License.
|
18
|
-
* ========================================================= */
|
19
|
-
|
20
|
-
!function( $ ) {
|
21
|
-
|
22
|
-
// Picker object
|
23
|
-
|
24
|
-
var Datepicker = function(element, options){
|
25
|
-
this.element = $(element);
|
26
|
-
this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
|
27
|
-
this.picker = $(DPGlobal.template)
|
28
|
-
.appendTo('body')
|
29
|
-
.on({
|
30
|
-
click: $.proxy(this.click, this),
|
31
|
-
mousedown: $.proxy(this.mousedown, this)
|
32
|
-
});
|
33
|
-
this.isInput = this.element.is('input');
|
34
|
-
this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
|
35
|
-
|
36
|
-
if (this.isInput) {
|
37
|
-
this.element.on({
|
38
|
-
focus: $.proxy(this.show, this),
|
39
|
-
blur: $.proxy(this.hide, this),
|
40
|
-
keyup: $.proxy(this.update, this)
|
41
|
-
});
|
42
|
-
} else {
|
43
|
-
if (this.component){
|
44
|
-
this.component.on('click', $.proxy(this.show, this));
|
45
|
-
} else {
|
46
|
-
this.element.on('click', $.proxy(this.show, this));
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
this.viewMode = 0;
|
51
|
-
this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
|
52
|
-
this.weekEnd = this.weekStart == 0 ? 6 : this.weekStart - 1;
|
53
|
-
this.fillDow();
|
54
|
-
this.fillMonths();
|
55
|
-
this.update();
|
56
|
-
this.showMode();
|
57
|
-
};
|
58
|
-
|
59
|
-
Datepicker.prototype = {
|
60
|
-
constructor: Datepicker,
|
61
|
-
|
62
|
-
show: function(e) {
|
63
|
-
this.picker.show();
|
64
|
-
this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
|
65
|
-
this.place();
|
66
|
-
$(window).on('resize', $.proxy(this.place, this));
|
67
|
-
if (e ) {
|
68
|
-
e.stopPropagation();
|
69
|
-
e.preventDefault();
|
70
|
-
}
|
71
|
-
if (!this.isInput) {
|
72
|
-
$(document).on('mousedown', $.proxy(this.hide, this));
|
73
|
-
}
|
74
|
-
this.element.trigger({
|
75
|
-
type: 'show',
|
76
|
-
date: this.date
|
77
|
-
});
|
78
|
-
},
|
79
|
-
|
80
|
-
hide: function(){
|
81
|
-
this.picker.hide();
|
82
|
-
$(window).off('resize', this.place);
|
83
|
-
this.viewMode = 0;
|
84
|
-
this.showMode();
|
85
|
-
if (!this.isInput) {
|
86
|
-
$(document).off('mousedown', this.hide);
|
87
|
-
}
|
88
|
-
this.setValue();
|
89
|
-
this.element.trigger({
|
90
|
-
type: 'hide',
|
91
|
-
date: this.date
|
92
|
-
});
|
93
|
-
},
|
94
|
-
|
95
|
-
setValue: function() {
|
96
|
-
var formated = DPGlobal.formatDate(this.date, this.format);
|
97
|
-
if (!this.isInput) {
|
98
|
-
if (this.component){
|
99
|
-
this.element.find('input').prop('value', formated);
|
100
|
-
}
|
101
|
-
this.element.data('date', formated);
|
102
|
-
} else {
|
103
|
-
this.element.prop('value', formated);
|
104
|
-
}
|
105
|
-
},
|
106
|
-
|
107
|
-
place: function(){
|
108
|
-
var offset = this.component ? this.component.offset() : this.element.offset();
|
109
|
-
this.picker.css({
|
110
|
-
top: offset.top + this.height,
|
111
|
-
left: offset.left
|
112
|
-
});
|
113
|
-
},
|
114
|
-
|
115
|
-
update: function(){
|
116
|
-
this.date = DPGlobal.parseDate(
|
117
|
-
this.isInput ? this.element.prop('value') : this.element.data('date'),
|
118
|
-
this.format
|
119
|
-
);
|
120
|
-
this.viewDate = new Date(this.date);
|
121
|
-
this.fill();
|
122
|
-
},
|
123
|
-
|
124
|
-
fillDow: function(){
|
125
|
-
var dowCnt = this.weekStart;
|
126
|
-
var html = '<tr>';
|
127
|
-
while (dowCnt < this.weekStart + 7) {
|
128
|
-
html += '<th class="dow">'+DPGlobal.dates.daysMin[(dowCnt++)%7]+'</th>';
|
129
|
-
}
|
130
|
-
html += '</tr>';
|
131
|
-
this.picker.find('.datepicker-days thead').append(html);
|
132
|
-
},
|
133
|
-
|
134
|
-
fillMonths: function(){
|
135
|
-
var html = '';
|
136
|
-
var i = 0
|
137
|
-
while (i < 12) {
|
138
|
-
html += '<span class="month">'+DPGlobal.dates.monthsShort[i++]+'</span>';
|
139
|
-
}
|
140
|
-
this.picker.find('.datepicker-months td').append(html);
|
141
|
-
},
|
142
|
-
|
143
|
-
fill: function() {
|
144
|
-
var d = new Date(this.viewDate),
|
145
|
-
year = d.getFullYear(),
|
146
|
-
month = d.getMonth(),
|
147
|
-
currentDate = this.date.valueOf();
|
148
|
-
this.picker.find('.datepicker-days th:eq(1)')
|
149
|
-
.text(DPGlobal.dates.months[month]+' '+year);
|
150
|
-
var prevMonth = new Date(year, month-1, 28,0,0,0,0),
|
151
|
-
day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
|
152
|
-
prevMonth.setDate(day);
|
153
|
-
prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
|
154
|
-
var nextMonth = new Date(prevMonth);
|
155
|
-
nextMonth.setDate(nextMonth.getDate() + 42);
|
156
|
-
nextMonth = nextMonth.valueOf();
|
157
|
-
html = [];
|
158
|
-
var clsName;
|
159
|
-
while(prevMonth.valueOf() < nextMonth) {
|
160
|
-
if (prevMonth.getDay() == this.weekStart) {
|
161
|
-
html.push('<tr>');
|
162
|
-
}
|
163
|
-
clsName = '';
|
164
|
-
if (prevMonth.getMonth() < month) {
|
165
|
-
clsName += ' old';
|
166
|
-
} else if (prevMonth.getMonth() > month) {
|
167
|
-
clsName += ' new';
|
168
|
-
}
|
169
|
-
if (prevMonth.valueOf() == currentDate) {
|
170
|
-
clsName += ' active';
|
171
|
-
}
|
172
|
-
html.push('<td class="day'+clsName+'">'+prevMonth.getDate() + '</td>');
|
173
|
-
if (prevMonth.getDay() == this.weekEnd) {
|
174
|
-
html.push('</tr>');
|
175
|
-
}
|
176
|
-
prevMonth.setDate(prevMonth.getDate()+1);
|
177
|
-
}
|
178
|
-
this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
|
179
|
-
var currentYear = this.date.getFullYear();
|
180
|
-
|
181
|
-
var months = this.picker.find('.datepicker-months')
|
182
|
-
.find('th:eq(1)')
|
183
|
-
.text(year)
|
184
|
-
.end()
|
185
|
-
.find('span').removeClass('active');
|
186
|
-
if (currentYear == year) {
|
187
|
-
months.eq(this.date.getMonth()).addClass('active');
|
188
|
-
}
|
189
|
-
|
190
|
-
html = '';
|
191
|
-
year = parseInt(year/10, 10) * 10;
|
192
|
-
var yearCont = this.picker.find('.datepicker-years')
|
193
|
-
.find('th:eq(1)')
|
194
|
-
.text(year + '-' + (year + 9))
|
195
|
-
.end()
|
196
|
-
.find('td');
|
197
|
-
year -= 1;
|
198
|
-
for (var i = -1; i < 11; i++) {
|
199
|
-
html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+'">'+year+'</span>';
|
200
|
-
year += 1;
|
201
|
-
}
|
202
|
-
yearCont.html(html);
|
203
|
-
},
|
204
|
-
|
205
|
-
click: function(e) {
|
206
|
-
e.stopPropagation();
|
207
|
-
e.preventDefault();
|
208
|
-
var target = $(e.target).closest('span, td, th');
|
209
|
-
if (target.length == 1) {
|
210
|
-
switch(target[0].nodeName.toLowerCase()) {
|
211
|
-
case 'th':
|
212
|
-
switch(target[0].className) {
|
213
|
-
case 'switch':
|
214
|
-
this.showMode(1);
|
215
|
-
break;
|
216
|
-
case 'prev':
|
217
|
-
case 'next':
|
218
|
-
this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
|
219
|
-
this.viewDate,
|
220
|
-
this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
|
221
|
-
DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1)
|
222
|
-
);
|
223
|
-
this.fill();
|
224
|
-
break;
|
225
|
-
}
|
226
|
-
break;
|
227
|
-
case 'span':
|
228
|
-
if (target.is('.month')) {
|
229
|
-
var month = target.parent().find('span').index(target);
|
230
|
-
this.viewDate.setMonth(month);
|
231
|
-
} else {
|
232
|
-
var year = parseInt(target.text(), 10)||0;
|
233
|
-
this.viewDate.setFullYear(year);
|
234
|
-
}
|
235
|
-
this.showMode(-1);
|
236
|
-
this.fill();
|
237
|
-
break;
|
238
|
-
case 'td':
|
239
|
-
if (target.is('.day')){
|
240
|
-
var day = parseInt(target.text(), 10)||1;
|
241
|
-
var month = this.viewDate.getMonth();
|
242
|
-
if (target.is('.old')) {
|
243
|
-
month -= 1;
|
244
|
-
} else if (target.is('.new')) {
|
245
|
-
month += 1;
|
246
|
-
}
|
247
|
-
var year = this.viewDate.getFullYear();
|
248
|
-
this.date = new Date(year, month, day,0,0,0,0);
|
249
|
-
this.viewDate = new Date(year, month, day,0,0,0,0);
|
250
|
-
this.fill();
|
251
|
-
this.setValue();
|
252
|
-
this.element.trigger({
|
253
|
-
type: 'changeDate',
|
254
|
-
date: this.date
|
255
|
-
});
|
256
|
-
}
|
257
|
-
break;
|
258
|
-
}
|
259
|
-
}
|
260
|
-
},
|
261
|
-
|
262
|
-
mousedown: function(e){
|
263
|
-
e.stopPropagation();
|
264
|
-
e.preventDefault();
|
265
|
-
},
|
266
|
-
|
267
|
-
showMode: function(dir) {
|
268
|
-
if (dir) {
|
269
|
-
this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
|
270
|
-
}
|
271
|
-
this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
|
272
|
-
}
|
273
|
-
};
|
274
|
-
|
275
|
-
$.fn.datepicker = function ( option ) {
|
276
|
-
return this.each(function () {
|
277
|
-
var $this = $(this),
|
278
|
-
data = $this.data('datepicker'),
|
279
|
-
options = typeof option == 'object' && option;
|
280
|
-
if (!data) {
|
281
|
-
$this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
|
282
|
-
}
|
283
|
-
if (typeof option == 'string') data[option]();
|
284
|
-
});
|
285
|
-
};
|
286
|
-
|
287
|
-
$.fn.datepicker.defaults = {
|
288
|
-
};
|
289
|
-
$.fn.datepicker.Constructor = Datepicker;
|
290
|
-
|
291
|
-
var DPGlobal = {
|
292
|
-
modes: [
|
293
|
-
{
|
294
|
-
clsName: 'days',
|
295
|
-
navFnc: 'Month',
|
296
|
-
navStep: 1
|
297
|
-
},
|
298
|
-
{
|
299
|
-
clsName: 'months',
|
300
|
-
navFnc: 'FullYear',
|
301
|
-
navStep: 1
|
302
|
-
},
|
303
|
-
{
|
304
|
-
clsName: 'years',
|
305
|
-
navFnc: 'FullYear',
|
306
|
-
navStep: 10
|
307
|
-
}],
|
308
|
-
dates:{
|
309
|
-
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
310
|
-
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
311
|
-
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
|
312
|
-
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
313
|
-
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
314
|
-
},
|
315
|
-
isLeapYear: function (year) {
|
316
|
-
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
|
317
|
-
},
|
318
|
-
getDaysInMonth: function (year, month) {
|
319
|
-
return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
|
320
|
-
},
|
321
|
-
parseFormat: function(format){
|
322
|
-
var separator = format.match(/[.\/-].*?/),
|
323
|
-
parts = format.split(/\W+/);
|
324
|
-
if (!separator || !parts || parts.length == 0){
|
325
|
-
throw new Error("Invalid date format.");
|
326
|
-
}
|
327
|
-
return {separator: separator, parts: parts};
|
328
|
-
},
|
329
|
-
parseDate: function(date, format) {
|
330
|
-
var parts = date.split(format.separator),
|
331
|
-
date = new Date(1970, 1, 1, 0, 0, 0),
|
332
|
-
val;
|
333
|
-
if (parts.length == format.parts.length) {
|
334
|
-
for (var i=0, cnt = format.parts.length; i < cnt; i++) {
|
335
|
-
val = parseInt(parts[i], 10)||1;
|
336
|
-
switch(format.parts[i]) {
|
337
|
-
case 'dd':
|
338
|
-
case 'd':
|
339
|
-
date.setDate(val);
|
340
|
-
break;
|
341
|
-
case 'mm':
|
342
|
-
case 'm':
|
343
|
-
date.setMonth(val - 1);
|
344
|
-
break;
|
345
|
-
case 'yy':
|
346
|
-
date.setFullYear(2000 + val);
|
347
|
-
break;
|
348
|
-
case 'yyyy':
|
349
|
-
date.setFullYear(val);
|
350
|
-
break;
|
351
|
-
}
|
352
|
-
}
|
353
|
-
}
|
354
|
-
return date;
|
355
|
-
},
|
356
|
-
formatDate: function(date, format){
|
357
|
-
var val = {
|
358
|
-
d: date.getDate(),
|
359
|
-
m: date.getMonth() + 1,
|
360
|
-
yy: date.getFullYear().toString().substring(2),
|
361
|
-
yyyy: date.getFullYear()
|
362
|
-
};
|
363
|
-
val.dd = (val.d < 10 ? '0' : '') + val.d;
|
364
|
-
val.mm = (val.m < 10 ? '0' : '') + val.m;
|
365
|
-
var date = [];
|
366
|
-
for (var i=0, cnt = format.parts.length; i < cnt; i++) {
|
367
|
-
date.push(val[format.parts[i]]);
|
368
|
-
}
|
369
|
-
return date.join(format.separator);
|
370
|
-
},
|
371
|
-
headTemplate: '<thead>'+
|
372
|
-
'<tr>'+
|
373
|
-
'<th class="prev"><i class="icon-arrow-left"/></th>'+
|
374
|
-
'<th colspan="5" class="switch"></th>'+
|
375
|
-
'<th class="next"><i class="icon-arrow-right"/></th>'+
|
376
|
-
'</tr>'+
|
377
|
-
'</thead>',
|
378
|
-
contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
|
379
|
-
};
|
380
|
-
DPGlobal.template = '<div class="datepicker dropdown-menu">'+
|
381
|
-
'<div class="datepicker-days">'+
|
382
|
-
'<table class=" table-condensed">'+
|
383
|
-
DPGlobal.headTemplate+
|
384
|
-
'<tbody></tbody>'+
|
385
|
-
'</table>'+
|
386
|
-
'</div>'+
|
387
|
-
'<div class="datepicker-months">'+
|
388
|
-
'<table class="table-condensed">'+
|
389
|
-
DPGlobal.headTemplate+
|
390
|
-
DPGlobal.contTemplate+
|
391
|
-
'</table>'+
|
392
|
-
'</div>'+
|
393
|
-
'<div class="datepicker-years">'+
|
394
|
-
'<table class="table-condensed">'+
|
395
|
-
DPGlobal.headTemplate+
|
396
|
-
DPGlobal.contTemplate+
|
397
|
-
'</table>'+
|
398
|
-
'</div>'+
|
399
|
-
'</div>';
|
400
|
-
|
401
|
-
}( window.jQuery )
|