Skip to content

Commit

Permalink
templates: restrict load template for resource creation.
Browse files Browse the repository at this point in the history
To avoid parent reference problem, the 'load template' button should be
only displayed for resource creation (and hide when a resource is edited).

Closes rero/rero-ils#1471.

Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai committed Jan 18, 2021
1 parent 65432bc commit 2a9a054
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{{ 'Cancel' | translate }}
</button>
<!-- load from template button -->
<button *ngIf="editorSettings.template.loadFromTemplate"
<button *ngIf="canLoadTemplate()"
type="button"
id="editor-load-template-button"
class="btn btn-outline-primary btn-sm ml-1"
Expand Down
10 changes: 10 additions & 0 deletions projects/rero/ng-core/src/lib/record/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,16 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
});
}

/**
* Can the `load template` should be visible.
* The 'load template' button will be visible only if the corresponding setting is set and the user
* isn't in 'edit mode' (load template is only available for new resources)
* @return True if the button could be visible ; False otherwise
*/
canLoadTemplate() {
return this.editorSettings.template.loadFromTemplate && !this.pid;
}

/********************* Private ***************************************/

/**
Expand Down

0 comments on commit 2a9a054

Please sign in to comment.