Debian Codegraph @

extensions/VisualEditor/editcheck/modules/EditCheckDialog.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface EditCheckDialog class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Find and replace dialog.
9 *
10 * @class
11 * @extends ve.ui.ToolbarDialog
12 *
13 * @constructor
14 * @param {Object} [config] Configuration options
15 */
16 ve.ui.EditCheckDialog = function VeUiEditCheckDialog( config ) {
17 // Parent constructor
18 ve.ui.EditCheckDialog.super.call( this, config );
19
20 // Pre-initialization
21 this.$element.addClass( 've-ui-editCheckDialog' );
22 };
23
24 /* Inheritance */
25
26 OO.inheritClass( ve.ui.EditCheckDialog, ve.ui.ToolbarDialog );
27
28 ve.ui.EditCheckDialog.static.name = 'editCheckDialog';
29
30 ve.ui.EditCheckDialog.static.position = 'side';
31
32 ve.ui.EditCheckDialog.static.size = 'medium';
33
34 ve.ui.EditCheckDialog.static.framed = false;
35
36 // // Invisible title for accessibility
37 // ve.ui.EditCheckDialog.static.title =
38 // OO.ui.deferMsg( 'visualeditor-find-and-replace-title' );
39
40 /* Methods */
41
42 /**
43 * @inheritdoc
44 */
45 ve.ui.EditCheckDialog.prototype.initialize = function () {
46 // Parent method
47 ve.ui.EditCheckDialog.super.prototype.initialize.call( this );
48
49 this.updateDebounced = ve.debounce( this.update.bind( this ), 100 );
50 };
51
52 ve.ui.EditCheckDialog.prototype.update = function () {
53 const surfaceView = this.surface.getView();
54 const checks = mw.editcheck.editCheckFactory.createAllByListener( 'onDocumentChange', this.surface.getModel() );
55 const $checks = $( '<div>' );
56 const selections = [];
57 checks.forEach( ( check ) => {
58 $checks.append( new OO.ui.MessageWidget( {
59 type: 'warning',
60 label: check.message,
61 framed: false
62 } ).$element );
63 selections.push( ve.ce.Selection.static.newFromModel( check.highlight.getSelection(), surfaceView ) );
64 } );
65 surfaceView.drawSelections( 'editCheckWarning', selections );
66 this.$body.empty().append( $checks );
67 };
68
69 /**
70 * @inheritdoc
71 */
72 ve.ui.EditCheckDialog.prototype.getSetupProcess = function ( data ) {
73 return ve.ui.EditCheckDialog.super.prototype.getSetupProcess.call( this, data )
74 .first( () => {
75 this.surface = data.surface;
76 this.surface.getModel().on( 'undoStackChange', this.updateDebounced );
77 this.update();
78 }, this );
79 };
80
81 /**
82 * @inheritdoc
83 */
84 ve.ui.EditCheckDialog.prototype.getReadyProcess = function ( data ) {
85 return ve.ui.EditCheckDialog.super.prototype.getReadyProcess.call( this, data )
86 .next( () => {
87 }, this );
88 };
89
90 /**
91 * @inheritdoc
92 */
93 ve.ui.EditCheckDialog.prototype.getTeardownProcess = function ( data ) {
94 return ve.ui.EditCheckDialog.super.prototype.getTeardownProcess.call( this, data )
95 .next( () => {
96 this.surface.getModel().off( 'undoStackChange', this.updateDebounced );
97 }, this );
98 };
99
100 /* Registration */
101
102 ve.ui.windowFactory.register( ve.ui.EditCheckDialog );
103
104 ve.ui.commandRegistry.register(
105 new ve.ui.Command(
106 'editCheckDialog', 'window', 'toggle', { args: [ 'editCheckDialog' ] }
107 )
108 );
109
110 /**
111 * @class
112 * @extends ve.ui.ToolbarDialogTool
113 * @constructor
114 * @param {OO.ui.ToolGroup} toolGroup
115 * @param {Object} [config] Configuration options
116 */
117 ve.ui.EditCheckDialogTool = function VeUiEditCheckDialogTool() {
118 ve.ui.EditCheckDialogTool.super.apply( this, arguments );
119 };
120 OO.inheritClass( ve.ui.EditCheckDialogTool, ve.ui.ToolbarDialogTool );
121 ve.ui.EditCheckDialogTool.static.name = 'editCheckDialog';
122 ve.ui.EditCheckDialogTool.static.group = 'notices';
123 ve.ui.EditCheckDialogTool.static.icon = 'robot';
124 ve.ui.EditCheckDialogTool.static.title = 'Edit check'; // OO.ui.deferMsg( 'visualeditor-dialog-command-help-title' );
125 ve.ui.EditCheckDialogTool.static.autoAddToCatchall = false;
126 ve.ui.EditCheckDialogTool.static.commandName = 'editCheckDialog';
127
128 // Demo button for opening edit check sidebar
129 // ve.ui.toolFactory.register( ve.ui.EditCheckDialogTool );