Skip to content

Commit

Permalink
Added "contract names" support #2880
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Aug 23, 2024
1 parent ca02902 commit 6e3bf57
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 28 deletions.
83 changes: 64 additions & 19 deletions grails-app/assets/components/javascript/associated-orgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ ko.components.register('associated-orgs', {
*/
viewModel: function (params) {
var self = this;
self.organisationSearchUrl = params.organisationSearchUrl;
self.organisationViewUrl = params.organisationViewUrl;

var $modal = $('#add-or-edit-organisation');
$modal.find('form').validationEngine();

function AssociatedOrg(associatedOrg) {
var self = this;

associatedOrg = associatedOrg || {};
self.name = ko.observable(associatedOrg.name);
self.organisationName = ko.observable(associatedOrg.organisationName);
self.description = ko.observable(associatedOrg.description);
self.organisationId = ko.observable(associatedOrg.organisationId);
self.fromDate = ko.observable(associatedOrg.fromDate).extend({simpleDate:false});
self.toDate = ko.observable(associatedOrg.toDate).extend({simpleDate:false});

self.toJSON = function() {
return ko.mapping.toJS(self);
this.name = ko.observable(associatedOrg.name);
this.organisationName = ko.observable(associatedOrg.organisationName);
this.description = ko.observable(associatedOrg.description);
this.organisationId = ko.observable(associatedOrg.organisationId);
this.fromDate = ko.observable(associatedOrg.fromDate).extend({simpleDate:false});
this.toDate = ko.observable(associatedOrg.toDate).extend({simpleDate:false});

this.toJSON = function() {
return ko.mapping.toJS(this);
}


}

self.associatedOrgs = ko.observableArray(_.map(params.associatedOrgs(), function(org) {
Expand All @@ -58,6 +58,7 @@ ko.components.register('associated-orgs', {
self.validationNamespace = params.validationNamespace;
self.relationshipTypes = ['Service provider', 'Grantee', 'Sponsor'];
self.organisationSearchUrl = params.organisationSearchUrl;
self.allowedNames = ko.observableArray([]);

self.removeAssociatedOrg = function (org) {
self.associatedOrgs.remove(org);
Expand All @@ -77,8 +78,38 @@ ko.components.register('associated-orgs', {
}

function openEditModal() {
copy(self.selectedOrganisation, self.editableOrganisation);
$modal.modal('show');

var orgId = self.selectedOrganisation.organisationId();
if (orgId) {
findMatchingOrganisation(orgId, function(matchingOrg) {
if (matchingOrg) {
self.allowedNames(self.allowedNamesForOrganisation(matchingOrg._source));

copy(self.selectedOrganisation, self.editableOrganisation);
$modal.modal('show');
}
else {
bootbox.alert("Unable to edit organisation")
}
});
}
else {
copy(self.selectedOrganisation, self.editableOrganisation);
$modal.modal('show');
}

}

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

callback(matchingOrg);
}
});
}

self.okPressed = function () {
Expand All @@ -87,11 +118,9 @@ ko.components.register('associated-orgs', {
return;
}
if (!_.contains(self.associatedOrgs(), self.selectedOrganisation)) {
self.associatedOrgs.push(self.editableOrganisation);
}
else {
copy(self.editableOrganisation, self.selectedOrganisation);
self.associatedOrgs.push(self.selectedOrganisation);
}
copy(self.editableOrganisation, self.selectedOrganisation);
self.close();
}

Expand All @@ -102,12 +131,25 @@ ko.components.register('associated-orgs', {
function copy(source, destination) {
destination.organisationId(source.organisationId());
destination.name(source.name());
destination.organisationName(source.organisationName());
destination.description(source.description());
destination.fromDate(source.fromDate());
destination.toDate(source.toDate());
}

self.allowedNamesForOrganisation = function(organisation) {
var allowedNames = [];
allowedNames.push(organisation.name);
if (organisation.entityName) {
allowedNames.push(organisation.entityName);
}
if (organisation.businessNames) {
allowedNames = allowedNames.concat(organisation.businessNames);
}
if (organisation.contractNames) {
allowedNames = allowedNames.concat(organisation.contractNames);
}
return allowedNames;
}

/**
* This method is designed to be used by the jquery validation engine so a passed validation will
Expand All @@ -120,6 +162,8 @@ ko.components.register('associated-orgs', {
}
}

self.organisationNames = ko.observableArray();

self.selectOrganisation = function(item) {

if (item && item.source) {
Expand All @@ -128,6 +172,7 @@ ko.components.register('associated-orgs', {
if (!self.editableOrganisation.name()) {
self.editableOrganisation.name(item.source.name);
}
self.allowedNames(self.allowedNamesForOrganisation(item.source));
}
else {
self.editableOrganisation.organisationId(null);
Expand Down
17 changes: 9 additions & 8 deletions grails-app/assets/components/template/associated-orgs.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div>
<!-- ko if: $data.organisationId() -->
<a href="" data-bind="href:$parent.viewOrganisationUrl + $data.organisationId()">
<a href="" data-bind="attr:{href:$parent.organisationViewUrl + '/' + $data.organisationId()}">
<span data-bind="text:name"></span>
</a>
<!-- /ko -->
Expand Down Expand Up @@ -38,7 +38,7 @@

</div>

<!-- ko with:editableOrganisation -->
<!-- ko using:editableOrganisation -->
<div id="add-or-edit-organisation" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand All @@ -58,24 +58,25 @@ <h4 class="modal-title" id="title">Organisation relationship</h4>
</div>
<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>
<input type="text" class="form-control" id="name-to-use" data-bind="value:name"
data-validation-engine="validate[required]" data-prompt-position="topLeft">

<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>
<div class="form-group">
<label class="required" for="relationship-description">Relationship to the project</label>
<select id="relationship-description" name="description" class="form-control form-control-sm" data-bind="options:$parent.relationshipTypes, value:description"></select>
<select id="relationship-description" name="description" class="form-control form-control-sm" data-bind="enable:organisationId(), options:$parent.relationshipTypes, value:description"></select>
</div>
<div class="form-group">
<label for="relationship-from-date">From date</label>
<div class="input-group input-append">
<input id="relationship-from-date" name="relationship-from-date" autocomplete="off" class="form-control" data-bind="datepicker:fromDate.date" type="text">
<input id="relationship-from-date" name="relationship-from-date" autocomplete="off" class="form-control" data-bind="enable:organisationId(), datepicker:fromDate.date" type="text">
<span class="input-group-text open-datepicker"><i class="fa fa-th"></i></span>
</div>
</div>
<div class="form-group">
<label for="relationship-to-date">To date</label>
<div class="input-group input-append">
<input id="relationship-to-date" class="form-control" autocomplete="off" data-bind="datepicker:toDate.date" name="to-date" type="text"
<input id="relationship-to-date" class="form-control" autocomplete="off" data-bind="enable:organisationId(), datepicker:toDate.date" name="to-date" type="text"
data-validation-engine="validate[future[#relationship-from-date]]" data-prompt-position="topLeft">
<span class="input-group-text open-datepicker"><i class="fa fa-th"></i></span>
</div>
Expand All @@ -84,7 +85,7 @@ <h4 class="modal-title" id="title">Organisation relationship</h4>

<div class="modal-footer">
<button type="button" class="btn btn-sm btn-success" name="save-org-changes"
data-bind="click:$parent.okPressed">OK</button>
data-bind="enable:organisationId(), click:$parent.okPressed">OK</button>
<button class="btn btn-sm btn-danger" data-bind="click:$parent.close">Cancel</button>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions grails-app/assets/javascripts/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//= require attach-document-no-ui
//= require reportService
//= require components.js
//= require ecodata-components.js
/**
* Knockout view model for organisation pages.
* @param props JSON/javascript representation of the organisation.
Expand Down Expand Up @@ -171,6 +172,7 @@ OrganisationViewModel = function (props, options) {
self.name = ko.observable(props.name);
self.entityName = ko.observable(props.entityName);
self.businessNames = ko.observableArray(props.businessNames);
self.contractNames = ko.observableArray(props.contractNames);
self.acronym = ko.observable(props.acronym);
self.description = ko.observable(props.description).extend({markdown:true});
self.abn = ko.observable(props.abn);
Expand Down
1 change: 1 addition & 0 deletions grails-app/assets/javascripts/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ function ProjectPageViewModel(project, sites, activities, userRoles, config) {
_.extend(this, new ProjectViewModel(project));

self.organisationSearchUrl = config.organisationSearchUrl;
self.organisationViewUrl = config.organisationViewUrl;

self.internalOrderId = ko.observable(project.internalOrderId);
self.userIsCaseManager = ko.observable(userRoles.grantManager);
Expand Down
8 changes: 8 additions & 0 deletions grails-app/views/organisation/_about.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@

<span id="orgDescription" data-bind="html:description.markdownToHtml()"></span>

<g:if test="${organisation.abn}">
<p>ABN: <span id="orgAbn">${organisation.abn}</span></p>
</g:if>
<g:if test="${organisation.state}">
<p>State: ${organisation.state}</p>
</g:if>
<g:if test="${organisation.postcode}">
<p>Postcode: ${organisation.postcode}</p>
</g:if>
</div>
</div>

Expand Down
9 changes: 9 additions & 0 deletions grails-app/views/organisation/_organisationDetails.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
<input type="text" id="name" class="form-control form-control-sm w-100" data-bind="value:name" data-validation-engine="validate[required]" placeholder="Organisation name">
</div>
</section>
<section class="form-group row">
<label class="col-sm-3 form-check-label">Contract name/s: <fc:iconHelp><g:message code="organisation.contractNames.help"/></fc:iconHelp></label>
<div class="col-sm-9">
<multi-input params="values: contractNames">
<input type="text" data-validation-engine="validate[required]" data-bind="value:val" class="form-control form-control-sm input-group-append">
</multi-input>
</div>
</section>

<section class="form-group row">

<label for="acronym" class="col-sm-3 form-check-label">Acronym: <fc:iconHelp><g:message code="organisation.acronym.help"/></fc:iconHelp></label>
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"></associated-orgs>
<associated-orgs params="associatedOrgs:associatedOrgs, validationNamespace:'projectSettingsAssociatedOrgs', organisationSearchUrl:organisationSearchUrl, organisationViewUrl:organisationViewUrl"></associated-orgs>

<div class="row mb-2">
<div class="col-sm-12">
Expand Down
1 change: 1 addition & 0 deletions grails-app/views/project/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ var config = {
config.speciesImageUrl = fcConfig.speciesImageUrl;
config.speciesProfileUrl = fcConfig.speciesProfileUrl;
config.organisationSearchUrl = fcConfig.organisationSearchUrl;
config.organisationViewUrl = fcConfig.organisationLinkBaseUrl;
project.mapFeatures = $.parseJSON('${mapFeatures?.encodeAsJavaScript()}');
var viewModel = new ProjectPageViewModel(project, project.sites, project.activities || [], userRoles, config);
viewModel.loadPrograms(programs);
Expand Down

0 comments on commit 6e3bf57

Please sign in to comment.