@@ -72,12 +72,12 @@ ngApp.factory('AnnotationDeleteFactory', function ($resource, FilesFactory) {
72
72
} ) ;
73
73
} ) ;
74
74
75
- ngApp . directive ( 'onimageload' , function ( ) {
75
+ ngApp . directive ( 'onimageload' , function ( ) {
76
76
return {
77
77
restrict : 'A' ,
78
- link : function ( scope , element , attrs ) {
78
+ link : function ( scope , element , attrs ) {
79
79
scope . element = element ;
80
- element . bind ( 'load' , function ( ) {
80
+ element . bind ( 'load' , function ( ) {
81
81
scope . $apply ( attrs . onimageload ) ;
82
82
} ) ;
83
83
}
@@ -154,19 +154,24 @@ ngApp.controller('PageImageController',
154
154
e . style . top = item . annotation . box . y + "px" ;
155
155
e . style . width = item . annotation . box . width + "px" ;
156
156
e . style . height = item . annotation . box . height + "px" ;
157
- e . setAttribute ( "class" , "rectangle" ) ;
157
+ e . setAttribute ( "class" , "rendered-annotation rectangle" ) ;
158
+ e . setAttribute ( "data-annotation-id" , item . id ) ;
158
159
element . parentNode . appendChild ( e ) ;
159
160
}
160
161
}
161
162
} ;
162
163
164
+ $scope . $on ( 'annotation-deleted' , function ( event , args ) {
165
+ angular . element ( 'div.rendered-annotation[data-annotation-id=' + args . id + ']' ) . remove ( ) ;
166
+ } ) ;
167
+
163
168
$scope . onImageMouseDown = function ( $event , page ) {
164
169
updateMousePosition ( $event ) ;
165
170
$scope . drawingElement = document . createElement ( "div" ) ;
166
171
$scope . drawingElement . style . position = "absolute" ;
167
172
$scope . drawingElement . style . left = $scope . mouse . x + "px" ;
168
173
$scope . drawingElement . style . top = $scope . mouse . y + "px" ;
169
- $scope . drawingElement . setAttribute ( "class" , "rectangle" ) ;
174
+ $scope . drawingElement . setAttribute ( "class" , "rendered-annotation rectangle" ) ;
170
175
171
176
$event . target . parentNode . appendChild ( $scope . drawingElement ) ;
172
177
} ;
@@ -225,10 +230,11 @@ ngApp.controller('PageImageController',
225
230
. then (
226
231
function ( result ) {
227
232
ant . fieldText = result ;
228
- AnnotationAddFactory . save ( ant , function ( ) {
233
+ AnnotationAddFactory . save ( ant , function ( response ) {
234
+ $scope . drawingElement . setAttribute ( "data-annotation-id" , response . id ) ;
235
+ $scope . drawingElement = null ;
229
236
$rootScope . $broadcast ( 'annotation-added' ) ;
230
237
} ) ;
231
- $scope . drawingElement = null ;
232
238
} ,
233
239
function ( ) {
234
240
$scope . drawingElement . parentNode . removeChild ( $scope . drawingElement ) ;
@@ -259,8 +265,8 @@ ngApp.controller('CommentsController',
259
265
annotationId : item . id
260
266
}
261
267
}
262
- ) . success ( function ( ) {
263
- $rootScope . $broadcast ( 'annotation-deleted' ) ;
268
+ ) . success ( function ( response ) {
269
+ $rootScope . $broadcast ( 'annotation-deleted' , response ) ;
264
270
} ) ;
265
271
} ;
266
272
}
0 commit comments