/*global alert*/
var app = require('ampersand-app');
var PageView = require('./base');
var templates = require('../templates');
var PersonForm = require('../forms/person');


module.exports = PageView.extend({
    pageTitle: 'view person',
    template: templates.pages.personView,
    bindings: {
        'model.fullName': {
            hook: 'name'
        },
        'model.avatar': {
            type: 'attribute',
            hook: 'avatar',
            name: 'src'
        },
        'model.editUrl': {
            type: 'attribute',
            hook: 'edit',
            name: 'href'
        }
    },
    events: {
        'click [data-hook~=delete]': 'handleDeleteClick'
    },
    initialize: function (spec) {
        var self = this;
        app.people.getOrFetch(spec.id, {all: true}, function (err, model) {
            if (err) alert('couldnt find a model with id: ' + spec.id);
            self.model = model;
        });
    },
    handleDeleteClick: function () {
        this.model.destroy({success: function () {
            app.navigate('collections');
        }});
    }
});
