This repository has been archived by the owner on May 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #613 from algolia/feat/push-settings-button
feat(admin): add buttons to re-push the settings
- Loading branch information
Showing
5 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(function($) { | ||
|
||
$(function() { | ||
var $buttons = $('.algolia-push-settings-button'); | ||
$buttons.on('click', handleButtonClick); | ||
}); | ||
|
||
|
||
function handleButtonClick(e) { | ||
$clickedButton = $(e.currentTarget); | ||
var index = $clickedButton.data('index'); | ||
if (!index) { | ||
throw new Error('Clicked button has no "data-index" set.'); | ||
} | ||
|
||
disableButton($clickedButton); | ||
|
||
pushSettings($clickedButton, index); | ||
} | ||
|
||
function disableButton($button) { | ||
$button.prop('disabled', true); | ||
} | ||
|
||
function enableButton($button) { | ||
$button.prop('disabled', false); | ||
} | ||
|
||
function pushSettings($clickedButton, index) { | ||
|
||
var data = { | ||
'action': 'algolia_push_settings', | ||
'index_id': index | ||
}; | ||
|
||
$.post(ajaxurl, data, function(response) { | ||
if(typeof response.success === 'undefined') { | ||
alert('An error occurred'); | ||
enableButton($clickedButton); | ||
return; | ||
} | ||
|
||
alert('Settings correctly pushed for index: ' + index); | ||
enableButton($clickedButton); | ||
}).fail(function(response) { | ||
alert('An error occurred: ' + response.responseText); | ||
enableButton($clickedButton); | ||
}); | ||
} | ||
|
||
})(jQuery); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters