Skip to content

Instantly share code, notes, and snippets.

@darkleaf
Created August 2, 2013 08:15
Show Gist options
  • Save darkleaf/6138275 to your computer and use it in GitHub Desktop.
Save darkleaf/6138275 to your computer and use it in GitHub Desktop.
$ ->
$groups_selector = $('#user_advertisement_company_fb_page_id')
$fb_accounts_selector = $('#user_advertisement_company_facebook_account_id')
$stub_message = $('<option/>', text: 'Идет загрузка…')
group_filler = ->
if @value
previous_value = $('option', $groups_selector).val()
$groups_selector.html $stub_message
$.getJSON "/api/facebook_accounts/#{@value}/pages", (data) ->
$groups_selector.empty()
$.each data, (index, page) ->
$groups_selector.append $('<option/>', value: page.id, text: page.name)
$groups_selector.val previous_value
else
$groups_selector.empty()
group_filler.call $fb_accounts_selector[0]
$fb_accounts_selector.change group_filler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment