UNPKG

@lipagas/fleetops-engine

Version:

Fleet & Transport Management Extension for Fleetbase

132 lines (114 loc) 3.27 kB
import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { underscore } from '@ember/string'; import { task } from 'ember-concurrency'; import contextComponentCallback from '@lipagas/ember-core/utils/context-component-callback'; import applyContextComponentArguments from '@lipagas/ember-core/utils/apply-context-component-arguments'; export default class FleetFormPanelComponent extends Component { /** * @service store */ @service store; /** * @service notifications */ @service notifications; /** * @service hostRouter */ @service hostRouter; /** * @service intl */ @service intl; /** * @service contextPanel */ @service contextPanel; /** * Overlay context. * @type {any} * @memberof FleetFormPanelComponent */ @tracked context; /** * All possible order status options * * @var {String} * @memberof FleetFormPanelComponent */ @tracked statusOptions = ['active', 'disabled', 'decommissioned']; /** * Constructs the component and applies initial state. */ constructor() { super(...arguments); this.fleet = this.args.fleet; applyContextComponentArguments(this); } /** * Sets the overlay context. * * @action * @param {OverlayContextObject} overlayContext * @memberof FleetFormPanelComponent */ @action setOverlayContext(overlayContext) { this.context = overlayContext; contextComponentCallback(this, 'onLoad', ...arguments); } /** * Task to save fleet. * * @return {void} * @memberof FleetFormPanelComponent */ @task *save() { contextComponentCallback(this, 'onBeforeSave', this.fleet); try { this.fleet = yield this.fleet.save(); } catch (error) { this.notifications.serverError(error); return; } this.notifications.success(this.intl.t('fleet-ops.component.fleet-form-panel.success-message', { fleetName: this.fleet.name })); contextComponentCallback(this, 'onAfterSave', this.fleet); } /** * View the details of the fleet. * * @action * @memberof FleetFormPanelComponent */ @action onViewDetails() { const isActionOverrided = contextComponentCallback(this, 'onViewDetails', this.fleet); if (!isActionOverrided) { this.contextPanel.focus(this.fleet, 'viewing'); } } /** * Handles cancel button press. * * @action * @returns {any} * @memberof FleetFormPanelComponent */ @action onPressCancel() { return contextComponentCallback(this, 'onPressCancel', this.fleet); } /** * Update relation on a model. * * @param {String} relation * @param {Model|null} value * @memberof FleetFormPanelComponent */ @action updateRelationship(relation, value) { this.fleet.set(relation, value); if (!value) { this.fleet.set(underscore(relation) + '_uuid', null); } } }