| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.FragmentWindow = function VeUiFragmentWindow() { |
| 17 |
|
| 18 |
this.fragment = null; |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
OO.initClass( ve.ui.FragmentWindow ); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
ve.ui.FragmentWindow.prototype.getFragment = function () { |
| 34 |
return this.fragment; |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
ve.ui.FragmentWindow.prototype.getActionWidgetConfig = function ( config ) { |
| 42 |
if ( config.action === 'done' && OO.ui.isMobile() ) { |
| 43 |
|
| 44 |
config = ve.extendObject( { |
| 45 |
icon: 'check', |
| 46 |
invisibleLabel: true |
| 47 |
}, config ); |
| 48 |
} |
| 49 |
return config; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
ve.ui.FragmentWindow.prototype.getSetupProcess = function ( data, process ) { |
| 58 |
data = data || {}; |
| 59 |
return process.first( () => { |
| 60 |
if ( !( data.fragment instanceof ve.dm.SurfaceFragment ) ) { |
| 61 |
throw new Error( 'Cannot open dialog: opening data must contain a fragment' ); |
| 62 |
} |
| 63 |
this.fragment = data.fragment; |
| 64 |
this.initialFragment = data.fragment; |
| 65 |
this.selectFragmentOnClose = data.selectFragmentOnClose !== false; |
| 66 |
|
| 67 |
this.previousSelection = this.fragment.getSelection(); |
| 68 |
} ).next( () => { |
| 69 |
|
| 70 |
if ( !this.isEditing() && this.isReadOnly() ) { |
| 71 |
return ve.createDeferred().reject().promise(); |
| 72 |
} |
| 73 |
this.actions.setMode( this.getMode() ); |
| 74 |
} ); |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
ve.ui.FragmentWindow.prototype.getTeardownProcess = function ( data, process ) { |
| 82 |
ve.track( 'activity.' + this.constructor.static.name, { action: 'dialog-' + ( data && data.action || 'abort' ) } ); |
| 83 |
return process.next( () => { |
| 84 |
this.fragment = null; |
| 85 |
this.initialFragment = null; |
| 86 |
this.previousSelection = null; |
| 87 |
} ); |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ve.ui.FragmentWindow.prototype.isReadOnly = function () { |
| 96 |
const fragment = this.getFragment(), |
| 97 |
surface = fragment && fragment.getSurface(); |
| 98 |
|
| 99 |
return surface && surface.isReadOnly(); |
| 100 |
}; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
ve.ui.FragmentWindow.prototype.getMode = function () { |
| 112 |
if ( this.isReadOnly() ) { |
| 113 |
return 'readonly'; |
| 114 |
} |
| 115 |
if ( this.getFragment() ) { |
| 116 |
return this.isEditing() ? 'edit' : 'insert'; |
| 117 |
} |
| 118 |
return ''; |
| 119 |
}; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
ve.ui.FragmentWindow.prototype.isEditing = function () { |
| 129 |
return !!this.fragment.getSelectedModels().length; |
| 130 |
}; |