/* Copyright 2009 Palm, Inc.  All rights reserved. */

Photos.Scene.Summary = Class.create(Photos.Scene.Base, {
	setup: function($super) {
		$super();
		this.highlights = {items: []};
		this.controller.setupWidget('more_button', {}, {
			disabled: (this.sceneModel.more === undefined),
			label: this.sceneModel.getMoreText()
		});
		this.controller.setupWidget('highlights_list', {
			itemTemplate: this.templatePrefix + 'albums/entry'
		}, this.highlights);
		this.controller.get('title').update(
			this.sceneModel.getTitle());
		this.controller.get('headline').update(
			this.sceneModel.getHeadline());
		this.controller.get('highlight').update(
			this.sceneModel.getHighlightTitle());
		this.autoListen(this.controller.get('highlights_list'),
			Mojo.Event.listTap, this.highlightTapped.bind(this));
		this.autoListen(this.controller.get('headline_target'),
			Mojo.Event.tap, this.headlineTapped.bind(this));
		this.autoListen(this.controller.get('more_button'),
			Mojo.Event.tap, this.moreTapped.bind(this));
	},

	aboutToActivate: function($super, callback) {
		$super(callback);

		function gotHighlights(items) {
			this.highlights.items = $A(items);
			this.controller.modelChanged(this.highlights);
			this.ready();
		}

		this.sceneModel.requestHighlights(gotHighlights.bind(this));
	},

	showScene: function(scene, params) {
		this.pushWithTemplate(null, scene, params);
	},

	highlightTapped: function(event) {
		this.showScene('thumbs', {
			model: this.sceneModel.getThumbsModel(event.item)
		});
	},

	headlineTapped: function(event) {
		if (this.sceneModel.headline) {
			this.sceneModel.headline(this.showScene.bind(this));
		}
	},

	moreTapped: function(event) {
		if (this.sceneModel.more) {
			this.sceneModel.more(this.showScene.bind(this));
		}
	}
});

