<repo_name>hbrysiewicz/sony-proto<file_sep>/app/routes/index.js
import Ember from 'ember';
import App from 'proto/app';
import Image from 'proto/models/image';

export default Ember.Route.extend({
  // setupController: function(controller) {
  //   // get all images for default canvas
  //   var cat = Image.create({
  //     guid: App.generateUUID(),
  //     x: 300,
  //     y: 300,
  //     height: 50,
  //     width: 50,
  //     url: 'http://upload.wikimedia.org/wikipedia/commons/2/22/Turkish_Van_Cat.jpg',
  //     layer: 1
  //   });
  //   controller.set('content', [cat]);
  // }
});

<file_sep>/app/controllers/index.js
import Ember from 'ember';
import App from 'proto/app';
import Image from 'proto/models/image';

export default Ember.ArrayController.extend({
  queryParams: ['serialized'],
  isAdding: false,
  newImage: null,

  serialized: function(key, val) {
    if (arguments.length === 2) {
      var parsed = JSON.parse(decodeURI(val));
      var content = [];
      parsed.forEach(function(item) {
        item = Image.create(item);
        content.pushObject(item);
      });
      this.set('content', content);
      return val;
    }
    return encodeURI(JSON.stringify(this.get('content')));
  }.property('content.@each','content.@each.x','content.@each.y'),

  actions: {
    addImage: function() {
      this.set('isAdding', true);
      var newImage = Image.create();
      this.set('newImage', newImage);
    },

    saveImage: function() {
      var newImage = this.get('newImage');
      var newGuid = App.generateUUID();
      newImage.set('guid', newGuid);
      this.get('content').pushObject(newImage);
      this.set('newImage', null);
    }
  }
});
<file_sep>/app/app.js
import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
import config from './config/environment';

Ember.MODEL_FACTORY_INJECTIONS = true;

var App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver: Resolver
});

App.generateUUID = function() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
    return v.toString(16);
  });
};

loadInitializers(App, config.modulePrefix);

export default App;
