Xmpp.Views.Popup ||= {}

class Xmpp.Views.Popup.FriendRequestView extends Xmpp.Views.Popup.PopupView
  template: JST["backbone/templates/popup/friend_request"]
  className: 'friend-reqeust'

  events:
    'submit form': 'approve'

  initialize: (options) ->
    @name = options.name
    @jid  = options.jid

    @events = _.extend(@events, @superEvents())

  render: ->
    super(@template(new_contact: @name))
    $(@el).css(width: '20%', 'z-index': 999)
    this

  approve: (e) ->
    e.preventDefault()
    App.debug ['approve request', @jid]
    App.Com.answerFriendRequest(@jid, true)
    @remove(e)

  close: (e) ->
    e.preventDefault()
    App.debug ['cancel request', @jid]
    App.Com.answerFriendRequest(@jid, false)
    @remove(e)