Limit_Access_Content.js 5.57 KB
Newer Older
1 2 3

var messageLevel = {};

Masaru Abe committed
4
function checkLimitContent(contentId, funcOk, funcCancel, isNotUnlockScreen) {
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

    var levelContent = parseInt(messageLevel[contentId].alertMessageLevel);

    if (levelContent == 1) {
        if ($('#limit_level1').length <= 0) {
            var html = '<section class="sectionLimitAccess" id="limit_level1">';
            html += '<h1 class="lang" lang="txtContentWarning">' + i18nText("txtContentWarning") + '</h1>';
            html += '<p class="message"></p>';
            html += '<p class="deletebtn">';
            html += '<a lang="dspOK" class="ok lang">' + i18nText("dspOK") + '</a>';
            html += '<a lang="dspCancel" class="cancel lang">' + i18nText("dspCancel") + '</a>';            
            html += '</p>';
            html += '</section>';
            $('body').append(html);
        }

        $('#limit_level1 .deletebtn .cancel').unbind('click').click(
Masaru Abe committed
22 23 24
            function () {
                if (isNotUnlockScreen != 1) {
                    unlockLayout();
25
                }
Masaru Abe committed
26 27 28 29 30
                $('#limit_level1').hide();
                //キャンセル
                funcCancel();
            }
        );
31 32 33 34 35 36 37 38 39 40 41

        lockLayout();

        $('#limit_level1 .message').html(messageLevel[contentId].alertMessage);
        $('#limit_level1').show().center();
        $('#limit_level1 .deletebtn .ok').unbind('click').click(
            function () {
                if (isNotUnlockScreen != 1) {
                    unlockLayout();
                }
                $('#limit_level1').hide();
Masaru Abe committed
42
                funcOk();
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
            }
        );
    }
    else if (levelContent == 2) {

        if ($('#limit_level2').length <= 0) {

            var html = '<section class="sectionLimitAccess" id="limit_level2">';
            html += '<h1 class="lang" lang="txtContentPWTitle">' + i18nText("txtContentPWTitle") + '</h1>';
            html += '<p class="message">';
            html += '<label class="text lang" lang="txtContentPWMsg">' + i18nText("txtContentPWMsg") + '</label>';
            html += '<input type="password" />';
            html += '<label class="error" id="lblMessageLimitError"></label>';
            html += '</p>';
            html += '<p class="deletebtn">';
            html += '<a lang="dspOK" class="ok lang">' + i18nText("dspOK") + '</a>';
            html += '<a lang="dspCancel" class="cancel lang">' + i18nText("dspCancel") + '</a>';            
            html += '</p>';
            html += '</section>';

            $('body').append(html);

            // press enter at input password
            $('#limit_level2 .message input').keydown(
Masaru Abe committed
67 68 69 70
                function (e) {
                    var code = (e.keyCode ? e.keyCode : e.which);
                    if (code == 13) { //Enter keycode
                        $('#limit_level2 .deletebtn .ok').click();
71 72 73
                    }
                }
            );
Masaru Abe committed
74
        }
75

Masaru Abe committed
76 77 78 79 80 81 82 83 84 85
        $('#limit_level2 .deletebtn .cancel').unbind('click').click(
            function () {
                if (isNotUnlockScreen != 1) {
                    unlockLayout();
                }
                $('#limit_level2').hide();
                //キャンセル
                funcCancel();
            }
        );
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

        // lock layout
        lockLayout();

        //reset input password
        $('#limit_level2 .message input').val('');

        // hide error message
        $('#lblMessageLimitError').hide();

        // show dialog
        $('#limit_level2').show().center();
        
        $('#limit_level2 .deletebtn .ok').unbind('click').click(
            function () {
                var password = $('#limit_level2 .message input').val();
                if (!ValidationUtil.CheckRequiredForText(password)) {
                    $('#lblMessageLimitError').html(i18nText('msgPwdEmpty')).show();
                    return;
                }

                // start login
                var params = {
                    previousSid: ClientData.userInfo_sid(),
                    loginId: ClientData.userInfo_loginId_session(),
                    password: password,
                    urlpath: ClientData.userInfo_accountPath()
                };
                // Get url to login
                var sysSettings = avwSysSetting();
                var apiLoginUrl = sysSettings.apiLoginUrl;

                avwCmsApiSyncWithUrl(apiLoginUrl, null, 'webClientLogin', 'GET', params,
Masaru Abe committed
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
                    function (data) {
                        if (data.result == 'success') {

                            // update sid id
                            ClientData.userInfo_sid(data.sid);

                            if (isNotUnlockScreen != 1) {
                                unlockLayout();
                            }
                            $('#limit_level2').hide();
                            // open content
                            funcOk();
                        }
                        else {
                            $('#lblMessageLimitError').html(format(i18nText('msgLoginErrWrong'), data.errorMessage).toString()).show();
                        }
                    },
                    function (xhr, statusText, errorThrown) {
                        var errorCode = 'E001';
                        if (xhr.responseText && xhr.status != 0) {
                            errorCode = JSON.parse(xhr.responseText).errorMessage;
                        }
                        $('#lblMessageLimitError').html(format(i18nText('msgLoginErrWrong'), errorCode).toString()).show();
                    }
                );
144 145 146 147 148 149

            }
        );
    }
    else // content level 0 or null
    {
Masaru Abe committed
150
        funcOk();
151 152
    }
};