summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/group.js
blob: 903c838e266e2a9bba735de73f87746c7cbff93b (plain)
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
import $ from 'jquery';
import { slugifyWithHyphens } from './lib/utils/text_utility';

export default class Group {
  constructor() {
    this.groupPath = $('#group_path');
    this.groupName = $('#group_name');
    this.updateHandler = this.update.bind(this);
    this.resetHandler = this.reset.bind(this);
    if (this.groupName.val() === '') {
      this.groupName.on('keyup', this.updateHandler);
      this.groupPath.on('keydown', this.resetHandler);
    }
  }

  update() {
    const slug = slugifyWithHyphens(this.groupName.val());
    this.groupPath.val(slug);
  }

  reset() {
    this.groupName.off('keyup', this.updateHandler);
    this.groupPath.off('keydown', this.resetHandler);
  }
}