add multiple parent/child relations

This commit is contained in:
Michele Artini 2024-11-29 14:14:20 +01:00
parent d40d9adc9c
commit b5f9fed5da
2 changed files with 31 additions and 28 deletions

View File

@ -271,25 +271,22 @@
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td class="text-right" style="width: 120px; vertical-align: middle;">This organization</td> <td colspan="4" class="text-right">
<td style="width: 140px;"> <button type="button" class="btn btn-sm btn-outline-success"
<select class="custom-select custom-select-sm" ng-model="newRelType"> ng-click="setRelationType('IsChildOf')"
<option disabled="disabled" value=''>rel type...</option> data-toggle="modal"
<!-- NB: The showed value MUST be the inverse --> data-target="#selectRelatedOrgModal"
<option value="IsChildOf">is child of</option> ng-hide="mode == 'readonly'">
<option value="IsParentOf">is parent of</option> <i class="fa fa-plus"></i> add parents
</select> </button>
</td>
<td> <button type="button" class="btn btn-sm btn-outline-success"
<input type="text" placeholder="related organization..." readonly="readonly" ng-click="setRelationType('IsParentOf')"
class="form-control form-control-sm text-primary" data-toggle="modal"
ng-model="newRelation.name" ng-click="resetSelectedRelation()" data-target="#selectRelatedOrgModal"
data-toggle="modal" data-target="#selectRelatedOrgModal" ng-hide="mode == 'readonly'"/> ng-hide="mode == 'readonly'">
<input type="text" placeholder="related organization..." disabled="disabled" <i class="fa fa-plus"></i> add children
class="form-control form-control-sm" ng-model="newRelation.name" ng-show="mode == 'readonly'"/> </button>
</td>
<td class="text-right">
<button type="button" class="btn btn-sm btn-outline-success" ng-disabled="!newRelType || !newRelation.id" ng-click="addNewRelation()"><i class="fa fa-plus"></i></button>
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
@ -340,5 +337,5 @@
</div> </div>
</div> </div>
<select-org-modal modal-id="selectRelatedOrgModal" selected-org="newRelation" filter-status="approved" on-select="addRelation()" multiple="true"></select-org-modal>
<select-org-modal modal-id="selectRelatedOrgModal" selected-org="newRelation" filter-status="approved"></select-org-modal>

View File

@ -172,21 +172,27 @@ orgsModule.directive('orgFormMetadata', function($http, $location, $route, $rout
}, },
templateUrl: 'resources/html/parts/org_metadata.form.html', templateUrl: 'resources/html/parts/org_metadata.form.html',
link: function(scope, element, attrs, ctrl) { link: function(scope, element, attrs, ctrl) {
scope.newRelation = {};
scope.newRelType = ''; scope.newRelType = '';
scope.resetSelectedRelation = function() {
scope.newRelation = {}; scope.newRelation = {};
scope.addRelation = function() {
for (var i = 0; i < scope.org.relations.length; i++) {
if (scope.org.relations[i].relatedOrgId == scope.newRelation.id) {
alert("The selected organization has been already added !!!");
return;
}
} }
scope.addNewRelation = function() {
scope.org.relations.push({ scope.org.relations.push({
'relatedOrgId' : scope.newRelation.id, 'relatedOrgId' : scope.newRelation.id,
'relatedOrgName' : scope.newRelation.name, 'relatedOrgName' : scope.newRelation.name,
'type' : scope.newRelType 'type' : scope.newRelType
}); });
scope.newRelation = {}; }
scope.newRelType = '';
scope.setRelationType = function(relType) {
scope.newRelType = relType;
} }
scope.save = function() { scope.save = function() {