| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.TableDialog = function VeUiTableDialog( config ) { |
| 17 |
|
| 18 |
ve.ui.TableDialog.super.call( this, config ); |
| 19 |
|
| 20 |
this.$element.addClass( 've-ui-tableDialog' ); |
| 21 |
}; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
OO.inheritClass( ve.ui.TableDialog, ve.ui.FragmentDialog ); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
ve.ui.TableDialog.static.name = 'table'; |
| 30 |
|
| 31 |
ve.ui.TableDialog.static.size = 'medium'; |
| 32 |
|
| 33 |
ve.ui.TableDialog.static.title = OO.ui.deferMsg( 'visualeditor-dialog-table-title' ); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
ve.ui.TableDialog.prototype.initialize = function () { |
| 41 |
|
| 42 |
ve.ui.TableDialog.super.prototype.initialize.call( this ); |
| 43 |
|
| 44 |
this.initialValues = null; |
| 45 |
|
| 46 |
this.panel = new OO.ui.PanelLayout( { |
| 47 |
padded: true, |
| 48 |
expanded: false, |
| 49 |
classes: [ 've-ui-tableDialog-panel' ] |
| 50 |
} ); |
| 51 |
|
| 52 |
this.captionToggle = new OO.ui.ToggleSwitchWidget(); |
| 53 |
this.captionField = new OO.ui.FieldLayout( this.captionToggle, { |
| 54 |
align: 'left', |
| 55 |
label: ve.msg( 'visualeditor-dialog-table-caption' ) |
| 56 |
} ); |
| 57 |
|
| 58 |
this.captionToggle.connect( this, { change: 'updateActions' } ); |
| 59 |
|
| 60 |
this.panel.$element.append( this.captionField.$element ); |
| 61 |
|
| 62 |
this.$body.append( this.panel.$element ); |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ve.ui.TableDialog.prototype.updateActions = function () { |
| 69 |
this.actions.setAbilities( { done: !ve.compare( this.getValues(), this.initialValues ) } ); |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
ve.ui.TableDialog.prototype.getValues = function () { |
| 80 |
return { |
| 81 |
caption: this.captionToggle.getValue() |
| 82 |
}; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
ve.ui.TableDialog.prototype.getSetupProcess = function ( data ) { |
| 89 |
return ve.ui.TableDialog.super.prototype.getSetupProcess.call( this, data ) |
| 90 |
.next( () => { |
| 91 |
const isReadOnly = this.isReadOnly(); |
| 92 |
this.initialValues = { |
| 93 |
caption: !!this.getFragment().getSelection().getTableNode( |
| 94 |
this.getFragment().getDocument() |
| 95 |
).getCaptionNode() |
| 96 |
}; |
| 97 |
this.captionToggle.setValue( this.initialValues.caption ).setDisabled( isReadOnly ); |
| 98 |
this.closingFragment = null; |
| 99 |
this.updateActions(); |
| 100 |
} ); |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
ve.ui.TableDialog.prototype.getActionProcess = function ( action ) { |
| 107 |
return ve.ui.TableDialog.super.prototype.getActionProcess.call( this, action ) |
| 108 |
.next( () => { |
| 109 |
if ( action === 'done' ) { |
| 110 |
const surfaceModel = this.getFragment().getSurface(); |
| 111 |
const selection = surfaceModel.getSelection(); |
| 112 |
const captionNode = this.getFragment().getSelection().getTableNode( |
| 113 |
this.getFragment().getDocument() |
| 114 |
).getCaptionNode(); |
| 115 |
if ( this.captionToggle.getValue() !== this.initialValues.caption ) { |
| 116 |
let fragment; |
| 117 |
if ( this.initialValues.caption ) { |
| 118 |
fragment = surfaceModel.getLinearFragment( captionNode.getOuterRange(), true ); |
| 119 |
fragment.removeContent(); |
| 120 |
} else { |
| 121 |
fragment = surfaceModel.getLinearFragment( new ve.Range( selection.tableRange.start + 1 ), true ); |
| 122 |
|
| 123 |
fragment.insertContent( [ |
| 124 |
{ type: 'tableCaption' }, |
| 125 |
{ type: 'paragraph', internal: { generated: 'wrapper' } }, |
| 126 |
{ type: '/paragraph' }, |
| 127 |
{ type: '/tableCaption' } |
| 128 |
], false ); |
| 129 |
|
| 130 |
|
| 131 |
this.closingFragment = fragment.collapseToStart().adjustLinearSelection( 2, 2 ); |
| 132 |
} |
| 133 |
} |
| 134 |
this.close( { action: 'done' } ); |
| 135 |
} |
| 136 |
} ); |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
ve.ui.TableDialog.prototype.getTeardownProcess = function ( action ) { |
| 143 |
return ve.ui.TableDialog.super.prototype.getTeardownProcess.call( this, action ) |
| 144 |
.first( () => { |
| 145 |
this.fragment = this.closingFragment || this.fragment; |
| 146 |
} ); |
| 147 |
}; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
ve.ui.windowFactory.register( ve.ui.TableDialog ); |