Commit 2b2e02db authored by Sean Hammond's avatar Sean Hammond

Replace editing with editing()

Replace AnnotationController's vm.editing boolean with a vm.editing()
method.

This removes some duplicated state, as both vm.editing and vm.action
were recording whether or not the annotation was being edited.
parent 967b3929
......@@ -162,7 +162,6 @@ function AnnotationController(
vm.action = 'view';
vm.document = null;
vm.editing = false;
// Copy isSidebar from $scope onto vm for consistency (we want this
// directive's templates to always access variables from vm rather than
// directly from scope).
......@@ -187,6 +186,20 @@ function AnnotationController(
var highlight = model.$highlight;
/**
* @ngdoc method
* @name annotation.AnnotationController#editing.
* @returns {boolean} `true` if this annotation is currently being edited
* (i.e. the annotation editor form should be open), `false` otherwise.
*/
vm.editing = function() {
if (vm.action === 'create' || vm.action === 'edit') {
return true;
} else {
return false;
}
};
/**
* @ngdoc method
* @name annotation.AnnotationController#group.
......@@ -350,7 +363,6 @@ function AnnotationController(
updateDraft(model);
}
vm.action = model.id ? 'edit' : 'create';
vm.editing = true;
vm.preview = 'no';
};
......@@ -361,7 +373,6 @@ function AnnotationController(
* if they are open.
*/
vm.view = function() {
vm.editing = false;
vm.action = 'view';
};
......@@ -598,7 +609,7 @@ function AnnotationController(
// the drafts service. They will be restored when this annotation is
// next loaded.
$scope.$on(events.GROUP_FOCUSED, function() {
if (!vm.editing) {
if (!vm.editing()) {
return;
}
......
......@@ -358,6 +358,23 @@ describe('annotation', function() {
});
});
describe('AnnotationController.editing()', function() {
it('returns true if action is "create"', function() {
controller.action = 'create';
assert(controller.editing());
});
it('returns true if action is "edit"', function() {
controller.action = 'edit';
assert(controller.editing());
});
it('returns false if action is "view"', function() {
controller.action = 'view';
assert(!controller.editing());
});
});
describe('when the annotation is a highlight', function() {
beforeEach(function() {
annotation.$highlight = true;
......@@ -922,7 +939,7 @@ describe('annotation', function() {
text: 'unsaved-text'
});
createDirective();
assert.isTrue(controller.editing);
assert.isTrue(controller.editing());
});
it('uses the text and tags from the draft if present', function() {
......
......@@ -30,7 +30,7 @@
title="This annotation is visible only to you.">
<i class="h-icon-lock"></i><span class="annotation-header__group-name" ng-show="!vm.group().url">Only me</span>
</span>
<i class="h-icon-border-color" ng-show="vm.isHighlight() && !vm.editing" title="This is a highlight. Click 'edit' to add a note or tag."></i>
<i class="h-icon-border-color" ng-show="vm.isHighlight() && !vm.editing()" title="This is a highlight. Click 'edit' to add a note or tag."></i>
<span class="annotation-citation"
ng-bind-html="vm.document | documentTitle"
ng-if="!vm.isSidebar">
......@@ -48,7 +48,7 @@
<a class="annotation-timestamp"
target="_blank"
title="{{vm.annotation.updated | moment:'LLLL'}}"
ng-if="!vm.editing && vm.annotation.updated"
ng-if="!vm.editing() && vm.annotation.updated"
ng-href="{{vm.baseURI}}a/{{vm.annotation.id}}"
>{{vm.timestamp}}</a>
</header>
......@@ -70,16 +70,16 @@
<!-- Body -->
<section name="text" class="annotation-body">
<excerpt enabled="feature('truncate_annotations') && !vm.editing">
<excerpt enabled="feature('truncate_annotations') && !vm.editing()">
<markdown ng-model="vm.annotation.text"
read-only="!vm.editing"
read-only="!vm.editing()"
></markdown>
</excerpt>
</section>
<!-- / Body -->
<!-- Tags -->
<div class="annotation-body form-field" ng-if="vm.editing">
<div class="annotation-body form-field" ng-if="vm.editing()">
<tags-input ng-model="vm.annotation.tags"
name="tags"
class="tags"
......@@ -94,7 +94,7 @@
</div>
<div class="annotation-body tags tags-read-only"
ng-if="vm.annotation.tags.length && !vm.editing">
ng-if="vm.annotation.tags.length && !vm.editing()">
<ul class="tag-list">
<li class="tag-item" ng-repeat="tag in vm.annotation.tags">
<a href="/stream?q=tag:'{{tag.text|urlencode}}'" target="_blank">{{tag.text}}</a>
......@@ -104,7 +104,7 @@
<!-- / Tags -->
<footer class="annotation-footer">
<div class="annotation-form-actions" ng-if="vm.editing" ng-switch="vm.action">
<div class="annotation-form-actions" ng-if="vm.editing()" ng-switch="vm.action">
<button ng-switch-when="delete"
ng-click="vm.save()"
class="dropdown-menu-btn"><i class="h-icon-check btn-icon"></i> Delete</button>
......@@ -119,7 +119,7 @@
</div>
<div class="annotation-section annotation-license"
ng-show="vm.isShared() && vm.editing">
ng-show="vm.isShared() && vm.editing()">
<a href="http://creativecommons.org/publicdomain/zero/1.0/"
title="View more information about the Creative Commons Public Domain license"
target="_blank">
......@@ -135,7 +135,7 @@
when="{'0': '', 'one': '1 reply', 'other': '{} replies'}"></a>
</div>
<div class="annotation-actions" ng-if="!vm.editing && vm.annotation.id">
<div class="annotation-actions" ng-if="!vm.editing() && vm.annotation.id">
<button class="small btn btn-clean"
ng-click="vm.reply()"
><i class="h-icon-reply btn-icon"></i> Reply</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment