jquery-form: Remove jquery-form use from get-API-key form in user settings.

This commit is contained in:
Yashashvi Dave
2018-05-18 18:51:44 +05:30
parent 9278cdf75b
commit 3654d4f92d
4 changed files with 30 additions and 25 deletions

View File

@@ -65,9 +65,9 @@ casper.then(function () {
*/ */
casper.then(function () { casper.then(function () {
casper.waitUntilVisible('#get_api_key_password', function () { casper.waitUntilVisible('#get_api_key_button', function () {
casper.fill('form[action^="/json/fetch_api_key"]', {password:test_credentials.default_user.password}); casper.fill('#get_api_key_form', {password:test_credentials.default_user.password});
casper.click('button[name="view_api_key"]'); casper.click('#get_api_key_button');
}); });
}); });

View File

@@ -93,8 +93,6 @@ run_test('set_up', () => {
$.validator = { addMethod: function () {} }; $.validator = { addMethod: function () {} };
$("#get_api_key_box form").ajaxForm = function () {};
$("#create_bot_form").validate = function () {}; $("#create_bot_form").validate = function () {};
$('#create_bot_type').on = function (action, f) { $('#create_bot_type').on = function (action, f) {

View File

@@ -165,14 +165,22 @@ exports.set_up = function () {
$("#get_api_key_box").hide(); $("#get_api_key_box").hide();
$("#show_api_key_box").hide(); $("#show_api_key_box").hide();
$("#get_api_key_box form").ajaxForm({
dataType: 'json', // This seems to be ignored. We still get back an xhr. $("#get_api_key_button").on("click", function (e) {
success: function (resp, statusText, xhr) { var data = {};
var result = JSON.parse(xhr.responseText); e.preventDefault();
e.stopPropagation();
data.password = $("#get_api_key_password").val();
channel.post({
url: '/json/fetch_api_key',
dataType: 'json',
data: data,
success: function (data) {
var settings_status = $('#account-settings-status').expectOne(); var settings_status = $('#account-settings-status').expectOne();
$("#get_api_key_password").val(""); $("#get_api_key_password").val("");
$("#api_key_value").text(result.api_key); $("#api_key_value").text(data.api_key);
$("#show_api_key_box").show(); $("#show_api_key_box").show();
$("#get_api_key_box").hide(); $("#get_api_key_box").hide();
settings_status.hide(); settings_status.hide();
@@ -183,6 +191,7 @@ exports.set_up = function () {
$("#get_api_key_box").show(); $("#get_api_key_box").show();
}, },
}); });
});
$("#show_api_key_box").on("click", "button.regenerate_api_key", function () { $("#show_api_key_box").on("click", "button.regenerate_api_key", function () {
channel.post({ channel.post({

View File

@@ -195,14 +195,12 @@
<div id="get_api_key_box"> <div id="get_api_key_box">
<p>{{t "Please re-enter your password to confirm your identity." }} <p>{{t "Please re-enter your password to confirm your identity." }}
<a href="/accounts/password/reset/" target="_blank">{{t "Never had one? Forgotten it?" }}</a></p> <a href="/accounts/password/reset/" target="_blank">{{t "Never had one? Forgotten it?" }}</a></p>
<form action="/json/fetch_api_key" method="post" class="form-horizontal"> <form cslass="form-horizontal" id="get_api_key_form">
<div class="control-group"> <div class="control-group">
<label for="password" class="control-label">{{t "Current password" }}</label> <label for="password" class="control-label">{{t "Current password" }}</label>
<input type="password" autocomplete="off" <input type="password" autocomplete="off"
name="password" id="get_api_key_password" value="" /> name="password" id="get_api_key_password" value="" />
</div> <button type="submit" name="view_api_key" id="get_api_key_button"
<div class="control-group">
<button type="submit" name="view_api_key"
class="button sea-green">{{t 'Get API key' }}</button> class="button sea-green">{{t 'Get API key' }}</button>
</div> </div>
</form> </form>