Debian Codegraph @

extensions/VisualEditor/editcheck/modules/EditCheckInspector.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface EditCheckInspector class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Edit check inspector
9 *
10 * @class
11 * @extends ve.ui.FragmentInspector
12 *
13 * @constructor
14 * @param {Object} [config] Configuration options
15 */
16 ve.ui.EditCheckInspector = function VeUiEditCheckInspector( config ) {
17 // Parent constructor
18 ve.ui.EditCheckInspector.super.call( this, config );
19
20 // Pre-initialization
21 this.$element.addClass( 've-ui-editCheckInspector' );
22 };
23
24 /* Inheritance */
25
26 OO.inheritClass( ve.ui.EditCheckInspector, ve.ui.FragmentInspector );
27
28 ve.ui.EditCheckInspector.static.name = 'editCheckReferencesInspector';
29
30 // ve.ui.EditCheckInspector.static.title = OO.ui.deferMsg( 'editcheck-dialog-title' );
31 ve.ui.EditCheckInspector.static.title = OO.ui.deferMsg( 'editcheck-dialog-addref-title' );
32
33 // ve.ui.EditCheckInspector.static.size = 'context';
34
35 ve.ui.EditCheckInspector.static.actions = [
36 {
37 label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
38 flags: [ 'safe', 'back' ],
39 modes: [ 'mobile', 'desktop' ]
40 },
41 {
42 action: 'continue',
43 icon: 'next',
44 flags: [ 'primary', 'progressive' ],
45 modes: [ 'mobile' ]
46 }
47 ];
48
49 /* Methods */
50
51 /**
52 * @inheritdoc
53 */
54 ve.ui.EditCheckInspector.prototype.initialize = function () {
55 // Parent method
56 ve.ui.EditCheckInspector.super.prototype.initialize.call( this );
57
58 // Survey panel
59 this.answerRadioSelect = new OO.ui.RadioSelectWidget( {
60 items: [
61 new OO.ui.RadioOptionWidget( {
62 data: 'uncertain',
63 label: ve.msg( 'editcheck-dialog-addref-reject-uncertain' )
64 } ),
65 new OO.ui.RadioOptionWidget( {
66 data: 'common-knowledge',
67 label: ve.msg( 'editcheck-dialog-addref-reject-common-knowledge' )
68 } ),
69 new OO.ui.RadioOptionWidget( {
70 data: 'irrelevant',
71 label: ve.msg( 'editcheck-dialog-addref-reject-irrelevant' )
72 } ),
73 new OO.ui.RadioOptionWidget( {
74 data: 'other',
75 label: ve.msg( 'editcheck-dialog-addref-reject-other' )
76 } )
77 ]
78 } );
79 this.answerRadioSelect.connect( this, { select: 'updateActions' } );
80
81 this.answerConfirm = new OO.ui.ButtonWidget( {
82 flags: [ 'progressive' ],
83 framed: false,
84 label: ve.msg( 'ooui-dialog-process-continue' ),
85 disabled: true
86 } );
87 this.answerConfirm.toggle( !OO.ui.isMobile() );
88 this.answerConfirm.connect( this, { click: [ 'executeAction', 'continue' ] } );
89
90 this.form.addItems(
91 new OO.ui.FieldsetLayout( {
92 label: ve.msg( 'editcheck-dialog-addref-reject-question' ),
93 items: [
94 new OO.ui.FieldLayout( this.answerRadioSelect, {
95 label: ve.msg( 'editcheck-dialog-addref-reject-description' ),
96 align: 'top'
97 } ),
98 new OO.ui.FieldLayout( this.answerConfirm, {
99 align: 'left'
100 } )
101 ]
102 } )
103 );
104 };
105
106 ve.ui.EditCheckInspector.prototype.updateActions = function () {
107 const isSelected = !!this.answerRadioSelect.findSelectedItem();
108 // desktop
109 this.answerConfirm.setDisabled( !isSelected );
110 // mobile
111 this.actions.setAbilities( { continue: isSelected } );
112 };
113
114 /**
115 * @inheritdoc
116 */
117 ve.ui.EditCheckInspector.prototype.getSetupProcess = function ( data ) {
118 data = data || {};
119 return ve.ui.EditCheckInspector.super.prototype.getSetupProcess.call( this, data )
120 .first( function () {
121 this.surface = data.surface;
122 this.saveProcessDeferred = data.saveProcessDeferred;
123 this.answerRadioSelect.selectItem( null );
124 }, this );
125 };
126
127 /**
128 * @inheritdoc
129 */
130 ve.ui.EditCheckInspector.prototype.getReadyProcess = function ( data ) {
131 return ve.ui.EditCheckInspector.super.prototype.getReadyProcess.call( this, data )
132 .first( function () {
133 this.actions.setMode( OO.ui.isMobile() ? 'mobile' : 'desktop' );
134 this.updateActions();
135 }, this );
136 };
137
138 ve.ui.EditCheckInspector.prototype.getActionProcess = function ( action ) {
139 if ( action === '' ) {
140 return new OO.ui.Process( function () {
141 this.close();
142 }, this );
143 }
144
145 if ( action === 'continue' ) {
146 return new OO.ui.Process( function () {
147 this.close( { action: 'reject', reason: this.answerRadioSelect.findSelectedItem().getData() } );
148 ve.track( 'activity.editCheckReferences', { action: 'dialog-choose-' + this.answerRadioSelect.findSelectedItem().getData() } );
149 }, this );
150 }
151
152 return ve.ui.EditCheckInspector.super.prototype.getActionProcess.call( this, action );
153 };
154
155 /* Registration */
156
157 ve.ui.windowFactory.register( ve.ui.EditCheckInspector );