|
@@ -1,5 +1,5 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
-import { NavController, AlertController } from 'ionic-angular';
|
|
|
+import { NavController, AlertController, ToastController } from 'ionic-angular';
|
|
|
import { DefaultListable } from '../../defaults/default-listable';
|
|
|
import { INavigable } from '../../interfaces/navigable-interface';
|
|
|
import { Product } from '../../models/product';
|
|
@@ -16,7 +16,8 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
|
|
|
constructor(
|
|
|
public navCtrl: NavController,
|
|
|
public data: DataProvider,
|
|
|
- public alertCtrl: AlertController
|
|
|
+ public alertCtrl: AlertController,
|
|
|
+ public toastCtrl: ToastController
|
|
|
){
|
|
|
super();
|
|
|
this.initialize();
|
|
@@ -41,15 +42,15 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- openItem(product: any) {
|
|
|
-
|
|
|
+ openItem(index: number) {
|
|
|
+ this.navCtrl.push(ProductDetailsPage, this.elements[index]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
removeItem() {
|
|
|
- let confirm = this.alertCtrl.create({
|
|
|
+ this.alertCtrl.create({
|
|
|
title: "Confirmar",
|
|
|
message: "Desea borrar este producto?",
|
|
|
buttons: [
|
|
@@ -63,17 +64,24 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
|
|
|
text: "Aceptar",
|
|
|
handler: () => {
|
|
|
let item = this.elements[this.selectedIndex];
|
|
|
+ this.toggleDelete(-1);
|
|
|
|
|
|
- this.data.delete("product", item).then(() => {
|
|
|
-
|
|
|
- }).catch(() => {
|
|
|
+ this.data.delete("product", item).then(result => {
|
|
|
+ this.elements.splice(this.selectedIndex, 1);
|
|
|
|
|
|
+ this.toastCtrl.create({
|
|
|
+ message: "Producto eliminado",
|
|
|
+ duration: 500
|
|
|
+ }).present();
|
|
|
+ }).catch(() => {
|
|
|
+ this.toastCtrl.create({
|
|
|
+ message: "No se pudo eliminar el producto",
|
|
|
+ duration: 500
|
|
|
+ }).present();
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
- });
|
|
|
-
|
|
|
- confirm.present();
|
|
|
+ }).present();
|
|
|
}
|
|
|
}
|