3 * Wrapper for the RC form with hide/show links
4 * Must be constructed after the model is initialized.
6 * @extends OO.ui.Widget
9 * @param {mw.rcfilters.dm.FiltersViewModel} filtersModel Changes list view model
10 * @param {mw.rcfilters.dm.ChangesListViewModel} changeListModel Changes list view model
11 * @param {mw.rcfilters.Controller} controller RCfilters controller
12 * @param {jQuery} $formRoot Root element of the form to attach to
13 * @param {Object} config Configuration object
15 mw
.rcfilters
.ui
.FormWrapperWidget
= function MwRcfiltersUiFormWrapperWidget( filtersModel
, changeListModel
, controller
, $formRoot
, config
) {
16 config
= config
|| {};
19 mw
.rcfilters
.ui
.FormWrapperWidget
.parent
.call( this, $.extend( {}, config
, {
23 OO
.ui
.mixin
.PendingElement
.call( this, config
);
25 this.changeListModel
= changeListModel
;
26 this.filtersModel
= filtersModel
;
27 this.controller
= controller
;
28 this.$submitButton
= this.$element
.find( 'form input[type=submit]' );
31 .on( 'click', 'a[data-params]', this.onLinkClick
.bind( this ) );
34 .on( 'submit', 'form', this.onFormSubmit
.bind( this ) );
37 this.changeListModel
.connect( this, {
38 invalidate
: 'onChangesModelInvalidate',
39 update
: 'onChangesModelUpdate'
43 this.cleanUpFieldset();
45 .addClass( 'mw-rcfilters-ui-FormWrapperWidget' );
50 OO
.inheritClass( mw
.rcfilters
.ui
.FormWrapperWidget
, OO
.ui
.Widget
);
51 OO
.mixinClass( mw
.rcfilters
.ui
.FormWrapperWidget
, OO
.ui
.mixin
.PendingElement
);
54 * Respond to link click
56 * @param {jQuery.Event} e Event
57 * @return {boolean} false
59 mw
.rcfilters
.ui
.FormWrapperWidget
.prototype.onLinkClick = function ( e
) {
60 this.controller
.updateChangesList( $( e
.target
).data( 'params' ) );
65 * Respond to form submit event
67 * @param {jQuery.Event} e Event
68 * @return {boolean} false
70 mw
.rcfilters
.ui
.FormWrapperWidget
.prototype.onFormSubmit = function ( e
) {
73 // Collect all data from form
74 $( e
.target
).find( 'input:not([type="hidden"],[type="submit"]), select' ).each( function () {
77 if ( !$( this ).is( ':checkbox' ) || $( this ).is( ':checked' ) ) {
78 value
= $( this ).val();
81 data
[ $( this ).prop( 'name' ) ] = value
;
84 this.controller
.updateChangesList( data
);
89 * Respond to model invalidate
91 mw
.rcfilters
.ui
.FormWrapperWidget
.prototype.onChangesModelInvalidate = function () {
93 this.$submitButton
.prop( 'disabled', true );
97 * Respond to model update, replace the show/hide links with the ones from the
98 * server so they feature the correct state.
100 * @param {jQuery|string} $changesList Updated changes list
101 * @param {jQuery} $fieldset Updated fieldset
103 mw
.rcfilters
.ui
.FormWrapperWidget
.prototype.onChangesModelUpdate = function ( $changesList
, $fieldset
) {
104 this.$submitButton
.prop( 'disabled', false );
106 // Replace the entire fieldset
107 this.$element
.empty().append( $fieldset
.contents() );
108 // Make sure enhanced RC re-initializes correctly
109 mw
.hook( 'wikipage.content' ).fire( this.$element
);
111 this.cleanUpFieldset();
117 * Clean up the old-style show/hide that we have implemented in the filter list
119 mw
.rcfilters
.ui
.FormWrapperWidget
.prototype.cleanUpFieldset = function () {
120 var $namespaceSelect
= this.$element
.find( '#namespace' ),
121 collapseCookieName
= 'changeslist-state';
123 this.$element
.find( '.rcshowhideoption[data-feature-in-structured-ui=1]' ).each( function () {
124 // HACK: Remove the text node after the span.
125 // If there isn't one, we're at the end, so remove the text node before the span.
126 // This would be unnecessary if we added separators with CSS.
127 if ( this.nextSibling
&& this.nextSibling
.nodeType
=== Node
.TEXT_NODE
) {
128 this.parentNode
.removeChild( this.nextSibling
);
129 } else if ( this.previousSibling
&& this.previousSibling
.nodeType
=== Node
.TEXT_NODE
) {
130 this.parentNode
.removeChild( this.previousSibling
);
132 // Remove the span itself
133 this.parentNode
.removeChild( this );
136 // Hide namespaces and tags
137 if ( mw
.config
.get( 'wgStructuredChangeFiltersEnableExperimentalViews' ) ) {
138 $namespaceSelect
.closest( 'tr' ).detach();
139 this.$element
.find( '.mw-tagfilter-label' ).closest( 'tr' ).detach();
142 if ( !this.$element
.find( '.mw-recentchanges-table tr' ).length
) {
143 this.$element
.find( 'hr' ).detach();
147 // see resources/src/mediawiki.special/mediawiki.special.changelist.legend.js
148 this.$element
.find( '.mw-changeslist-legend' )
150 collapsed
: mw
.cookie
.get( collapseCookieName
) === 'collapsed'
152 .on( 'beforeExpand.mw-collapsible', function () {
153 mw
.cookie
.set( collapseCookieName
, 'expanded' );
155 .on( 'beforeCollapse.mw-collapsible', function () {
156 mw
.cookie
.set( collapseCookieName
, 'collapsed' );