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( ...@@ -162,7 +162,6 @@ function AnnotationController(
vm.action = 'view'; vm.action = 'view';
vm.document = null; vm.document = null;
vm.editing = false;
// Copy isSidebar from $scope onto vm for consistency (we want this // Copy isSidebar from $scope onto vm for consistency (we want this
// directive's templates to always access variables from vm rather than // directive's templates to always access variables from vm rather than
// directly from scope). // directly from scope).
...@@ -187,6 +186,20 @@ function AnnotationController( ...@@ -187,6 +186,20 @@ function AnnotationController(
var highlight = model.$highlight; 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 * @ngdoc method
* @name annotation.AnnotationController#group. * @name annotation.AnnotationController#group.
...@@ -350,7 +363,6 @@ function AnnotationController( ...@@ -350,7 +363,6 @@ function AnnotationController(
updateDraft(model); updateDraft(model);
} }
vm.action = model.id ? 'edit' : 'create'; vm.action = model.id ? 'edit' : 'create';
vm.editing = true;
vm.preview = 'no'; vm.preview = 'no';
}; };
...@@ -361,7 +373,6 @@ function AnnotationController( ...@@ -361,7 +373,6 @@ function AnnotationController(
* if they are open. * if they are open.
*/ */
vm.view = function() { vm.view = function() {
vm.editing = false;
vm.action = 'view'; vm.action = 'view';
}; };
...@@ -598,7 +609,7 @@ function AnnotationController( ...@@ -598,7 +609,7 @@ function AnnotationController(
// the drafts service. They will be restored when this annotation is // the drafts service. They will be restored when this annotation is
// next loaded. // next loaded.
$scope.$on(events.GROUP_FOCUSED, function() { $scope.$on(events.GROUP_FOCUSED, function() {
if (!vm.editing) { if (!vm.editing()) {
return; return;
} }
......
...@@ -358,6 +358,23 @@ describe('annotation', function() { ...@@ -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() { describe('when the annotation is a highlight', function() {
beforeEach(function() { beforeEach(function() {
annotation.$highlight = true; annotation.$highlight = true;
...@@ -922,7 +939,7 @@ describe('annotation', function() { ...@@ -922,7 +939,7 @@ describe('annotation', function() {
text: 'unsaved-text' text: 'unsaved-text'
}); });
createDirective(); createDirective();
assert.isTrue(controller.editing); assert.isTrue(controller.editing());
}); });
it('uses the text and tags from the draft if present', function() { it('uses the text and tags from the draft if present', function() {
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
title="This annotation is visible only to you."> 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> <i class="h-icon-lock"></i><span class="annotation-header__group-name" ng-show="!vm.group().url">Only me</span>
</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" <span class="annotation-citation"
ng-bind-html="vm.document | documentTitle" ng-bind-html="vm.document | documentTitle"
ng-if="!vm.isSidebar"> ng-if="!vm.isSidebar">
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<a class="annotation-timestamp" <a class="annotation-timestamp"
target="_blank" target="_blank"
title="{{vm.annotation.updated | moment:'LLLL'}}" 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}}" ng-href="{{vm.baseURI}}a/{{vm.annotation.id}}"
>{{vm.timestamp}}</a> >{{vm.timestamp}}</a>
</header> </header>
...@@ -70,16 +70,16 @@ ...@@ -70,16 +70,16 @@
<!-- Body --> <!-- Body -->
<section name="text" class="annotation-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" <markdown ng-model="vm.annotation.text"
read-only="!vm.editing" read-only="!vm.editing()"
></markdown> ></markdown>
</excerpt> </excerpt>
</section> </section>
<!-- / Body --> <!-- / Body -->
<!-- Tags --> <!-- 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" <tags-input ng-model="vm.annotation.tags"
name="tags" name="tags"
class="tags" class="tags"
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
</div> </div>
<div class="annotation-body tags tags-read-only" <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"> <ul class="tag-list">
<li class="tag-item" ng-repeat="tag in vm.annotation.tags"> <li class="tag-item" ng-repeat="tag in vm.annotation.tags">
<a href="/stream?q=tag:'{{tag.text|urlencode}}'" target="_blank">{{tag.text}}</a> <a href="/stream?q=tag:'{{tag.text|urlencode}}'" target="_blank">{{tag.text}}</a>
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
<!-- / Tags --> <!-- / Tags -->
<footer class="annotation-footer"> <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" <button ng-switch-when="delete"
ng-click="vm.save()" ng-click="vm.save()"
class="dropdown-menu-btn"><i class="h-icon-check btn-icon"></i> Delete</button> class="dropdown-menu-btn"><i class="h-icon-check btn-icon"></i> Delete</button>
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
</div> </div>
<div class="annotation-section annotation-license" <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/" <a href="http://creativecommons.org/publicdomain/zero/1.0/"
title="View more information about the Creative Commons Public Domain license" title="View more information about the Creative Commons Public Domain license"
target="_blank"> target="_blank">
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
when="{'0': '', 'one': '1 reply', 'other': '{} replies'}"></a> when="{'0': '', 'one': '1 reply', 'other': '{} replies'}"></a>
</div> </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" <button class="small btn btn-clean"
ng-click="vm.reply()" ng-click="vm.reply()"
><i class="h-icon-reply btn-icon"></i> Reply</button> ><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