diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 8a30212a76..5231727647 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -131,6 +131,7 @@
//= require client_books/index
//= require calls/form
//= require communities/form
+//= require communities/show
//= require quantitative_types/index
//= require calls/index
//= require referees/index
diff --git a/app/assets/javascripts/communities/show.coffee b/app/assets/javascripts/communities/show.coffee
new file mode 100644
index 0000000000..554ce35912
--- /dev/null
+++ b/app/assets/javascripts/communities/show.coffee
@@ -0,0 +1,8 @@
+CIF.CommunitiesShow = do ->
+ _init = ->
+ _buttonHelpTextPophover()
+
+ _buttonHelpTextPophover = ->
+ $("button[data-content]").popover();
+
+ { init: _init }
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index 49e2865a95..197be2cece 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -44,6 +44,7 @@
@import 'user/custom_fields/*';
@import 'clients/*';
@import 'client_books/index';
+@import 'communities/*';
@import 'families/*';
@import 'users/*';
@import 'partners/*';
diff --git a/app/assets/stylesheets/communities/show.scss b/app/assets/stylesheets/communities/show.scss
new file mode 100644
index 0000000000..22db8b4d5a
--- /dev/null
+++ b/app/assets/stylesheets/communities/show.scss
@@ -0,0 +1,78 @@
+body[id='communities-show'] {
+
+ .community {
+ .community-detail {
+ padding-top: 5px;
+ padding-bottom: 5px;
+ }
+ }
+
+ .agreegate table {
+ font-weight: 600;
+
+ .spacing-first-col {
+ width: 70%;
+ }
+ }
+
+ .small-btn-margin {
+ margin-top: 8px;
+ }
+
+ .btn-fit {
+ min-width: 170px;
+ }
+
+ // .h3-header {
+ // margin: 0;
+ // width: 87%;
+ // }
+
+ // small.top-right-icon {
+ // position: absolute;
+ // top: 16px;
+ // right: 30px;
+
+ // i {
+ // font-size: 24px;
+ // padding-top: 5px;
+ // }
+ // }
+
+ td.spacing-first-col {
+ width: 217px;
+ }
+
+ // .pushing-top {
+ // margin-top: 15px;
+ // }
+
+ // .pushing-bottom {
+ // margin-bottom: 15px;
+ // }
+
+ .label.label-default {
+ line-height: 2.2;
+ margin-right: 3px;
+ }
+
+ .scrollable-dropdown-menu {
+ height: auto;
+ max-height: 200px;
+ overflow-x: hidden;
+ padding: 15px;
+ width: 300px;
+ }
+
+ @media screen and (min-width: 768px) {
+ .scrollable-dropdown-menu {
+ width: 350px;
+ }
+ }
+
+ @media screen and (min-width: 991px){
+ .scrollable-dropdown-menu {
+ width: 400px;
+ }
+ }
+}
diff --git a/app/classes/ability.rb b/app/classes/ability.rb
index 00cf899a9c..193067423d 100644
--- a/app/classes/ability.rb
+++ b/app/classes/ability.rb
@@ -34,6 +34,7 @@ def initialize(user)
can :manage, Client, case_worker_clients: { user_id: user.id }
can :manage, CustomFieldProperty, custom_formable_type: 'Client'
can :manage, CustomFieldProperty, custom_formable_type: 'Family'
+ can :manage, CustomFieldProperty, custom_formable_type: 'Community'
can :manage, ClientEnrollment
can :manage, ClientEnrollmentTracking
can :manage, LeaveProgram
@@ -68,6 +69,7 @@ def initialize(user)
can :manage, CustomFieldProperty, custom_formable_type: 'Client'
can :manage, CustomFieldProperty, custom_formable_type: 'Family'
can :manage, CustomFieldProperty, custom_formable_type: 'Partner'
+ can :manage, CustomFieldProperty, custom_formable_type: 'Community'
can :manage, CustomField
can :manage, ClientEnrollment
can :manage, ClientEnrollmentTracking
@@ -92,6 +94,7 @@ def initialize(user)
can :manage, Client
can :manage, CustomFieldProperty, custom_formable_type: 'Client'
can :manage, CustomFieldProperty, custom_formable_type: 'Family'
+ can :manage, CustomFieldProperty, custom_formable_type: 'Community'
can :manage, ClientEnrollment
can :manage, ClientEnrollmentTracking
can :manage, LeaveProgram
diff --git a/app/controllers/communities_controller.rb b/app/controllers/communities_controller.rb
index 64a0238fb0..879b0735dd 100644
--- a/app/controllers/communities_controller.rb
+++ b/app/controllers/communities_controller.rb
@@ -44,7 +44,11 @@ def create
end
end
- def show;end
+ def show
+ custom_field_ids = @community.custom_field_properties.pluck(:custom_field_id)
+ @free_community_forms = CustomField.community_forms.not_used_forms(custom_field_ids).order_by_form_title
+ @group_community_custom_fields = @community.custom_field_properties.group_by(&:custom_field_id)
+ end
def edit
end
diff --git a/app/controllers/custom_field_properties_controller.rb b/app/controllers/custom_field_properties_controller.rb
index 4b6bcff470..060eec6181 100644
--- a/app/controllers/custom_field_properties_controller.rb
+++ b/app/controllers/custom_field_properties_controller.rb
@@ -108,6 +108,8 @@ def find_entity
@custom_formable = Partner.includes(custom_field_properties: [:custom_field]).find(params[:partner_id])
elsif params[:user_id].present?
@custom_formable = User.includes(custom_field_properties: [:custom_field]).find(params[:user_id])
+ elsif params[:community_id].present?
+ @custom_formable = Community.includes(custom_field_properties: [:custom_field]).find(params[:community_id])
end
end
diff --git a/app/models/community.rb b/app/models/community.rb
index c074cfc0ee..47bf35772b 100644
--- a/app/models/community.rb
+++ b/app/models/community.rb
@@ -37,6 +37,8 @@ class Community < ActiveRecord::Base
has_many :quantitative_cases, through: :community_quantitative_cases
has_many :viewable_quantitative_cases, -> { joins(:quantitative_type).where('quantitative_types.visible_on LIKE ?', "%community%") }, through: :community_quantitative_cases, source: :quantitative_case
+ has_many :custom_field_properties, as: :custom_formable, dependent: :destroy
+ has_many :custom_fields, through: :custom_field_properties, as: :custom_formable
has_many :community_members, dependent: :destroy
accepts_nested_attributes_for :community_members, reject_if: :all_blank, allow_destroy: true
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 7fa288ac29..77127c9833 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -2,13 +2,14 @@ class CustomField < ActiveRecord::Base
include UpdateFieldLabelsFormBuilder
FREQUENCIES = ['Daily', 'Weekly', 'Monthly', 'Yearly'].freeze
- ENTITY_TYPES = ['Client', 'Family', 'Partner', 'User'].freeze
+ ENTITY_TYPES = ['Client', 'Community', 'Family', 'Partner', 'User'].freeze
has_many :custom_field_properties, dependent: :restrict_with_error
has_many :clients, through: :custom_field_properties, source: :custom_formable, source_type: 'Client'
has_many :users, through: :custom_field_properties, source: :custom_formable, source_type: 'User'
has_many :partners, through: :custom_field_properties, source: :custom_formable, source_type: 'Partner'
has_many :families, through: :custom_field_properties, source: :custom_formable, source_type: 'Family'
+ has_many :communities, through: :custom_field_properties, source: :custom_formable, source_type: 'Community'
has_many :custom_field_permissions, dependent: :destroy
has_many :user_permissions, through: :custom_field_permissions
@@ -30,6 +31,7 @@ class CustomField < ActiveRecord::Base
scope :by_form_title, ->(value) { where('form_title iLIKE ?', "%#{value.squish}%") }
scope :client_forms, -> { where(entity_type: 'Client') }
scope :family_forms, -> { where(entity_type: 'Family') }
+ scope :community_forms, -> { where(entity_type: 'Community') }
scope :partner_forms, -> { where(entity_type: 'Partner') }
scope :user_forms, -> { where(entity_type: 'User') }
scope :not_used_forms, ->(value) { where.not(id: value) }
diff --git a/app/views/communities/show.html.haml b/app/views/communities/show.html.haml
index 9a89d9403e..9dc030e288 100644
--- a/app/views/communities/show.html.haml
+++ b/app/views/communities/show.html.haml
@@ -27,9 +27,24 @@
.col-md-3
.col-sm-12
- .panel.panel-default.case-management-tool-set
- .panel-body.text-center{ style: 'min-height: 50px; background-color: yellow;' }
- %h3 Case Management Tool Set
+ .btn-group.small-btn-margin
+ %button.btn-sm.btn.btn-success.dropdown-toggle.btn-fit{ class: ('disabled' if @group_community_custom_fields.empty?), data: { toggle: "dropdown", trigger: 'hover', html: 'true', content: "#{I18n.t('inline_help.communities.show.active_form')}", placement: "bottom" } }
+ = t('.additional_forms')
+ %span.caret
+ %ul.dropdown-menu.scrollable-dropdown-menu
+ - @group_community_custom_fields.each do |_, community_custom_fields|
+ %li
+ %p= link_to community_custom_fields.first.custom_field.form_title, community_custom_field_properties_path(@community, custom_field_id: community_custom_fields.first.custom_field_id)
+
+ - if can? :manage, CustomFieldProperty
+ .btn-group.small-btn-margin
+ %button.btn-sm.btn.btn-success.dropdown-toggle.btn-fit{ class: ('disabled' if @free_community_forms.empty?), data: { toggle: "dropdown", trigger: 'hover', html: 'true', content: "#{I18n.t('inline_help.communities.show.add_form')}", placement: "bottom" } }
+ = t('.add_form')
+ %span.caret
+ %ul.dropdown-menu.scrollable-dropdown-menu
+ - @free_community_forms.each do |custom_field|
+ %li
+ %p= link_to custom_field.form_title, new_community_custom_field_property_path(@community, custom_field_id: custom_field)
.ibox.mini-margin
.ibox-title
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c350408b38..bbe5be5793 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2228,6 +2228,8 @@ en:
new:
new_community_title: New Community
show:
+ add_form: Add Form
+ additional_forms: Community's Active Forms
address: Address
all_beneficiaries: To Count All Beneficiaries (direct members and their household members)
are_you_sure: Are you sure you want to delete?
diff --git a/config/locales/inline_help_en.yml b/config/locales/inline_help_en.yml
index 562a556031..d11654fc4c 100644
--- a/config/locales/inline_help_en.yml
+++ b/config/locales/inline_help_en.yml
@@ -124,6 +124,10 @@ en:
reject: Reject indicates your organization cannot work with the client for some reason. The case will remain in the database and show Exited status with exit circumstance as Reject Referral.
status: "Accepted – Organization has accepted the case and working with the client. Active – Client is enrolled in one or more program streams. Exited – Organization has rejected the case or no longer supporting the client. Referred – Client record exists in the OSCaR system but not yet accepted or rejected."
tasks: View all the overdue, current and upcoming tasks here. This is a read-only option for Managers and Caseworkers. New tasks can’t be added here.
+ communities:
+ show:
+ active_form: Add/View/Edit the custom forms already applied to the community.
+ add_form: These custom forms are specific to your NGO. Select one from the list to load the form. Once you fill and save it, the form will be attached to the community.
custom:
custom_id1: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to Manage >> Setting >> Custom Labels. This is different from Client ID auto-generated in OSCaR for every case.
custom_id2: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to Manage >> Setting >> Custom Labels.
diff --git a/config/locales/inline_help_km.yml b/config/locales/inline_help_km.yml
index 18e1f79c51..2725e4c5ff 100644
--- a/config/locales/inline_help_km.yml
+++ b/config/locales/inline_help_km.yml
@@ -150,6 +150,10 @@ km:
Exited - អង្គការមិនទទួលយកករណី ឬលែងជួយដល់អតិថិជន។
Referred - កំណត់ត្រាអតិថិជនមាននៅក្នុងប្រព័ន្ធ OSCaR ប៉ុន្តែមិនទាន់មានការទទួលយក ឬមិនទទួលយកនៅឡើយទេ។
tasks: សូមមើលកាតព្វកិច្ចដែលផុតកំណត់ កាតព្វកិច្ចសព្វថ្ងៃ ព្រមទាំងកាតព្វកិច្ចបន្ទាប់ នៅទីនេះ។ កាត្វកិច្ចទាំងនេះ គ្រាន់តែអាចអានបានតែប៉ុណ្ណោះ សម្រាប់អ្នកគ្រប់គ្រង និងបុគ្គលិកគ្រប់គ្រងករណី។ កាតព្វកិច្ចថ្មីមិនអាចបន្ថែមនៅត្រង់នេះបានទេ។
+ communities:
+ show:
+ active_form: បន្ថែម/មើល/កែតម្រូវ ទម្រង់បែបបទផ្សេងៗ ដែលត្រូវបានបង្កើតរួចរាល់ សម្រាប់សហគមន៍។
+ add_form: ទម្រង់បែបបទទាំងនេះគឺប្រើប្រាស់ សម្រាប់តែអង្គការរបស់អ្នក។ ជ្រើសយកមួយពីក្នុងបញ្ជី ដើម្បីទាញយកទម្រង់បែបបទនេះ។ បន្ទាប់ពីអ្នកបំពេញរួចរាល់ ហើយរក្សាវាទុក ទម្រង់បែបបទនឹងត្រូវបានភ្ជាប់ ទៅនឹងប្រវត្តិរូបរបស់សហគមន៍។
custom:
custom_id1: |-
លេខសម្គាល់ករណីជំនួស (ID)ទាក់ទងនឹងអតិថិជន។ ក្នុងករណីដែលអតិថិជនគ្រប់គ្រងរួមគ្នា ឬអតិថិជនដែលត្រូវបានបញ្ជូនមកតាមរយៈអង្គភាពផ្សេង សូមបញ្ចូលលេខសម្គាល់ ដែលធ្លាប់បានប្រើនៅលើក្រដាសឯកសារ កំណត់ត្រា ឬទិន្នន័យមូលដ្ឋានពីមុន។ ការនេះនឹងជួយនៅក្នុងការតាមដានកំណត់ត្រាអតិថិជន។
diff --git a/config/locales/inline_help_my.yml b/config/locales/inline_help_my.yml
index 4dc00eff32..fe616696e7 100644
--- a/config/locales/inline_help_my.yml
+++ b/config/locales/inline_help_my.yml
@@ -124,6 +124,10 @@ my:
reject: Reject indicates your organization cannot work with the client for some reason. The case will remain in the database and show Exited status with exit circumstance as Reject Referral.
status: Accepted – Organization has accepted the case and working with the client. Active – Client is enrolled in one or more program streams. Exited – Organization has rejected the case or no longer supporting the client. Referred – Client record exists in the OSCaR system but not yet accepted or rejected.
tasks: View all the overdue, current and upcoming tasks here. This is a read-only option for Managers and Caseworkers. New tasks can’t be added here.
+ communities:
+ show:
+ active_form: Add/View/Edit the custom forms already applied to the community.
+ add_form: These custom forms are specific to your NGO. Select one from the list to load the form. Once you fill and save it, the form will be attached to the community.
custom:
custom_id1: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to Manage >> Setting >> Custom Labels. This is different from Client ID auto-generated in OSCaR for every case.
custom_id2: Alternate case identification (ID) number related to the client. In the case of jointly managed clients or clients referred through other organization(s), enter the ID that was used on the previous paperwork, record, or database. This will help in tracking client record. Admin, This field name is customizable. To change the name, go to Manage >> Setting >> Custom Labels.
diff --git a/config/locales/km.yml b/config/locales/km.yml
index 805c2abd29..549eb92ed2 100644
--- a/config/locales/km.yml
+++ b/config/locales/km.yml
@@ -2220,6 +2220,8 @@ km:
new:
new_community_title: New Community
show:
+ add_form: Add Form
+ additional_forms: Community's Active Forms
address: Address
all_beneficiaries: To Count All Beneficiaries (direct members and their household members)
are_you_sure: Are you sure you want to delete?
diff --git a/config/locales/my.yml b/config/locales/my.yml
index 222f82ac0e..69180b1724 100644
--- a/config/locales/my.yml
+++ b/config/locales/my.yml
@@ -2216,6 +2216,8 @@ my:
new:
new_community_title: New Community
show:
+ add_form: Add Form
+ additional_forms: Community's Active Forms
address: Address
all_beneficiaries: To Count All Beneficiaries (direct members and their household members)
are_you_sure: Are you sure you want to delete?
diff --git a/config/routes.rb b/config/routes.rb
index 6b09ee1769..35ed166244 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -163,7 +163,9 @@
get 'version' => 'families#version'
end
- resources :communities
+ resources :communities do
+ resources :custom_field_properties
+ end
resources :partners do
resources :custom_field_properties
diff --git a/spec/models/community_spec.rb b/spec/models/community_spec.rb
new file mode 100644
index 0000000000..a12e167a24
--- /dev/null
+++ b/spec/models/community_spec.rb
@@ -0,0 +1,4 @@
+describe Community, 'associations' do
+ it { is_expected.to have_many(:custom_field_properties).dependent(:destroy) }
+ it { is_expected.to have_many(:custom_fields).through(:custom_field_properties) }
+end
diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb
index 0bd03fff3e..5a24f631f9 100644
--- a/spec/models/custom_field_spec.rb
+++ b/spec/models/custom_field_spec.rb
@@ -5,6 +5,7 @@
describe CustomField, 'associations' do
it { is_expected.to have_many(:custom_field_properties).dependent(:restrict_with_error) }
it { is_expected.to have_many(:clients).through(:custom_field_properties).source(:custom_formable) }
+ it { is_expected.to have_many(:communities).through(:custom_field_properties).source(:custom_formable) }
it { is_expected.to have_many(:families).through(:custom_field_properties).source(:custom_formable) }
it { is_expected.to have_many(:partners).through(:custom_field_properties).source(:custom_formable) }
it { is_expected.to have_many(:users).through(:custom_field_properties).source(:custom_formable) }
@@ -99,6 +100,18 @@
is_expected.not_to include(other_custom_field)
end
end
+
+ context 'community forms' do
+ let!(:custom_field) { create(:custom_field, form_title: 'Community Form', entity_type: 'Community') }
+ let!(:other_custom_field) { create(:custom_field, form_title: 'Prison Record', entity_type: 'Partner') }
+ subject { CustomField.community_forms }
+ it 'should include forms with community entity type' do
+ is_expected.to include(custom_field)
+ end
+ it 'should not include forms without community entity type' do
+ is_expected.not_to include(other_custom_field)
+ end
+ end
end
describe CustomField, 'CONSTANTS' do
@@ -106,7 +119,7 @@
expect(CustomField::FREQUENCIES).to eq(['Daily', 'Weekly', 'Monthly', 'Yearly'])
end
it 'ENTITY_TYPES' do
- expect(CustomField::ENTITY_TYPES).to eq(['Client', 'Family', 'Partner', 'User'])
+ expect(CustomField::ENTITY_TYPES).to eq(['Client', 'Community', 'Family', 'Partner', 'User'])
end
end
@@ -149,4 +162,4 @@
end
end
end
-end
\ No newline at end of file
+end