ken_nogi/pleasanter/develop/#リフォームラボ/■イオン多摩平シフト管理/sites/scripts/3.予定編集ウインドウ.js
Kenichiro NOGI 7176dc33ec pleasanter
2025-07-10 10:15:35 +09:00

137 lines
5.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
@config : next999.json
@filename : ${psFileBasename}
@title : 3.予定編集ウインドウ
@name :
@siteIds : 310511
@siteTitles : イオン多摩平シフト管理
@disabled: false
*/
//$(document).on('click', 'div.item', function (e) {
$p.ex.changeTimeDataWindow = function (dataId, pageX, pageY) {
const $item = $('div.item[data-id="' + dataId + '"]');
$('#edit-modal').remove();
const itemId = $item.attr('data-id');
const posX = pageX;
const posY = pageY;
// 既存データ取得
const textParts = $item.text().trim().split('-');
const startTime = textParts[1] ? textParts[1].trim() : '';
const endTime = textParts[2] ? textParts[2].trim() : '';
// 休憩時間NumDがデータに含まれていれば取得、なければ自動計算
let restTime = '';
if (textParts[3]) {
restTime = textParts[3].trim();
} else if (startTime !== '' && endTime !== '') {
const diff = parseInt(endTime, 10) - parseInt(startTime, 10);
restTime = (diff > 4) ? 1 : 0;
} else {
restTime = 0;
}
// モーダルHTML休憩時間も追加
const modalHtml = `
<div id="edit-modal" style="
position: absolute; left: ${posX}px; top: ${posY}px; z-index: 99999;
background: #fff; border: 1px solid #888; border-radius: 8px; padding: 16px; box-shadow: 0 2px 12px #888;">
<label>開始時間: <input type="number" id="edit-start" min="0" max="23" value="${startTime}" style="width:60px;"> 時</label><br>
<label>終了時間: <input type="number" id="edit-end" min="0" max="23" value="${endTime}" style="width:60px;"> 時</label><br>
<label>休憩時間: <input type="number" id="edit-rest" min="0" max="8" value="${restTime}" style="width:60px;" readonly> 時</label>
</div>
`;
$('body').append(modalHtml);
$('body').css('overflow', 'hidden');
// 入力制限ロジック
$('#edit-start, #edit-end').on('input', function () {
let start = parseInt($('#edit-start').val(), 10);
let end = parseInt($('#edit-end').val(), 10);
// startTimeはendTimeより大きくできない
if (!isNaN(end)) {
$('#edit-start').attr('max', end);
} else {
$('#edit-start').attr('max', 23);
}
// endTimeはstartTimeより小さくできない
if (!isNaN(start)) {
$('#edit-end').attr('min', start);
} else {
$('#edit-end').attr('min', 0);
}
// 休憩時間自動計算
if (!isNaN(start) && !isNaN(end)) {
const diff = end - start;
const rest = (diff > 4) ? 1 : 0;
$('#edit-rest').val(rest);
} else {
$('#edit-rest').val(0);
}
});
setTimeout(() => {
$(document).on('mousedown.editModal', async function (event) {
if (!$(event.target).closest('#edit-modal').length) {
// 入力値取得
const newStart = $('#edit-start').val();
const newEnd = $('#edit-end').val();
const newRest = $('#edit-rest').val();
// 変更がない場合は何もせず閉じる
if (newStart === startTime && newEnd === endTime && newRest == restTime) {
$('#edit-modal').remove();
$(document).off('mousedown.editModal');
$('body').css('overflow', '');
return;
}
// 更新リクエスト送信
const pleasanterUrl = 'https://' + location.hostname + '/pleasanter/api/items/' + itemId + '/update';
const jsonBody = {
'ApiVersion': 1.1,
'ApiKey': apiKey,
'NumHash': {
'NumA': newStart,
'NumB': newEnd,
'NumD': newRest // 休憩時間を追加
}
};
try {
const pleasanterRes = await fetch(pleasanterUrl, {
'method': 'POST',
'headers': { 'Content-Type': 'application/json' },
'body': JSON.stringify(jsonBody)
});
const resData = await pleasanterRes.json();
if (resData.StatusCode === 200) {
$('#edit-modal').remove();
$(document).off('mousedown.editModal');
$('body').css('overflow', '');
location.reload();
} else {
alert('更新に失敗しました');
$('#edit-modal').remove();
$(document).off('mousedown.editModal');
$('body').css('overflow', '');
}
} catch (err) {
alert('通信エラーが発生しました');
$('#edit-modal').remove();
$(document).off('mousedown.editModal');
$('body').css('overflow', '');
}
}
});
}, 10);
}
// モーダル内クリック時は閉じない
$(document).on('click', '#edit-modal', function (e) {
e.stopPropagation();
});