ecm_staff 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +27 -0
  4. data/app/admin/ecm_staff_business_units.rb +88 -0
  5. data/app/admin/ecm_staff_organisations.rb +59 -0
  6. data/app/admin/ecm_staff_people.rb +105 -0
  7. data/app/admin/ecm_staff_person_positions.rb +53 -0
  8. data/app/admin/ecm_staff_positions.rb +68 -0
  9. data/app/assets/stylesheets/ecm/staff/person.css.erb +7 -0
  10. data/app/assets/stylesheets/ecm/staff/person_position.css.erb +32 -0
  11. data/app/assets/stylesheets/ecm_staff.css +3 -0
  12. data/app/assets/stylesheets/ecm_staff_active_admin.css.scss.erb +14 -0
  13. data/app/controllers/ecm/staff/business_units_controller.rb +11 -0
  14. data/app/controllers/ecm/staff/organisations_controller.rb +7 -0
  15. data/app/controllers/ecm/staff/people_controller.rb +11 -0
  16. data/app/models/ecm/staff/base.rb +9 -0
  17. data/app/models/ecm/staff/business_unit.rb +57 -0
  18. data/app/models/ecm/staff/organisation.rb +42 -0
  19. data/app/models/ecm/staff/person.rb +94 -0
  20. data/app/models/ecm/staff/person_position.rb +23 -0
  21. data/app/models/ecm/staff/position.rb +50 -0
  22. data/app/views/bootstrap/_media_list_item.html.erb +17 -0
  23. data/app/views/ecm/staff/business_units/_business_unit_list_item.html.erb +17 -0
  24. data/app/views/ecm/staff/business_units/index.html.erb +5 -0
  25. data/app/views/ecm/staff/organisations/_organisation.html.erb +9 -0
  26. data/app/views/ecm/staff/organisations/index.html.erb +5 -0
  27. data/app/views/ecm/staff/people/_person.html.erb +17 -0
  28. data/app/views/ecm/staff/people/_person_in_index.html.erb +20 -0
  29. data/app/views/ecm/staff/people/_person_positions_table.html.erb +14 -0
  30. data/app/views/ecm/staff/people/index.html.erb +3 -0
  31. data/app/views/ecm/staff/people/show.html.erb +7 -0
  32. data/app/views/ecm/staff/person_positions/_person_position.html.erb +5 -0
  33. data/app/views/ecm/staff/person_positions/_person_position_as_table_row.html.erb +5 -0
  34. data/db/migrate/001_create_ecm_staff_organisations.rb +16 -0
  35. data/db/migrate/002_create_ecm_staff_business_units.rb +26 -0
  36. data/db/migrate/003_create_ecm_staff_positions.rb +23 -0
  37. data/db/migrate/004_create_ecm_staff_person_positions.rb +17 -0
  38. data/db/migrate/005_create_ecm_staff_people.rb +22 -0
  39. data/db/migrate/006_create_ecm_staff_organisation_translations.rb +15 -0
  40. data/db/migrate/007_create_ecm_staff_business_unit_translations.rb +15 -0
  41. data/db/migrate/008_create_ecm_staff_position_translations.rb +15 -0
  42. data/db/migrate/009_create_ecm_staff_person_translations.rb +15 -0
  43. data/lib/ecm/staff/configuration.rb +25 -0
  44. data/lib/ecm/staff/engine.rb +14 -0
  45. data/lib/ecm/staff/exceptions.rb +7 -0
  46. data/lib/ecm/staff/routing.rb +19 -0
  47. data/lib/ecm/staff/version.rb +6 -0
  48. data/lib/ecm_staff.rb +21 -0
  49. data/lib/generators/ecm/staff/install/install_generator.rb +15 -0
  50. data/lib/generators/ecm/staff/install/templates/ecm_staff.rb +16 -0
  51. data/lib/generators/ecm/staff/locales/locales_generator.rb +16 -0
  52. data/lib/generators/ecm/staff/locales/templates/de.yml +77 -0
  53. data/lib/generators/ecm/staff/locales/templates/en.yml +77 -0
  54. data/lib/tasks/ecm_staff_tasks.rake +4 -0
  55. metadata +680 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Roberto Vasquez Angel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = ECM Staff
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'EcmStaff'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,88 @@
1
+ ActiveAdmin.register Ecm::Staff::BusinessUnit do
2
+ menu :parent => Proc.new { I18n.t('ecm.staff.active_admin.menu') }.call
3
+
4
+ # Nested set settings
5
+ config.sort_order = 'lft_asc'
6
+ sortable_tree_member_actions
7
+
8
+ form do |f|
9
+ f.inputs do
10
+ f.input :organisation, :as => :select, :collection => Ecm::Staff::Organisation.all.collect { |o| [ o.to_s, o.id ] }
11
+ f.input :parent, :as => :select, :collection => nested_set_options(Ecm::Staff::BusinessUnit, f.object) { |bu| "#{'&#160;&#160;&#160;&#160;' * bu.depth}&bull; #{bu.to_s}".html_safe }
12
+ end # f.inputs
13
+
14
+ f.translate_inputs do |t|
15
+ t.input :name
16
+ t.input :description
17
+ end # f.inputs
18
+
19
+ f.inputs do
20
+ f.input :markup_language, :as => :select, :collection => Ecm::Staff::Configuration.markup_languages.map(&:to_s)
21
+ end # f.inputs
22
+
23
+ f.actions
24
+ end # form
25
+
26
+ index do
27
+ selectable_column
28
+ sortable_tree_columns
29
+ column :organisation
30
+ sortable_tree_indented_column :name
31
+ column :people_count
32
+ column :description
33
+ column :created_at
34
+ column :updated_at
35
+ default_actions
36
+ end # def
37
+
38
+ show :title => :to_s do
39
+ I18n.available_locales.each do |locale|
40
+ panel "#{Ecm::Staff::BusinessUnit.human_attribute_name(:description)} - #{locale}" do
41
+ Globalize.with_locale(locale) { ecm_staff_business_unit.description.to_html.html_safe }
42
+ end
43
+ end
44
+
45
+ panel Ecm::Staff::BusinessUnit.human_attribute_name(:children) do
46
+ table_for ecm_staff_business_unit.descendants, :i18n => Ecm::Staff::BusinessUnit do
47
+ sortable_tree_columns
48
+ column :organisation
49
+ sortable_tree_indented_column :name
50
+ column :people_count
51
+ column :description
52
+ column :created_at
53
+ column :updated_at
54
+ column do |child|
55
+ link_to(I18n.t('active_admin.view'), [:admin, child], :class => "member_link view_link") +
56
+ link_to(I18n.t('active_admin.edit'), [:edit, :admin, child], :class => "member_link edit_link")
57
+ end
58
+ end # table_for
59
+ end # panel
60
+
61
+ panel Ecm::Staff::BusinessUnit.human_attribute_name(:person_positions) do
62
+ table_for ecm_staff_business_unit.person_positions, :i18n => Ecm::Staff::PersonPosition do
63
+ column :position
64
+ column :person
65
+ column :begin_at
66
+ column :end_at
67
+ column :created_at
68
+ column :updated_at
69
+ column do |pp|
70
+ link_to(I18n.t('active_admin.view'), [:admin, pp], :class => "member_link view_link") +
71
+ link_to(I18n.t('active_admin.edit'), [:edit, :admin, pp], :class => "member_link edit_link")
72
+ end # column
73
+ end # table_for
74
+ end # panel
75
+ end # show
76
+
77
+ sidebar Ecm::Staff::BusinessUnit.human_attribute_name(:details), :only => :show do
78
+ attributes_table_for ecm_staff_business_unit do
79
+ row :organisation
80
+ row :parent
81
+ row :name
82
+ row :markup_language
83
+ row :depth
84
+ row :created_at
85
+ row :updated_at
86
+ end
87
+ end # sidebar
88
+ end
@@ -0,0 +1,59 @@
1
+ ActiveAdmin.register Ecm::Staff::Organisation do
2
+ menu :parent => Proc.new { I18n.t('ecm.staff.active_admin.menu') }.call
3
+
4
+ form do |f|
5
+ f.translate_inputs do |t|
6
+ t.input :name
7
+ t.input :description
8
+ end # f.inputs
9
+
10
+ f.inputs do
11
+ f.input :markup_language, :as => :select, :collection => Ecm::Staff::Configuration.markup_languages.map(&:to_s)
12
+ end # f.inputs
13
+
14
+ f.actions
15
+ end # form
16
+
17
+ index do
18
+ selectable_column
19
+ column :name
20
+ column :description
21
+ column :created_at
22
+ column :updated_at
23
+ default_actions
24
+ end # index
25
+
26
+ show :title => :to_s do
27
+ I18n.available_locales.each do |locale|
28
+ panel "#{Ecm::Staff::Organisation.human_attribute_name(:description)} - #{locale}" do
29
+ Globalize.with_locale(locale) { ecm_staff_organisation.description.to_html.html_safe }
30
+ end
31
+ end
32
+
33
+ panel Ecm::Staff::Organisation.human_attribute_name(:business_units) do
34
+ table_for ecm_staff_organisation.business_units, :i18n => Ecm::Staff::BusinessUnit do
35
+ sortable_tree_columns
36
+ sortable_tree_indented_column :name
37
+ column :people_count
38
+ column :description
39
+ column :created_at
40
+ column :updated_at
41
+ column do |bu|
42
+ link_to(I18n.t('active_admin.view'), [:admin, bu], :class => "member_link view_link") +
43
+ link_to(I18n.t('active_admin.edit'), [:edit, :admin, bu], :class => "member_link edit_link")
44
+ end # column
45
+ end # table_for
46
+ end # panel
47
+ end # show
48
+
49
+ sidebar Ecm::Staff::Organisation.human_attribute_name(:details), :only => :show do
50
+ attributes_table_for ecm_staff_organisation do
51
+ I18n.available_locales.each do |locale|
52
+ Globalize.with_locale(locale) { row :name }
53
+ end
54
+ row :markup_language
55
+ row :created_at
56
+ row :updated_at
57
+ end
58
+ end # sidebar
59
+ end
@@ -0,0 +1,105 @@
1
+ include ActiveAdmin::ActsAsList::Helper
2
+
3
+ ActiveAdmin.register Ecm::Staff::Person do
4
+ menu :parent => Proc.new { I18n.t('ecm.staff.active_admin.menu') }.call
5
+
6
+ config.sort_order = 'position'
7
+ sortable_member_actions
8
+
9
+ form do |f|
10
+ f.translate_inputs do |t|
11
+ t.input :prefix
12
+ end # f.inputs
13
+
14
+ f.inputs do
15
+ f.input :firstname
16
+ f.input :lastname
17
+ f.input :birthdate, :as => :datepicker
18
+ end
19
+
20
+ f.translate_inputs do |t|
21
+ t.input :description
22
+ end # f.inputs
23
+
24
+ f.inputs do
25
+ f.input :markup_language, :as => :select, :collection => Ecm::Staff::Configuration.markup_languages.map(&:to_s)
26
+ end # f.inputs
27
+
28
+ f.inputs do
29
+ f.has_many :person_positions do |pp|
30
+ if pp.object.persisted?
31
+ pp.input :_destroy, :as => :boolean, :label => I18n.t('active_admin.delete')
32
+ end
33
+ pp.input :business_unit
34
+ pp.input :position
35
+
36
+ pp.input :begin_at, :as => :datepicker
37
+ pp.input :end_at, :as => :datepicker
38
+ end
39
+ end
40
+
41
+ form_inputs_for_pictureable(f)
42
+
43
+ f.actions
44
+ end # form
45
+
46
+ index do
47
+ selectable_column
48
+ sortable_columns
49
+ column :preview_picture do |ecm_staff_person|
50
+ if ecm_staff_person.preview_picture.present?
51
+ image_tag(ecm_staff_person.preview_picture_image_url(:small_thumb))
52
+ else
53
+ div(:class => 'preview-picture-placeholder') { '&#x263A'.html_safe }
54
+ end
55
+ end # column
56
+ column :prefix
57
+ column :firstname
58
+ column :lastname
59
+ column :age, :sortable => false
60
+ column :birthdate
61
+ column :created_at
62
+ column :updated_at
63
+ default_actions
64
+ end # index
65
+
66
+ show :title => :to_s do
67
+ I18n.available_locales.each do |locale|
68
+ panel "#{Ecm::Staff::Person.human_attribute_name(:description)} - #{locale}" do
69
+ # Globalize.with_locale(locale) { mu(ecm_staff_person, :description) }
70
+ Globalize.with_locale(locale) { ecm_staff_person.description.to_html.html_safe }
71
+ end
72
+ end
73
+
74
+ panel Ecm::Staff::Person.human_attribute_name(:person_positions) do
75
+ table_for ecm_staff_person.person_positions, :i18n => Ecm::Staff::PersonPosition do
76
+ column :position
77
+ column :begin_at
78
+ column :end_at
79
+ column :created_at
80
+ column :updated_at
81
+ column do |pp|
82
+ link_to(I18n.t('active_admin.view'), [:admin, pp], :class => "member_link view_link") +
83
+ link_to(I18n.t('active_admin.edit'), [:edit, :admin, pp], :class => "member_link edit_link")
84
+ end # column
85
+ end # table_for
86
+ end # panel
87
+
88
+ panel_for_pictureable
89
+ end # show
90
+
91
+ sidebar Ecm::Staff::Person.human_attribute_name(:details), :only => :show do
92
+ attributes_table_for ecm_staff_person do
93
+ row :preview_picture do |ecm_staff_person|
94
+ image_tag(ecm_staff_person.preview_picture_image_url(:small_thumb)) unless ecm_staff_person.preview_picture_image_url(:small_thumb).nil?
95
+ end
96
+ row :prefix
97
+ row :fullname
98
+ row :age
99
+ row :birthdate
100
+ row :markup_language
101
+ row :created_at
102
+ row :updated_at
103
+ end
104
+ end # sidebar
105
+ end
@@ -0,0 +1,53 @@
1
+ ActiveAdmin.register Ecm::Staff::PersonPosition do
2
+ menu :parent => Proc.new { I18n.t('ecm.staff.active_admin.menu') }.call
3
+
4
+ form do |f|
5
+ f.inputs do
6
+ f.input :person
7
+ f.input :business_unit
8
+ f.input :position
9
+ end # f.inputs
10
+
11
+ f.inputs do
12
+ f.input :begin_at, :as => :datepicker
13
+ f.input :end_at, :as => :datepicker
14
+ end # f.inputs
15
+
16
+ # f.inputs do
17
+ # f.input :markup_language, :as => :select, :collection => Ecm::References::Configuration.markup_languages.map(&:to_s)
18
+ # end # f.inputs
19
+
20
+ f.actions
21
+ end # form
22
+
23
+ index do
24
+ selectable_column
25
+ column :position
26
+ column :person
27
+ column :organisation
28
+ column :business_unit
29
+ column :begin_at
30
+ column :end_at
31
+ default_actions
32
+ end # index
33
+
34
+ show do
35
+ I18n.available_locales.each do |locale|
36
+ panel "#{Ecm::Staff::Position.human_attribute_name(:description)} - #{locale}" do
37
+ Globalize.with_locale(locale) { mu(ecm_staff_person_position.position, :description) }
38
+ end
39
+ end
40
+ end # show
41
+
42
+ sidebar Ecm::Staff::PersonPosition.human_attribute_name(:details), :only => :show do
43
+ attributes_table_for ecm_staff_person_position do
44
+ row :person
45
+ row :business_unit
46
+ row :position
47
+ row :begin_at
48
+ row :end_at
49
+ row :created_at
50
+ row :updated_at
51
+ end
52
+ end # sidebar
53
+ end
@@ -0,0 +1,68 @@
1
+ ActiveAdmin.register Ecm::Staff::Position do
2
+ menu :parent => Proc.new { I18n.t('ecm.staff.active_admin.menu') }.call
3
+
4
+ # Nested set settings
5
+ config.sort_order = 'lft_asc'
6
+ sortable_tree_member_actions
7
+
8
+ form do |f|
9
+ f.inputs do
10
+ f.input :parent, :as => :select, :collection => nested_set_options(Ecm::Staff::Position, f.object) { |p| "#{'&#160;&#160;&#160;&#160;' * p.depth}&bull; #{p.to_s}".html_safe }
11
+ end # f.inputs
12
+
13
+ f.inputs do
14
+ f.input :name
15
+ f.input :description
16
+ end # f.inputs
17
+
18
+ # f.inputs do
19
+ # f.input :markup_language, :as => :select, :collection => Ecm::References::Configuration.markup_languages.map(&:to_s)
20
+ # end # f.inputs
21
+
22
+ f.actions
23
+ end # form
24
+
25
+ index do
26
+ selectable_column
27
+ sortable_tree_columns
28
+ sortable_tree_indented_column :name
29
+ column :people_count
30
+ column :description
31
+ column :created_at
32
+ column :updated_at
33
+ default_actions
34
+ end # index
35
+
36
+ show do
37
+ I18n.available_locales.each do |locale|
38
+ panel "#{Ecm::Staff::Position.human_attribute_name(:description)} - #{locale}" do
39
+ Globalize.with_locale(locale) { mu(ecm_staff_position, :description) }
40
+ end # panel
41
+ end # I18n.available_locales
42
+
43
+ panel Ecm::Staff::Position.human_attribute_name(:person_positions) do
44
+ table_for ecm_staff_position.person_positions, :i18n => Ecm::Staff::PersonPosition do
45
+ column :person
46
+ column :begin_at
47
+ column :end_at
48
+ column :created_at
49
+ column :updated_at
50
+ column do |pp|
51
+ link_to(I18n.t('active_admin.view'), [:admin, pp], :class => "member_link view_link") +
52
+ link_to(I18n.t('active_admin.edit'), [:edit, :admin, pp], :class => "member_link edit_link")
53
+ end # column
54
+ end # table_for
55
+ end # panel
56
+ end # show
57
+
58
+ sidebar Ecm::Staff::Position.human_attribute_name(:details), :only => :show do
59
+ attributes_table_for ecm_staff_position do
60
+ row :name
61
+ row :parent
62
+ row :depth
63
+ row :markup_language
64
+ row :created_at
65
+ row :updated_at
66
+ end
67
+ end # sidebar
68
+ end
@@ -0,0 +1,7 @@
1
+ .preview-picture-placeholder a {
2
+ text-decoration: none;
3
+ }
4
+
5
+ .person-preview .media-heading a {
6
+ text-decoration: none;
7
+ }
@@ -0,0 +1,32 @@
1
+ .person-preview .preview-picture-placeholder, .person-preview .preview-picture {
2
+ height: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").first %>px;
3
+ width: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").last %>px;
4
+ text-align: center;
5
+ font-size: 64px;
6
+ line-height: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").first %>px;
7
+ padding: 0px;
8
+ }
9
+
10
+ .person-preview .preview-picture img {
11
+ height: auto;
12
+ width: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").last %>px;
13
+ }
14
+
15
+ .person-preview .media-heading, .person-preview .media-heading h4 {
16
+ height: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").first %>px;
17
+ line-height: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").first.to_i + 10 %>px;
18
+ margin-bottom: 10px;
19
+ }
20
+
21
+ .person-preview .person-description {
22
+ margin-top: 20px;
23
+ }
24
+
25
+ .person-preview .person-positions {
26
+ clear: both;
27
+ }
28
+
29
+ .person-preview .table {
30
+ margin-left: auto;
31
+ margin-right: auto;
32
+ }
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ./ecm/staff/
3
+ */
@@ -0,0 +1,14 @@
1
+ .preview-picture-placeholder {
2
+ height: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").first %>px;
3
+ width: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").last %>px;
4
+ text-align: center;
5
+ font-size: 64px !important;
6
+ line-height: <%= Ecm::Pictures::Configuration.picture_image_styles[:medium_thumb].split("x").first %>px;
7
+ padding: 0px;
8
+ background-color: #F5F5F5;
9
+ border: 1px solid #E3E3E3 !important;
10
+ border-radius: 4px;
11
+ box-shadow: 0 1px rgba(0, 0, 0, 0.05) inset;
12
+ }
13
+
14
+ @import "active_admin/translate";
@@ -0,0 +1,11 @@
1
+ module Ecm::Staff
2
+ class BusinessUnitsController < ApplicationController
3
+ def index
4
+ @business_units = BusinessUnit.all
5
+ end # def
6
+
7
+ # def show
8
+ # @reference_category = Category.with_public_visibility.find(params[:id])
9
+ # end # def
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Ecm::Staff
2
+ class OrganisationsController < ApplicationController
3
+ def index
4
+ @organisations = Organisation.all
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Ecm::Staff
2
+ class PeopleController < ApplicationController
3
+ def index
4
+ @people = Person.includes( :person_positions => :position ).all
5
+ end
6
+
7
+ def show
8
+ @person = Person.includes( :person_positions => :position ).find(params[:id])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Ecm::Staff
2
+ class Base < ActiveRecord::Base
3
+ self.abstract_class = true
4
+
5
+ def self.table_name_prefix
6
+ 'ecm_staff_'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,57 @@
1
+ class Ecm::Staff::BusinessUnit < Ecm::Staff::Base
2
+ # associations
3
+ belongs_to :organisation
4
+ has_many :person_positions, :dependent => :restrict
5
+ has_many :people, :through => :person_positions
6
+
7
+ # attributes
8
+ attr_accessible :description,
9
+ :name,
10
+ :markup_language,
11
+ :organisation_id,
12
+ :parent_id,
13
+ :slug
14
+
15
+ # callbacks
16
+ after_initialize :set_defaults
17
+
18
+ # globalization support
19
+ translates :description, :name, :slug
20
+ attr_accessible :translations, :translations_attributes
21
+ accepts_nested_attributes_for :translations
22
+
23
+ # default scope
24
+ default_scope :order => 'lft'
25
+
26
+ # friendly id support
27
+ extend FriendlyId
28
+ friendly_id :name, :use => :slugged
29
+
30
+ # markup support
31
+ acts_as_markup :language => :variable,
32
+ :columns => [ :description ]
33
+
34
+ # nested set support
35
+ acts_as_nested_set
36
+
37
+ # validations
38
+ validates :organisation, :presence => true
39
+ validates :name, :presence => true,
40
+ :uniqueness => { :scope => [ :organisation_id ] }
41
+
42
+ def people_count
43
+ people.count
44
+ end # def
45
+
46
+ def to_s
47
+ name
48
+ end # def
49
+
50
+ private
51
+
52
+ def set_defaults
53
+ if self.new_record?
54
+ self.markup_language ||= Ecm::Staff::Configuration.default_markup_language
55
+ end # if
56
+ end # def
57
+ end # class Ecm::Staff::BusinessUnit < Ecm::Staff::Base
@@ -0,0 +1,42 @@
1
+ class Ecm::Staff::Organisation < Ecm::Staff::Base
2
+ # associations
3
+ has_many :business_units
4
+
5
+ # attributes
6
+ attr_accessible :description,
7
+ :markup_language,
8
+ :name
9
+
10
+ # callbacks
11
+ after_initialize :set_defaults
12
+
13
+ # globalization support
14
+ translates :description, :name, :slug
15
+ attr_accessible :translations, :translations_attributes
16
+ accepts_nested_attributes_for :translations
17
+
18
+ # friendly id support
19
+ extend FriendlyId
20
+ friendly_id :name, :use => [ :slugged, :globalize ]
21
+
22
+ # markup support
23
+ acts_as_markup :language => :variable,
24
+ :columns => [ :description ]
25
+
26
+ # validations
27
+ validates :markup_language, :inclusion => Ecm::Staff::Configuration.markup_languages.map(&:to_s)
28
+ validates :name, :presence => true,
29
+ :uniqueness => true
30
+
31
+ def to_s
32
+ name
33
+ end # def
34
+
35
+ private
36
+
37
+ def set_defaults
38
+ if self.new_record?
39
+ self.markup_language ||= Ecm::Staff::Configuration.default_markup_language
40
+ end # if
41
+ end # def
42
+ end # class Ecm::Staff::Organisation < Ecm::Staff::Base