Skip to content

Instantly share code, notes, and snippets.

@camwest
Created July 10, 2009 20:17
Show Gist options
  • Select an option

  • Save camwest/144781 to your computer and use it in GitHub Desktop.

Select an option

Save camwest/144781 to your computer and use it in GitHub Desktop.
public class EpisodeItemViewPresentationModel extends EventDispatcher
{
//-----------------------------------------------
// Statics
//-----------------------------------------------
public static const PUBLISHED:String = "published";
public static const UPLOADING:String = "uploading";
public static const PENDING:String = "pending";
//-----------------------------------------------
// Getters & Setters
//-----------------------------------------------
private var _episode:Episode;
private var changeWatcher:ChangeWatcher;
[Bindable(Event="stateChanged")] public function get episode():Episode
{
return _episode;
}
public function set episode(value:Episode):void
{
_episode = value;
// watch for changes on the id property of the episode
changeWatcher = ChangeWatcher.watch(value, "id", episodeIdChangeListener, false, true);
dispatchEvent( new Event("stateChanged") );
}
// ~~~~~~~~~~~~~~~~~~ state ~~~~~~~~~~~~~~~~~~~~~
private var _state:String = UPLOADING;
[Bindable(Event="stateChanged")] public function get state():String
{
if ( episode.approved ) {
return PUBLISHED;
} else {
if ( episode.video_url ) {
return PENDING;
}
}
return _state;
}
//-----------------------------------------------
// Constructor
//-----------------------------------------------
private var dispatcher:IEventDispatcher;
public function EpisodeItemViewPresentationModel(dispatcher:IEventDispatcher)
{
this.dispatcher = dispatcher;
}
//-----------------------------------------------
// Public
//-----------------------------------------------
public function cancel():void
{
dispatcher.dispatchEvent( new EpisodeEvent( EpisodeEvent.CANCEL_UPLOAD ) );
_state = PENDING;
dispatchEvent( new Event("stateChanged") );
}
//-----------------------------------------------
// Private
//-----------------------------------------------
//-----------------------------------------------
// Event Handlers
//-----------------------------------------------
private function episodeIdChangeListener(e:PropertyChangeEvent):void
{
dispatchEvent( new Event("stateChanged") );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment