-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow updating ebp allowed organizations
- Loading branch information
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require('../app').controller('EBPOrganizationsController', /* @ngInject */function ($scope, db, api, ngToast) { | ||
const $ctrl = this | ||
$ctrl.organizations = Object.values(db.organizations).map( | ||
function (organization) { | ||
return { | ||
slug: organization.slug, | ||
label: organization.toString(), | ||
allowed: false | ||
} | ||
} | ||
) | ||
|
||
$ctrl.requestAllowedOrganizations = function () { | ||
api.ebp.allowedOrganizations().then(function (res) { | ||
$ctrl.organizations.forEach(function (organization) { | ||
organization.allowed = res.includes(organization.slug) | ||
}) | ||
}) | ||
} | ||
|
||
$ctrl.save = function () { | ||
const allowed = $ctrl.organizations | ||
.filter(function (organization) { | ||
return organization.allowed | ||
}) | ||
.map(function (organization) { | ||
return organization.slug | ||
}) | ||
api.ebp.updateAllowedOrganizations(allowed).then(function () { | ||
$scope.editform.$setPristine() | ||
ngToast.create( | ||
{ | ||
className: 'success', | ||
content: 'Organizations updated' | ||
}) | ||
$ctrl.requestAllowedOrganizations() | ||
}) | ||
} | ||
|
||
$ctrl.requestAllowedOrganizations() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
<div>Organizations</div> | ||
<div ng-controller="EBPOrganizationsController as $ctrl"> | ||
<form name="editform" | ||
role="form" | ||
class="table-responsive" | ||
confirm-on-exit="editform.$dirty" | ||
confirm-message-window="{{'SPECIES_UNSAVED_DATA_TITLE' | translate}}" | ||
confirm-message-route="{{'SPECIES_UNSAVED_DATA_MESSAGE' | translate}}"> | ||
<table class="table table-hover table-striped table-responsive"> | ||
<thead> | ||
<tr> | ||
<th>#</th> | ||
<th>Organization</th> | ||
<th>Allowed</th> | ||
<th class="btn-group btn-group-xs"> | ||
<button ng-disabled="editform.$pristine" | ||
type="button" | ||
class="btn btn-success btn-xs" | ||
title="{{'SPECIES_BUTTON_SAVE' | translate}}" | ||
ng-click="$ctrl.save()"> | ||
<i class="fa fa-check fa-fw"></i> | ||
</button> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr class="hover" ng-repeat="item in $ctrl.organizations track by item.slug"> | ||
<td>{{$index}}</td> | ||
<td> | ||
{{item.label }} | ||
</td> | ||
<td colspan="2"> | ||
<input type="checkbox" ng-model="item.allowed" /> | ||
</td> | ||
</tr> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<th>#</th> | ||
<th>Organization</th> | ||
<th>Allowed</th> | ||
<th class="btn-group btn-group-xs"> | ||
<button ng-disabled="editform.$pristine" | ||
type="button" | ||
class="btn btn-success btn-xs" | ||
title="{{'SPECIES_BUTTON_SAVE' | translate}}" | ||
ng-click="$ctrl.save()"> | ||
<i class="fa fa-check fa-fw"></i> | ||
</button> | ||
</th> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</form> | ||
</div> |