From 16da8238a82fe59bb6f45b7f1c3502807af6088a Mon Sep 17 00:00:00 2001 From: Sylvain Jermini Date: Thu, 27 Oct 2016 14:49:09 +0200 Subject: [PATCH] #213 handle deletion of the event template override --- .../resources/edit/resources-edit.html | 2 +- .../feature/resources/edit/resources-edit.js | 22 ++++++++++++------- .../js/admin/service/resource-service.js | 4 +++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.html b/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.html index 0afa34677a..e22a9d3584 100644 --- a/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.html +++ b/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.html @@ -13,7 +13,7 @@

Edit resource: {{$ctrl.resourceName}}

- +
diff --git a/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.js b/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.js index e7bcbebb3d..6489a4b0cc 100644 --- a/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.js +++ b/src/main/webapp/resources/js/admin/feature/resources/edit/resources-edit.js @@ -15,12 +15,9 @@ function ResourcesEditCtrl(ResourceService, EventService) { var ctrl = this; ctrl.saveFor = saveFor; + ctrl.deleteFor = deleteFor; ctrl.$onInit = function() { - ctrl.templateBodies = {}; - - ctrl.resources = {}; - loadAll() } @@ -30,7 +27,16 @@ function ResourcesEditCtrl(ResourceService, EventService) { ResourceService.uploadFile(ctrl.event.organizationId, ctrl.event.id, {fileAsString: newText, name: getFileName(locale), type: 'text/plain'}).then(loadAll); } + function deleteFor(locale) { + ResourceService.deleteFile(ctrl.event.organizationId, ctrl.event.id, getFileName(locale)).then(loadAll); + } + function loadAll() { + ctrl.templateBodies = {}; + ctrl.resources = {}; + ctrl.resourcesMetadata = {}; + + EventService.getSelectedLanguages(ctrl.event.shortName).then(function(lang) { ctrl.locales = lang.data; return lang.data; @@ -45,11 +51,12 @@ function ResourcesEditCtrl(ResourceService, EventService) { }); ResourceService.getMetadataForEventResource(ctrl.event.organizationId, ctrl.event.id, getFileName(locale)).then(function(res) { - ResourceService.getEventResource(ctrl.event.organizationId, ctrl.event.id, getFileName(locale)).then(function(res) { - console.log(res); - ctrl.resources[locale] = res.data; + ctrl.resourcesMetadata[locale] = res.data; + ResourceService.getEventResource(ctrl.event.organizationId, ctrl.event.id, getFileName(locale)).then(function(resource) { + ctrl.resources[locale] = resource.data; }) }, function() { + //if there is no file for the given locale, use the template instead p.then(function(data) { ctrl.resources[locale] = data; }) @@ -61,7 +68,6 @@ function ResourcesEditCtrl(ResourceService, EventService) { function getFileName(locale) { return ctrl.resourceName+'_'+locale+'.ms'; } - } })(); \ No newline at end of file diff --git a/src/main/webapp/resources/js/admin/service/resource-service.js b/src/main/webapp/resources/js/admin/service/resource-service.js index d8b8fe73f7..bd2d9cdd55 100644 --- a/src/main/webapp/resources/js/admin/service/resource-service.js +++ b/src/main/webapp/resources/js/admin/service/resource-service.js @@ -4,7 +4,6 @@ angular.module('adminApplication').service('ResourceService', function($http) { return { - listTemplates: function() { return $http.get('api/overridable-template/'); }, @@ -19,6 +18,9 @@ angular.module('adminApplication').service('ResourceService', function($http) { }, uploadFile: function(orgId, eventId, file) { return $http.post('api/resource-event/'+orgId+'/'+eventId+'/', file); + }, + deleteFile: function(orgId, eventId, name) { + return $http.delete('api/resource-event/'+orgId+'/'+eventId+'/'+name); } }; });