<commit_before>
// ----------------------------------------------------------------
// Login Class

class LoginModel extends SwitchModel {
  constructor({
    name,
    lsKeyView,
    triggerSelector,
    switchSelector,
    loginTrigger = 'click',
    loginSelector = null,
    loginIdSelector = null,
    loginPasswordSelector = null,
    logoutTrigger = 'click',
    logoutSelector = null
  } = {}) {
    super({
      name: name,
      lsKeyView: lsKeyView,
      triggerSelector: triggerSelector,
      switchSelector: switchSelector
    });
    
    this.NAME = name;
    this.LOGIN_TRIGGER = loginTrigger;
    this.LOGIN_SELECTOR = loginSelector;
    
    this.LOGOUT_TRIGGER = logoutTrigger;
    this.LOGOUT_SELECTOR = logoutSelector;
    
    this.LOGIN_ID_SELECTOR = loginIdSelector;
    this.LOGIN_PASSWORD_SELECTOR = loginPasswordSelector;
    // this.LOGIN_CHECK_SELECTOR = '#login-check';
    
    this.LOGIN_AREA_SELECTOR = '#login-area';
    this.$LOGIN_AREA_SELECTOR = $(this.LOGIN_AREA_SELECTOR);
    this.TEMPLATE_LOGINED_SELECTOR = '#logined-template';
    this.$TEMPLATE_LOGINED_SELECTOR = $(this.TEMPLATE_LOGINED_SELECTOR);
    this.TEMPLATE_NOT_LOGIN_SELECTOR = '#not-login-template';
    this.$TEMPLATE_NOT_LOGIN_SELECTOR = $(this.TEMPLATE_NOT_LOGIN_SELECTOR);
  }
}

class LoginView extends SwitchView {
  constructor(_model = new LoginModel()) {
    super(_model);
  }
}

// ----------------------------------------------------------------
// Controller

class LoginController extends CommonController {
  constructor(_obj) {
    super(_obj);
    
    this.model = new LoginModel(_obj);
    this.view = new LoginView(this.model);
  }
}

// ----------------------------------------------------------------
// Event

class LoginEvent extends CommonEvent {
  constructor({
    name = 'Login Event'
  } = {})
  {
    super({
      name: name
    });
    
    this.NAME = name;
    this.CONTROLLER = new LoginController({
      name: 'Login Switch',
      lsKeyView: 'login',
      triggerSelector: '#action-login',
      switchSelector: '#login-area',
      loginSelector: '#login-submit',
      loginIdSelector: '#login-id',
      loginPasswordSelector: '#login-password',
      logoutSelector: '#logined-logout'
    });
    
    this.LOGIN = false;
    this.ID = null;
    
    this.setOn();
    this.generateLoginArea();
  }
  
  setOn() {
    SetEvent.setOn(
      this.CONTROLLER.model.LOGIN_TRIGGER,
      this.CONTROLLER.model.LOGIN_SELECTOR,
      () => {
        this.submitLogin();
      }
    );
    SetEvent.setOn(
      this.CONTROLLER.model.LOGOUT_TRIGGER,
      this.CONTROLLER.model.LOGOUT_SELECTOR,
      () => {
        this.submitLogout();
      }
    );
  }
  
  generateLoginArea(_loginAlert = 'success', _loginFailedMessage = null) {
    let template = null;
    if (this.LOGIN) {
      // ログインしているとき
      Log.logClass(this.NAME, 'Logined');
      template = this.CONTROLLER.model.$TEMPLATE_LOGINED_SELECTOR.text();
      
    } else {
      // ログインしていないとき
      Log.logClass(this.NAME, 'Not login');
      template = this.CONTROLLER.model.$TEMPLATE_NOT_LOGIN_SELECTOR.text();
      
    }
    const compiled = _.template(template);
    const model = {
      id: this.ID
    };
    
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.empty();
    if (_loginFailedMessage != null) {
      const alertTemplate = this.CONTROLLER.model.$ALERT_TEMPLATE.text();
      const alertCompiled = _.template(alertTemplate);
      const alertModel = {
        type: _loginAlert,
        message: _loginFailedMessage
      };
      this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.append(alertCompiled(alertModel));
    }
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.append(compiled(model));
    
    BCBProcess.initPopover();
  }
  
  generateLoading() {
    const template = this.CONTROLLER.model.$LOADING_TEMPLATE.text();
    const compiled = _.template(template);
    const model = {
      header: `${this.ID} でログイン`,
      message: 'ログイン中...'
    };
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.empty();
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.html(compiled(model));
  }
  
  submitLogin() {
    Log.logClassKey(this.NAME, 'Login', 'submit');
    this.ID = $(this.CONTROLLER.model.LOGIN_ID_SELECTOR).val();
    this.PASSWORD = $(this.CONTROLLER.model.LOGIN_PASSWORD_SELECTOR).val();
    
    this.generateLoading();
    
    $.ajax({
      url: 'ruby/getSQLiteResult.rb',
      data: {
        query: `SELECT name FROM User where name = '${this.ID}' and password = '${<PASSWORD>}';`
      },
      dataType: 'json',
      success: (_data) => {
        if (Object.keys(_data).length > 0) {
          this.ID = Object.keys(_data)[0];
          this.LOGIN = true;
          this.generateLoginArea('success', `ユーザー ${this.ID} でログインしました。`);<commit_msg>Update submitLogin in LoginEvent<commit_after>
// ----------------------------------------------------------------
// Login Class

class LoginModel extends SwitchModel {
  constructor({
    name,
    lsKeyView,
    triggerSelector,
    switchSelector,
    loginTrigger = 'click',
    loginSelector = null,
    loginIdSelector = null,
    loginPasswordSelector = null,
    logoutTrigger = 'click',
    logoutSelector = null
  } = {}) {
    super({
      name: name,
      lsKeyView: lsKeyView,
      triggerSelector: triggerSelector,
      switchSelector: switchSelector
    });
    
    this.NAME = name;
    this.LOGIN_TRIGGER = loginTrigger;
    this.LOGIN_SELECTOR = loginSelector;
    
    this.LOGOUT_TRIGGER = logoutTrigger;
    this.LOGOUT_SELECTOR = logoutSelector;
    
    this.LOGIN_ID_SELECTOR = loginIdSelector;
    this.LOGIN_PASSWORD_SELECTOR = loginPasswordSelector;
    // this.LOGIN_CHECK_SELECTOR = '#login-check';
    
    this.LOGIN_AREA_SELECTOR = '#login-area';
    this.$LOGIN_AREA_SELECTOR = $(this.LOGIN_AREA_SELECTOR);
    this.TEMPLATE_LOGINED_SELECTOR = '#logined-template';
    this.$TEMPLATE_LOGINED_SELECTOR = $(this.TEMPLATE_LOGINED_SELECTOR);
    this.TEMPLATE_NOT_LOGIN_SELECTOR = '#not-login-template';
    this.$TEMPLATE_NOT_LOGIN_SELECTOR = $(this.TEMPLATE_NOT_LOGIN_SELECTOR);
  }
}

class LoginView extends SwitchView {
  constructor(_model = new LoginModel()) {
    super(_model);
  }
}

// ----------------------------------------------------------------
// Controller

class LoginController extends CommonController {
  constructor(_obj) {
    super(_obj);
    
    this.model = new LoginModel(_obj);
    this.view = new LoginView(this.model);
  }
}

// ----------------------------------------------------------------
// Event

class LoginEvent extends CommonEvent {
  constructor({
    name = 'Login Event'
  } = {})
  {
    super({
      name: name
    });
    
    this.NAME = name;
    this.CONTROLLER = new LoginController({
      name: 'Login Switch',
      lsKeyView: 'login',
      triggerSelector: '#action-login',
      switchSelector: '#login-area',
      loginSelector: '#login-submit',
      loginIdSelector: '#login-id',
      loginPasswordSelector: '#login-password',
      logoutSelector: '#logined-logout'
    });
    
    this.LOGIN = false;
    this.ID = null;
    
    this.setOn();
    this.generateLoginArea();
  }
  
  setOn() {
    SetEvent.setOn(
      this.CONTROLLER.model.LOGIN_TRIGGER,
      this.CONTROLLER.model.LOGIN_SELECTOR,
      () => {
        this.submitLogin();
      }
    );
    SetEvent.setOn(
      this.CONTROLLER.model.LOGOUT_TRIGGER,
      this.CONTROLLER.model.LOGOUT_SELECTOR,
      () => {
        this.submitLogout();
      }
    );
  }
  
  generateLoginArea(_loginAlert = 'success', _loginFailedMessage = null) {
    let template = null;
    if (this.LOGIN) {
      // ログインしているとき
      Log.logClass(this.NAME, 'Logined');
      template = this.CONTROLLER.model.$TEMPLATE_LOGINED_SELECTOR.text();
      
    } else {
      // ログインしていないとき
      Log.logClass(this.NAME, 'Not login');
      template = this.CONTROLLER.model.$TEMPLATE_NOT_LOGIN_SELECTOR.text();
      
    }
    const compiled = _.template(template);
    const model = {
      id: this.ID
    };
    
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.empty();
    if (_loginFailedMessage != null) {
      const alertTemplate = this.CONTROLLER.model.$ALERT_TEMPLATE.text();
      const alertCompiled = _.template(alertTemplate);
      const alertModel = {
        type: _loginAlert,
        message: _loginFailedMessage
      };
      this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.append(alertCompiled(alertModel));
    }
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.append(compiled(model));
    
    BCBProcess.initPopover();
  }
  
  generateLoading() {
    const template = this.CONTROLLER.model.$LOADING_TEMPLATE.text();
    const compiled = _.template(template);
    const model = {
      header: `${this.ID} でログイン`,
      message: 'ログイン中...'
    };
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.empty();
    this.CONTROLLER.model.$LOGIN_AREA_SELECTOR.html(compiled(model));
  }
  
  submitLogin() {
    Log.logClassKey(this.NAME, 'Login', 'submit');
    this.ID = $(this.CONTROLLER.model.LOGIN_ID_SELECTOR).val();
    this.PASSWORD = $(this.CONTROLLER.model.LOGIN_PASSWORD_SELECTOR).val();
    this.PASSWORD_HASH = <PASSWORD>(this.PASSWORD);
    
    this.generateLoading();
    
    $.ajax({
      url: 'ruby/loginUser.rb',
      data: {
        id: this.ID,
        password: <PASSWORD>
      },
      success: (_data) => {
        Log.logClass('loginUser ajax success', _data);
        if (_data.length > 0) {
          this.ID = _data;
          this.LOGIN = true;
          this.generateLoginArea('success', `ユーザー ${this.ID} でログインしました。`);
{'fraction_non_alphanumeric': 0.1635718756519925, 'fraction_numerical': 0.00031295639474233255, 'mean_word_length': 2.4008513657325294, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '574902', 'n_tokens_mistral': 3142, 'n_tokens_neox': 3112, 'n_words': 465}