Changeset View
Changeset View
Standalone View
Standalone View
assets/src/bundles/admin/deposit.js
/** | /** | ||||
* Copyright (C) 2018-2022 The Software Heritage developers | * Copyright (C) 2018-2022 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 {getHumanReadableDate} from 'utils/functions'; | import {getHumanReadableDate, genLink} from 'utils/functions'; | ||||
function genSwhLink(data, type, linkText = '') { | function genSwhLink(data, type, linkText = '') { | ||||
if (type === 'display' && data && data.startsWith('swh')) { | if (type === 'display' && data && data.startsWith('swh')) { | ||||
const browseUrl = Urls.browse_swhid(data); | const browseUrl = Urls.browse_swhid(data); | ||||
const formattedSWHID = data.replace(/;/g, ';<br/>'); | const formattedSWHID = data.replace(/;/g, ';<br/>'); | ||||
if (!linkText) { | if (!linkText) { | ||||
linkText = formattedSWHID; | linkText = formattedSWHID; | ||||
} | } | ||||
return `<a href="${browseUrl}">${linkText}</a>`; | return `<a href="${browseUrl}">${linkText}</a>`; | ||||
} | } | ||||
return data; | return data; | ||||
} | } | ||||
function genLink(data, type, openInNewTab = false, linkText = '') { | |||||
if (type === 'display' && data) { | |||||
const sData = encodeURI(data); | |||||
if (!linkText) { | |||||
linkText = sData; | |||||
} | |||||
let attrs = ''; | |||||
if (openInNewTab) { | |||||
attrs = 'target="_blank" rel="noopener noreferrer"'; | |||||
} | |||||
return `<a href="${sData}" ${attrs}>${linkText}</a>`; | |||||
} | |||||
return data; | |||||
} | |||||
export function initDepositAdmin(username, isStaff) { | export function initDepositAdmin(username, isStaff) { | ||||
let depositsTable; | let depositsTable; | ||||
$(document).ready(() => { | $(document).ready(() => { | ||||
$.fn.dataTable.ext.errMode = 'none'; | $.fn.dataTable.ext.errMode = 'none'; | ||||
depositsTable = $('#swh-admin-deposit-list') | depositsTable = $('#swh-admin-deposit-list') | ||||
.on('error.dt', (e, settings, techNote, message) => { | .on('error.dt', (e, settings, techNote, message) => { | ||||
$('#swh-admin-deposit-list-error').text(message); | $('#swh-admin-deposit-list-error').text(message); | ||||
}) | }) | ||||
▲ Show 20 Lines • Show All 159 Lines • Show Last 20 Lines |