All files / ext.wikilambda.app/components/widgets/publish LeaveEditorDialog.vue

100% Statements 101/101
100% Branches 5/5
100% Functions 3/3
100% Lines 101/101

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1021x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 3x 3x 18x 18x 18x 18x 18x 18x 3x 3x 3x 3x 3x 18x 18x 18x 18x 18x 18x 18x 18x 18x 1x 1x  
<!--
	WikiLambda Vue component for the Leave Editor Dialog which is displayed when the user attempts to leave
	the page before saving their changes.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-app-leave-editor-dialog">
		<cdx-dialog
			:open="showDialog"
			:title="i18n( 'wikilambda-editor-leave-edit-mode-header' ).text()"
			:close-button-label="i18n( 'wikilambda-dialog-close' ).text()"
			:use-close-button="true"
			:primary-action="primaryAction"
			:default-action="defaultAction"
			@update:open="stayOnPage"
			@primary="leavePage"
			@default="stayOnPage"
		>
			<div>{{ i18n( 'wikilambda-publish-lose-changes-prompt' ).text() }}</div>
		</cdx-dialog>
	</div>
</template>
 
<script>
const { computed, defineComponent, inject } = require( 'vue' );
const { CdxDialog } = require( '../../../../codex.js' );
 
module.exports = exports = defineComponent( {
	name: 'wl-leave-editor-dialog',
	components: {
		'cdx-dialog': CdxDialog
	},
	props: {
		showDialog: {
			type: Boolean,
			required: true,
			default: false
		},
		continueCallback: {
			type: Function,
			required: false,
			default: undefined
		}
	},
	emits: [ 'close-dialog', 'before-exit' ],
	setup( props, { emit } ) {
		const i18n = inject( 'i18n' );
 
		// Dialog actions
		/**
		 * Returns an object of type PrimaryModalAction that describes
		 * the action of the primary (save or publish) dialog button.
		 *
		 * @return {Object}
		 */
		const primaryAction = computed( () => ( {
			actionType: 'destructive',
			label: i18n( 'wikilambda-discard-edits' ).text()
		} ) );
 
		/**
		 * Returns an object of type ModalAction that describes
		 * the action of the secondary (cancel) button.
		 *
		 * @return {Object}
		 */
		const defaultAction = computed( () => ( {
			label: i18n( 'wikilambda-continue-editing' ).text()
		} ) );
 
		// Actions
		/**
		 * On click "Continue editing" option, simply close the dialog
		 */
		function stayOnPage() {
			emit( 'close-dialog' );
		}
 
		/**
		 * On click "Discard edits" option, handle state and event
		 * listeners for exit and close the dialog
		 */
		function leavePage() {
			emit( 'before-exit' );
			if ( props.continueCallback ) {
				props.continueCallback();
			}
		}
 
		return {
			defaultAction,
			leavePage,
			primaryAction,
			stayOnPage,
			i18n
		};
	}
} );
</script>