Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionDialog.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface MWExtensionDialog class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * Dialog for editing generic MediaWiki extensions.
10 *
11 * @class
12 * @abstract
13 * @extends ve.ui.NodeDialog
14 * @mixes ve.ui.MWExtensionWindow
15 *
16 * @constructor
17 * @param {Object} [config] Configuration options
18 */
19 ve.ui.MWExtensionDialog = function VeUiMWExtensionDialog() {
20 // Parent constructor
21 ve.ui.MWExtensionDialog.super.apply( this, arguments );
22
23 // Mixin constructors
24 ve.ui.MWExtensionWindow.call( this );
25 };
26
27 /* Inheritance */
28
29 OO.inheritClass( ve.ui.MWExtensionDialog, ve.ui.NodeDialog );
30
31 OO.mixinClass( ve.ui.MWExtensionDialog, ve.ui.MWExtensionWindow );
32
33 /* Methods */
34
35 /**
36 * @inheritdoc
37 */
38 ve.ui.MWExtensionDialog.prototype.initialize = function () {
39 // Parent method
40 ve.ui.MWExtensionDialog.super.prototype.initialize.call( this );
41
42 // Mixin method
43 ve.ui.MWExtensionWindow.prototype.initialize.call( this );
44
45 // Initialization
46 this.$element.addClass( 've-ui-mwExtensionDialog' );
47 };
48
49 /**
50 * @inheritdoc
51 */
52 ve.ui.MWExtensionDialog.prototype.getSetupProcess = function ( data ) {
53 data = data || {};
54 // Parent process
55 const process = ve.ui.MWExtensionDialog.super.prototype.getSetupProcess.call( this, data );
56 // Mixin process
57 return ve.ui.MWExtensionWindow.prototype.getSetupProcess.call( this, data, process );
58 };
59
60 /**
61 * @inheritdoc
62 */
63 ve.ui.MWExtensionDialog.prototype.getReadyProcess = function ( data ) {
64 data = data || {};
65 // Parent process
66 const process = ve.ui.MWExtensionDialog.super.prototype.getReadyProcess.call( this, data );
67 // Mixin process
68 return ve.ui.MWExtensionWindow.prototype.getReadyProcess.call( this, data, process );
69 };
70
71 /**
72 * @inheritdoc
73 */
74 ve.ui.MWExtensionDialog.prototype.getTeardownProcess = function ( data ) {
75 data = data || {};
76 // Parent process
77 const process = ve.ui.MWExtensionDialog.super.prototype.getTeardownProcess.call( this, data );
78 // Mixin process
79 return ve.ui.MWExtensionWindow.prototype.getTeardownProcess.call( this, data, process );
80 };
81
82 /**
83 * @inheritdoc
84 */
85 ve.ui.MWExtensionDialog.prototype.getActionProcess = function ( action ) {
86 if ( action === '' ) {
87 if ( this.hasMeaningfulEdits() ) {
88 // eslint-disable-next-line arrow-body-style
89 return new OO.ui.Process( () => {
90 return this.confirmAbandon().then( ( confirm ) => {
91 if ( confirm ) {
92 /* We may need to rethink this if something in the
93 dependency chain adds to the current behaviour */
94 this.close();
95 }
96 } );
97 } );
98 }
99 }
100
101 // Parent process
102 const process = ve.ui.MWExtensionDialog.super.prototype.getActionProcess.call( this, action );
103 // Mixin process
104 return ve.ui.MWExtensionWindow.prototype.getActionProcess.call( this, action, process ).next( () => {
105 if ( action === 'done' ) {
106 this.close( { action: 'done' } );
107 }
108 } );
109 };
110
111 /**
112 * Show a confirmation prompt before closing the dialog.
113 * Displays a default prompt of `mw-widgets-abandonedit`.
114 *
115 * @param {jQuery|string|Function} [prompt] Prompt, defaults to visualeditor-dialog-extension-abandonedit
116 * @return {jQuery.Promise} Close promise
117 */
118 ve.ui.MWExtensionDialog.prototype.confirmAbandon = function ( prompt ) {
119 if ( prompt === undefined ) {
120 prompt = ve.msg( 'visualeditor-dialog-extension-abandonedit' );
121 }
122 return OO.ui.confirm( prompt, {
123 actions: [
124 {
125 action: 'reject',
126 label: ve.msg( 'mw-widgets-abandonedit-keep' ),
127 flags: 'safe'
128 },
129 {
130 action: 'accept',
131 label: ve.msg( 'mw-widgets-abandonedit-discard' ),
132 flags: 'destructive'
133 }
134 ]
135 } );
136 };