Use Schedule Delete Modal Component in scheduleRow Component.

This commit is contained in:
Alexis Lahouze 2017-07-25 15:58:54 +02:00
parent 46f5f72bd4
commit 53a29062ea
2 changed files with 14 additions and 45 deletions

View File

@ -1,25 +0,0 @@
<!-- vim: set tw=80 ts=2 sw=2 sts=2: -->
<div class="modal top am-fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="modal-title">{{ title }}</h3>
</div>
<div class="modal-body" id="modal-body">
<p>Voulez-vous supprimer l'opération #{{ operation.id }} ayant pour libellé :<br/>{{ operation.label }}
</p>
</div>
<div class="modal-footer">
<button class="btn btn-danger" type="button" ng-click="$delete()">
Supprimer
</button>
<button class="btn btn-default" type="button" ng-click="$hide()">
Annuler
</button>
</div>
</div>
</div>
</div>

View File

@ -3,13 +3,14 @@ import { CurrencyPipe } from '@angular/common';
import { Component, Inject, Input, Output, EventEmitter, OnInit } from '@angular/core'; import { Component, Inject, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { Logger } from '@nsalaun/ng-logger'; import { Logger } from '@nsalaun/ng-logger';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { ScheduleDeleteModalComponent } from './scheduleDeleteModal.component';
import { ScheduleService } from './schedule.service'; import { ScheduleService } from './schedule.service';
import { Schedule } from './schedule'; import { Schedule } from './schedule';
var scheduleFormTmpl = require('./schedule.form.tmpl.html'), var scheduleFormTmpl = require('./schedule.form.tmpl.html');
scheduleDeleteTmpl = require('./schedule.delete.tmpl.html');
@Component({ @Component({
selector: 'tr[schedule-row]', selector: 'tr[schedule-row]',
@ -59,7 +60,8 @@ export class ScheduleRowComponent {
private scheduleService: ScheduleService, private scheduleService: ScheduleService,
private logger: Logger, private logger: Logger,
private toastrService: ToastrService, private toastrService: ToastrService,
@Inject('$modal') private $modal @Inject('$modal') private $modal,
private ngbModal: NgbModal
) {} ) {}
save(schedule: Schedule) { save(schedule: Schedule) {
@ -77,23 +79,15 @@ export class ScheduleRowComponent {
confirmDelete() { confirmDelete() {
var title = "Delete schedule #" + this.schedule.id; var title = "Delete schedule #" + this.schedule.id;
this.$modal({ const modal = this.ngbModal.open(ScheduleDeleteModalComponent, {
templateUrl: scheduleDeleteTmpl, windowClass: 'in'
controller: function($scope, title, schedule, $delete) { });
$scope.title = title;
$scope.operation = schedule; modal.componentInstance.schedule = this.schedule;
$scope.$delete = () => {
$scope.$hide(); modal.result.then((schedule: Schedule) => {
$delete($scope.operation); this.delete(schedule);
}; }, (reason) => function(reason) {
},
locals: {
title: title,
schedule: this.schedule,
$delete: (schedule) => {
this.delete(schedule);
}
}
}); });
} }