<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" type="text/css" href="../../css/angular.css">
    <script type="text/javascript" src="../../lib/underscore/underscore.js"></script>
    <script type="text/javascript" src="../../lib/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="../../src/angular-bootstrap.js"></script>
    <script type="text/javascript" src="tweeterclient.js"></script>
  </head>
  <body ng:class="status" ng:init="mute={}" ng:watch="$anchor.user: tweets = fetchTweets($anchor.user)">
    <div class="addressbook box">
      <h1>Address Book</h1>
      [ Filter: <input type="text" ng:model="userFilter"/>]
      <ul>
        <li ng:repeat="user in users.$filter(userFilter).$orderBy('screen_name')" ng:class-even="'even'" ng:class-odd="'odd'">
          <a href="" ng:click="$anchor.user=user.screen_name"><img src="{{user.profile_image_url}}"/></a>
          <a href="" ng:click="$anchor.user=user.screen_name">{{user.screen_name}}</a>
          as <span class="nickname">{{user.name}}</span>
          [ <a href="#" ng:click="$anchor.edituser=user.screen_name">edit</a>
          | <a href="#" ng:click="users.$remove(user)">X</a>
          | <a href="#" ng:click="mute[user.screen_name] = ! mute[user.screen_name]">mute</a>
          ]
          <div class="notes">{{user.notes|linky}}</div>
          <div class="clrleft"></div>
        </li>
      </ul>
      <hr/>
      <div ng:show="$anchor.edituser" ng:eval="user = users.$find({:$.screen_name == $anchor.edituser})">
        <div class="editor">
          <label>Username:</label>
          <input type="text" ng:model="user.screen_name" disabled="disabled"/>
          <label>Name:</label>
          <input type="text" ng:model="user.name"/>
          <label>Image:</label>
          <input type="text" ng:model="user.profile_image_url"/>
          <label>Notes:</label>
          <textarea type="text" ng:model="user.notes"></textarea>

          <input type="button" ng:click="$anchor.edituser=undefined" value="Close"/>
        </div>
      </div>
      <hr/>
      <div class="debug">
mute={{mute|json}}

userFilter={{userFilter|json}}

tweetFilter={{tweetFilter|json}}

$anchor={{$anchor}}

users={{users}}

tweets={{tweets}}
      </div>
    </div>
    <div class="tweeter box">
      <h1>Tweets: {{$anchor.user}}</h1>
      [ Filter: <input type="text" ng:model="tweetFilter"/>
        <span ng:show="$anchor.user">| <a href="#user=">&lt;&lt; All</a></span>
      ]
      <div class="loading">Loading...</div>
      <ul>
       <li ng:repeat="tweet in tweets.$filter(tweetFilter).$filter({:!mute[$.user.screen_name]})"
           ng:class-even="'even'" ng:class-odd="'odd'"
           ng:eval="user = users.$find({: $.screen_name == tweet.user.screen_name}) || tweet.user">
         <img src="{{user.profile_image_url}}"/>
         [ <a href="" ng:click="$anchor.user=user.screen_name">{{user.nickname || user.name || user.screen_name }}</a>
         | <a href="" ng:click="users.$includeIf(user, true)">+</a>
         ]:
         {{tweet.text | linky}}
         <span class="notes">{{tweet.created_at}}</span>
         <span class="notes">{{user.notes}}</span>
         <div class="clrleft"></div>
       </li>
      </ul>
    </div>
  </body>
</html>
