Ember WordPress test 4

If you access a post via an URL like http://broerse.net/ember/wp3/#/posts/3787 I didn’t know how to return the post with an ‘id’ from the objects created with findAll. I ended up fetching the specific post by ‘id’ from JetPack again. With much help from ‘melc’ and StackOverflow I changed my test to this:

http://broerse.net/ember/wp4/#/posts/3787

You can download the source from http://broerse.net/ember/wp4/wp4.zip or download the Ember Starter kit from http://emberjs.com/ and replace index.html and app.js files.

app.js

App = Ember.Application.create();

App.Router.map(function() {
  this.resource('posts', function() {
    this.resource('post', { path: ':post_id' });
  });
});

App.Post = Ember.Object.extend();

App.Post.reopenClass({
  findAll: function() {
    return Ember.$.ajax({ url: 'http://public-api.wordpress.com/rest/v1/sites/58826716/posts/?number=10', dataType: "jsonp", type: 'GET' }).then(function(data) {
      return data.posts.map(function(post) {
        post['id'] = post['ID'];
        delete post['ID'];
        return App.Post.create(post);
      });
    });
  },
 
  find: function(id) {
    return Ember.$.ajax({ url: 'http://public-api.wordpress.com/rest/v1/sites/58826716/posts/' + id + '/', dataType: "jsonp", type: 'GET' }).then(function(post) {
      post['id'] = post['ID'];
      delete post['ID'];
      return App.Post.create(post);
    });
  }

});
 
App.PostsRoute = Ember.Route.extend({
  model: function() {
    return App.Post.findAll();
  }
});

App.PostRoute = Ember.Route.extend({
  model: function(params) {
    var post = this.modelFor("posts").findBy("id",parseInt(params.post_id));
    if(Em.isEmpty(post)){
      return App.Post.find(params.post_id);   
    } else {
      return post;
    }
  }
});

Ember WordPress test 3

To extend http://broerse.net/ember/wp2/ I added a fix for the WordPress JetPack ‘ID’. Ember uses ‘id’ by default. See:

http://broerse.net/ember/wp3/

You can download the source from http://broerse.net/ember/wp3/wp3.zip or download the Ember Starter kit from http://emberjs.com/ and replace app.js and index.html with these files:

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
  <link rel="stylesheet" href="css/bootstrap.css">
  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
  <script type="text/x-handlebars">
    <div class="navbar">
      <div class="navbar-inner">
        <a class="brand" href="#">Home</a>
        <ul class="nav">
          <li>{{#linkTo 'posts'}}Posts{{/linkTo}}</li>
        </ul>
      </div>
    </div>
    {{outlet}}
  </script>

  <script type="text/x-handlebars" id="posts">
    <div class="container-fluid">
      <div class="row-fluid">
        <div class="span3">
          <table class='table'>
            <thead>
              <tr><th>Recent Posts</th></tr>
            </thead>
            {{#each model}}
            <tr><td>
              {{#linkTo 'post' this}}{{{title}}}{{/linkTo}}
            </td></tr>
            {{/each}}
          </table>
        </div>
        <div class="span9">
          {{outlet}}
        </div>
      </div>
    </div>
  </script>

  <script type="text/x-handlebars" id="posts/index">
    <p>Please select a post</p>
  </script>

  <script type="text/x-handlebars" id="post">
    <h1>{{{title}}}</h1>
    <h2>by {{{author.name}}} <small class='muted'>({{date}})</small></h2>

    <hr>

    {{{content.content}}}

  </script>

  <script src="js/libs/jquery-1.10.2.js"></script>
  <script src="js/libs/handlebars-1.1.2.js"></script>
  <script src="js/libs/ember-1.2.0.js"></script>
  <script src="js/app.js"></script>
</body>
</html>

app.js

App = Ember.Application.create();

App.Router.map(function() {
  this.resource('posts', function() {
    this.resource('post', { path: ':post_id' });
  });
});

App.Post = Ember.Object.extend();

App.Post.reopenClass({
  findAll: function() {
    return Ember.$.ajax({ url: 'http://public-api.wordpress.com/rest/v1/sites/58826716/posts/?number=10', dataType: "jsonp", type: 'GET' }).then(function(data) {
      return data.posts.map(function(post) {
        post['id'] = post['ID'];
        delete post['ID'];
        return App.Post.create(post);
      });
    });
  },

  find: function(id) {
    return Ember.$.ajax({ url: 'http://public-api.wordpress.com/rest/v1/sites/58826716/posts/' + id + '/', dataType: "jsonp", type: 'GET' }).then(function(post) {
      post['id'] = post['ID'];
      delete post['ID'];
      return App.Post.create(post);
    });
  }

});

App.PostsRoute = Ember.Route.extend({
  model: function() {
    return App.Post.findAll();
  }
});

App.PostRoute = Ember.Route.extend({
  model: function(params) {
    return App.Post.find(params.post_id);
  }
});

WordPress 2.7.1.

buddhist-temple-made-of-beer-bottles

Theo Updated this blog to WordPress version 2.7.1.
I can still post 😉 And upload images with beer bottles with the Flash uploader again…. Also updated the wp-comments-post.php file for extra XSall spam protection like this:

  if ( get_option(comment_registration’) || !$GLOBALS[xsall’]->loggedin )
    wp_die( __(Sorry, you must be logged in to post a comment.’) );

Comments on this blog

You can only leave a comment on this blog if your logged-in via the XSall.com OSO. You normally found out about this after you wrote a comment. This was quite some pain because you had to write your comment twice. I fixed this today. Now you can’t write a comment before you are logged-in.

Images again

I unable to upload images with the Flash up-loader from WordPress since I installed Flash 10. After Theo updated WordPress to the newest version I am able to “bypass” the Flash up-loader and select files the old way. So here is an Image for you:

How to fix a bug by WordPress

As I wrote here the famous WordPress bug would be fixed in version 2.5. So my blog was upgraded to version 2.5 by Theo. The bug is gone because I now can’t insert any image. I get some javascript errors if I try. Strange way to fix a bug.

Mullenweg wants you to be a podcaster on WordPress.com

3 Gigabyte on-line for your MP3’s. Will audio podcasters move from LibSyn or PodShow to WordPress.com? Read more.

WordPress Theme

I changed my WordPress Theme today. So all you RSS junkies visit my site to have a look. I wanted to use the color Red because there is Red in the Favicon and it is my old  “Trealize” color.

The Famous WordPress bug fixed in version 2.5 ?

The milestone for the famous bug I talked about here will be fixed in WordPress 2.5. This version will be out somewhere between new year and christmas. So I will need to do the bug hunting myself as promised.

In WordPress 2.3.1 most annoying bug not fixed

We are all suffering from the now famous WordPress bug but according to the bug report it is not fixed because the WordPress developers can’t reproduce the bug?? Perhaps only non English IE7 browsers produce the bug. If this is not fixed soon I will start hunting for the bug myself. It really starts to annoy me.