@fleetbase/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
59 lines (51 loc) • 2.15 kB
JavaScript
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { task } from 'ember-concurrency';
export default class MaintenancePartsIndexEditController extends Controller {
hostRouter;
intl;
notifications;
modalsManager;
events;
overlay;
get actionButtons() {
return [{ icon: 'eye', fn: this.view }];
}
*save(part) {
try {
yield part.save();
this.events.trackResourceUpdated(part);
this.overlay?.close();
yield this.hostRouter.transitionTo('console.fleet-ops.maintenance.parts.index.details', part);
this.notifications.success(this.intl.t('common.resource-updated-success', { resource: this.intl.t('resource.part'), resourceName: part.name }));
} catch (err) {
this.notifications.serverError(err);
}
}
cancel() {
if (this.model.hasDirtyAttributes) {
return this.#confirmContinueWithUnsavedChanges(this.model);
}
return this.hostRouter.transitionTo('console.fleet-ops.maintenance.parts.index');
}
view() {
if (this.model.hasDirtyAttributes) {
return this.#confirmContinueWithUnsavedChanges(this.model);
}
return this.hostRouter.transitionTo('console.fleet-ops.maintenance.parts.index.details', this.model);
}
#confirmContinueWithUnsavedChanges(part, options = {}) {
return this.modalsManager.confirm({
title: this.intl.t('common.continue-without-saving'),
body: this.intl.t('common.continue-without-saving-prompt', { resource: this.intl.t('resource.part') }),
acceptButtonText: this.intl.t('common.continue'),
confirm: async () => {
part.rollbackAttributes();
await this.hostRouter.transitionTo('console.fleet-ops.maintenance.parts.index.details', part);
},
...options,
});
}
}