Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
fa596904
Commit
fa596904
authored
Dec 04, 2015
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move event-listener functions out of init()
parent
8cb8ee78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
44 deletions
+49
-44
annotation.js
h/static/scripts/directive/annotation.js
+49
-44
No files found.
h/static/scripts/directive/annotation.js
View file @
fa596904
...
...
@@ -215,52 +215,14 @@ function AnnotationController(
*/
newlyCreatedByHighlightButton
=
model
.
$highlight
||
false
;
$scope
.
$on
(
'$destroy'
,
function
()
{
updateTimestamp
=
angular
.
noop
;
});
// Watch for changes to the domain model and recreate the view model when it
// changes.
$scope
.
$watch
((
function
()
{
return
model
;}),
function
(
model
,
old
)
{
if
(
model
.
updated
!==
old
.
updated
)
{
// Discard saved drafts.
drafts
.
remove
(
model
);
}
updateTimestamp
(
model
===
old
);
// Repeat on first run.
vm
.
render
();
},
true
);
// When the current group changes, persist any unsaved changes using
// the drafts service. They will be restored when this annotation is
// next loaded.
$scope
.
$on
(
events
.
GROUP_FOCUSED
,
function
()
{
if
(
!
vm
.
editing
())
{
return
;
}
// Call `onDestroy()` when this AnnotationController's scope is removed.
$scope
.
$on
(
'$destroy'
,
onDestroy
);
// Move any new annotations to the currently focused group when
// switching groups. See GH #2689 for context.
if
(
!
model
.
id
)
{
var
newGroup
=
groups
.
focused
().
id
;
var
isShared
=
permissions
.
isShared
(
vm
.
annotation
.
permissions
,
vm
.
annotation
.
group
);
if
(
isShared
)
{
model
.
permissions
=
permissions
.
shared
(
newGroup
);
vm
.
annotation
.
permissions
=
model
.
permissions
;
}
model
.
group
=
newGroup
;
vm
.
annotation
.
group
=
model
.
group
;
}
// Call `onModelChange()` whenever `model` changes.
$scope
.
$watch
((
function
()
{
return
model
;}),
onModelChange
,
true
);
// if we have a draft, update it, otherwise (eg. when the user signs out)
// do not create a new one.
if
(
drafts
.
get
(
model
))
{
var
draftDomainModel
=
{};
updateDomainModel
(
draftDomainModel
,
vm
.
annotation
);
updateDraft
(
draftDomainModel
);
}
});
// Call `onGroupFocused()` whenever the currently-focused group changes.
$scope
.
$on
(
events
.
GROUP_FOCUSED
,
onGroupFocused
);
// New annotations (just created locally by the client, rather then
// received from the server) have some fields missing. Add them.
...
...
@@ -285,6 +247,49 @@ function AnnotationController(
}
}
/** Called when this AnnotationController instance's scope is removed. */
function
onDestroy
()
{
updateTimestamp
=
angular
.
noop
;
}
/** Called whenever the currently-focused group changes. */
function
onGroupFocused
()
{
if
(
!
vm
.
editing
())
{
return
;
}
// Move any new annotations to the currently focused group when
// switching groups. See GH #2689 for context.
if
(
!
model
.
id
)
{
var
newGroup
=
groups
.
focused
().
id
;
var
isShared
=
permissions
.
isShared
(
vm
.
annotation
.
permissions
,
vm
.
annotation
.
group
);
if
(
isShared
)
{
model
.
permissions
=
permissions
.
shared
(
newGroup
);
vm
.
annotation
.
permissions
=
model
.
permissions
;
}
model
.
group
=
newGroup
;
vm
.
annotation
.
group
=
model
.
group
;
}
if
(
drafts
.
get
(
model
))
{
var
draftDomainModel
=
{};
updateDomainModel
(
draftDomainModel
,
vm
.
annotation
);
updateDraft
(
draftDomainModel
);
}
}
/** Called whenever `model` changes. */
function
onModelChange
(
model
,
old
)
{
if
(
model
.
updated
!==
old
.
updated
)
{
// Discard saved drafts.
drafts
.
remove
(
model
);
}
updateTimestamp
(
model
===
old
);
// Repeat on first run.
vm
.
render
();
}
/**
* @ngdoc method
* @name annotation.AnnotationController#isHighlight.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment