| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ui.AuthorListPopupTool = function VeUiAuthorListPopupTool( toolGroup, config ) { |
| 19 |
this.$authorList = $( '<div>' ); |
| 20 |
|
| 21 |
|
| 22 |
ve.ui.AuthorListPopupTool.super.call( this, toolGroup, ve.extendObject( { |
| 23 |
popup: { |
| 24 |
classes: [ 've-ui-authorListWidget-listPopup' ], |
| 25 |
$content: this.$authorList, |
| 26 |
padded: true, |
| 27 |
align: 'backwards' |
| 28 |
} |
| 29 |
}, config ) ); |
| 30 |
|
| 31 |
|
| 32 |
this.toolbar.connect( this, { surfaceChange: 'onSurfaceChange' } ); |
| 33 |
|
| 34 |
this.$element.addClass( 've-ui-authorListPopupTool' ); |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
OO.inheritClass( ve.ui.AuthorListPopupTool, OO.ui.PopupTool ); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
ve.ui.AuthorListPopupTool.prototype.onSurfaceChange = function ( oldSurface, newSurface ) { |
| 50 |
|
| 51 |
this.setup( newSurface ); |
| 52 |
}; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
ve.ui.AuthorListPopupTool.prototype.onPopupToggle = function ( visible ) { |
| 58 |
|
| 59 |
ve.ui.AuthorListPopupTool.super.prototype.onPopupToggle.apply( this, arguments ); |
| 60 |
|
| 61 |
if ( visible ) { |
| 62 |
this.selfItem.focus(); |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
ve.ui.AuthorListPopupTool.prototype.setup = function ( surface ) { |
| 72 |
this.oldName = ''; |
| 73 |
this.updatingName = false; |
| 74 |
this.synchronizer = surface.getModel().synchronizer; |
| 75 |
this.authorItems = {}; |
| 76 |
|
| 77 |
this.surface = surface; |
| 78 |
|
| 79 |
if ( !this.synchronizer ) { |
| 80 |
this.setDisabled( true ); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
this.changeNameDebounced = ve.debounce( this.changeName.bind( this ), 250 ); |
| 87 |
|
| 88 |
this.selfItem = new ve.ui.AuthorItemWidget( |
| 89 |
this.synchronizer, |
| 90 |
this.popup.$element, |
| 91 |
{ editable: true, authorId: this.synchronizer.getAuthorId() } |
| 92 |
); |
| 93 |
this.$authorList.prepend( this.selfItem.$element ); |
| 94 |
this.selfItem.connect( this, { |
| 95 |
change: 'onSelfItemChange', |
| 96 |
changeColor: 'onSelfItemChangeColor' |
| 97 |
} ); |
| 98 |
|
| 99 |
this.synchronizer.connect( this, { |
| 100 |
authorChange: 'onSynchronizerAuthorUpdate', |
| 101 |
authorDisconnect: 'onSynchronizerAuthorDisconnect' |
| 102 |
} ); |
| 103 |
|
| 104 |
for ( const authorId in this.synchronizer.authors ) { |
| 105 |
this.onSynchronizerAuthorUpdate( +authorId ); |
| 106 |
} |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
ve.ui.AuthorListPopupTool.prototype.onSelfItemChange = function () { |
| 115 |
if ( !this.updatingName ) { |
| 116 |
this.changeNameDebounced(); |
| 117 |
} |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
ve.ui.AuthorListPopupTool.prototype.onSelfItemChangeColor = function ( color ) { |
| 126 |
this.synchronizer.changeAuthor( { color: color } ); |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.ui.AuthorListPopupTool.prototype.changeName = function () { |
| 133 |
this.synchronizer.changeAuthor( { name: this.selfItem.getName() } ); |
| 134 |
}; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
ve.ui.AuthorListPopupTool.prototype.updateAuthorCount = function () { |
| 140 |
this.setTitle( ( Object.keys( this.authorItems ).length + 1 ).toString() ); |
| 141 |
}; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
ve.ui.AuthorListPopupTool.prototype.onSynchronizerAuthorUpdate = function ( authorId ) { |
| 149 |
let authorItem = this.authorItems[ authorId ]; |
| 150 |
|
| 151 |
if ( authorId !== this.synchronizer.getAuthorId() ) { |
| 152 |
if ( !authorItem ) { |
| 153 |
authorItem = new ve.ui.AuthorItemWidget( this.synchronizer, this.popup.$element, { authorId: authorId } ); |
| 154 |
this.authorItems[ authorId ] = authorItem; |
| 155 |
this.updateAuthorCount(); |
| 156 |
this.$authorList.append( authorItem.$element ); |
| 157 |
} else { |
| 158 |
authorItem.update(); |
| 159 |
} |
| 160 |
} else { |
| 161 |
|
| 162 |
if ( this.selfItem.getName() === this.oldName ) { |
| 163 |
|
| 164 |
this.updatingName = true; |
| 165 |
try { |
| 166 |
this.selfItem.setAuthorId( this.synchronizer.getAuthorId() ); |
| 167 |
this.selfItem.update(); |
| 168 |
} finally { |
| 169 |
this.updatingName = false; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
this.oldName = this.synchronizer.getAuthorData( authorId ).name; |
| 174 |
}; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
ve.ui.AuthorListPopupTool.prototype.onSynchronizerAuthorDisconnect = function ( authorId ) { |
| 182 |
const authorItem = this.authorItems[ authorId ]; |
| 183 |
if ( authorItem ) { |
| 184 |
authorItem.$element.remove(); |
| 185 |
delete this.authorItems[ authorId ]; |
| 186 |
this.updateAuthorCount(); |
| 187 |
} |
| 188 |
}; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
ve.ui.AuthorListPopupTool.static.name = 'authorList'; |
| 193 |
ve.ui.AuthorListPopupTool.static.group = 'users'; |
| 194 |
ve.ui.AuthorListPopupTool.static.icon = 'userAvatar'; |
| 195 |
ve.ui.AuthorListPopupTool.static.title = '1'; |
| 196 |
ve.ui.AuthorListPopupTool.static.autoAddToCatchall = false; |
| 197 |
ve.ui.AuthorListPopupTool.static.autoAddToGroup = false; |
| 198 |
ve.ui.AuthorListPopupTool.static.displayBothIconAndLabel = true; |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
ve.ui.toolFactory.register( ve.ui.AuthorListPopupTool ); |