| 1 |
'use strict'; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.MWReferencesListDialog = function VeUiMWReferencesListDialog( config ) { |
| 18 |
|
| 19 |
ve.ui.MWReferencesListDialog.super.call( this, config ); |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.ui.MWReferencesListDialog, ve.ui.NodeDialog ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
ve.ui.MWReferencesListDialog.static.name = 'referencesList'; |
| 29 |
|
| 30 |
ve.ui.MWReferencesListDialog.static.title = |
| 31 |
OO.ui.deferMsg( 'cite-ve-dialog-referenceslist-title' ); |
| 32 |
|
| 33 |
ve.ui.MWReferencesListDialog.static.modelClasses = [ ve.dm.MWReferencesListNode ]; |
| 34 |
|
| 35 |
ve.ui.MWReferencesListDialog.static.size = 'medium'; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
ve.ui.MWReferencesListDialog.prototype.getBodyHeight = function () { |
| 43 |
return Math.max( 150, Math.ceil( this.editPanel.$element[ 0 ].scrollHeight ) ); |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
ve.ui.MWReferencesListDialog.prototype.initialize = function () { |
| 50 |
|
| 51 |
ve.ui.MWReferencesListDialog.super.prototype.initialize.call( this ); |
| 52 |
|
| 53 |
|
| 54 |
this.panels = new OO.ui.StackLayout(); |
| 55 |
this.editPanel = new OO.ui.PanelLayout( { |
| 56 |
scrollable: true, padded: true |
| 57 |
} ); |
| 58 |
this.optionsFieldset = new OO.ui.FieldsetLayout(); |
| 59 |
|
| 60 |
this.groupInput = new ve.ui.MWReferenceGroupInputWidget( { |
| 61 |
$overlay: this.$overlay, |
| 62 |
emptyGroupName: ve.msg( 'cite-ve-dialog-reference-options-group-placeholder' ) |
| 63 |
} ); |
| 64 |
const groupField = new OO.ui.FieldLayout( this.groupInput, { |
| 65 |
align: 'top', |
| 66 |
label: ve.msg( 'cite-ve-dialog-reference-options-group-label' ) |
| 67 |
} ); |
| 68 |
|
| 69 |
this.responsiveCheckbox = new OO.ui.CheckboxInputWidget(); |
| 70 |
const responsiveField = new OO.ui.FieldLayout( this.responsiveCheckbox, { |
| 71 |
align: 'inline', |
| 72 |
label: ve.msg( 'cite-ve-dialog-reference-options-responsive-label' ) |
| 73 |
} ); |
| 74 |
|
| 75 |
|
| 76 |
this.optionsFieldset.addItems( [ groupField, responsiveField ] ); |
| 77 |
this.editPanel.$element.append( this.optionsFieldset.$element ); |
| 78 |
this.panels.addItems( [ this.editPanel ] ); |
| 79 |
this.$body.append( this.panels.$element ); |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
ve.ui.MWReferencesListDialog.prototype.onChange = function () { |
| 86 |
this.updateActions(); |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.ui.MWReferencesListDialog.prototype.updateActions = function () { |
| 93 |
this.actions.setAbilities( { done: this.isModified() } ); |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
ve.ui.MWReferencesListDialog.prototype.isModified = function () { |
| 100 |
if ( !this.selectedNode ) { |
| 101 |
return true; |
| 102 |
} |
| 103 |
|
| 104 |
const refGroup = this.groupInput.getValue(); |
| 105 |
const listGroup = 'mwReference/' + refGroup; |
| 106 |
const isResponsive = this.responsiveCheckbox.isSelected(); |
| 107 |
|
| 108 |
const oldListGroup = this.selectedNode.getAttribute( 'listGroup' ); |
| 109 |
const oldResponsive = this.selectedNode.getAttribute( 'isResponsive' ); |
| 110 |
|
| 111 |
return listGroup !== oldListGroup || isResponsive !== oldResponsive; |
| 112 |
}; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
ve.ui.MWReferencesListDialog.prototype.getActionProcess = function ( action ) { |
| 118 |
if ( action === 'done' ) { |
| 119 |
return new OO.ui.Process( () => { |
| 120 |
|
| 121 |
|
| 122 |
const refGroup = this.groupInput.getValue(); |
| 123 |
const listGroup = 'mwReference/' + refGroup; |
| 124 |
const isResponsive = this.responsiveCheckbox.isSelected(); |
| 125 |
|
| 126 |
if ( this.selectedNode ) { |
| 127 |
|
| 128 |
const surfaceModel = this.getFragment().getSurface(); |
| 129 |
const doc = surfaceModel.getDocument(); |
| 130 |
|
| 131 |
if ( this.isModified() ) { |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
const mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) ) || {}; |
| 137 |
delete mwData.autoGenerated; |
| 138 |
|
| 139 |
const attrChanges = { |
| 140 |
listGroup: listGroup, |
| 141 |
refGroup: refGroup, |
| 142 |
isResponsive: isResponsive, |
| 143 |
mw: mwData |
| 144 |
}; |
| 145 |
surfaceModel.change( |
| 146 |
ve.dm.TransactionBuilder.static.newFromAttributeChanges( |
| 147 |
doc, this.selectedNode.getOuterRange().start, attrChanges |
| 148 |
) |
| 149 |
); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
this.close( { action: action } ); |
| 154 |
} ); |
| 155 |
} |
| 156 |
|
| 157 |
return ve.ui.MWReferencesListDialog.super.prototype.getActionProcess.call( this, action ); |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
ve.ui.MWReferencesListDialog.prototype.getSetupProcess = function ( data ) { |
| 164 |
return ve.ui.MWReferencesListDialog.super.prototype.getSetupProcess.call( this, data ) |
| 165 |
.next( () => { |
| 166 |
if ( !( this.selectedNode instanceof ve.dm.MWReferencesListNode ) ) { |
| 167 |
throw new Error( 'Cannot open dialog: references list must be selected' ); |
| 168 |
} |
| 169 |
|
| 170 |
this.groupInput.setValue( this.selectedNode.getAttribute( 'refGroup' ) ); |
| 171 |
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( this.getFragment().getDocument() ); |
| 172 |
this.groupInput.populateMenu( docRefs.getAllGroupNames() ); |
| 173 |
|
| 174 |
this.responsiveCheckbox.setSelected( this.selectedNode.getAttribute( 'isResponsive' ) ); |
| 175 |
|
| 176 |
const isReadOnly = this.isReadOnly(); |
| 177 |
this.groupInput.setReadOnly( isReadOnly ); |
| 178 |
this.responsiveCheckbox.setDisabled( isReadOnly ); |
| 179 |
|
| 180 |
this.groupInput.connect( this, { change: 'onChange' } ); |
| 181 |
this.responsiveCheckbox.connect( this, { change: 'onChange' } ); |
| 182 |
|
| 183 |
this.updateActions(); |
| 184 |
} ); |
| 185 |
}; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
ve.ui.MWReferencesListDialog.prototype.getTeardownProcess = function ( data ) { |
| 191 |
return ve.ui.MWReferencesListDialog.super.prototype.getTeardownProcess.call( this, data ) |
| 192 |
.next( () => { |
| 193 |
this.groupInput.disconnect( this ); |
| 194 |
this.responsiveCheckbox.disconnect( this ); |
| 195 |
} ); |
| 196 |
}; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
ve.ui.MWReferencesListDialog.prototype.getReadyProcess = function ( data ) { |
| 202 |
return ve.ui.MWReferencesListDialog.super.prototype.getReadyProcess.call( this, data ) |
| 203 |
.next( () => { |
| 204 |
this.groupInput.focus(); |
| 205 |
} ); |
| 206 |
}; |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
ve.ui.windowFactory.register( ve.ui.MWReferencesListDialog ); |