@@ -182,6 +182,7 @@ function calculateImageScale() {
182
182
* If an annotation is currently edited, an update is triggered instead.
183
183
*
184
184
* @param annotation the annotation to be created, as returned by getValidAnnotation
185
+ * @return whether the annotation was successfully created
185
186
*/
186
187
async function createAnnotation ( annotation ) {
187
188
@@ -194,6 +195,8 @@ function calculateImageScale() {
194
195
editing = true ;
195
196
}
196
197
198
+ let success = true ;
199
+
197
200
$ ( '.js_feedback' ) . stop ( ) . addClass ( 'hidden' ) ;
198
201
$ ( '.annotate_button' ) . prop ( 'disabled' , true ) ;
199
202
try {
@@ -209,11 +212,13 @@ function calculateImageScale() {
209
212
if ( data . detail === 'similar annotation exists.' ) {
210
213
displayFeedback ( $ ( '#feedback_annotation_exists_deleted' ) ) ;
211
214
$ ( '#annotation_edit_button_' + gEditAnnotationId ) . parent ( ) . parent ( ) . fadeOut ( ) . remove ( ) ;
215
+ success = false ;
212
216
} else {
213
217
displayFeedback ( $ ( '#feedback_annotation_updated' ) ) ;
214
218
}
215
219
} else {
216
220
displayFeedback ( $ ( '#feedback_annotation_exists' ) ) ;
221
+ success = false ;
217
222
}
218
223
} else if ( response . status === 201 ) {
219
224
displayFeedback ( $ ( '#feedback_annotation_created' ) ) ;
@@ -227,9 +232,11 @@ function calculateImageScale() {
227
232
} catch ( e ) {
228
233
console . log ( e ) ;
229
234
displayFeedback ( $ ( '#feedback_connection_error' ) ) ;
235
+ success = false ;
230
236
} finally {
231
237
$ ( '.annotate_button' ) . prop ( 'disabled' , false ) ;
232
238
}
239
+ return success ;
233
240
}
234
241
235
242
async function loadAnnotationTypeList ( ) {
@@ -1173,9 +1180,15 @@ function calculateImageScale() {
1173
1180
$ ( '#last_button' ) . click ( async function ( event ) {
1174
1181
try {
1175
1182
let annotation = getValidAnnotation ( true ) ;
1176
- await createAnnotation ( annotation ) ;
1177
- let imageId = await loadAdjacentImage ( - 1 ) ;
1178
- await changeImage ( imageId , annotation ) ;
1183
+ if ( await createAnnotation ( annotation ) ) {
1184
+ let imageId = await loadAdjacentImage ( - 1 ) ;
1185
+ await changeImage ( imageId , annotation ) ;
1186
+ } else {
1187
+ tool . clear ( ) ;
1188
+ resetSelection ( ) ;
1189
+ tool . drawExistingAnnotations ( globals . currentAnnotationsOfSelectedType ) ;
1190
+ displayExistingAnnotations ( gCurrentAnnotations ) ;
1191
+ }
1179
1192
} catch ( e ) {
1180
1193
console . log ( e ) ;
1181
1194
}
@@ -1191,9 +1204,15 @@ function calculateImageScale() {
1191
1204
$ ( '#next_button' ) . click ( async function ( event ) {
1192
1205
try {
1193
1206
let annotation = getValidAnnotation ( true ) ;
1194
- await createAnnotation ( annotation ) ;
1195
- let imageId = await loadAdjacentImage ( 1 ) ;
1196
- await changeImage ( imageId , annotation ) ;
1207
+ if ( await createAnnotation ( annotation ) ) {
1208
+ let imageId = await loadAdjacentImage ( 1 ) ;
1209
+ await changeImage ( imageId , annotation ) ;
1210
+ } else {
1211
+ tool . clear ( ) ;
1212
+ resetSelection ( ) ;
1213
+ tool . drawExistingAnnotations ( globals . currentAnnotationsOfSelectedType ) ;
1214
+ displayExistingAnnotations ( gCurrentAnnotations ) ;
1215
+ }
1197
1216
} catch ( e ) {
1198
1217
console . log ( e ) ;
1199
1218
}
0 commit comments