Skip to content

Commit

Permalink
Support org->org associations #2880
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Aug 23, 2024
1 parent 1e2a12d commit 2b816a0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 26 deletions.
19 changes: 13 additions & 6 deletions grails-app/assets/components/javascript/associated-orgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ko.components.register('associated-orgs', {
var self = this;
self.organisationSearchUrl = params.organisationSearchUrl;
self.organisationViewUrl = params.organisationViewUrl;
self.displayName = params.displayName;
self.relationshipTypes = params.relationshipTypes;

var $modal = $('#add-or-edit-organisation');
$modal.find('form').validationEngine();
Expand Down Expand Up @@ -56,7 +58,7 @@ ko.components.register('associated-orgs', {
params.associatedOrgs(self.associatedOrgs());

self.validationNamespace = params.validationNamespace;
self.relationshipTypes = ['Service provider', 'Grantee', 'Sponsor'];

self.organisationSearchUrl = params.organisationSearchUrl;
self.allowedNames = ko.observableArray([]);

Expand All @@ -82,10 +84,10 @@ ko.components.register('associated-orgs', {
var orgId = self.selectedOrganisation.organisationId();
if (orgId) {
findMatchingOrganisation(orgId, function(matchingOrg) {
if (matchingOrg) {
if (matchingOrg && matchingOrg._source) {
self.allowedNames(self.allowedNamesForOrganisation(matchingOrg._source));

copy(self.selectedOrganisation, self.editableOrganisation);
$('#searchOrganisation').val(matchingOrg._source.name);
$modal.modal('show');
}
else {
Expand All @@ -94,17 +96,17 @@ ko.components.register('associated-orgs', {
});
}
else {
copy(self.selectedOrganisation, self.editableOrganisation);
self.clearSelectedOrganisation();
$modal.modal('show');
}

}

function findMatchingOrganisation(organisationId, callback) {
$.get(self.organisationSearchUrl+'?searchTerm='+orgId).done(function(results) {
$.get(self.organisationSearchUrl+'?searchTerm='+organisationId).done(function(results) {
if (results && results.hits && results.hits.hits) {
var matchingOrg = _.find(results.hits.hits, function (hit) {
return hit._id == orgId;
return hit._id == organisationId;
});

callback(matchingOrg);
Expand Down Expand Up @@ -181,8 +183,13 @@ ko.components.register('associated-orgs', {
}

self.clearSelectedOrganisation = function() {
$('#searchOrganisation').val('');
self.allowedNames([]);
self.editableOrganisation.organisationId(null);
self.editableOrganisation.name('');
self.editableOrganisation.description('');
self.editableOrganisation.fromDate('');
self.editableOrganisation.toDate('');
}

self.editableOrganisation = new AssociatedOrg();
Expand Down
13 changes: 10 additions & 3 deletions grails-app/assets/components/template/associated-orgs.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,27 @@ <h4 class="modal-title" id="title">Organisation relationship</h4>
<div class="form-group">
<label for="searchOrganisation">Search for an existing organisation</label>
<div class="input-group input-append">
<input type="text" id="searchOrganisation" name="organisation-search"autocomplete="off" class="form-control form-control-sm" placeholder="Search organisations..."
<input type="text" id="searchOrganisation" name="organisation-search" autocomplete="off" class="form-control form-control-sm" placeholder="Search organisations..."
data-bind="enable:!organisationId(), elasticSearchAutocomplete:{url:$parent.organisationSearchUrl, value:'name', label:'name', result:$parent.selectOrganisation}"/>
<span class="input-group-text"><i class="fa fa-remove" data-bind="click:$parent.clearSelectedOrganisation"></i></span>
</div>
</div>
</div>
<!-- ko if:$parent.displayName -->
<div class="form-group">
<label for="name-to-use" class="required">Organisation name as it appears on the project page (e.g. name used in contract)</label>

<select class="form-control" id="name-to-use" data-bind="enable:organisationId(), value:name, options:$parent.allowedNames"
data-validation-engine="validate[required]" data-prompt-position="topLeft"></select>
</div>
<!-- /ko -->
<div class="form-group">
<label class="required" for="relationship-description">Relationship to the project</label>
<label class="required" for="relationship-description">Relationship</label>
<!-- ko if:$parent.relationshipTypes -->
<select id="relationship-description" name="description" class="form-control form-control-sm" data-bind="enable:organisationId(), options:$parent.relationshipTypes, value:description"></select>
<!-- /ko -->
<!-- ko if:!$parent.relationshipTypes -->
<input type="text" id="relationship-description" name="description" class="form-control form-control-sm" data-bind="enable:organisationId(), value:description"></input>
<!-- /ko -->
</div>
<div class="form-group">
<label for="relationship-from-date">From date</label>
Expand Down
1 change: 0 additions & 1 deletion grails-app/assets/javascripts/knockout-custom-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ ko.bindingHandlers.elasticSearchAutocomplete = {
};
options.select = function(event, ui) {
result(ui.item);
$(this).val(""); // Clear the search field
};

$(element).autocomplete(options);
Expand Down
14 changes: 14 additions & 0 deletions grails-app/assets/stylesheets/associated-orgs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

.associatedOrgs .associated-org-list {
display: grid;
grid-template-columns: 3em max-content auto;
}
.associatedOrgs .associated-org-list div {
padding: 5px;
padding-top: 3px;
padding-bottom: 3px;
}
.associatedOrgs .associated-org-list div.controls {
padding: 5px;
margin-right: 5px;
}
6 changes: 6 additions & 0 deletions grails-app/assets/stylesheets/organisation.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
*= require slider-pro/css/slider-pro.css
*= require projects-by-program
*= require jquery-ui/themes/base/all.css
*= require associated-orgs.css
*= require_self
*/

Expand Down Expand Up @@ -97,3 +99,7 @@
input.dateControl {
max-width: 300px !important;
}
/** So autocomplete dropdown appears when used in a modal */
.ui-autocomplete {
z-index:10000;
}
15 changes: 1 addition & 14 deletions grails-app/assets/stylesheets/project.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*= require dataSets
*= require activity.css
*= require prettytextdiff/pretty_text_diff_basic.css
*= require associated-orgs.css
*= require_self
*/

Expand Down Expand Up @@ -358,20 +359,6 @@ li.select2-search input {
margin-left: 5px;
}

.associatedOrgs .associated-org-list {
display: grid;
grid-template-columns: 3em max-content auto;
}
.associatedOrgs .associated-org-list div {
padding: 5px;
padding-top: 3px;
padding-bottom: 3px;
}
.associatedOrgs .associated-org-list div.controls {
padding: 5px;
margin-right: 5px;
}

.ui-autocomplete {
z-index:10000;
}
2 changes: 1 addition & 1 deletion grails-app/views/organisation/_organisationDetails.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<label class="col-form-label col-sm-3" for="url">Associated organisations: <fc:iconHelp><g:message
code="organisation.associatedOrgs.help"/></fc:iconHelp></label>
<div class="controls col-sm-9">
<associated-orgs params="associatedOrgs:associatedOrgs, organisationSearchUrl:organisationSearchUrl"></associated-orgs>
<associated-orgs params="associatedOrgs:associatedOrgs, organisationSearchUrl:organisationSearchUrl, displayName:false"></associated-orgs>

</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/project/_editProject.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</g:if>


<associated-orgs params="associatedOrgs:associatedOrgs, validationNamespace:'projectSettingsAssociatedOrgs', organisationSearchUrl:organisationSearchUrl, organisationViewUrl:organisationViewUrl"></associated-orgs>
<associated-orgs params="associatedOrgs:associatedOrgs, validationNamespace:'projectSettingsAssociatedOrgs', organisationSearchUrl:organisationSearchUrl, organisationViewUrl:organisationViewUrl, displayName:true, relationshipTypes: ['Service provider', 'Grantee', 'Sponsor']"></associated-orgs>

<div class="row mb-2">
<div class="col-sm-12">
Expand Down

0 comments on commit 2b816a0

Please sign in to comment.