Changeset View
Changeset View
Standalone View
Standalone View
assets/src/bundles/save/index.js
/** | /** | ||||
* Copyright (C) 2018-2021 The Software Heritage developers | * Copyright (C) 2018-2021 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
import {handleFetchError, csrfPost, isGitRepoUrl, htmlAlert, removeUrlFragment} from 'utils/functions'; | import {handleFetchError, isGitRepoUrl, htmlAlert, removeUrlFragment} from 'utils/functions'; | ||||
import {swhSpinnerSrc} from 'utils/constants'; | import {swhSpinnerSrc} from 'utils/constants'; | ||||
let saveRequestsTable; | let saveRequestsTable; | ||||
function originSaveRequest(originType, originUrl, | function originSaveRequest(originType, originUrl, | ||||
acceptedCallback, pendingCallback, errorCallback) { | acceptedCallback, pendingCallback, errorCallback) { | ||||
let addSaveOriginRequestUrl = Urls.origin_save_request(originType, originUrl); | let addSaveOriginRequestUrl = Urls.api_1_save_origin(originType, originUrl); | ||||
let headers = { | |||||
'Accept': 'application/json', | |||||
'Content-Type': 'application/json' | |||||
}; | |||||
$('.swh-processing-save-request').css('display', 'block'); | $('.swh-processing-save-request').css('display', 'block'); | ||||
csrfPost(addSaveOriginRequestUrl, headers) | fetch(addSaveOriginRequestUrl, {method: 'POST'}) | ||||
.then(handleFetchError) | .then(handleFetchError) | ||||
.then(response => response.json()) | .then(response => response.json()) | ||||
.then(data => { | .then(data => { | ||||
$('.swh-processing-save-request').css('display', 'none'); | $('.swh-processing-save-request').css('display', 'none'); | ||||
if (data.save_request_status === 'accepted') { | if (data.save_request_status === 'accepted') { | ||||
acceptedCallback(); | acceptedCallback(); | ||||
} else { | } else { | ||||
pendingCallback(); | pendingCallback(); | ||||
▲ Show 20 Lines • Show All 422 Lines • Show Last 20 Lines |