|
1 | 1 | import { UmbDocumentTypeDetailRepository } from '../../document-types/repository/detail/document-type-detail.repository.js';
|
2 | 2 | import { UmbDocumentPropertyDatasetContext } from '../property-dataset-context/document-property-dataset-context.js';
|
3 |
| -import { UMB_DOCUMENT_ENTITY_TYPE, type UmbDocumentEntityTypeUnion } from '../entity.js'; |
| 3 | +import { UMB_DOCUMENT_ENTITY_TYPE } from '../entity.js'; |
4 | 4 | import { UmbDocumentDetailRepository } from '../repository/index.js';
|
5 | 5 | import type {
|
6 | 6 | UmbDocumentVariantPublishModel,
|
@@ -52,7 +52,7 @@ import {
|
52 | 52 | UmbRequestReloadChildrenOfEntityEvent,
|
53 | 53 | UmbRequestReloadStructureForEntityEvent,
|
54 | 54 | } from '@umbraco-cms/backoffice/entity-action';
|
55 |
| -import { UMB_DISCARD_CHANGES_MODAL, UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; |
| 55 | +import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; |
56 | 56 | import {
|
57 | 57 | UMB_VALIDATION_CONTEXT,
|
58 | 58 | UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
|
@@ -171,7 +171,6 @@ export class UmbDocumentWorkspaceContext
|
171 | 171 | constructor(host: UmbControllerHost) {
|
172 | 172 | super(host, UMB_DOCUMENT_WORKSPACE_ALIAS);
|
173 | 173 |
|
174 |
| - window.addEventListener('willchangestate', this.#onWillNavigate); |
175 | 174 | this.addValidationContext(new UmbValidationContext(this));
|
176 | 175 |
|
177 | 176 | new UmbVariantValuesValidationPathTranslator(this);
|
@@ -924,68 +923,11 @@ export class UmbDocumentWorkspaceContext
|
924 | 923 | return new UmbDocumentPropertyDatasetContext(host, this, variantId);
|
925 | 924 | }
|
926 | 925 |
|
927 |
| - #hasUnpersistedChanges() { |
928 |
| - const persisted = this.#persistedData.getValue(); |
929 |
| - const current = this.#currentData.getValue(); |
930 |
| - return jsonStringComparison(persisted, current) === false; |
931 |
| - } |
932 |
| - |
933 |
| - #resetCurrentData() { |
934 |
| - this.#currentData.setValue(this.#persistedData.getValue()); |
935 |
| - } |
936 |
| - |
937 |
| - #willNavigateAway(newUrl: string) { |
938 |
| - let willNavigateAway = false; |
939 |
| - |
940 |
| - if (this.getIsNew()) { |
941 |
| - const parent = this.#parent.getValue()!; |
942 |
| - const documentTypeUnique = this.#currentData.getValue()!.documentType.unique; |
943 |
| - |
944 |
| - const createPath = UMB_CREATE_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({ |
945 |
| - parentEntityType: parent.entityType as UmbDocumentEntityTypeUnion, |
946 |
| - parentUnique: parent.unique, |
947 |
| - documentTypeUnique, |
948 |
| - }); |
949 |
| - willNavigateAway = !newUrl.includes(createPath); |
950 |
| - } else { |
951 |
| - const editPath = UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({ |
952 |
| - unique: this.getUnique()!, |
953 |
| - }); |
954 |
| - willNavigateAway = !newUrl.includes(editPath); |
955 |
| - } |
956 |
| - |
957 |
| - return willNavigateAway; |
958 |
| - } |
959 |
| - |
960 |
| - #onWillNavigate = async (e: CustomEvent) => { |
961 |
| - const newUrl = e.detail.url; |
962 |
| - |
963 |
| - if (this.#willNavigateAway(newUrl) && this.#hasUnpersistedChanges()) { |
964 |
| - e.preventDefault(); |
965 |
| - const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT); |
966 |
| - const modal = modalManager.open(this, UMB_DISCARD_CHANGES_MODAL); |
967 |
| - |
968 |
| - try { |
969 |
| - // navigate to the new url when discarding changes |
970 |
| - await modal.onSubmit(); |
971 |
| - // Reset the current data so we don't end in a endless loop of asking to discard changes. |
972 |
| - this.#resetCurrentData(); |
973 |
| - history.pushState({}, '', e.detail.url); |
974 |
| - return true; |
975 |
| - } catch { |
976 |
| - return false; |
977 |
| - } |
978 |
| - } |
979 |
| - |
980 |
| - return true; |
981 |
| - }; |
982 |
| - |
983 | 926 | public override destroy(): void {
|
984 | 927 | this.#persistedData.destroy();
|
985 | 928 | this.#currentData.destroy();
|
986 | 929 | this.structure.destroy();
|
987 | 930 | this.#languageRepository.destroy();
|
988 |
| - window.removeEventListener('willchangestate', this.#onWillNavigate); |
989 | 931 | super.destroy();
|
990 | 932 | }
|
991 | 933 | }
|
|
0 commit comments