| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MWMetaDialog = function VeUiMWMetaDialog( config ) { |
| 18 |
|
| 19 |
ve.ui.MWMetaDialog.super.call( this, config ); |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.ui.MWMetaDialog, ve.ui.FragmentDialog ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
ve.ui.MWMetaDialog.static.name = 'meta'; |
| 29 |
|
| 30 |
ve.ui.MWMetaDialog.static.title = |
| 31 |
OO.ui.deferMsg( 'visualeditor-dialog-meta-title' ); |
| 32 |
|
| 33 |
ve.ui.MWMetaDialog.static.size = 'large'; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
ve.ui.MWMetaDialog.prototype.getBodyHeight = function () { |
| 41 |
return 400; |
| 42 |
}; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
ve.ui.MWMetaDialog.prototype.initialize = function () { |
| 48 |
|
| 49 |
ve.ui.MWMetaDialog.super.prototype.initialize.call( this ); |
| 50 |
|
| 51 |
|
| 52 |
this.panels = new OO.ui.StackLayout(); |
| 53 |
this.bookletLayout = new OO.ui.BookletLayout( { outlined: true } ); |
| 54 |
this.categoriesPage = new ve.ui.MWCategoriesPage( 'categories', { $overlay: this.$overlay } ); |
| 55 |
this.settingsPage = new ve.ui.MWSettingsPage( 'settings', { $overlay: this.$overlay } ); |
| 56 |
this.advancedSettingsPage = new ve.ui.MWAdvancedSettingsPage( 'advancedSettings', { $overlay: this.$overlay } ); |
| 57 |
this.languagesPage = new ve.ui.MWLanguagesPage( 'languages', { $overlay: this.$overlay } ); |
| 58 |
this.templatesUsedPage = new ve.ui.MWTemplatesUsedPage( 'templatesUsed', { $overlay: this.$overlay } ); |
| 59 |
|
| 60 |
|
| 61 |
this.$body.append( this.panels.$element ); |
| 62 |
this.panels.addItems( [ this.bookletLayout ] ); |
| 63 |
this.bookletLayout.addPages( [ |
| 64 |
this.categoriesPage, |
| 65 |
this.settingsPage, |
| 66 |
this.advancedSettingsPage, |
| 67 |
this.languagesPage, |
| 68 |
this.templatesUsedPage |
| 69 |
] ); |
| 70 |
|
| 71 |
this.bookletLayout.$menu.find( '[role=listbox]' ).first().attr( 'aria-label', OO.ui.deferMsg( 'visualeditor-dialog-meta-title' ) ); |
| 72 |
this.oldSettings = null; |
| 73 |
this.widgetList = this.getAllWidgets(); |
| 74 |
}; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
ve.ui.MWMetaDialog.prototype.compareSettings = function () { |
| 80 |
const newSettings = this.extractSettings(); |
| 81 |
return !ve.compare( newSettings, this.oldSettings ); |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.ui.MWMetaDialog.prototype.getAllWidgets = function () { |
| 93 |
const widgetList = []; |
| 94 |
|
| 95 |
|
| 96 |
$.each( this.bookletLayout.pages, ( pageName, page ) => { |
| 97 |
const fieldsets = page.getFieldsets(); |
| 98 |
fieldsets.forEach( ( fieldset, fieldsetIndex ) => { |
| 99 |
fieldset.items.forEach( ( item, itemIndex ) => { |
| 100 |
const widget = item.fieldWidget; |
| 101 |
|
| 102 |
widgetList.push( { |
| 103 |
widget: widget, |
| 104 |
name: pageName + '/' + fieldsetIndex + '/' + itemIndex, |
| 105 |
hasChildren: widget.items !== undefined |
| 106 |
} ); |
| 107 |
} ); |
| 108 |
} ); |
| 109 |
} ); |
| 110 |
|
| 111 |
return widgetList; |
| 112 |
}; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
ve.ui.MWMetaDialog.prototype.assignEvents = function () { |
| 118 |
const widgetList = this.getAllWidgets(); |
| 119 |
|
| 120 |
widgetList.forEach( ( value ) => { |
| 121 |
value.widget.connect( this, { |
| 122 |
change: 'updateActions', |
| 123 |
select: 'updateActions' |
| 124 |
} ); |
| 125 |
} ); |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.ui.MWMetaDialog.prototype.extractValue = function ( field ) { |
| 133 |
if ( field instanceof OO.ui.TextInputWidget ) { |
| 134 |
return field.getValue(); |
| 135 |
} else if ( field instanceof OO.ui.CheckboxInputWidget ) { |
| 136 |
return field.isSelected(); |
| 137 |
} else if ( field instanceof OO.ui.ButtonOptionWidget ) { |
| 138 |
return field.selected; |
| 139 |
} else if ( field instanceof ve.ui.MWCategoryItemWidget ) { |
| 140 |
return { |
| 141 |
value: field.value, |
| 142 |
sortKey: field.sortKey }; |
| 143 |
} else { |
| 144 |
throw new Error( 'Unhandled widget type', field ); |
| 145 |
} |
| 146 |
}; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
ve.ui.MWMetaDialog.prototype.extractSettings = function () { |
| 156 |
const ret = []; |
| 157 |
|
| 158 |
this.widgetList.forEach( ( value ) => { |
| 159 |
if ( value.hasChildren ) { |
| 160 |
value.widget.items.forEach( ( item, index ) => { |
| 161 |
ret.push( { |
| 162 |
name: item.name + '/' + index, |
| 163 |
value: this.extractValue( item ) |
| 164 |
} ); |
| 165 |
} ); |
| 166 |
} else { |
| 167 |
ret.push( { |
| 168 |
name: value.name, |
| 169 |
value: this.extractValue( value.widget ) |
| 170 |
} ); |
| 171 |
} |
| 172 |
} ); |
| 173 |
|
| 174 |
return ret; |
| 175 |
}; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
ve.ui.MWMetaDialog.prototype.updateActions = function () { |
| 181 |
this.actions.setAbilities( { |
| 182 |
done: this.settingsPage.checkValidRedirect() && this.compareSettings() |
| 183 |
} ); |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
ve.ui.MWMetaDialog.prototype.isEditing = function () { |
| 190 |
|
| 191 |
return true; |
| 192 |
}; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
ve.ui.MWMetaDialog.prototype.getActionProcess = function ( action ) { |
| 198 |
const surfaceModel = this.getFragment().getSurface(); |
| 199 |
|
| 200 |
if ( action === 'done' ) { |
| 201 |
return new OO.ui.Process( () => { |
| 202 |
surfaceModel.applyStaging(); |
| 203 |
this.close( { action: action } ); |
| 204 |
} ); |
| 205 |
} |
| 206 |
|
| 207 |
return ve.ui.MWMetaDialog.super.prototype.getActionProcess.call( this, action ) |
| 208 |
.next( () => { |
| 209 |
surfaceModel.popStaging(); |
| 210 |
} ); |
| 211 |
}; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
ve.ui.MWMetaDialog.prototype.getSetupProcess = function ( data ) { |
| 217 |
data = data || {}; |
| 218 |
return ve.ui.MWMetaDialog.super.prototype.getSetupProcess.call( this, data ) |
| 219 |
.next( () => { |
| 220 |
const surfaceModel = this.getFragment().getSurface(), |
| 221 |
promises = [], |
| 222 |
selectWidget = this.bookletLayout.outlineSelectWidget, |
| 223 |
visualOnlyPages = [ 'categories', 'settings', 'advancedSettings', 'languages' ], |
| 224 |
isSource = ve.init.target.getSurface().getMode() === 'source'; |
| 225 |
|
| 226 |
visualOnlyPages.forEach( ( page ) => { |
| 227 |
selectWidget.findItemFromData( page ).setDisabled( isSource ); |
| 228 |
} ); |
| 229 |
|
| 230 |
if ( isSource && visualOnlyPages.indexOf( data.page || 'categories' ) !== -1 ) { |
| 231 |
data.page = 'templatesUsed'; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
surfaceModel.pushStaging(); |
| 236 |
|
| 237 |
const config = { |
| 238 |
data: data, |
| 239 |
isReadOnly: this.isReadOnly() |
| 240 |
}; |
| 241 |
|
| 242 |
|
| 243 |
promises.push( this.categoriesPage.setup( surfaceModel.getFragment(), config ) ); |
| 244 |
promises.push( this.settingsPage.setup( surfaceModel.getFragment(), config ) ); |
| 245 |
promises.push( this.advancedSettingsPage.setup( surfaceModel.getFragment(), config ) ); |
| 246 |
return ve.promiseAll( promises ); |
| 247 |
} ) |
| 248 |
.next( () => { |
| 249 |
if ( data.page && this.bookletLayout.getPage( data.page ) ) { |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
this.bookletLayout.autoFocus = false; |
| 256 |
this.bookletLayout.setPage( data.page ); |
| 257 |
this.bookletLayout.autoFocus = true; |
| 258 |
} |
| 259 |
|
| 260 |
if ( this.oldSettings === null ) { |
| 261 |
this.assignEvents(); |
| 262 |
} |
| 263 |
this.oldSettings = this.extractSettings(); |
| 264 |
|
| 265 |
this.actions.setAbilities( { done: false } ); |
| 266 |
} ); |
| 267 |
}; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
ve.ui.MWMetaDialog.prototype.getReadyProcess = function ( data ) { |
| 273 |
data = data || {}; |
| 274 |
return ve.ui.MWMetaDialog.super.prototype.getReadyProcess.call( this, data ) |
| 275 |
.next( () => { |
| 276 |
if ( data.page && this.bookletLayout.getPage( data.page ) ) { |
| 277 |
this.bookletLayout.getPage( data.page ).focus(); |
| 278 |
} |
| 279 |
} ); |
| 280 |
}; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
ve.ui.MWMetaDialog.prototype.getTeardownProcess = function ( data ) { |
| 286 |
data = data || {}; |
| 287 |
return ve.ui.MWMetaDialog.super.prototype.getTeardownProcess.call( this, data ) |
| 288 |
.first( () => { |
| 289 |
|
| 290 |
this.categoriesPage.teardown( { action: data.action } ); |
| 291 |
this.settingsPage.teardown( { action: data.action } ); |
| 292 |
this.advancedSettingsPage.teardown( { action: data.action } ); |
| 293 |
|
| 294 |
this.bookletLayout.setPage( 'categories' ); |
| 295 |
this.bookletLayout.resetScroll(); |
| 296 |
} ); |
| 297 |
}; |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
ve.ui.windowFactory.register( ve.ui.MWMetaDialog ); |