ilios/frontend

View on GitHub
packages/frontend/app/components/program/header.js

Summary

Maintainability
A
0 mins
Test Coverage
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { validatable, Length, NotBlank } from 'ilios-common/decorators/validation';
import { dropTask } from 'ember-concurrency';

@validatable
export default class ProgramHeaderComponent extends Component {
  @NotBlank() @Length(3, 200) @tracked title;

  @action
  load() {
    this.title = this.args.program.title;
  }

  changeTitle = dropTask(async () => {
    if (this.title !== this.args.program.title) {
      this.addErrorDisplayFor('title');
      const isValid = await this.isValid('title');
      if (!isValid) {
        return false;
      }
      this.args.program.set('title', this.title);
      await this.args.program.save();
      this.title = this.args.program.title;
      this.removeErrorDisplayFor('title');
    }
  });
}