@fleetbase/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
82 lines (71 loc) • 2.77 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 ConnectivityTelematicsEditController extends Controller {
hostRouter;
intl;
notifications;
modalsManager;
events;
overlay;
get actionButtons() {
return [
{
icon: 'eye',
fn: this.view,
},
];
}
*save(telematic) {
try {
yield telematic.save();
this.events.trackResourceUpdated(telematic);
this.overlay?.close();
yield this.hostRouter.transitionTo('console.fleet-ops.connectivity.telematics.details', telematic);
this.notifications.success(
this.intl.t('common.resource-updated-success', {
resource: this.intl.t('resource.telematic'),
resourceName: telematic.name ?? telematic.provider,
})
);
} catch (err) {
this.notifications.serverError(err);
}
}
cancel() {
if (this.model.hasDirtyAttributes) {
return this.#confirmContinueWithUnsavedChanges(this.model);
}
return this.hostRouter.transitionTo('console.fleet-ops.connectivity.telematics.index');
}
view() {
if (this.model.hasDirtyAttributes) {
return this.#confirmContinueWithUnsavedChanges(this.model);
}
return this.hostRouter.transitionTo('console.fleet-ops.connectivity.telematics.details', this.model);
}
openConnectionTestDialog() {
this.modalsManager.show('modals/telematic-connection-diagnostics', {
title: 'Test Connection',
acceptButtonText: 'Run Test',
acceptButtonIcon: 'plug',
declineButtonText: 'Close',
telematic: this.model,
onTested: () => this.hostRouter.refresh(),
});
}
#confirmContinueWithUnsavedChanges(telematic, 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.telematic') }),
acceptButtonText: this.intl.t('common.continue'),
confirm: async () => {
telematic.rollbackAttributes();
await this.hostRouter.transitionTo('console.fleet-ops.connectivity.telematics.details', telematic);
},
...options,
});
}
}