/** * Copyright (c) 2007 - 2009 Adobe * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ package insync.contacts.presentation { import flash.events.Event; import flash.events.EventDispatcher; import insync.application.ContentDestination; import insync.contacts.Contact; import insync.contacts.RemoveContactEvent; import insync.contacts.SaveContactEvent; import insync.messaging.ComposeMessageEvent; [Event(name="compose", type="insync.messaging.ComposeMessageEvent")] [ManagedEvents(names="compose")] public class ContactFormPM extends EventDispatcher { public static const SAVED:String="saved"; [MessageDispatcher] public var dispatcher:Function; [Bindable] public var canRemove:Boolean=true; [Bindable] [CommandStatus(type="insync.contacts.SaveContactEvent")] public var isSaving:Boolean; [Bindable] public var status:String; public function sendMessage(contact:Contact):void { dispatcher(ComposeMessageEvent.newComposeMessage(contact, ContentDestination.MESSAGE_COMPOSE)); } public function canSave(isSaving:Boolean, isValid:Boolean):Boolean { return !isSaving && isValid; } [Bindable("saved")] public function getContactHeading(contact:Contact):String { return contact && contact.id > 0 ? contact.fullName : "New Contact"; } [Bindable("saved")] public function getContactId(contact:Contact):String { return contact.id > 0 ? String(contact.id) : "-"; } public function remove(contact:Contact):void { dispatcher(new RemoveContactEvent(contact)); } public function save(contact:Contact):void { dispatcher(new SaveContactEvent(contact)); status="Saving contact..."; } [CommandResult] public function onSaveResult(result:*, event:SaveContactEvent):void { status="Contact saved."; dispatchEvent(new Event(SAVED)); } [CommandError] public function onSaveFault(result:*, event:SaveContactEvent):void { status="Unable to save contact."; } } }