common.js 37.8 KB
Newer Older
1 2 3 4 5 6 7 8 9
/**
 * common js of app(web).
 * The following is written.
 * 1.language
 * 2.loading
 * 3.alert
 * 4.url
 * 5.cms communication
 * 6.check if user is logged in
Takumi Imai committed
10
 * 7.jquery event
11 12 13
 *
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
 */
Takumi Imai committed
14 15
var COMMON = {};

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
CONSTANT.PAGE_NAME = {
    DASHBOARD: 'dashboard',
    OPERATION_LIST: 'workList',
    REPORT_LIST: 'reportList',
    REPORT_FORM: 'reportForm',
    MESSAGE_DETAIL: 'pushMessageDetail',
    MESSAGE_LIST: 'pushMessageList',
    SEND_MESSAGE: 'sendMessage',
    SETTING: 'accountSetting',
    PICKUP: 'pickup',
    PDF_PRINT: 'pdfPrint',
    DEFAULT: 'index',
    LOGIN: './login.html',
};

COMMON.loginCheckPageList = [CONSTANT.PAGE_NAME.DEFAULT, CONSTANT.PAGE_NAME.DASHBOARD, CONSTANT.PAGE_NAME.REPORT_LIST, CONSTANT.PAGE_NAME.REPORT_FORM,
     CONSTANT.PAGE_NAME.MESSAGE_DETAIL, CONSTANT.PAGE_NAME.MESSAGE_LIST, CONSTANT.PAGE_NAME.SEND_MESSAGE, CONSTANT.PAGE_NAME.SETTING,
     CONSTANT.PAGE_NAME.PICKUP, CONSTANT.PAGE_NAME.PDF_PRINT];
Takumi Imai committed
34

35 36
COMMON.hasErrorKey = 'AVW_HASERR';
$(document).ready(function() {
37 38
    const checkUrl = location.href.substring(location.href.lastIndexOf('/') + 1 ,location.href.lastIndexOf(".html"));
    if (COMMON.loginCheckPageList.includes(checkUrl)) {
39 40 41 42 43
        if (!COMMON.checkLogin(CONSTANT.PAGE_NAME.LOGIN)){
            return;
        }
    }
})
Takumi Imai committed
44 45 46 47
/**
 * page transition without outputting a warning message
 * @param {*} url
 */
Takumi Imai committed
48
COMMON.avwScreenMove = function (url) {
49
    COMMON.showLoading();
Takumi Imai committed
50 51 52 53 54 55 56 57 58 59 60
    window.onbeforeunload = null;
    window.location = url;
};

/**
 * show loading dialog
 * show msg by key
 *
 * @param {String} key
 */
COMMON.showLoading = function () {
Kang Donghun committed
61 62 63 64
    // $(window).resize(function() {
    $('#loader').css( {
        'width': $(window).width(),
        'height': $(window).height()
Kang Donghun committed
65
    });
Kang Donghun committed
66
    // });
67
    document.getElementById('loader').style.display = 'block';
Takumi Imai committed
68 69 70 71 72 73
};

/**
 * close loading
 */
COMMON.closeLoading = function () {
74 75 76
    setTimeout(function(){ 
        document.getElementById('loader').style.display = 'none';
    }, 1000);
Takumi Imai committed
77 78 79
};

/**
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
 * 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 = {
NGUYEN HOANG SON committed
153
        titleCode: 'error',
NGUYEN HOANG SON committed
154
        confirmNoCode: 'close'
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    }
    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)
    });
};

/**
Takumi Imai committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
 * close alert
 */
COMMON.alertClose = function () {
    $('.alert-overlay').addClass('d-none');
    $('.alert-area').addClass('d-none');
    $('body').css('overflow', 'visible');
};

/**
 * go Url page With Current Params
 *
 * ios will remove all web types data when reopen webview
 * need add common parameters: app, lang, debug, mobile_flg, isChat, ...
 *
 * @param {String} url
 * @param {Object} params
 */
COMMON.goUrlWithCurrentParams = function (url, params) {
    if (!params) {
        location.href = CONSTANT.URL.WEB.BASE + url;
    }

    const mixParams = Object.assign(COMMON.getUrlParameter(), params);
    if (url.includes('?')) {
        location.href = url + '&' + new URLSearchParams(mixParams);
    } else {
        location.href = url + '?' + new URLSearchParams(mixParams);
    }
};

/**
 * get url parameter
 *
 */
COMMON.getUrlParameter = function () {
    var ret = {};
    if (location.search) {
        var param = {};
        location.search
            .substring(1)
            .split('&')
            .forEach(function (val) {
                var kv = val.split('=');
                param[kv[0]] = kv[1];
            });
        ret = param;
    }
    console.log({ ret: ret });
    return ret;
};

/**
 * get sid in local Storage
 *
 */
COMMON.getSid = function () {
    return ClientData.userInfo_sid();
};

/**
 * cms communication
 *
 * @param {String} url
 * @param {Json} param
 * @param {boolean} async
 * @param {Object} callback
 * @param {Object} errorCallback
Takumi Imai committed
238
 * @param {number} type
Takumi Imai committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
 */
COMMON.cmsAjax = function (url, param, async = true, callback, errorCallback, type) {
    var sysSettings = new COMMON.sysSetting();
    if (url) {
        $.ajax({
            type: 'post',
            url: url,
            data: param,
            dataType: type ? type : 'json',
            cache: false,
            async: async,
            crossDomain: true,
            beforeSend: function (xhr) {
                xhr.setRequestHeader('X-AGT-AppId', sysSettings.appName);
                xhr.setRequestHeader('X-AGT-AppVersion', sysSettings.appVersion);
            },
            success: function (result) {
                if (type == 'text') {
                    if (callback) callback(result);
                    return;
                }
                if (result.httpStatus == '200') {
                    if (callback) callback(result);
                } else if (errorCallback) {
                    errorCallback(result);
                } else if (result.httpStatus == '401') {
                    COMMON.goUrlWithCurrentParams(CONSTANT.PAGE_NAME.LOGIN);
                } else if (result.httpStatus == '403') {
267
                    COMMON.closeLoading();
268
                    COMMON.showAlert('errorOccurred');
Takumi Imai committed
269
                } else {
270
                    COMMON.closeLoading();
271
                    COMMON.showAlert(result.message);
Takumi Imai committed
272 273 274 275 276 277
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (errorCallback) {
                    errorCallback(XMLHttpRequest, textStatus, errorThrown);
                } else {
278
                    COMMON.closeLoading();
279
                    COMMON.showAlert('errorCommunicationFailed');
Takumi Imai committed
280 281 282 283 284 285 286
                }
            },
        });
    } else {
        if (errorCallback) {
            errorCallback();
        } else {
287
            COMMON.closeLoading();
288
            COMMON.showAlert('errorOccurred');
Takumi Imai committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
        }
    }
};

/**
 * Check if user is logged in
 *
 * @param {boolean} async
 */
COMMON.checkAuth = function (async = true) {
    let params = {};
    params.sid = COMMON.getSid;
    const url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.AUTH_SESSION;
    COMMON.cmsAjax(url, params, async, null, function () {
        COMMON.goUrlWithCurrentParams(CONSTANT.PAGE_NAME.LOGIN);
    });
};

var ClientData = {
Takumi Imai committed
308
    // Local :userInfo_account path:String
Takumi Imai committed
309 310 311 312 313 314 315 316
    userInfo_accountPath: function (data) {
        if (arguments.length > 0) {
            COMMON.userSetting().set(CONSTANT.KEYS.userInfo_accountPath, data);
        } else {
            return COMMON.userSetting().get(CONSTANT.KEYS.userInfo_accountPath);
        }
    },

Takumi Imai committed
317
    // Local :userInfo_loginID:String
Takumi Imai committed
318 319 320 321 322 323 324 325
    userInfo_loginId: function (data) {
        if (arguments.length > 0) {
            COMMON.userSetting().set(CONSTANT.KEYS.userInfo_loginId, data);
        } else {
            return COMMON.userSetting().get(CONSTANT.KEYS.userInfo_loginId);
        }
    },

Takumi Imai committed
326
    // Local :userInfo_Account Information Storage Flag:Char(Y:Available, N:Not Available)
Takumi Imai committed
327 328 329 330 331 332 333 334
    userInfo_rememberLogin: function (data) {
        if (arguments.length > 0) {
            COMMON.userSetting().set(CONSTANT.KEYS.userInfo_rememberLogin, data);
        } else {
            return COMMON.userSetting().get(CONSTANT.KEYS.userInfo_rememberLogin);
        }
    },

Takumi Imai committed
335
    // Session :userInfo_loginID:String
Takumi Imai committed
336 337 338 339 340 341 342 343
    userInfo_loginId_session: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.userInfo_loginId, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.userInfo_loginId);
        }
    },

Takumi Imai committed
344
    // Session :userInfo_account path:String
Takumi Imai committed
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
    userInfo_accountPath_session: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.userInfo_accountPath, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.userInfo_accountPath);
        }
    },

    // Session
    userInfo_userName: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.userInfo_userName, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.userInfo_userName);
        }
    },

Takumi Imai committed
362
    // Local :userInfo_Last login date and time:Datetime
Takumi Imai committed
363 364 365 366 367 368 369 370
    userInfo_lastLoginTime: function (data) {
        if (arguments.length > 0) {
            COMMON.operateData(arguments, CONSTANT.KEYS.userInfo_lastLoginTime, undefined);
        } else {
            return COMMON.operateData(arguments, CONSTANT.KEYS.userInfo_lastLoginTime, undefined);
        }
    },

Takumi Imai committed
371
    // Session:userInfo_SessionID:String
Takumi Imai committed
372 373 374 375 376 377 378 379 380 381 382 383 384
    userInfo_sid: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.userInfo_sid, data);
            // COMMON.userSetting().set(CONSTANT.KEYS.userInfo_sid, data);
        } else {
            // return COMMON.userSetting().get(CONSTANT.KEYS.userInfo_sid);
            if (COMMON.userSession()) {
                return SessionStorageUtils.get(CONSTANT.KEYS.userInfo_sid);
            }
            return null;
        }
    },

Takumi Imai committed
385
    // Local: userInfo_SessionID:String
Takumi Imai committed
386 387 388 389 390 391 392 393
    userInfo_sid_local: function (data) {
        if (arguments.length > 0) {
            COMMON.userSetting().set(CONSTANT.KEYS.userInfo_sid_local, data);
        } else {
            return COMMON.userSetting().get(CONSTANT.KEYS.userInfo_sid_local);
        }
    },

Takumi Imai committed
394
    // Local: Session ID backup
Takumi Imai committed
395 396 397 398 399 400 401 402
    userInfo_sid_local_bak: function (data) {
        if (arguments.length > 0) {
            COMMON.userSetting().set(CONSTANT.KEYS.userInfo_sid_bak, data);
        } else {
            return COMMON.userSetting().get(CONSTANT.KEYS.userInfo_sid_bak);
        }
    },

Takumi Imai committed
403
    // Session :Notification information (pushInfo)_Number of new arrivals:Interger
Takumi Imai committed
404 405 406 407 408 409 410 411
    pushInfo_newMsgNumber: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.pushInfo_newMsgNumber, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.pushInfo_newMsgNumber);
        }
    },

Takumi Imai committed
412
    // apiUrl
Takumi Imai committed
413 414 415 416 417 418 419
    conf_apiUrl: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.conf_apiUrl, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.conf_apiUrl);
        }
    },
Takumi Imai committed
420 421

    // api login url
Takumi Imai committed
422 423 424 425 426 427 428
    conf_apiLoginUrl: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.conf_apiLoginUrl, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.conf_apiLoginUrl);
        }
    },
Takumi Imai committed
429 430

    //check api url
Takumi Imai committed
431 432 433 434 435 436 437
    conf_checkApiUrl: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.conf_checkApiUrl, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.conf_checkApiUrl);
        }
    },
Takumi Imai committed
438 439

    // api resorce dl url
Takumi Imai committed
440 441 442 443 444 445 446 447
    conf_apiResourceDlUrl: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.conf_apiResourceDlUrl, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.conf_apiResourceDlUrl);
        }
    },

Takumi Imai committed
448
    // Local :userInfo_password_skip_datetime:Datetime
Takumi Imai committed
449 450 451 452 453 454 455 456
    userInfo_pwdSkipDt: function (data) {
        if (arguments.length > 0) {
            COMMON.operateData(arguments, CONSTANT.KEYS.userInfo_pwdSkipDt, undefined);
        } else {
            return COMMON.operateData(arguments, CONSTANT.KEYS.userInfo_pwdSkipDt, undefined);
        }
    },

Takumi Imai committed
457
    // Session :Business Option (serviceOpt)_ABookCheck:Char(Y:Enable, N:Disable)
Takumi Imai committed
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
    serviceOpt_abook_check: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.serviceOpt_abook_check, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.serviceOpt_abook_check);
        }
    },

    // Session : Tenant Service_Option(serviceOpt)_ChatFunction:Char(Y:Use, N:Unused)
    serviceOpt_chat_function: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.serviceOpt_abook_check, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.serviceOpt_abook_check);
        }
    },

Takumi Imai committed
475
    // Session :Business Option(serviceOpt)_Forced password change at first login:Integer(0:None, 1:Prompt, 2:Forced)
Takumi Imai committed
476 477 478 479 480 481 482 483
    serviceOpt_force_pw_change_on_login: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.serviceOpt_force_pw_change_on_login, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.serviceOpt_force_pw_change_on_login);
        }
    },

Takumi Imai committed
484
    // Session :Business Option(serviceOpt)_Forced password change at regular login:Integer(0:None, 1:Prompt, 2:Forced)
Takumi Imai committed
485 486 487 488 489 490 491 492
    serviceOpt_force_pw_change_periodically: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.serviceOpt_force_pw_change_periodically, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.serviceOpt_force_pw_change_periodically);
        }
    },

Takumi Imai committed
493
    // Session :Business option (serviceOpt)_arbitrary push message:Char(Y:possible, N:not possible)
Takumi Imai committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
    serviceOpt_usable_push_message: function (data) {
        if (arguments.length > 0) {
            SessionStorageUtils.set(CONSTANT.KEYS.serviceOpt_usable_push_message, data);
        } else {
            return SessionStorageUtils.get(CONSTANT.KEYS.serviceOpt_usable_push_message);
        }
    },

    // Local
    JumpQueue: function (data) {
        if (arguments.length > 0) {
            COMMON.operateData(arguments, CONSTANT.KEYS.JumpQueue, []);
        } else {
            return COMMON.operateData(arguments, CONSTANT.KEYS.JumpQueue, []);
        }
    },

    // Local
    IsJumpBack: function (data) {
        if (arguments.length > 0) {
            COMMON.operateData(arguments, CONSTANT.KEYS.IsJumpBack, undefined);
        } else {
            return COMMON.operateData(arguments, CONSTANT.KEYS.IsJumpBack, undefined);
        }
    },
};

/*
 * Variables
 */
COMMON.userSessionObj = null;
COMMON.userSettingObj = null;
COMMON.sysSettingObj = null;

/*
 * User Settings Class Definition
 */
var UserSetting = function () {
    this.US_KEY = 'AVWUS';
    this.userSetting = this.load();
};
/* get user setting from localStorage */
UserSetting.prototype.load = function () {
    var storage = window.localStorage;
    var value = null;
    var js = null;
    if (storage) {
        var value = storage.getItem(this.US_KEY);
        if (!value) {
Takumi Imai committed
543
            value = '{}'; // empty JSON string
Takumi Imai committed
544 545 546 547 548
        }
        js = JSON.parse(value);
    }
    return js;
};
Takumi Imai committed
549 550 551 552 553 554

/**
 * store user setting
 * @param {*} key
 * @param {*} value
 */
Takumi Imai committed
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
UserSetting.prototype.set = function (key, value) {
    this.userSetting = this.load();
    var values = this.userSetting;
    if (!values) {
        values = { key: value };
    } else {
        values[key] = value;
    }
    var storage = window.localStorage;
    if (storage) {
        var jsonStr = JSON.stringify(values);
        storage.setItem(this.US_KEY, jsonStr);
    }
    this.userSetting = values;
};
Takumi Imai committed
570 571 572 573 574 575

/**
 *  grab user setting
 * @param {*} key
 * @returns
 */
Takumi Imai committed
576 577 578 579 580 581 582 583
UserSetting.prototype.get = function (key) {
    this.userSetting = this.load();
    var values = this.userSetting;
    if (values) {
        return values[key];
    }
    return null;
};
Takumi Imai committed
584 585 586 587 588

/**
 * show user setting object list
 * @param {*} elmid
 */
Takumi Imai committed
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
UserSetting.prototype.show = function (elmid) {
    var storage = window.localStorage;
    var tags = '<p>';
    if (storage) {
        var value = storage.getItem(this.US_KEY);
        if (value) {
            var js = JSON.parse(value);
            $.each(js, function (k, v) {
                tags = tags + '<b>' + k + '</b>:' + v + '<br />';
            });
        }
        tags = tags + '</p>';
        $(elmid).html(tags);
    }
};
Takumi Imai committed
604
/* Retrieve a list of user-set keys */
Takumi Imai committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
UserSetting.prototype.keys = function () {
    var storage = window.localStorage;
    var keyList = [];
    if (storage) {
        var value = storage.getItem(this.US_KEY);
        if (value) {
            var js = JSON.parse(value);
            var i = 0;
            $.each(js, function (k, v) {
                keyList[i++] = k;
            });
        }
        return keyList;
    }
    return null;
};
Takumi Imai committed
621 622 623 624 625

/**
 * Delete user settings
 * @param {*} key
 */
Takumi Imai committed
626 627 628 629 630 631 632 633 634 635 636 637 638
UserSetting.prototype.remove = function (key) {
    var storage = window.localStorage;
    if (storage) {
        var value = storage.getItem(this.US_KEY);
        if (value) {
            var js = JSON.parse(value);
            if (js) {
                delete js[key];
                storage.setItem(this.US_KEY, JSON.stringify(js));
            }
        }
    }
};
Takumi Imai committed
639
/* Delete all user settings */
Takumi Imai committed
640 641 642 643 644 645 646 647 648 649 650 651 652
UserSetting.prototype.removeAll = function () {
    var storage = window.localStorage;
    if (storage) {
        storage.remove(this.US_KEY);
    }
};

/*
 * User Session Class Definition
 */
var UserSession = function () {
    this.available = false;
};
Takumi Imai committed
653 654 655 656 657

/**
 * Initialize User Session
 * @param {*} option
 */
Takumi Imai committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
UserSession.prototype.init = function (option) {
    this.available = false;
    if (option == 'restore') {
        var value = null;
        try {
            value = this._get('init');
        } catch (e) {
            value = null;
        } finally {
            if (value) {
                this.available = true;
            }
        }
    } else {
        this.set('init', new Date().toLocaleString());
        this.available = true;
    }
};
Takumi Imai committed
676 677 678 679 680 681

/**
 * store key, value item to user session
 * @param {*} key
 * @param {*} value
 */
Takumi Imai committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695
UserSession.prototype.set = function (key, value) {
    var storage = window.sessionStorage;
    if (storage) {
        if (this.available == false) {
            if (key == 'init') {
                storage.setItem('AVWS_' + key, value);
            } else {
                throw new Error('Session destoryed.');
            }
        } else {
            storage.setItem('AVWS_' + key, value);
        }
    }
};
Takumi Imai committed
696 697 698 699 700 701

/**
 * get session item value
 * @param {*} key
 * @returns
 */
Takumi Imai committed
702 703 704 705 706 707 708 709 710
UserSession.prototype.get = function (key) {
    var value = null;
    if (this.available) {
        value = this._get(key);
    } else {
        throw new Error('Session Destroyed.');
    }
    return value;
};
Takumi Imai committed
711 712 713 714 715 716

/**
 * get item value from session storage
 * @param {*} key
 * @returns
 */
Takumi Imai committed
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
UserSession.prototype._get = function (key) {
    var storage = window.sessionStorage;
    var value = null;
    if (storage) {
        value = storage.getItem('AVWS_' + key);
    }
    return value;
};
/* destroy user session */
UserSession.prototype.destroy = function () {
    var storage = window.sessionStorage;
    if (storage) {
        storage.clear();
        this.available = false;
    }
};
Takumi Imai committed
733 734 735 736 737

/**
 * show user session object list
 * @param {*} elmid
 */
Takumi Imai committed
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
UserSession.prototype.show = function (elmid) {
    var storage = window.sessionStorage;
    var tags = '<p>';
    if (storage) {
        for (var i = 0; i < storage.length; i++) {
            var key = storage.key(i);
            var value = storage.getItem(key);
            tags = tags + '<b>' + key + '</b>:' + value + '<br />';
        }
        tags = tags + '</p>';
        $(elmid).html(tags);
    }
};

/* Initialize system */
$(function () {
Takumi Imai committed
754
    // Determine the path where the system configuration files are located
Takumi Imai committed
755 756 757 758 759 760 761 762 763 764

    var location = window.location.toString().toLowerCase();

    var sysFile = '';
    if (location.indexOf('/abweb') < 0) {
        sysFile = '../abweb/common/json/sys/conf.json';
    } else {
        sysFile = '../common/json/sys/conf.json';
    }

Takumi Imai committed
765
    // Read the system configuration file
Takumi Imai committed
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
    $.ajax({
        url: sysFile,
        async: false,
        cache: false,
        dataType: 'json',
        success: function (data) {
            COMMON.sysSettingObj = data;
        },
        error: function (xmlHttpRequest, txtStatus, errorThrown) {
            var error = 'Could not load the system configuration file. Please check it.';
            error += '\n' + xmlHttpRequest.status + ' ' + txtStatus + ' ' + errorThrown + ' : ' + sysFile;
            alert(error);
        },
    });

Takumi Imai committed
781
    // Clear error conditions once at load time.
Takumi Imai committed
782 783
    COMMON.clearError();

Takumi Imai committed
784
    //#31919 [Investigation] Business meeting support system GoogleChrome does not work with Bitch in/out.
Takumi Imai committed
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
    navigator.pointerEnabled = navigator.maxTouchPoints > 0; // Edge 17 touch support workaround
    document.documentElement.ontouchstart = navigator.maxTouchPoints > 0 ? function () {} : undefined; // Chrome 70 touch support workaround
});

// Hide the locking layout
COMMON.unlockLayout = function () {
    $('#avw-sys-modal').hide();
};

// Show the locking layout
COMMON.lockLayout = function () {
    if (document.getElementById('avw-sys-modal')) {
        $('#avw-sys-modal').show();
    } else {
        var tags = '<div id="avw-sys-modal"></div>';
        $('body').prepend(tags);
        $('#avw-sys-modal').css({
            opacity: 0.7,
            position: 'fixed',
            top: '0',
            left: '0',
            width: $(window).width(),
            height: $(window).height(),
            background: '#999',
            'z-index': 100,
        });
        // resize error page
        $(window).resize(function () {
            $('#avw-sys-modal').css({
                width: $(window).width(),
                height: $(window).height(),
            });
        });
    }
};

Takumi Imai committed
821
/* Clear error condition */
Takumi Imai committed
822 823 824 825 826 827
COMMON.clearError = function () {
    var session = window.sessionStorage;
    if (session) {
        session.setItem(COMMON.hasErrorKey, false);
    }
};
Takumi Imai committed
828
/* Get error status */
Takumi Imai committed
829 830 831 832 833 834 835 836
COMMON.hasError = function () {
    var session = window.sessionStorage;
    var isError = false;
    if (session) {
        isError = session.getItem(COMMON.hasErrorKey);
    }
    return isError == 'true';
};
Takumi Imai committed
837
/* Set to error condition */
Takumi Imai committed
838 839 840 841 842 843
COMMON.setErrorState = function () {
    var session = window.sessionStorage;
    if (session) {
        session.setItem(COMMON.hasErrorKey, true);
    }
};
Takumi Imai committed
844

Takumi Imai committed
845 846 847 848 849 850 851 852 853
/* get user session object */
COMMON.userSession = function () {
    if (!COMMON.userSessionObj) {
        var obj = new UserSession();
        obj.init('restore');
        if (obj.available) {
            COMMON.userSessionObj = obj;
            return COMMON.userSessionObj;
        } else {
Kang Donghun committed
854
            return null;
Takumi Imai committed
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
        }
    }
    return COMMON.userSessionObj;
};
/* create user session object */
COMMON.createUserSession = function () {
    if (COMMON.userSessionObj) {
        COMMON.userSessionObj.destroy();
    } else {
        COMMON.userSessionObj = new UserSession();
        COMMON.userSessionObj.init();
    }
    return COMMON.userSessionObj;
};

/* get user setting object */
COMMON.userSetting = function () {
    if (COMMON.userSettingObj == null) {
        COMMON.userSettingObj = new UserSetting();
    }
    return COMMON.userSettingObj;
};

/* get system setting object */
COMMON.sysSetting = function () {
    return COMMON.sysSettingObj;
};

/*
 * Operations for session storage [start]
 */

var SessionStorageUtils = {
    login: function () {
        if (COMMON.userSession()) {
            // Skip this case
        } else {
            COMMON.avwCreateUserSession();
        }
    },
    get: function (strKey) {
        return COMMON.userSession().get(strKey);
    },
    set: function (strKey, objValue) {
        COMMON.userSession().set(strKey, objValue);
    },
    clear: function () {
        if (COMMON.userSession()) {
            COMMON.userSession().destroy();
        }
    },
    remove: function (strKey) {
        COMMON.userSession().set(strKey, null);
    },
};

/*
 * Operations for local storage
 */
var LocalStorageUtils = {
    getUniqueId: function () {
        var uniqueId = '';

        if (COMMON.userSetting().get(CONSTANT.KEYS.userInfo_accountPath)) {
            uniqueId += COMMON.userSetting().get(CONSTANT.KEYS.userInfo_accountPath);
        }
        if (COMMON.userSetting().get(CONSTANT.KEYS.userInfo_loginId)) {
            uniqueId += '.' + COMMON.userSetting().get(CONSTANT.KEYS.userInfo_loginId);
        }
        if (uniqueId != '') {
            uniqueId += '.';
        }

        return uniqueId;
    },
    get: function (strKey) {
        var key = this.getUniqueId() + strKey;

        return COMMON.userSetting().get(key);
    },
    set: function (strKey, objValue) {
        var key = this.getUniqueId() + strKey;
        COMMON.userSetting().set(key, objValue);
    },
    remove: function (strKey) {
        var key = this.getUniqueId() + strKey;
        COMMON.userSetting().remove(key);
        SessionStorageUtils.remove(strKey);
    },
    clear: function () {
        var localStorageKeys = COMMON.userSetting().keys();
        for (var nIndex = 0; nIndex < localStorageKeys.length; nIndex++) {
            var strKey = localStorageKeys[nIndex];

            if ((strKey + '').contains(this.getUniqueId())) {
                COMMON.userSetting().remove(strKey);
            }
        }
    },
    existKey: function (strKey) {
        var keys = COMMON.userSetting().keys();
        var findKey = this.getUniqueId() + strKey;
        var isExisted = false;
        if (keys != null && keys != undefined) {
            for (var nIndex = 0; nIndex < keys.length; nIndex++) {
                if (keys[nIndex] == findKey) {
                    isExisted = true;
                    break;
                }
            }
        }
        return isExisted;
    },
};

Takumi Imai committed
970 971 972 973 974
/**
 * String.format function def.
 * @param {*} fmt
 * @returns
 */
Takumi Imai committed
975 976 977 978 979 980 981 982
COMMON.format = function (fmt) {
    for (var i = 1; i < arguments.length; i++) {
        var reg = new RegExp('\\{' + (i - 1) + '\\}', 'g');
        fmt = fmt.replace(reg, arguments[i]);
    }
    return fmt;
};

Takumi Imai committed
983 984 985 986 987 988
/**
 * Get param url
 * @param {*} name
 * @param {*} url
 * @returns
 */
Takumi Imai committed
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
COMMON.getUrlParam = function (name, url) {
    if (!url) {
        url = window.location.href;
    }

    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regexS = '[\\?&]' + name + '=([^&#]*)';
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null) {
        return '';
    } else {
        return results[1];
    }
};

Takumi Imai committed
1005
// Toogle Logout Nortice
Takumi Imai committed
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
COMMON.ToogleLogoutNortice = function () {
    window.onbeforeunload = function (event) {
        var message = I18N.i18nText('sysInfoWithoutLogout');
        var e = event || window.event;
        if (e) {
            e.returnValue = message;
        }
        return message;
    };
};

Takumi Imai committed
1017 1018
/**
 * * Get data from localstorage and sessionstorage synchronization If has any
Takumi Imai committed
1019 1020 1021 1022
 * param (args.length > 0) -> setter If has not param (args.length = 0) ->
 * getter . Get from session: + if it existed and key existed in localstorage ->
 * return result + else: set value from local to sessionstorage -> return value
 * of sessionstorage if value is not empty, otherwise, return default result.
Takumi Imai committed
1023 1024 1025 1026
 * @param {*} args
 * @param {*} strKey
 * @param {*} returnDefaultData
 * @returns
Takumi Imai committed
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
 */
COMMON.operateData = function (args, strKey, returnDefaultData) {
    if (args.length > 0) {
        var data = args[0];
        LocalStorageUtils.set(strKey, data);
        SessionStorageUtils.set(strKey, JSON.stringify(data));
    } else {
        if (
            SessionStorageUtils.get(strKey) != 'undefined' &&
            SessionStorageUtils.get(strKey) != undefined &&
            SessionStorageUtils.get(strKey) != '' &&
            SessionStorageUtils.get(strKey) != null &&
            SessionStorageUtils.get(strKey) != 'null'
        ) {
            if (LocalStorageUtils.existKey(strKey) == true) {
                return JSON.parse(SessionStorageUtils.get(strKey));
            } else {
                return returnDefaultData;
            }
        } else {
            if (LocalStorageUtils.existKey(strKey) == true) {
                SessionStorageUtils.set(strKey, JSON.stringify(LocalStorageUtils.get(strKey)));
                return JSON.parse(SessionStorageUtils.get(strKey));
            }
            return returnDefaultData;
        }
    }
};

/**
 * UTC current Time (millisecond)
 *
 * @returns UTC time
 */
COMMON.currentTime = function () {
    return Date.now();
};

1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
/**
 * check login information in window.sessionStorage
 *
 * @returns boolean
 */
COMMON.checkLogin = function (option) {
    var userSession = COMMON.userSession();
    if(!userSession) {

        /* エラー画面を表示 */
        var tags = '<div id="avw-auth-error">' +
                   '<div style="display:table; width:100%; height:100%;">' +
                   '<div style="display:table-cell; text-align:center; vertical-align:middle;">' +
                   '<p><h4>Authentication error</h4>Please use it after login.</p>' +
                   '<div><button id="avw-unauth-ok">OK</button></div>' +
                   '</div></div></div>';
        $('body').prepend(tags);
        $('#avw-auth-error').css({
            'opacity': 1,
            'position': 'fixed',
            'top': '0',
            'left': '0',
1087
            'background': "#ffffff",
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
            'width': $(window).width(),
            'height': $(window).height(),
            'zIndex': '10000'
        });
        // resize error page
        $(window).resize(function() {
            $('#avw-auth-error').css( {
                'width': $(window).width(),
                'height': $(window).height()
            });
        });

        var returnPage;
        if(option) {
            returnPage = option
        } else {
            var sysSetting = COMMON.sysSetting();
            returnPage = sysSetting.loginPage;
        }
        /* ログイン画面に戻る */
        $('#avw-unauth-ok').click(function() {
            window.location = returnPage;
        });
        return false;
    }
    return true;
}

Takumi Imai committed
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
/*
 * Operations for session storage [ end ]
 */

// =============================================================================================
// Utils for string, date, number [start]
// =============================================================================================
/*
 * Convert date to JP format date time [start]
 */

/*
 * YYYY/MM/DD HH:MM:SS
 */
Date.prototype.jpDateTimeString = function () {
    var strResult = '';
    var strYear = this.getFullYear() + '';
    var strMonth = this.getMonth() + 1 + '';
    var strDayInMonth = this.getDate() + '';
    var strHour = this.getHours() + '';
    var strMinute = this.getMinutes() + '';
    var strSecond = this.getSeconds() + '';

    strResult += strYear.padLeft('0', 4) + '/' + strMonth.padLeft('0', 2) + '/' + strDayInMonth.padLeft('0', 2);
    strResult += ' ' + strHour.padLeft('0', 2) + ':' + strMinute.padLeft('0', 2) + ':' + strSecond.padLeft('0', 2);
    return strResult;
};
/*
 * YYYY-MM-DD HH:MM:SS
 */
Date.prototype.jpDateTimeString1 = function () {
    var strResult = '';
    var strYear = this.getFullYear() + '';
    var strMonth = this.getMonth() + 1 + '';
    var strDayInMonth = this.getDate() + '';
    var strHour = this.getHours() + '';
    var strMinute = this.getMinutes() + '';
    var strSecond = this.getSeconds() + '';

    strResult += strYear.padLeft('0', 4) + '-' + strMonth.padLeft('0', 2) + '-' + strDayInMonth.padLeft('0', 2);
    strResult += ' ' + strHour.padLeft('0', 2) + ':' + strMinute.padLeft('0', 2) + ':' + strSecond.padLeft('0', 2);
    return strResult;
};
/*
 * yyyy/MM/dd
 */
Date.prototype.jpDateString = function () {
    var strResult = '';
    var strYear = this.getFullYear() + '';
    var strMonth = this.getMonth() + 1 + '';
    var strDayInMonth = this.getDate() + '';

    strResult += strYear.padLeft('0', 4) + '/' + strMonth.padLeft('0', 2) + '/' + strDayInMonth.padLeft('0', 2);

    return strResult;
};
/*
 * HH:mm:ss
 */
Date.prototype.jpTimeString = function () {
    var strResult = '';
    var strHour = this.getHours() + '';
    var strMinute = this.getMinutes() + '';
    var strSecond = this.getSeconds() + '';

    strResult += ' ' + strHour.padLeft('0', 2) + ':' + strMinute.padLeft('0', 2) + ':' + strSecond.padLeft('0', 2);
    return strResult;
};
/*
 * HH:mm
 */
Date.prototype.jpShortTimeString = function () {
    var strResult = '';
    var strHour = this.getHours() + '';
    var strMinute = this.getMinutes() + '';
    var strSecond = this.getSeconds() + '';

    strResult += ' ' + strHour.padLeft('0', 2) + ':' + strMinute.padLeft('0', 2);
    return strResult;
};
/*
 * yyyyMMddHHmmss
 */
Date.prototype.toIdString = function () {
    var strResult = '';
    var strYear = this.getFullYear() + '';
    var strMonth = this.getMonth() + 1 + '';
    var strDayInMonth = this.getDate() + '';
    var strHour = this.getHours() + '';
    var strMinute = this.getMinutes() + '';
    var strSecond = this.getSeconds() + '';
    var strMilisecond = this.getMilliseconds() + '';

    strResult += strYear.padLeft('0', 4) + strMonth.padLeft('0', 2) + strDayInMonth.padLeft('0', 2);
    strResult += strHour.padLeft('0', 2) + strMinute.padLeft('0', 2) + strSecond.padLeft('0', 2) + strMilisecond.padLeft('0', 3);
    return strResult;
};
Takumi Imai committed
1213 1214 1215 1216 1217 1218

/**
 *  Subtract date to get days
 * @param {*} targetDate
 * @returns
 */
Takumi Imai committed
1219 1220 1221 1222 1223
Date.prototype.subtractByDays = function (targetDate) {
    var milis = Math.abs(this - targetDate);
    var days = Math.floor(milis / (60 * 60 * 24 * 1000));
    return days;
};
Takumi Imai committed
1224 1225 1226 1227 1228 1229

/**
 * add seconds
 * @param {*} plusSeconds
 * @returns
 */
Takumi Imai committed
1230 1231 1232 1233 1234
Date.prototype.addSeconds = function (plusSeconds) {
    var newDate = new Date(this.getTime() + plusSeconds * 1000);
    return newDate;
};

Takumi Imai committed
1235 1236 1237 1238 1239
/**
 *  Subtract date to get days
 * @param {*} targetDate
 * @returns
 */
Takumi Imai committed
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
Date.prototype.subtractBySeconds = function (targetDate) {
    var milis = Math.abs(this - targetDate);
    var days = Math.floor(milis / 1000);
    return days;
};

/*
 * Convert date to JP format date time [ end ]
 */

// trimming space from both side of the string
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, '');
};

// trimming space from left side of the string
String.prototype.trimLeft = function () {
    return this.replace(/^\s+/, '');
};

// trimming space from right side of the string
String.prototype.trimRight = function () {
    return this.replace(/\s+$/, '');
};

Takumi Imai committed
1265 1266 1267 1268 1269 1270
/**
 * String: pads left
 * @param {*} padString
 * @param {*} length
 * @returns
 */
Takumi Imai committed
1271 1272 1273 1274 1275 1276
String.prototype.padLeft = function (padString, length) {
    var str = this;
    while (str.length < length) str = padString + str;
    return str;
};

Takumi Imai committed
1277 1278 1279 1280 1281 1282
/**
 * String: pads right
 * @param {*} padString
 * @param {*} length
 * @returns
 */
Takumi Imai committed
1283 1284 1285 1286 1287
String.prototype.padRight = function (padString, length) {
    var str = this;
    while (str.length < length) str = str + padString;
    return str;
};
Takumi Imai committed
1288 1289 1290 1291 1292 1293

/**
 * Check contain string
 * @param {*} string
 * @returns
 */
Takumi Imai committed
1294 1295 1296 1297 1298 1299 1300
String.prototype.contains = function (string) {
    if (this.indexOf(string) != -1) {
        return true;
    }
    return false;
};

Takumi Imai committed
1301 1302 1303 1304 1305 1306
/**
 * Number: pads left
 * @param {*} padString
 * @param {*} length
 * @returns
 */
Takumi Imai committed
1307 1308 1309 1310 1311
Number.prototype.padLeft = function (padString, length) {
    var str = this + '';
    return str.padLeft(padString, length);
};

Takumi Imai committed
1312 1313 1314 1315 1316 1317
/**
 * Number: pads right
 * @param {*} padString
 * @param {*} length
 * @returns
 */
Takumi Imai committed
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
Number.prototype.padRight = function (padString, length) {
    var str = this + '';
    return str.padRight(padString, length);
};
// Clear data of array
Array.prototype.clear = function () {
    this.splice(0, this.length);
};

// Function to set position of object to center
jQuery.fn.center = function () {
    this.css('position', 'fixed');

    this.css('top', ($(window).height() - this.height()) / 2 + 'px');
    this.css('left', ($(window).width() - this.width()) / 2 + 'px');

    return this;
};