Controller   = window.require 'spine/controller'
Activateable = window.require 'spine/controller/activateable'
Content      = window.require 'core/models/content'

###
# @deprecated
###
class PhotoItem extends Controller
	className : 'service-photo-item loading'
	elements  : 'img'	: 'img'

	@include Activateable

	photoOptions 	: null
	photoData		: null
	
	constructor: ->
		super
		@$bind('click', @toggle)
		@item = new Content()
		@listenTo Content, 'destroy', @_destroy
		@listenTo Content, 'create', @_create

	toggle: (e)=>
		return if @el.is '.loading'
		if @isActive()
			@item.destroy()
		else
			atts 					= {}
			atts["#{@attribute}"] 	= @photoData
			atts["options"] 	  	= @photoOptions
			@item.updateAttributes atts, {@attribute,from:@}

	done: =>
		@$trigger('itemReady').$removeClass 'loading'

	error: =>
		@$trigger('itemReady').release()

	_destroy: (item) =>
		if @item and item and item.eql(@item)
			@deactivate()
			@item = new Content()

	_create: (item) =>
		if @item and item and item.eql(@item)
			@activate()

module.exports = PhotoItem