Starts wiring up the language editor with the controller, ensure that you cannot delete a language at the repo level and makes sure that we return and show validation messages when the user tries to delete the default or last language.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name umbraco.resources.languageResource
|
||||
* @description Handles retrieving and updating language data
|
||||
**/
|
||||
function languageResource($q, $http, umbRequestHelper) {
|
||||
return {
|
||||
|
||||
getAll: function (id, alias) {
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"languageApiBaseUrl",
|
||||
"GetAllLanguages")),
|
||||
"Failed to get languages");
|
||||
},
|
||||
|
||||
deleteById: function (id) {
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"languageApiBaseUrl",
|
||||
"DeleteLanguage",
|
||||
{ id: id })),
|
||||
"Failed to delete item " + id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
angular.module('umbraco.resources').factory('languageResource', languageResource);
|
||||
@@ -1,7 +1,7 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function LanguagesEditController($timeout, $location, $routeParams, notificationsService, localizationService) {
|
||||
function LanguagesEditController($timeout, $location, $routeParams, notificationsService, localizationService, languageResource) {
|
||||
|
||||
var vm = this;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function LanguagesOverviewController($timeout, $location, notificationsService, localizationService) {
|
||||
function LanguagesOverviewController($timeout, $location, notificationsService, localizationService, languageResource) {
|
||||
|
||||
var vm = this;
|
||||
|
||||
@@ -32,55 +32,10 @@
|
||||
vm.page.name = vm.labels.languages;
|
||||
});
|
||||
|
||||
$timeout(function () {
|
||||
|
||||
vm.languages = [
|
||||
{
|
||||
"id": 1,
|
||||
"cultureDisplayName": "English (United States)",
|
||||
"culture": "en-US",
|
||||
"isDefault": true,
|
||||
"isMandatory": true
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"cultureDisplayName": "Danish",
|
||||
"culture": "da-DK",
|
||||
"isDefault": false,
|
||||
"isMandatory": true
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"cultureDisplayName": "Spanish (Spain)",
|
||||
"culture": "es-ES",
|
||||
"isDefault": false,
|
||||
"isMandatory": false
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"cultureDisplayName": "French (France)",
|
||||
"culture": "fr-FR",
|
||||
"isDefault": false,
|
||||
"isMandatory": false
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"cultureDisplayName": "German (Germany)",
|
||||
"culture": "de-DE",
|
||||
"isDefault": false,
|
||||
"isMandatory": true
|
||||
}
|
||||
];
|
||||
|
||||
languageResource.getAll().then(function(languages) {
|
||||
vm.languages = languages;
|
||||
vm.loading = false;
|
||||
|
||||
}, 1000);
|
||||
|
||||
/*
|
||||
$timeout(function () {
|
||||
navigationService.syncTree({ tree: "languages", path: "-1" });
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
function addLanguage() {
|
||||
@@ -97,10 +52,21 @@
|
||||
var confirmed = confirm("Are you sure you want to delete " + language.cultureDisplayName + "?");
|
||||
if(confirmed) {
|
||||
language.deleteButtonState = "busy";
|
||||
$timeout(function(){
|
||||
|
||||
languageResource.deleteById(language.id).then(function () {
|
||||
var index = vm.languages.indexOf(language);
|
||||
vm.languages.splice(index, 1);
|
||||
}, 1000);
|
||||
}, function (err) {
|
||||
language.deleteButtonState = "error";
|
||||
|
||||
//show any notifications
|
||||
if (angular.isArray(err.data.notifications)) {
|
||||
for (var i = 0; i < err.data.notifications.length; i++) {
|
||||
notificationsService.showNotification(err.data.notifications[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
event.preventDefault()
|
||||
event.stopPropagation();
|
||||
|
||||
Reference in New Issue
Block a user