Set a dictionary item translation to read-only if the user doesn't have permission to update the language

This commit is contained in:
Mads Rasmussen
2022-08-02 11:17:18 +02:00
parent c73cb30c58
commit 30c37ea0f4
3 changed files with 20 additions and 5 deletions

View File

@@ -6,7 +6,7 @@
* @description
* The controller for editing dictionary items
*/
function DictionaryEditController($scope, $routeParams, $location, dictionaryResource, navigationService, appState, editorState, contentEditingHelper, formHelper, notificationsService, localizationService) {
function DictionaryEditController($scope, $routeParams, $location, dictionaryResource, navigationService, appState, editorState, contentEditingHelper, formHelper, notificationsService, localizationService, userService) {
var vm = this;
@@ -26,6 +26,7 @@ function DictionaryEditController($scope, $routeParams, $location, dictionaryRes
vm.description = "";
vm.showBackButton = true;
vm.maxlength = 1000;
vm.currentUser = null;
vm.save = saveDictionary;
vm.back = back;
@@ -54,6 +55,12 @@ function DictionaryEditController($scope, $routeParams, $location, dictionaryRes
}
function bindDictionary(data) {
data.translations.forEach(translation => {
const allowUpdate = vm.currentUser.allowedLanguageIds && vm.currentUser.allowedLanguageIds.length > 0 && vm.currentUser.allowedLanguageIds.includes(translation.languageId);
translation.allowUpdate = allowUpdate;
});
localizationService.localize("dictionaryItem_description").then(function (value) {
vm.description = value.replace("%0%", data.name);
});
@@ -81,7 +88,14 @@ function DictionaryEditController($scope, $routeParams, $location, dictionaryRes
}
function onInit() {
loadDictionary();
vm.page.loading = true;
userService.getCurrentUser().then(user => {
vm.currentUser = user;
vm.page.loading = false;
loadDictionary();
});
}
function saveDictionary() {

View File

@@ -34,7 +34,8 @@
state="vm.page.saveButtonState"
shortcut="ctrl+s"
label="Save"
label-key="buttons_save">
label-key="buttons_save"
ng-disabled="vm.page.loading">
</umb-button>
</umb-editor-footer-content-right>

View File

@@ -2,13 +2,13 @@
<umb-box-content>
<p ng-bind-html="model.description"></p>
<umb-property ng-repeat="translation in model.content.translations | orderBy:'displayName'" property="translation.property">
<textarea rows="2" class="autogrow w-100"
id="{{translation.property.alias}}"
ng-model="translation.translation"
maxlength="1000"
ng-keyup="model.change(translation)"
ng-trim="false"></textarea>
ng-trim="false"
ng-readonly="!translation.allowUpdate"></textarea>
<div class="help" ng-if="translation.nearMaxLimit">
<p tabindex="0">
<span class="sr-only">{{ translation.displayName }} </span>