@@ -10,6 +10,12 @@ angular.module('annotate').directive('anAnnotatable',
1010 showAnnotations : '='
1111 } ,
1212 controller : function ( $scope , $attrs , $element ) {
13+
14+ $scope . addAnnotationPopup = {
15+ show : false ,
16+ x : null ,
17+ y : null ,
18+ }
1319 var canvas = $element . children ( '.canvas' )
1420 var image = $element . children ( 'img' )
1521
@@ -51,7 +57,13 @@ angular.module('annotate').directive('anAnnotatable',
5157 image . draggable = false
5258
5359 canvas . on ( 'click' , function ( event ) {
60+
61+ $scope . annotations . forEach ( function ( annotation ) {
62+ annotation . open = false ;
63+ } )
64+
5465 if ( event . target . className . indexOf ( 'canvas' ) > - 1 ) {
66+
5567 var xPos = event . offsetX
5668 var yPos = event . offsetY
5769
@@ -62,32 +74,52 @@ angular.module('annotate').directive('anAnnotatable',
6274 var yPosPercent = yPos / height * 100
6375
6476 $scope . $apply ( function ( ) {
65- Meteor . call ( 'incrementAnnotations' , function ( err , next ) {
66- if ( err ) console . log ( err )
67- Annotations . insert ( {
68- image : $scope . image . _id ,
69- xPos : xPosPercent ,
70- yPos : yPosPercent ,
71- date : new Date ( ) ,
72- owner : Meteor . userId ( ) ,
73- number : next ,
74- comments : [ ]
75- } , function ( err , annotationId ) {
76- if ( err ) console . log ( err )
77-
78- $scope . annotations . forEach ( function ( annotation ) {
79- if ( annotation . _id === annotationId ) {
80- annotation . open = true
81- }
82- } )
83- } )
84- console . log ( 'post-increment' , next )
85- } )
77+ $scope . addAnnotationPopup . show = true ;
78+ $scope . addAnnotationPopup . x = xPosPercent ;
79+ $scope . addAnnotationPopup . y = yPosPercent ;
8680 } )
81+ //
8782 }
8883 // and then now add more things to the annotation
8984 } )
9085
86+ $scope . confirmed = function ( obj ) {
87+ newAnnotation ( obj . x , obj . y )
88+ $scope . closePopup ( obj )
89+ }
90+
91+ $scope . closePopup = function ( obj ) {
92+ obj . x = null
93+ obj . y = null
94+ obj . show = false
95+ }
96+
97+ var newAnnotation = function ( xPosPercent , yPosPercent ) {
98+ // $scope.$apply(function () {
99+ Meteor . call ( 'incrementAnnotations' , function ( err , next ) {
100+ if ( err ) console . log ( err )
101+ Annotations . insert ( {
102+ image : $scope . image . _id ,
103+ xPos : xPosPercent ,
104+ yPos : yPosPercent ,
105+ date : new Date ( ) ,
106+ owner : Meteor . userId ( ) ,
107+ number : next ,
108+ comments : [ ]
109+ } , function ( err , annotationId ) {
110+ if ( err ) console . log ( err )
111+
112+ $scope . annotations . forEach ( function ( annotation ) {
113+ if ( annotation . _id === annotationId ) {
114+ annotation . open = true
115+ }
116+ } )
117+ } )
118+ console . log ( 'post-increment' , next )
119+ } )
120+ // })
121+ }
122+
91123 $scope . annotationOpened = function ( annotationId ) {
92124 $scope . annotations . forEach ( function ( annotation ) {
93125 if ( annotation . _id === annotationId ) {
0 commit comments