Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ $(document).ready(function () {
* エラーメッセージを表示
* @param {string} errorKey - エラーコードに対応する
*/
function showError(errorKey) {
let message = $("#" + errorKey).val() || "不明なエラーが発生しました";
function showError(msgText="") {
let message = msgText || $("#error_api_generic").val();
$("#oaPolicyError").text(message).css({
"display": "inline-block",
"color": "red",
Expand All @@ -38,7 +38,6 @@ $(document).ready(function () {
* OAポリシー取得ボタンのクリックイベント
*/
$(document).on("click", "#oapolicyurl", function () {
console.log("[OA Policy] ボタンがクリックされました");
resetPolicyInfo();

// メタデータ入力ISSN, eISSN, 雑誌名を取得
Expand All @@ -51,35 +50,32 @@ $(document).ready(function () {

// 入力チェック
if (!issn && !eissn && !title) {
showError("error_missing_input");
showError($("#error_missing_input").val());
return;
}

console.log(`[API] リクエスト送信: issn=${issn}, eissn=${eissn}, title=${title}`);

// バックエンドへリクエストを送信
$.ajax({
url: "/items/api/oa_policies",
type: "GET",
data: { issn: issn, eissn: eissn, title: title },
dataType: "json"
url: "/items/api/oa_policies",
type: "GET",
data: { issn: issn, eissn: eissn, title: title },
dataType: "json"
}).done(function (data) {
if (data.policy_url) {
showResult(data.policy_url);
} else {
showError("error_no_policy_found");
showError($("#error_no_policy_found").val());
}
}).fail(function (xhr) {
console.error("[API] リクエストエラー:", xhr);

const errorMap = {
400: "error_api_400",
401: "error_api_401",
404: "error_api_404",
429: "error_api_429",
500: "error_api_500"
};
showError(errorMap[xhr.status] || "error_api_generic");
let errMsg = "";
try {
const res = JSON.parse(xhr.responseText);
errMsg = res.error || $("#error_api_generic").val();
} catch (e) {
// parse error, fallback to generic message
errMsg = $("#error_api_generic").val();
}
showError(errMsg);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -280,40 +280,27 @@ <h3 class="panel-title">Contributor</h3>
form-templates-base="{{ url_for('static', filename=config.DEPOSIT_FORM_TEMPLATES_BASE) }}"
template="{{ url_for('static', filename=config.DEPOSIT_UI_JSTEMPLATE_FORM) }}">
</invenio-records-form>
<!-- OA Policy リンク取得 -->

<div class="form-group row">
<!-- ラベル -->
<label for="policy" class="col-sm-3 col-form-label text-right">
{{ _('oa_policy_label') }}
</label>

<!-- ボタン + URL + エラーメッセージ -->
<div class="col-sm-9">
<div class="input-group">
<!-- Policy 取得ボタン -->
<button type="button" class="btn btn-primary" id="oapolicyurl">
{{ _('oa_policy_export') }}
</button>
<!-- URL 表示 -->
<a id="oaPolicyUrl" href="#" target="_blank" class="ml-2 d-none">
<span id="oaPolicyText"></span>
</a>

<!-- エラーメッセージ -->
<span id="oaPolicyError" class="text-danger ml-2" aria-live="polite"></span>
<div class="col-sm-12 style-component">
<label class="col-sm-3 col-form-label text-right">{{ _('oa_policy_label') }}</label>
<div class="col-sm-9">
<div class="input-group">
<button type="button" class="btn btn-primary" id="oapolicyurl">
{{ _('oa_policy_export') }}
</button>
<a id="oaPolicyUrl" href="#" target="_blank" class="ml-2 d-none">
<span id="oaPolicyText"></span>
</a>
<span id="oaPolicyError" class="text-danger ml-2" aria-live="polite"></span>
</div>
<input type="hidden" id="error_missing_input" value="{{ _('Please enter ISSN, eISSN, or journal title') }}">
<input type="hidden" id="error_no_policy_found" value="{{ _('No Policy Information found') }}">
<input type="hidden" id="error_api_generic" value="{{ _('An unknown error occurred') }}">
</div>

<!-- エラーメッセージ(翻訳適用) -->
<input type="hidden" id="error_missing_input" value="{{ _('Please enter ISSN, eISSN, or journal title') }}">
<input type="hidden" id="error_no_policy_found" value="{{ _('No Policy Information found') }}">
<input type="hidden" id="error_api_400" value="{{ _('Invalid parameters') }}">
<input type="hidden" id="error_api_401" value="{{ _('Authentication error occurred') }}">
<input type="hidden" id="error_api_404" value="{{ _('No matching policy') }}">
<input type="hidden" id="error_api_429" value="{{ _('Request limit exceeded') }}">
<input type="hidden" id="error_api_500" value="{{ _('Internal server error') }}">
<input type="hidden" id="error_api_generic" value="{{ _('An unknown error occurred') }}">
</div>
</div>

{%- block feedback_mail_list %}
<div id="react"></div>
<div id="request-maillist"></div>
Expand Down
Binary file not shown.
Loading