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
Show 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,26 +215,45 @@ function AnnotationController(
...
@@ -215,26 +215,45 @@ function AnnotationController(
*/
*/
newlyCreatedByHighlightButton
=
model
.
$highlight
||
false
;
newlyCreatedByHighlightButton
=
model
.
$highlight
||
false
;
$scope
.
$on
(
'$destroy'
,
function
()
{
// Call `onDestroy()` when this AnnotationController's scope is removed.
updateTimestamp
=
angular
.
noop
;
$scope
.
$on
(
'$destroy'
,
onDestroy
);
});
// Watch for changes to the domain model and recreate the view model when it
// Call `onModelChange()` whenever `model` changes.
// changes.
$scope
.
$watch
((
function
()
{
return
model
;}),
onModelChange
,
true
);
$scope
.
$watch
((
function
()
{
return
model
;}),
function
(
model
,
old
)
{
if
(
model
.
updated
!==
old
.
updated
)
{
// Call `onGroupFocused()` whenever the currently-focused group changes.
// Discard saved drafts.
$scope
.
$on
(
events
.
GROUP_FOCUSED
,
onGroupFocused
);
drafts
.
remove
(
model
);
// New annotations (just created locally by the client, rather then
// received from the server) have some fields missing. Add them.
model
.
user
=
model
.
user
||
session
.
state
.
userid
;
model
.
group
=
model
.
group
||
groups
.
focused
().
id
;
model
.
permissions
=
model
.
permissions
||
permissions
[
'default'
](
model
.
group
);
// Automatically save new highlights to the server when they're created.
// Note that this line also gets called when the user logs in (since
// AnnotationController instances are re-created on login) so serves to
// automatically save highlights that were created while logged out when you
// log in.
saveNewHighlight
();
// If this annotation is not a highlight and if it's new (has just been
// created by the annotate button) or it has edits not yet saved to the
// server - then open the editor on AnnotationController instantiation.
if
(
!
newlyCreatedByHighlightButton
)
{
if
(
!
model
.
id
||
drafts
.
get
(
model
))
{
vm
.
edit
();
}
}
}
}
updateTimestamp
(
model
===
old
);
// Repeat on first run.
/** Called when this AnnotationController instance's scope is removed. */
vm
.
render
();
function
onDestroy
()
{
},
true
);
updateTimestamp
=
angular
.
noop
;
}
// When the current group changes, persist any unsaved changes using
/** Called whenever the currently-focused group changes. */
// the drafts service. They will be restored when this annotation is
function
onGroupFocused
()
{
// next loaded.
$scope
.
$on
(
events
.
GROUP_FOCUSED
,
function
()
{
if
(
!
vm
.
editing
())
{
if
(
!
vm
.
editing
())
{
return
;
return
;
}
}
...
@@ -253,36 +272,22 @@ function AnnotationController(
...
@@ -253,36 +272,22 @@ function AnnotationController(
vm
.
annotation
.
group
=
model
.
group
;
vm
.
annotation
.
group
=
model
.
group
;
}
}
// if we have a draft, update it, otherwise (eg. when the user signs out)
// do not create a new one.
if
(
drafts
.
get
(
model
))
{
if
(
drafts
.
get
(
model
))
{
var
draftDomainModel
=
{};
var
draftDomainModel
=
{};
updateDomainModel
(
draftDomainModel
,
vm
.
annotation
);
updateDomainModel
(
draftDomainModel
,
vm
.
annotation
);
updateDraft
(
draftDomainModel
);
updateDraft
(
draftDomainModel
);
}
}
});
// New annotations (just created locally by the client, rather then
// received from the server) have some fields missing. Add them.
model
.
user
=
model
.
user
||
session
.
state
.
userid
;
model
.
group
=
model
.
group
||
groups
.
focused
().
id
;
model
.
permissions
=
model
.
permissions
||
permissions
[
'default'
](
model
.
group
);
// Automatically save new highlights to the server when they're created.
// Note that this line also gets called when the user logs in (since
// AnnotationController instances are re-created on login) so serves to
// automatically save highlights that were created while logged out when you
// log in.
saveNewHighlight
();
// If this annotation is not a highlight and if it's new (has just been
// created by the annotate button) or it has edits not yet saved to the
// server - then open the editor on AnnotationController instantiation.
if
(
!
newlyCreatedByHighlightButton
)
{
if
(
!
model
.
id
||
drafts
.
get
(
model
))
{
vm
.
edit
();
}
}
/** 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
();
}
}
/**
/**
...
...
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