| @@ -1,19 +1,23 @@ | |||
| import { apptemplate, eventHnalder } from "@/common/app-template"; | |||
| import { AppID } from "@/common/appids"; | |||
| import { initMenuBox, setHeaderButton } from "@/common/header-button"; | |||
| import { KintoneEvent, サブテーブル設定, 値設定 } from "@/common/kintone-event"; | |||
| import { makeRecordData } from "@/common/rest-api-client"; | |||
| import { | |||
| ShowConfirmDialog, | |||
| SuccessDialog, | |||
| WarningDialog, | |||
| } from "@/middleware/swal"; | |||
| import { fillCandidates, noticeToCandidates } from "@/mypage/定期予約選考"; | |||
| import { | |||
| 定期予約選考, | |||
| 定期予約選考フィールド名, | |||
| 対象車室一覧行データ, | |||
| 選考ステータスDropdown, | |||
| } from "@/types/定期予約選考"; | |||
| import { 定期申込予約フィールド名, 状態Dropdown } from "@/types/定期申込予約"; | |||
| import { KintoneRestAPIClient } from "@kintone/rest-api-client"; | |||
| import { setup } from ".."; | |||
| import { KintoneEvent, サブテーブル設定, 値設定 } from "@/common/kintone-event"; | |||
| import { eventHnalder } from "@/common/app-template"; | |||
| import { forEach } from "lodash"; | |||
| import bulkRequest from "@/rest-api/bulk"; | |||
| // 検索用文字列をセットする | |||
| const setSearchCondition = (currentRecord: 定期予約選考) => { | |||
| @@ -38,82 +42,6 @@ const setSearchCondition = (currentRecord: 定期予約選考) => { | |||
| currentRecord.検索用_選考結果_レコード番号.value = results.join(","); | |||
| }; | |||
| const getCallBackHandleFillcandidates = (currentRecord: 定期予約選考) => { | |||
| return async () => { | |||
| const confirm = window.confirm("候補者を設定しますか?"); | |||
| if (!confirm || !currentRecord) return; | |||
| const result = await fillCandidates( | |||
| Number(currentRecord.レコード番号.value) | |||
| ); | |||
| if (result) { | |||
| window.alert("設定しました"); | |||
| location.reload(); | |||
| } else { | |||
| window.alert("失敗しました"); | |||
| } | |||
| }; | |||
| }; | |||
| const getCallBackHandleNoticeTocandidates = (currentRecord: 定期予約選考) => { | |||
| return async () => { | |||
| const confirm = window.confirm("対象者へメール送信しますか?"); | |||
| if (!confirm || !currentRecord) return; | |||
| const result = await noticeToCandidates( | |||
| Number(currentRecord.レコード番号.value) | |||
| ); | |||
| if (result) { | |||
| window.alert("通知しました"); | |||
| location.reload(); | |||
| } else { | |||
| window.alert("失敗しました"); | |||
| } | |||
| }; | |||
| }; | |||
| const getCallBackHandleFinish = (currentRecord: 定期予約選考) => { | |||
| return async () => { | |||
| const confirm = window.confirm("確定しますか"); | |||
| if (!confirm || !currentRecord) return; | |||
| const client = new KintoneRestAPIClient(); | |||
| // 選考のステータスを終了にする | |||
| const param = { | |||
| app: AppID.定期予約選考, | |||
| id: kintone.app.record.getId() ?? "", | |||
| record: makeRecordData({ | |||
| [定期予約選考フィールド名.選考ステータス]: 選考ステータスDropdown.終了, | |||
| }), | |||
| }; | |||
| // 申込のステータスを選考当選にする | |||
| const entries = { | |||
| app: AppID.定期申込予約, | |||
| records: currentRecord.選考結果一覧.value.map((row) => { | |||
| return { | |||
| id: row.value.選考結果一覧_申込レコード番号.value, | |||
| record: makeRecordData({ | |||
| [定期申込予約フィールド名.状態]: 状態Dropdown.選考当選, | |||
| }), | |||
| }; | |||
| }), | |||
| }; | |||
| try { | |||
| await client.record.updateRecord(param); | |||
| await client.record.updateRecords(entries); | |||
| } catch (e) { | |||
| // 失敗 | |||
| window.alert("失敗しました"); | |||
| throw e; | |||
| } | |||
| window.alert("成功しました。当選者の承認処理を行ってください"); | |||
| location.reload(); | |||
| }; | |||
| }; | |||
| setup(() => { | |||
| kintone.events.on( | |||
| [KintoneEvent.追加.レコード追加画面を表示した後], | |||
| @@ -160,7 +88,21 @@ setup(() => { | |||
| if (currentRecord.選考ステータス.value === 選考ステータスDropdown.起票) { | |||
| setHeaderButton( | |||
| "候補者設定", | |||
| getCallBackHandleFillcandidates(currentRecord) | |||
| apptemplate(async ({ needReloadAtEnd }) => { | |||
| const confirm = await ShowConfirmDialog({ | |||
| text: "候補者を設定しますか?", | |||
| }); | |||
| if (!confirm.isConfirmed || !currentRecord) return; | |||
| const result = await fillCandidates( | |||
| Number(currentRecord.レコード番号.value) | |||
| ); | |||
| if (!result) throw new Error(); | |||
| await SuccessDialog.fire(); | |||
| needReloadAtEnd(true); | |||
| }) | |||
| ); | |||
| } | |||
| if ( | |||
| @@ -169,14 +111,65 @@ setup(() => { | |||
| ) { | |||
| setHeaderButton( | |||
| "通知メール送信", | |||
| getCallBackHandleNoticeTocandidates(currentRecord) | |||
| apptemplate(async ({ needReloadAtEnd }) => { | |||
| const confirm = await ShowConfirmDialog({ | |||
| text: "対象者へメール送信しますか?", | |||
| }); | |||
| if (!confirm.isConfirmed || !currentRecord) return; | |||
| const result = await noticeToCandidates( | |||
| Number(currentRecord.レコード番号.value) | |||
| ); | |||
| if (!result) throw new Error(); | |||
| await SuccessDialog.fire(); | |||
| needReloadAtEnd(true); | |||
| }) | |||
| ); | |||
| } | |||
| if ( | |||
| currentRecord.選考ステータス.value === | |||
| 選考ステータスDropdown.候補者仮決定 | |||
| ) { | |||
| setHeaderButton("当選者確定", getCallBackHandleFinish(currentRecord)); | |||
| setHeaderButton( | |||
| "当選者確定", | |||
| apptemplate(async ({ needReloadAtEnd }) => { | |||
| const confirm = await ShowConfirmDialog({ text: "確定しますか" }); | |||
| if (!confirm.isConfirmed || !currentRecord) return; | |||
| const client = new KintoneRestAPIClient(); | |||
| // 選考のステータスを終了にする | |||
| bulkRequest.update({ | |||
| app: AppID.定期予約選考, | |||
| id: currentRecord.$id.value, | |||
| record: makeRecordData({ | |||
| [定期予約選考フィールド名.選考ステータス]: | |||
| 選考ステータスDropdown.終了, | |||
| }), | |||
| }); | |||
| // 申込のステータスを選考当選にする | |||
| currentRecord.選考結果一覧.value.forEach((row) => { | |||
| bulkRequest.update({ | |||
| app: AppID.定期申込予約, | |||
| id: row.value.選考結果一覧_申込レコード番号.value, | |||
| record: makeRecordData({ | |||
| [定期申込予約フィールド名.状態]: 状態Dropdown.選考当選, | |||
| }), | |||
| }); | |||
| }); | |||
| await bulkRequest.save(); | |||
| await SuccessDialog.fire(); | |||
| await WarningDialog.fire({ | |||
| text: "当選者の承認処理を行ってください", | |||
| }); | |||
| needReloadAtEnd(true); | |||
| }) | |||
| ); | |||
| } | |||
| }) | |||
| ); | |||