@@ -72,12 +72,12 @@ ngApp.factory('AnnotationDeleteFactory', function ($resource, FilesFactory) {
7272 } ) ;
7373} ) ;
7474
75- ngApp . directive ( 'onimageload' , function ( ) {
75+ ngApp . directive ( 'onimageload' , function ( ) {
7676 return {
7777 restrict : 'A' ,
78- link : function ( scope , element , attrs ) {
78+ link : function ( scope , element , attrs ) {
7979 scope . element = element ;
80- element . bind ( 'load' , function ( ) {
80+ element . bind ( 'load' , function ( ) {
8181 scope . $apply ( attrs . onimageload ) ;
8282 } ) ;
8383 }
@@ -154,19 +154,24 @@ ngApp.controller('PageImageController',
154154 e . style . top = item . annotation . box . y + "px" ;
155155 e . style . width = item . annotation . box . width + "px" ;
156156 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 ) ;
158159 element . parentNode . appendChild ( e ) ;
159160 }
160161 }
161162 } ;
162163
164+ $scope . $on ( 'annotation-deleted' , function ( event , args ) {
165+ angular . element ( 'div.rendered-annotation[data-annotation-id=' + args . id + ']' ) . remove ( ) ;
166+ } ) ;
167+
163168 $scope . onImageMouseDown = function ( $event , page ) {
164169 updateMousePosition ( $event ) ;
165170 $scope . drawingElement = document . createElement ( "div" ) ;
166171 $scope . drawingElement . style . position = "absolute" ;
167172 $scope . drawingElement . style . left = $scope . mouse . x + "px" ;
168173 $scope . drawingElement . style . top = $scope . mouse . y + "px" ;
169- $scope . drawingElement . setAttribute ( "class" , "rectangle" ) ;
174+ $scope . drawingElement . setAttribute ( "class" , "rendered-annotation rectangle" ) ;
170175
171176 $event . target . parentNode . appendChild ( $scope . drawingElement ) ;
172177 } ;
@@ -225,10 +230,11 @@ ngApp.controller('PageImageController',
225230 . then (
226231 function ( result ) {
227232 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 ;
229236 $rootScope . $broadcast ( 'annotation-added' ) ;
230237 } ) ;
231- $scope . drawingElement = null ;
232238 } ,
233239 function ( ) {
234240 $scope . drawingElement . parentNode . removeChild ( $scope . drawingElement ) ;
@@ -259,8 +265,8 @@ ngApp.controller('CommentsController',
259265 annotationId : item . id
260266 }
261267 }
262- ) . success ( function ( ) {
263- $rootScope . $broadcast ( 'annotation-deleted' ) ;
268+ ) . success ( function ( response ) {
269+ $rootScope . $broadcast ( 'annotation-deleted' , response ) ;
264270 } ) ;
265271 } ;
266272 }
0 commit comments