<commit_before>var g_appConfig =
    {
        basicPermissions: ['public_profile'],
        appId: '624861190962222'
    }

var g_appContext =
    {
        initialized: false,
        searchType: 'page',
        boardInfo:
        {
            id: 0,
            type: 'page',
            name: '',
        },
        postLoader: null,
        postDownloaderModal: null,
        currentFragment: undefined, // aka 'hash'
        tableGenerationOption: {},
    }

function switchPage(pageName) {
    $('.app-pages').addClass('hidden');
    $('#page-' + pageName).removeClass('hidden');
    $('html,body').scrollTop(0);
}
$().ready(function () { main(); });

function main() {
	ga_event_page_only_once('PageLoadComplete');
    $('body').css('display', '');
    wireEvents();
    wireEvents_post();
    wireEvents_gpe();
    switchPage('loading');
    SimpleTranslator.init(getParamMap()['lang'])
    SimpleTranslator.translate();
    initGraphApiLocale();
    fbmanager.jQueryInit(g_appConfig.appId, onFbInitialized);
}

function wireEvents() {
    $('#btn-basic-login').click(onBtnBasicLoginClick);
    $('#btn-search-my-pages').click(onBtnSearchMyPagesClick);
    $('#btn-search-my-groups').click(onBtnSearchMyGroupsClick);
    $('#btn-search-page').click(onBtnSearchPageClick);
    $('#btn-search-group').click(onBtnSearchGroupClick);
    $('#btn-search-result-more').click(onBtnPageSearchResultMoreClick);
    $('#btn-board-search-again').click(onBtnBoardSearchAgainClick);
    $('#btn-goto-search').click(onBtnGotoSearchClick);
    $('#btn-goto-post-list').click(onBtnGotoPostListClick);
    $('#btn-board-post-list-more').click(onBtnBoardPostListMoreClick);
    $('#btn-parse-comment-plugin').click(onBtnParseCommentPluginClick);
    $(window).bind('hashchange', applyFragmentValue);
}

function initGraphApiLocale() {
    $('#graph-api-locale').html('');
    var locale_array = [['en_US', 'English(US)'], ['ko_KR', '한국어']];
    $.each(locale_array, function () {
        $('<option>')
            .attr('value', this[0])
            .text(this[1])
            .appendTo($('#graph-api-locale'));
    });
}
function applyFragmentValue() {
    if (g_appContext.initialized == false)
        return;
    var hashValue = location.hash || '';
    if (hashValue.substr(0, 1) == '#')
        hashValue = hashValue.substr(1);
    if (g_appContext.currentFragment === hashValue)
        return;
    g_appContext.currentFragment = hashValue;

    if (hashValue.indexOf("board:") == 0) {
        trySetupBoard(
            hashValue.substr(6),
            board_loadSuccess,
            function () {
                alert(SimpleTranslator.getKey('fatal_error')); // TODO
            });
        return;
    }
    if (hashValue.indexOf("post:") == 0) {
        trySetupPost(
            hashValue.substr(5),
            post_loadSuccess,
            function () {
                alert(SimpleTranslator.getKey('fatal_error')); // TODO
            });
        return;
    }

    searchPage_start();
    return;
}

function setCommandFragment(fragment) {
    location.hash = fragment;
}

function onFbInitialized() {

    $('#shareBox').html('<div class="fb-like" data-href="http://kyungjaepark.com/pagepostmanager" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>');
    $('#commentBox').html('<div class="fb-comments" data-href="http://kyungjaepark.com/pagepostmanager" data-width="470" data-num_posts="3" data-order_by="reverse_time"></div>');
    FB.XFBML.parse(document.getElementById('shareBox'));
    FB.XFBML.parse(document.getElementById('fb-comments'));

    switchPage('welcome');
    processBasicLogin();
}

function processBasicLogin() {
    var lackingPermission = fbmanager.checkForLackingPermission(g_appConfig.basicPermissions);
    if (lackingPermission.length == 0) {
        $('#basic-login-box').addClass('hidden');
        onBasicLoginComplete();
    }
    else {
        $('#basic-login-box').removeClass('hidden');
        $('#btn-basic-login').prop('disabled', false);
    }
}

function onBtnBasicLoginClick() {
    $('#btn-basic-login').prop('disabled', true);
    FB.login(function (response) {
        fbmanager.refreshPermission(processBasicLogin);
    }, { scope: g_appConfig.basicPermissions, return_scopes: true });
}

function onBasicLoginComplete() {
	ga_event_page_only_once('FacebookLoginSuccess');
    g_appContext.initialized = true;
    applyFragmentValue();
}

// search ----------------------------------------------------------------------

function searchPage_start() {
    switchPage('search');
    searchPage_clear();
}

function searchPage_clear() {
    $('#txt-search').val('');
    $('#page-search-result').addClass('hidden');
    $('#page-search-result-empty').addClass('hidden');
}

function onBtnSearchMyPagesClick() {
    function onSuccess() {
        searchPage_startRequest('/me/accounts', {}, 'page');
    }
    var extraPermissions = ['pages_show_list'];
    var lackingPermission = fbmanager.checkForLackingPermission(extraPermissions);
    if (lackingPermission.length == 0) {
        onSuccess();
    }
    else {
        FB.login(function (response) {
            fbmanager.refreshPermission(function () {
                if (fbmanager.checkForLackingPermission(lackingPermission).length == 0)
                    onSuccess();
                else {
                    // TODO: 실패 안내 메시지
                }
            });
        }, { scope: lackingPermission, return_scopes: true });
    }
}

function onBtnSearchMyGroupsClick() {
    function onSuccess() {
        searchPage_startRequest('/me/groups', {}, 'group');
    }
    var extraPermissions = ['user_managed_groups'];
    var lackingPermission = fbmanager.checkForLackingPermission(extraPermissions);
    if (lackingPermission.length == 0) {
        onSuccess();
    }
    else {
        FB.login(function (response) {
            fbmanager.refreshPermission(function () {<commit_msg>add manage_pages permission for requirement<commit_after>var g_appConfig =
    {
        basicPermissions: ['public_profile'],
        appId: '624861190962222'
    }

var g_appContext =
    {
        initialized: false,
        searchType: 'page',
        boardInfo:
        {
            id: 0,
            type: 'page',
            name: '',
        },
        postLoader: null,
        postDownloaderModal: null,
        currentFragment: undefined, // aka 'hash'
        tableGenerationOption: {},
    }

function switchPage(pageName) {
    $('.app-pages').addClass('hidden');
    $('#page-' + pageName).removeClass('hidden');
    $('html,body').scrollTop(0);
}
$().ready(function () { main(); });

function main() {
	ga_event_page_only_once('PageLoadComplete');
    $('body').css('display', '');
    wireEvents();
    wireEvents_post();
    wireEvents_gpe();
    switchPage('loading');
    SimpleTranslator.init(getParamMap()['lang'])
    SimpleTranslator.translate();
    initGraphApiLocale();
    fbmanager.jQueryInit(g_appConfig.appId, onFbInitialized);
}

function wireEvents() {
    $('#btn-basic-login').click(onBtnBasicLoginClick);
    $('#btn-search-my-pages').click(onBtnSearchMyPagesClick);
    $('#btn-search-my-groups').click(onBtnSearchMyGroupsClick);
    $('#btn-search-page').click(onBtnSearchPageClick);
    $('#btn-search-group').click(onBtnSearchGroupClick);
    $('#btn-search-result-more').click(onBtnPageSearchResultMoreClick);
    $('#btn-board-search-again').click(onBtnBoardSearchAgainClick);
    $('#btn-goto-search').click(onBtnGotoSearchClick);
    $('#btn-goto-post-list').click(onBtnGotoPostListClick);
    $('#btn-board-post-list-more').click(onBtnBoardPostListMoreClick);
    $('#btn-parse-comment-plugin').click(onBtnParseCommentPluginClick);
    $(window).bind('hashchange', applyFragmentValue);
}

function initGraphApiLocale() {
    $('#graph-api-locale').html('');
    var locale_array = [['en_US', 'English(US)'], ['ko_KR', '한국어']];
    $.each(locale_array, function () {
        $('<option>')
            .attr('value', this[0])
            .text(this[1])
            .appendTo($('#graph-api-locale'));
    });
}
function applyFragmentValue() {
    if (g_appContext.initialized == false)
        return;
    var hashValue = location.hash || '';
    if (hashValue.substr(0, 1) == '#')
        hashValue = hashValue.substr(1);
    if (g_appContext.currentFragment === hashValue)
        return;
    g_appContext.currentFragment = hashValue;

    if (hashValue.indexOf("board:") == 0) {
        trySetupBoard(
            hashValue.substr(6),
            board_loadSuccess,
            function () {
                alert(SimpleTranslator.getKey('fatal_error')); // TODO
            });
        return;
    }
    if (hashValue.indexOf("post:") == 0) {
        trySetupPost(
            hashValue.substr(5),
            post_loadSuccess,
            function () {
                alert(SimpleTranslator.getKey('fatal_error')); // TODO
            });
        return;
    }

    searchPage_start();
    return;
}

function setCommandFragment(fragment) {
    location.hash = fragment;
}

function onFbInitialized() {

    $('#shareBox').html('<div class="fb-like" data-href="http://kyungjaepark.com/pagepostmanager" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>');
    $('#commentBox').html('<div class="fb-comments" data-href="http://kyungjaepark.com/pagepostmanager" data-width="470" data-num_posts="3" data-order_by="reverse_time"></div>');
    FB.XFBML.parse(document.getElementById('shareBox'));
    FB.XFBML.parse(document.getElementById('fb-comments'));

    switchPage('welcome');
    processBasicLogin();
}

function processBasicLogin() {
    var lackingPermission = fbmanager.checkForLackingPermission(g_appConfig.basicPermissions);
    if (lackingPermission.length == 0) {
        $('#basic-login-box').addClass('hidden');
        onBasicLoginComplete();
    }
    else {
        $('#basic-login-box').removeClass('hidden');
        $('#btn-basic-login').prop('disabled', false);
    }
}

function onBtnBasicLoginClick() {
    $('#btn-basic-login').prop('disabled', true);
    FB.login(function (response) {
        fbmanager.refreshPermission(processBasicLogin);
    }, { scope: g_appConfig.basicPermissions, return_scopes: true });
}

function onBasicLoginComplete() {
	ga_event_page_only_once('FacebookLoginSuccess');
    g_appContext.initialized = true;
    applyFragmentValue();
}

// search ----------------------------------------------------------------------

function searchPage_start() {
    switchPage('search');
    searchPage_clear();
}

function searchPage_clear() {
    $('#txt-search').val('');
    $('#page-search-result').addClass('hidden');
    $('#page-search-result-empty').addClass('hidden');
}

function onBtnSearchMyPagesClick() {
    function onSuccess() {
        searchPage_startRequest('/me/accounts', {}, 'page');
    }
    var extraPermissions = ['pages_show_list','manage_pages'];
    var lackingPermission = fbmanager.checkForLackingPermission(extraPermissions);
    if (lackingPermission.length == 0) {
        onSuccess();
    }
    else {
        FB.login(function (response) {
            fbmanager.refreshPermission(function () {
                if (fbmanager.checkForLackingPermission(lackingPermission).length == 0)
                    onSuccess();
                else {
                    // TODO: 실패 안내 메시지
                }
            });
        }, { scope: lackingPermission, return_scopes: true });
    }
}

function onBtnSearchMyGroupsClick() {
    function onSuccess() {
        searchPage_startRequest('/me/groups', {}, 'group');
    }
    var extraPermissions = ['user_managed_groups'];
    var lackingPermission = fbmanager.checkForLackingPermission(extraPermissions);
    if (lackingPermission.length == 0) {
        onSuccess();
    }
    else {
        FB.login(function (response) {
            fbmanager.refreshPermission(function () {
{'fraction_non_alphanumeric': 0.1728301886792453, 'fraction_numerical': 0.00570230607966457, 'mean_word_length': 2.9793126459793124, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7455354', 'n_tokens_mistral': 3526, 'n_tokens_neox': 3512, 'n_words': 480}