Commit c1e1eba7 by Takumi Imai

Merge branch 'feature/1.0_check_web_dev_son' into 'feature/1.0_check_web_dev'

implement alert and confirm modal

See merge request !60
parents 4447a725 e926cb25
<button type="button" id="showConfirmModalButton" class="btn btn-sm btn-tertiary d-none" data-toggle="modal" data-target="#confirm-modal"></button>
<div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog"> <div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content"> <div class="modal-content">
......
...@@ -45,6 +45,97 @@ COMMON.closeLoading = function () { ...@@ -45,6 +45,97 @@ COMMON.closeLoading = function () {
}; };
/** /**
* show confirm modal with yes, no buttons
* @param {Object} data - Object with {title, message, confirmYes, confirmNo}
* @param {callback} confirmCallback - The callback that handles the confirm button clicked
*/
COMMON.showConfirmModal = function (data, confirmCallback) {
if (data) {
let title = '';
if (data.title) {
title = data.title;
}
$('#confirm-modal .modal-title').text(title);
let message = '';
if (data.message) {
message = data.message;
}
$('#confirm-modal #msgModel').text(message);
if (data.confirmYes) {
$('#confirm-modal #confirmYes').text(data.confirmYes);
$('#confirm-modal #confirmYes').removeClass('d-none');
$('#confirm-modal #confirmYes').off('click');//remove all old click handlers
$('#confirm-modal #confirmYes').click(function() {
$('#confirm-modal .close').click();
if (confirmCallback) {
confirmCallback();
}
});
} else {
$('#confirm-modal #confirmYes').addClass('d-none');
}
if (data.confirmNo) {
$('#confirm-modal #confirmNo').text(data.confirmNo);
$('#confirm-modal #confirmNo').removeClass('d-none');
} else {
$('#confirm-modal #confirmNo').addClass('d-none');
}
}
$('#showConfirmModalButton').click();
};
/**
* Show confirm modal with defaults: title, yes, no
* @param {string} messageCode
* @param {callback} confirmCallback - The callback that handles the confirm button clicked
* @param {Object} options - Object with {title, message, confirmYes, confirmNo}
*/
COMMON.showConfirm = function (messageCode, confirmCallback, options = {}) {
const defaultParams = {
titleCode: 'confirmation',
confirmYesCode: 'confirmYes',
confirmNoCode: 'confirmNo'
}
const params = Object.assign(options, defaultParams);
let message = '';
if (messageCode) {
message = I18N.i18nText(messageCode);
} else if (params.message) {
message = params.message;
}
COMMON.showConfirmModal({
message: message,
title: I18N.i18nText(params.titleCode),
confirmYes: I18N.i18nText(params.confirmYesCode),
confirmNo: I18N.i18nText(params.confirmNoCode)
}, confirmCallback);
};
/**
* show alert message by confirm modal html
* @param {String} messageCode
* @param {Object} options - Data Options {message, titleCode, confirmNoCode}
*/
COMMON.showAlert = function (messageCode, options = {}) {
const defaultParams = {
titleCode: 'confirmation',
confirmNoCode: 'confirmNo'
}
const params = Object.assign(options, defaultParams);
let message = '';
if (messageCode) {
message = I18N.i18nText(messageCode);
} else if (params.message) {
message = params.message;
}
COMMON.showConfirmModal({
message: message,
title: I18N.i18nText(params.titleCode),
confirmNo: I18N.i18nText(params.confirmNoCode)
});
};
/**
* show alert * show alert
* *
* @param {String} msgCode * @param {String} msgCode
......
...@@ -117,5 +117,6 @@ ...@@ -117,5 +117,6 @@
"reportForm": "Report", "reportForm": "Report",
"periodicInspectionPeriod": "Periodic Inspection Period", "periodicInspectionPeriod": "Periodic Inspection Period",
"msgSendPushMessageSuccess":"we sent a push message", "msgSendPushMessageSuccess":"we sent a push message",
"error": "Error" "error": "Error",
"msgSendPushMessageConfirm": "Do you want to send message?"
} }
\ No newline at end of file
...@@ -115,5 +115,6 @@ ...@@ -115,5 +115,6 @@
"reportForm": "報告", "reportForm": "報告",
"periodicInspectionPeriod": "定期点検期間", "periodicInspectionPeriod": "定期点検期間",
"msgSendPushMessageSuccess":"プッシュメッセージ送信しました。", "msgSendPushMessageSuccess":"プッシュメッセージ送信しました。",
"error": "エラー" "error": "エラー",
"msgSendPushMessageConfirm": "Do you want to send message?"
} }
\ No newline at end of file
...@@ -114,5 +114,6 @@ ...@@ -114,5 +114,6 @@
"reportForm": "보고서", "reportForm": "보고서",
"periodicInspectionPeriod": "정기점검기간", "periodicInspectionPeriod": "정기점검기간",
"msgSendPushMessageSuccess":"푸시메시지를 보냈습니다.", "msgSendPushMessageSuccess":"푸시메시지를 보냈습니다.",
"error": "에러" "error": "에러",
"msgSendPushMessageConfirm": "Do you want to send message?"
} }
\ No newline at end of file
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
<!-- select template modal --> <!-- select template modal -->
<div id="includeTemplateModal"></div> <div id="includeTemplateModal"></div>
<div id="includeConfirmModal"></div>
<script type="text/javascript" src="../common/js/app.js"></script> <script type="text/javascript" src="../common/js/app.js"></script>
<script src="../common/js/event.js?__UPDATEID__"></script> <script src="../common/js/event.js?__UPDATEID__"></script>
</body> </body>
......
...@@ -39,21 +39,21 @@ SendMessage.getCurrentSendType = function () { ...@@ -39,21 +39,21 @@ SendMessage.getCurrentSendType = function () {
SendMessage.checkValidation = function () { SendMessage.checkValidation = function () {
const message = SendMessage.getCurrentMessageContent(); const message = SendMessage.getCurrentMessageContent();
if (!ValidationUtil.CheckRequiredForText(message)) { if (!ValidationUtil.CheckRequiredForText(message)) {
alert(I18N.i18nText('msgContentRequired')); COMMON.showAlert('msgContentRequired');
return false; return false;
} }
if (!ValidationUtil.CheckMaxLengthForByte(message, SendMessage.contentMaxLength)) { if (!ValidationUtil.CheckMaxLengthForByte(message, SendMessage.contentMaxLength)) {
alert(COMMON.format(I18N.i18nText('msgContentInvalidLength'), SendMessage.contentMaxLength)); COMMON.showAlert(null, {message: COMMON.format(I18N.i18nText('msgContentInvalidLength'), SendMessage.contentMaxLength)});
return false; return false;
} }
const operationId = SendMessage.getCurrentOperationId(); const operationId = SendMessage.getCurrentOperationId();
if (!ValidationUtil.IsNumber(operationId)) { if (!ValidationUtil.IsNumber(operationId)) {
alert(I18N.i18nText('msgOperationRequired')); COMMON.showAlert('msgOperationRequired');
return false; return false;
} }
const sendType = SendMessage.getCurrentSendType(); const sendType = SendMessage.getCurrentSendType();
if (!ValidationUtil.IsNumber(sendType)) { if (!ValidationUtil.IsNumber(sendType)) {
alert(I18N.i18nText('msgSendTypeRequired')); COMMON.showAlert('msgSendTypeRequired');
return false; return false;
} }
return true; return true;
...@@ -69,7 +69,9 @@ SendMessage.onClickSend = function () { ...@@ -69,7 +69,9 @@ SendMessage.onClickSend = function () {
const message = SendMessage.getCurrentMessageContent(); const message = SendMessage.getCurrentMessageContent();
const operationId = SendMessage.getCurrentOperationId(); const operationId = SendMessage.getCurrentOperationId();
const sendType = SendMessage.getCurrentSendType(); const sendType = SendMessage.getCurrentSendType();
SendMessage.postMessage(message, operationId, sendType); COMMON.showConfirm('msgSendPushMessageConfirm', function() {
SendMessage.postMessage(message, operationId, sendType);
});
}; };
/** /**
...@@ -92,7 +94,7 @@ SendMessage.postMessage = function (message, operationId, sendType) { ...@@ -92,7 +94,7 @@ SendMessage.postMessage = function (message, operationId, sendType) {
false, false,
function (json) { function (json) {
COMMON.closeLoading(); COMMON.closeLoading();
alert(I18N.i18nText('msgSendPushMessageSuccess')); COMMON.showAlert('msgSendPushMessageSuccess');
}, },
function () { function () {
console.log('SendMessage.postMessage error'); console.log('SendMessage.postMessage error');
...@@ -126,13 +128,14 @@ SendMessage.init = function () { ...@@ -126,13 +128,14 @@ SendMessage.init = function () {
//Check if user is logged in //Check if user is logged in
COMMON.checkAuth(false); COMMON.checkAuth(false);
TEMPLATE.loadHeader('#includedHeader'); TEMPLATE.loadHeader('#includedHeader');
TEMPLATE.loadConfirmModal('#includeConfirmModal');
const navs = [ const navs = [
{ {
titleLang: 'dashboard', titleLang: 'dashboard',
href: 'dashboard.html', href: 'dashboard.html',
}, },
{ {
titleLang: 'sendMessageTitle', titleLang: 'sendMessage',
}, },
]; ];
TEMPLATE.loadMainNavsTitle('#includedMainTitle', 'sendMessage', navs, null); TEMPLATE.loadMainNavsTitle('#includedMainTitle', 'sendMessage', navs, null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment