Skip to content

Instantly share code, notes, and snippets.

@ricogallo
Created November 27, 2012 15:56
Show Gist options
  • Save ricogallo/4155028 to your computer and use it in GitHub Desktop.
Save ricogallo/4155028 to your computer and use it in GitHub Desktop.
class window.ServicesView extends CommonView
SLOGAN_PLACEHOLDER: 'Enter a Slogan here. Sell your skills in a sentence.'
template: =>
"""
<div el="slogan_wrap">
<span el="counter"></span>
<textarea el="slogan"
placeholder="#{ServicesView::SLOGAN_PLACEHOLDER}"
maxlength="140"
size="140"></textarea>
</div>
<div class="button_row blank">
<a class="button sky" go="create_service">Add Product</a>
</div>
<div el="services">
<div style="clear:both"></div>
</div>
"""
bind: ->
@services = new ServiceList(@services_el)
# Inline editing for slogan
if @user
@slogan_wrap_el.html(
"""
<div class="slogan">
#{@user.slogan || ServicesView::SLOGAN_PLACEHOLDER}
</div>
"""
)
else
Helpers.inlineEditSetup 'slogan',
@slogan_el,
ServicesView::SLOGAN_PLACEHOLDER,
user
@counter_el.text("#{140 - @slogan_el.val().length} characters left")
@slogan_el.keydown =>
@counter_el.text("#{140 - @slogan_el.val().length} characters left")
# Build methods so that we can have nice urls
# For each permalink we need a url
@services.onItemClick (e) =>
item = e.item
if item.id == 'add'
if window.user
@go 'create_service'
else
target = e.targetNode[0]
if target.className.indexOf('remove') > -1
if confirm("""Are you sure you want to remove product "#{e.item.title}"?""")
@removeService(e.item)
else if target.className.indexOf('edit') > -1
@go 'edit_service', id: item.id
else # if target.className.indexOf('book_now') > -1
if window.user
if window.user.id == item.provider_id
@go 'inform_of_booking'
else if window.user.is_seller
@go 'seller_cant_book'
else
@current_service = item
@go item.permalink
else
new QuickSignup(=>
@go 'book_service', id: item.id
location.reload()
)
update: ->
super()
if @user
services = @user.services.map (s) -> new Service(s)
services.unshift({id:'add'})
@services.setItems(services)
removeService: (service) ->
service.remove (_user) =>
CurrentUser.setData(_user)
@user = window.user
page.notice "Your product has been removed."
@update()
create_service: ->
form = new CreateServiceForm (_user) =>
CurrentUser.setData(_user)
@user = window.user
form.close()
page.notice "Congratulations your product has been published"
@update()
edit_service: ->
form = new EditServiceForm (user) =>
window.user = new CurrentUser(user)
@user = window.user
page.notice "Your product was updated"
form.close()
@update()
inform_of_booking: ->
view = new CallFunctionView () =>
AlertDialogue.open(
"""
When others click this you'll receive a booking request.
"""
, () =>
@go 'default'
)
seller_cant_book: ->
view = new CallFunctionView () =>
AlertDialogue.open(
"""
Oops! Looks like you don't have a buyer account. Send an email
to info@milk.ly to have one activated.
"""
, () =>
@go 'default'
)
class ServiceList extends PureList
template: (service) ->
if service.id == 'add'
"""
<div class="service blank">
<div class="addService">
<div class="plus"></div>
<div class="under">
Add product
</div>
</div>
</div>
"""
else
category_icon = service.getCategory().icon ||
service.getCategory().parent().icon
footer_added = ''
if window.user && user.id == service.provider_id
footer_added += """
<div class="my_options">
<a class="serviceAction remove">Remove</a>
<a class="serviceAction edit">Edit</a>
</div>
"""
"""
<div class="service">
<div class="image">
<img src="#{service.getImage()}" onload="ImageHelper.fitSquare(this, 320)"/>
</div>
<div class="info">
<div class="category">
<img class="icon" src="#{category_icon}"/>
#{service.getCategory().name}
</div>
<div class="title">
#{service.title}
</div>
<div class="description">
#{service.description}
<div class="overlay white-fadeout"></div>
</div>
</div>
<div class="footer">
<!--
<div class="duration">Duration #{service.humanDuration()}</div>
-->
<div class="price">#{service.humanPrice()}</div>
#{footer_added}
</div>
</div>
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment