Skip to content

Commit

Permalink
#213 add reset option while editing the templates -> for reverting to…
Browse files Browse the repository at this point in the history
… the latest saved state
  • Loading branch information
syjer committed Oct 27, 2016
1 parent 16da823 commit ab35a8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h2>Edit resource: {{$ctrl.resourceName}}</h2>
</div>
<div class="pull-right">
<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="button" ng-click="$ctrl.resetFor(locale.locale)" class="btn btn-lg">Reset</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 @@ -16,6 +16,7 @@ function ResourcesEditCtrl(ResourceService, EventService) {

ctrl.saveFor = saveFor;
ctrl.deleteFor = deleteFor;
ctrl.resetFor = resetFor;

ctrl.$onInit = function() {
loadAll()
Expand All @@ -31,10 +32,15 @@ function ResourcesEditCtrl(ResourceService, EventService) {
ResourceService.deleteFile(ctrl.event.organizationId, ctrl.event.id, getFileName(locale)).then(loadAll);
}

function resetFor(locale) {
ctrl.resources[locale] = ctrl.originalResources[locale] || ctrl.templateBodies[locale];
}

function loadAll() {
ctrl.templateBodies = {};
ctrl.resources = {};
ctrl.resourcesMetadata = {};
ctrl.originalResources = {};


EventService.getSelectedLanguages(ctrl.event.shortName).then(function(lang) {
Expand All @@ -54,6 +60,7 @@ function ResourcesEditCtrl(ResourceService, EventService) {
ctrl.resourcesMetadata[locale] = res.data;
ResourceService.getEventResource(ctrl.event.organizationId, ctrl.event.id, getFileName(locale)).then(function(resource) {
ctrl.resources[locale] = resource.data;
ctrl.originalResources[locale] = resource.data;
})
}, function() {
//if there is no file for the given locale, use the template instead
Expand Down

0 comments on commit ab35a8b

Please sign in to comment.