Limit_Access_Content.js 5.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

var messageLevel = {};

function checkLimitContent(contentId, func,isNotUnlockScreen) {

    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(
                function () {
                    if (isNotUnlockScreen != 1) {
                        unlockLayout();
                    }
                    $('#limit_level1').hide();
                }
            );

        lockLayout();

        $('#limit_level1 .message').html(messageLevel[contentId].alertMessage);
        $('#limit_level1').show().center();
        $('#limit_level1 .deletebtn .ok').unbind('click').click(
            function () {
Vo Duc Thang committed
36 37 38 39 40 41

                if (isNotUnlockScreen != 1) {
                    unlockLayout();
                }
                $('#limit_level1').hide();

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
                func();
            }
        );
    }
    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(
                    function (e) {
                        var code = (e.keyCode ? e.keyCode : e.which);
                        if (code == 13) { //Enter keycode
                            $('#limit_level2 .deletebtn .ok').click();
                        }

                    }
            );
                }

            $('#limit_level2 .deletebtn .cancel').unbind('click').click(
                    function () {
                        if (isNotUnlockScreen != 1) {
                            unlockLayout();
                        }
                        $('#limit_level2').hide();
                    }
            );


        // lock layout
        lockLayout();

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

Vo Duc Thang committed
93 94 95
        // hide error message
        $('#lblMessageLimitError').hide();

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
        // 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,
	        function (data) {
	            if (data.result == 'success') {

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

Vo Duc Thang committed
125 126 127 128
	                if (isNotUnlockScreen != 1) {
	                    unlockLayout();
	                }
	                $('#limit_level2').hide();
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	                // open content
	                func();
	            }
	            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();
	        });

            }
        );
    }
    else // content level 0 or null
    {
        func();
    }
};