Limit_Access_Content.js 5.97 KB
Newer Older
1

Masaru Abe committed
2 3
//名前空間用のオブジェクトを用意する
var LIMIT_ACCESS_CONTENT = {};
4

Masaru Abe committed
5
LIMIT_ACCESS_CONTENT.messageLevel = {};
6

Masaru Abe committed
7 8
LIMIT_ACCESS_CONTENT.checkLimitContent = function(contentId, funcOk, funcCancel, isNotUnlockScreen) {

Masaru Abe committed
9 10 11 12 13 14 15 16
    var levelContent = 0;
    try {
    	levelContent = parseInt(LIMIT_ACCESS_CONTENT.messageLevel[contentId].alertMessageLevel);
    } catch(e){
    	//取得できない場合OKにする
    	levelContent = 0;
    }
    
17 18 19
    if (levelContent == 1) {
        if ($('#limit_level1').length <= 0) {
            var html = '<section class="sectionLimitAccess" id="limit_level1">';
20
            html += '<h1 class="lang" lang="txtContentWarning">' + I18N.i18nText("txtContentWarning") + '</h1>';
21 22
            html += '<p class="message"></p>';
            html += '<p class="deletebtn">';
23 24
            html += '<a lang="dspOK" class="ok lang">' + I18N.i18nText("dspOK") + '</a>';
            html += '<a lang="dspCancel" class="cancel lang">' + I18N.i18nText("dspCancel") + '</a>';            
25 26 27 28 29 30
            html += '</p>';
            html += '</section>';
            $('body').append(html);
        }

        $('#limit_level1 .deletebtn .cancel').unbind('click').click(
Masaru Abe committed
31 32
            function () {
                if (isNotUnlockScreen != 1) {
Masaru Abe committed
33
                    COMMON.unlockLayout();
34
                }
Masaru Abe committed
35 36 37 38 39
                $('#limit_level1').hide();
                //キャンセル
                funcCancel();
            }
        );
40

41
        COMMON.lockLayout();
42

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

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

            var html = '<section class="sectionLimitAccess" id="limit_level2">';
60
            html += '<h1 class="lang" lang="txtContentPWTitle">' + I18N.i18nText("txtContentPWTitle") + '</h1>';
61
            html += '<p class="message">';
62
            html += '<label class="text lang" lang="txtContentPWMsg">' + I18N.i18nText("txtContentPWMsg") + '</label>';
63 64 65 66
            html += '<input type="password" />';
            html += '<label class="error" id="lblMessageLimitError"></label>';
            html += '</p>';
            html += '<p class="deletebtn">';
67 68
            html += '<a lang="dspOK" class="ok lang">' + I18N.i18nText("dspOK") + '</a>';
            html += '<a lang="dspCancel" class="cancel lang">' + I18N.i18nText("dspCancel") + '</a>';            
69 70 71 72 73 74 75
            html += '</p>';
            html += '</section>';

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

            // press enter at input password
            $('#limit_level2 .message input').keydown(
Masaru Abe committed
76 77 78 79
                function (e) {
                    var code = (e.keyCode ? e.keyCode : e.which);
                    if (code == 13) { //Enter keycode
                        $('#limit_level2 .deletebtn .ok').click();
80 81 82
                    }
                }
            );
Masaru Abe committed
83
        }
84

Masaru Abe committed
85 86 87
        $('#limit_level2 .deletebtn .cancel').unbind('click').click(
            function () {
                if (isNotUnlockScreen != 1) {
Masaru Abe committed
88
                    COMMON.unlockLayout();
Masaru Abe committed
89 90 91 92 93 94
                }
                $('#limit_level2').hide();
                //キャンセル
                funcCancel();
            }
        );
95 96

        // lock layout
97
        COMMON.lockLayout();
98 99 100 101 102 103 104 105 106 107 108 109 110 111

        //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)) {
112
                    $('#lblMessageLimitError').html(I18N.i18nText('msgPwdEmpty')).show();
113 114 115 116 117 118 119 120 121 122 123
                    return;
                }

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

127
                AVWEB.avwCmsApiSyncWithUrl(apiLoginUrl, null, 'webClientLogin', 'GET', params,
Masaru Abe committed
128 129 130 131 132 133 134
                    function (data) {
                        if (data.result == 'success') {

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

                            if (isNotUnlockScreen != 1) {
Masaru Abe committed
135
                                COMMON.unlockLayout();
Masaru Abe committed
136 137 138 139 140 141
                            }
                            $('#limit_level2').hide();
                            // open content
                            funcOk();
                        }
                        else {
142
                            $('#lblMessageLimitError').html(AVWEB.format(I18N.i18nText('msgLoginErrWrong'), data.errorMessage).toString()).show();
Masaru Abe committed
143 144 145 146 147 148 149
                        }
                    },
                    function (xhr, statusText, errorThrown) {
                        var errorCode = 'E001';
                        if (xhr.responseText && xhr.status != 0) {
                            errorCode = JSON.parse(xhr.responseText).errorMessage;
                        }
150
                        $('#lblMessageLimitError').html(AVWEB.format(I18N.i18nText('msgLoginErrWrong'), errorCode).toString()).show();
Masaru Abe committed
151 152
                    }
                );
153 154 155 156 157 158

            }
        );
    }
    else // content level 0 or null
    {
Masaru Abe committed
159
        funcOk();
160 161
    }
};