Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (48 sloc) 2.16 KB
Base class for the two classes, DetailsReader and DetailsEditor, which are used
to implement the read and edit modes, respectively, on a contact card. The
shared aspects of the modes' layout and API is represented in this shared base
class window.ContactDetails extends Control
# Arrange content into two simple columns that can be populated by subclasses.
content: [
{ html: "div", ref: "left" }
{ html: "div", ref: "main" }
# The contact() property lets us set all the fields at once. Defining this
# with lets us keep a reference to the Contact object that
# was passed in.
contact: ( contact ) ->
# Define the main content() of a ContactDetails to be the contact.
content: Control.chain "contact"
# Expose the left and main regions as properties for use by subclasses.
left: Control.chain "$left", "content"
main: Control.chain "$main", "content"
# The base ContactDetails class exposes an API with getter/setter functions
# for address(), email(), etc., but leaves it subclasses to actually define
# where those values will be displayed. The Control.chain() helper generates
# a function that will set/get the content of the element/control with the
# given reference.
address: Control.chain "$address", "content"
email: Control.chain "$email", "content"
name: Control.chain "$name", "content"
phone: Control.chain "$phone", "content"
photo: Control.chain( "$photo", "prop/src", ( photo ) ->
# Hide img if photo is null; can't just set src to empty string.
# See
@$photo().toggle photo isnt null
# (Re)load the contact data into the control's fields. This is done when the
# contact is set, or when the control wants to update the displayed values in
# response to contact changes.
refresh: ->
contact = @contact()
# To invoke setters, we pass an empty value if the field is undefined.
@name ? ""
@email ? ""
@address contact.address() ? ""
@phone ? ""
@photo ? null