     obj
 
 class View extends Annotator.Plugin
+  events:
+    ".annotator-readmill-connect a click": "_onConnectClick"
+    ".annotator-readmill-logout a click":  "_onLogoutClick"
+
   classes:
     loggedIn: "annotator-readmill-logged-in"
 

    @store  = new Readmill.Store
    @client = new Readmill.Client @options

    token = options.accessToken || @store.get "access-token"
    @connected(token, silent: true) if token
    @unsaved = []

  constructor: () ->
    super jQuery(@template)

  connect: ->
    this.publish "connect", this

  login: (user) ->
    @updateUser(user) if user
    @element.addClass @classes.loggedIn
    this

  logout: ->
    newElement = jQuery(@template)

    @element.replaceWith newElement
    @element = newElement

    @user = null
    @updateBook @book

    this.publish "disconnect", this

  updateUser: (@user=@user) ->
    if @user
      @element.find(".annotator-readmill-fullname").escape(@user.fullname)
      @element.find(".annotator-readmill-username").escape(@user.username)
      @element.find(".annotator-readmill-avatar").attr("href", @user.permalink_url)
              .find("img").attr("src", @user.avatar_url)
    this

  updateBook: (@book=@book) ->
    if @book
      @element.find(".annotator-readmill-book").escape(@book.title or "Loading book…")
    this

  render: ->
    @updateBook()
    @updateUser()
    @element

  _onConnectClick: (event) =>
    event.preventDefault()
    this.connect()

  _onLogoutClick: (event) =>
    event.preventDefault()
    this.logout()

class Client
  @API_ENDPOINT: "https://api.readmill.com"
