| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.CommentAnnotationInspector = function VeUiCommentAnnotationInspector() { |
| 17 |
|
| 18 |
ve.ui.CommentAnnotationInspector.super.apply( this, arguments ); |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
OO.inheritClass( ve.ui.CommentAnnotationInspector, ve.ui.AnnotationInspector ); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
ve.ui.CommentAnnotationInspector.static.name = 'commentAnnotation'; |
| 28 |
|
| 29 |
ve.ui.CommentAnnotationInspector.static.title = |
| 30 |
OO.ui.deferMsg( 'visualeditor-commentinspector-title' ); |
| 31 |
|
| 32 |
ve.ui.CommentAnnotationInspector.static.modelClasses = [ ve.dm.CommentAnnotation ]; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
ve.ui.CommentAnnotationInspector.prototype.onTextInputChange = function () { |
| 42 |
this.updateActions(); |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
ve.ui.CommentAnnotationInspector.prototype.onTextInputResize = function () { |
| 49 |
this.updateSize(); |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
ve.ui.CommentAnnotationInspector.prototype.updateActions = function () { |
| 56 |
let isValid = false; |
| 57 |
|
| 58 |
this.textInput.getValidity() |
| 59 |
.then( () => { |
| 60 |
isValid = true; |
| 61 |
} ) |
| 62 |
.always( () => { |
| 63 |
this.actions.forEach( { actions: [ 'done', 'insert' ] }, ( action ) => { |
| 64 |
action.setDisabled( !isValid ); |
| 65 |
} ); |
| 66 |
} ); |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
ve.ui.CommentAnnotationInspector.prototype.shouldRemoveAnnotation = function () { |
| 73 |
return !this.textInput.getValue(); |
| 74 |
}; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
ve.ui.CommentAnnotationInspector.prototype.getInsertionText = function () { |
| 80 |
return '…'; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
ve.ui.CommentAnnotationInspector.prototype.getAnnotation = function () { |
| 87 |
const comments = ( this.initialAnnotation && this.initialAnnotation.getAttribute( 'comments' ).slice() ) || []; |
| 88 |
comments.push( { |
| 89 |
author: this.getFragment().getSurface().synchronizer.getAuthorData().name, |
| 90 |
text: this.textInput.getValue().trim() |
| 91 |
} ); |
| 92 |
return new ve.dm.CommentAnnotation( { |
| 93 |
type: 'commentAnnotation', |
| 94 |
attributes: { |
| 95 |
comments: comments |
| 96 |
} |
| 97 |
} ); |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
ve.ui.CommentAnnotationInspector.prototype.getAnnotationFromFragment = function () { |
| 104 |
return new ve.dm.CommentAnnotation( { |
| 105 |
type: 'commentAnnotation', |
| 106 |
attributes: { |
| 107 |
comments: [] |
| 108 |
} |
| 109 |
} ); |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
ve.ui.CommentAnnotationInspector.prototype.initialize = function () { |
| 116 |
|
| 117 |
ve.ui.CommentAnnotationInspector.super.prototype.initialize.call( this ); |
| 118 |
|
| 119 |
|
| 120 |
this.textInput = new OO.ui.MultilineTextInputWidget( { autosize: true } ); |
| 121 |
this.$thread = $( '<div>' ); |
| 122 |
this.$user = $( '<strong>' ); |
| 123 |
|
| 124 |
|
| 125 |
this.textInput.connect( this, { |
| 126 |
change: 'onTextInputChange', |
| 127 |
resize: 'onTextInputResize' |
| 128 |
} ); |
| 129 |
|
| 130 |
|
| 131 |
this.form.$element.append( |
| 132 |
this.$thread, |
| 133 |
$( '<div>' ).addClass( 've-ui-commentAnnotationContextItem-comment' ).append( |
| 134 |
this.$user, |
| 135 |
this.textInput.$element |
| 136 |
) |
| 137 |
); |
| 138 |
}; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
ve.ui.CommentAnnotationInspector.prototype.getSetupProcess = function ( data ) { |
| 144 |
return ve.ui.CommentAnnotationInspector.super.prototype.getSetupProcess.call( this, data ) |
| 145 |
.next( () => { |
| 146 |
if ( this.initialAnnotation ) { |
| 147 |
const $thread = ve.ui.CommentAnnotationContextItem.static.renderThread( this.initialAnnotation ); |
| 148 |
this.$thread.empty().append( $thread ); |
| 149 |
} |
| 150 |
this.$user.text( this.getFragment().getSurface().synchronizer.getAuthorData().name ); |
| 151 |
this.textInput.setValue( '' ); |
| 152 |
this.actions.forEach( { actions: [ 'done' ] }, ( action ) => { |
| 153 |
action.setLabel( ve.msg( 'visualeditor-commentannotationcontextitem-comment' ) ); |
| 154 |
} ); |
| 155 |
this.updateActions(); |
| 156 |
} ); |
| 157 |
}; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
ve.ui.CommentAnnotationInspector.prototype.getReadyProcess = function ( data ) { |
| 163 |
return ve.ui.CommentAnnotationInspector.super.prototype.getReadyProcess.call( this, data ) |
| 164 |
.next( () => { |
| 165 |
this.textInput.focus().select(); |
| 166 |
|
| 167 |
|
| 168 |
this.textInput.setValidityFlag( true ); |
| 169 |
} ); |
| 170 |
}; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
ve.ui.CommentAnnotationInspector.prototype.getHoldProcess = function ( data ) { |
| 176 |
return ve.ui.CommentAnnotationInspector.super.prototype.getHoldProcess.call( this, data ) |
| 177 |
.next( () => { |
| 178 |
this.textInput.blur(); |
| 179 |
} ); |
| 180 |
}; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
ve.ui.CommentAnnotationInspector.prototype.getTeardownProcess = function ( data ) { |
| 186 |
return ve.ui.CommentAnnotationInspector.super.prototype.getTeardownProcess.call( this, data ) |
| 187 |
.next( () => { |
| 188 |
this.textInput.setValue( '' ); |
| 189 |
} ); |
| 190 |
}; |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
ve.ui.windowFactory.register( ve.ui.CommentAnnotationInspector ); |