| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
const FormWrapperWidget = function MwRcfiltersUiFormWrapperWidget( filtersModel, changeListModel, controller, $formRoot, config ) { |
| 16 |
config = config || {}; |
| 17 |
|
| 18 |
|
| 19 |
FormWrapperWidget.super.call( this, Object.assign( {}, config, { |
| 20 |
$element: $formRoot |
| 21 |
} ) ); |
| 22 |
|
| 23 |
this.changeListModel = changeListModel; |
| 24 |
this.filtersModel = filtersModel; |
| 25 |
this.controller = controller; |
| 26 |
this.$submitButton = this.$element.find( 'form input[type=submit]' ); |
| 27 |
|
| 28 |
this.$element |
| 29 |
.on( 'click', 'a[data-params]', this.onLinkClick.bind( this ) ); |
| 30 |
|
| 31 |
this.$element |
| 32 |
.on( 'submit', 'form', this.onFormSubmit.bind( this ) ); |
| 33 |
|
| 34 |
|
| 35 |
this.changeListModel.connect( this, { |
| 36 |
invalidate: 'onChangesModelInvalidate', |
| 37 |
update: 'onChangesModelUpdate' |
| 38 |
} ); |
| 39 |
|
| 40 |
|
| 41 |
this.cleanUpFieldset(); |
| 42 |
this.$element |
| 43 |
.addClass( 'mw-rcfilters-ui-FormWrapperWidget' ); |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
OO.inheritClass( FormWrapperWidget, OO.ui.Widget ); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
FormWrapperWidget.prototype.onLinkClick = function ( e ) { |
| 57 |
this.controller.updateChangesList( $( e.target ).data( 'params' ) ); |
| 58 |
return false; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
FormWrapperWidget.prototype.onFormSubmit = function ( e ) { |
| 68 |
const data = {}; |
| 69 |
|
| 70 |
|
| 71 |
$( e.target ).find( 'input, select' ).each( function () { |
| 72 |
if ( this.type === 'hidden' || this.type === 'submit' ) { |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
if ( this.type === 'checkbox' && !this.checked ) { |
| 77 |
|
| 78 |
data[ this.name ] = ''; |
| 79 |
} else { |
| 80 |
|
| 81 |
data[ this.name ] = $( this ).val(); |
| 82 |
} |
| 83 |
} ); |
| 84 |
|
| 85 |
this.controller.updateChangesList( data ); |
| 86 |
return false; |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
FormWrapperWidget.prototype.onChangesModelInvalidate = function () { |
| 93 |
this.$submitButton.prop( 'disabled', true ); |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
FormWrapperWidget.prototype.onChangesModelUpdate = function ( $changesList, $fieldset, noResultsDetails, isInitialDOM ) { |
| 106 |
this.$submitButton.prop( 'disabled', false ); |
| 107 |
|
| 108 |
|
| 109 |
this.$element.empty().append( $fieldset.contents() ); |
| 110 |
|
| 111 |
if ( !isInitialDOM ) { |
| 112 |
|
| 113 |
mw.hook( 'wikipage.content' ).fire( this.$element ); |
| 114 |
} |
| 115 |
|
| 116 |
this.cleanUpFieldset(); |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
FormWrapperWidget.prototype.cleanUpFieldset = function () { |
| 123 |
this.$element.find( '.clshowhideoption[data-feature-in-structured-ui=1]' ).each( function () { |
| 124 |
|
| 125 |
|
| 126 |
|
| 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 ); |
| 131 |
} |
| 132 |
|
| 133 |
this.parentNode.removeChild( this ); |
| 134 |
} ); |
| 135 |
|
| 136 |
|
| 137 |
this.$element.find( '.namespaceForm' ).detach(); |
| 138 |
this.$element.find( '.mw-tagfilter-label' ).closest( 'tr' ).detach(); |
| 139 |
|
| 140 |
|
| 141 |
this.$element.find( '.targetForm' ).detach(); |
| 142 |
|
| 143 |
|
| 144 |
this.$element.find( '.rclinks, .cldays, .wlinfo' ).detach(); |
| 145 |
|
| 146 |
if ( !this.$element.find( '.mw-recentchanges-table tr' ).length ) { |
| 147 |
this.$element.find( '.mw-recentchanges-table, hr' ).detach(); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
this.$element.find( 'br' ).detach(); |
| 156 |
if ( !this.$element.find( '.rcshowhide' ).contents().length ) { |
| 157 |
this.$element.find( '.rcshowhide' ).detach(); |
| 158 |
} |
| 159 |
|
| 160 |
if ( this.$element.find( '.cloption' ).text().trim() === '' ) { |
| 161 |
this.$element.find( '.cloption-submit' ).detach(); |
| 162 |
} |
| 163 |
|
| 164 |
this.$element.find( |
| 165 |
'.rclistfrom, .rcnotefrom, .rcoptions-listfromreset' |
| 166 |
).detach(); |
| 167 |
|
| 168 |
|
| 169 |
this.$element.find( 'legend' ).detach(); |
| 170 |
|
| 171 |
|
| 172 |
if ( !this.$element.text().trim().length ) { |
| 173 |
this.$element.detach(); |
| 174 |
} |
| 175 |
}; |
| 176 |
|
| 177 |
module.exports = FormWrapperWidget; |