<commit_before>/* Login and logout related code, and email config dialog.
 * Copyright (C) 2012-2012 <NAME> (born 1979)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This file: Login and logout control flow, and dialogs for
 * email, login ok and login failure.
 * (Find guest login and OpenID login dialogs in other files.)
 */

(function() {

var d = { i: debiki.internal, u: debiki.v0.util };
var $ = d.i.$;


// Remembers which .dw-loginsubmit-on-click button (e.g. "Post as...")
// was clicked when a login dialog is shown.
var loginOnClickBtnClicked = null;

// True iff the user is to be asked whether or not s/he wants to be
// notified via email e.g. of replies.
var continueLoginAskAboutEmail = false;


/**
 * `data` can be:
 * {
 *    askAboutEmailNotfs: true/false -- optional
 *    mode: 'SubmitComment' -- optional, influences button titles in login dialogs
 * }
 */
d.i.$loginSubmitOnClick = function(loginEventHandler, data) {
  return function() {
    var $i = $(this);
    $i.addClass('dw-loginsubmit-on-click');
    !loginEventHandler || $i.bind('dwEvLoggedInOut', loginEventHandler);
    $i.on('click', null, data, d.i.$loginThenSubmit)
  };
};


// Invoke on a .login-on-click submit <input>. After the login
// has been completed, the button will be submitted, see
// continueAnySubmission(). If already logged in, submits immediately.
d.i.$loginThenSubmit = function(event) {
  loginOnClickBtnClicked = this;
  continueLoginAskAboutEmail = event.data && event.data.askAboutEmailNotfs;
  if (!d.i.Me.isLoggedIn()) {
    // Will call continueAnySubmission(), after login.
    // {{{ Hmm, could add a `continue' callback to showLogin() instead!?
    // But initLoginSimple/OpenId runs once only, so the very first
    // anonymous function is the only one considered, so a somewhat
    // global callback-to-invoke-state is needed anyway.
    // Better move login stuff to a separate module (with a module
    // local "global" callback state).}}}
    d.i.showLoginSubmitDialog(event.data.mode);
  } else {
    d.i.continueAnySubmission();
  }
  return false;  // skip default action; don't submit until after login
};

<commit_msg>Fix new-forum-topic button broken bug<commit_after>/* Login and logout related code, and email config dialog.
 * Copyright (C) 2012-2012 <NAME> (born 1979)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This file: Login and logout control flow, and dialogs for
 * email, login ok and login failure.
 * (Find guest login and OpenID login dialogs in other files.)
 */

(function() {

var d = { i: debiki.internal, u: debiki.v0.util };
var $ = d.i.$;


// Remembers which .dw-loginsubmit-on-click button (e.g. "Post as...")
// was clicked when a login dialog is shown.
var loginOnClickBtnClicked = null;

// True iff the user is to be asked whether or not s/he wants to be
// notified via email e.g. of replies.
var continueLoginAskAboutEmail = false;


/**
 * `data` can be:
 * {
 *    askAboutEmailNotfs: true/false -- optional
 *    mode: 'SubmitComment' -- optional, influences button titles in login dialogs
 * }
 */
d.i.$loginSubmitOnClick = function(loginEventHandler, data) {
  return function() {
    var $i = $(this);
    $i.addClass('dw-loginsubmit-on-click');
    !loginEventHandler || $i.bind('dwEvLoggedInOut', loginEventHandler);
    $i.on('click', null, data, d.i.$loginThenSubmit)
  };
};


// Invoke on a .login-on-click submit <input>. After the login
// has been completed, the button will be submitted, see
// continueAnySubmission(). If already logged in, submits immediately.
d.i.$loginThenSubmit = function(event) {
  loginOnClickBtnClicked = this;
  continueLoginAskAboutEmail = event.data && event.data.askAboutEmailNotfs;
  if (!d.i.Me.isLoggedIn()) {
    // Will call continueAnySubmission(), after login.
    // {{{ Hmm, could add a `continue' callback to showLogin() instead!?
    // But initLoginSimple/OpenId runs once only, so the very first
    // anonymous function is the only one considered, so a somewhat
    // global callback-to-invoke-state is needed anyway.
    // Better move login stuff to a separate module (with a module
    // local "global" callback state).}}}
    d.i.showLoginSubmitDialog(event.data ? event.data.mode : undefined);
  } else {
    d.i.continueAnySubmission();
  }
  return false;  // skip default action; don't submit until after login
};


{'fraction_non_alphanumeric': 0.1096499022569753, 'fraction_numerical': 0.004976008530300338, 'mean_word_length': 3.466666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2213710', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1619, 'n_words': 658}