Skip to content

Commit

Permalink
#213 handle deletion of the event template override
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Oct 27, 2016
1 parent 47d723c commit 16da823
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>Edit resource: {{$ctrl.resourceName}}</h2>
<textarea id="resource-{{locale.locale}}" ng-model="$ctrl.resources[locale.locale]" rows="20" class="form-control"></textarea>
</div>
<div class="pull-right">
<button type="button" class="btn btn-lg btn-warning" ng-click="$ctrl.deleteFor(locale.locale)">Delete</button>
<button ng-if="$ctrl.resourcesMetadata[locale.locale]" type="button" class="btn btn-lg btn-warning" ng-click="$ctrl.deleteFor(locale.locale)">Delete</button>
<button type="submit" class="btn btn-lg btn-default">Save</button>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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;
Expand All @@ -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;
})
Expand All @@ -61,7 +68,6 @@ function ResourcesEditCtrl(ResourceService, EventService) {
function getFileName(locale) {
return ctrl.resourceName+'_'+locale+'.ms';
}

}

})();
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

angular.module('adminApplication').service('ResourceService', function($http) {
return {

listTemplates: function() {
return $http.get('api/overridable-template/');
},
Expand All @@ -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);
}
};
});
Expand Down

0 comments on commit 16da823

Please sign in to comment.