|
@@ -1,9 +1,10 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
-import { NavController, AlertController, ToastController, LoadingController } from 'ionic-angular';
|
|
|
+import { NavController, AlertController, ToastController, LoadingController, PopoverController } from 'ionic-angular';
|
|
|
import { DefaultListable } from '../../defaults/default-listable';
|
|
|
import { INavigable } from '../../interfaces/navigable-interface';
|
|
|
import { Product } from '../../models/product';
|
|
|
import { ProductDetailsPage } from '../product-details/product-details';
|
|
|
+import { ProductOptions } from './product-options';
|
|
|
import { DataProvider } from '../../providers/data-provider';
|
|
|
|
|
|
@Component({
|
|
@@ -12,12 +13,15 @@ import { DataProvider } from '../../providers/data-provider';
|
|
|
})
|
|
|
export class ProductListPage extends DefaultListable<Product> implements INavigable {
|
|
|
|
|
|
+ popover: any = null;
|
|
|
+
|
|
|
constructor(
|
|
|
public navCtrl: NavController,
|
|
|
public alertCtrl: AlertController,
|
|
|
public toastCtrl: ToastController,
|
|
|
public dataProvider: DataProvider,
|
|
|
- public loadingController: LoadingController
|
|
|
+ public loadingController: LoadingController,
|
|
|
+ public popoverCtrl: PopoverController
|
|
|
){
|
|
|
super();
|
|
|
}
|
|
@@ -44,6 +48,19 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ loadMore(e) {
|
|
|
+ this.seekRange();
|
|
|
+
|
|
|
+ if (this.isToSeek()) {
|
|
|
+ e.enable(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ e.complete();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Goto page
|
|
|
*/
|
|
@@ -54,15 +71,42 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- openItem(index: number) {
|
|
|
- this.toggleDelete(-1);
|
|
|
- this.navCtrl.push(ProductDetailsPage, this.elements[index]);
|
|
|
+ showOptions(e, item) {
|
|
|
+ this.popover = this.popoverCtrl.create(ProductOptions, {
|
|
|
+ item: item
|
|
|
+ });
|
|
|
+
|
|
|
+ this.popover.present({
|
|
|
+ ev: e
|
|
|
+ });
|
|
|
+
|
|
|
+ this.popover.onDidDismiss(data => {
|
|
|
+ switch (data.role) {
|
|
|
+ case "open":
|
|
|
+ this.openItem(data.item);
|
|
|
+ break;
|
|
|
+ case "delete":
|
|
|
+ this.askIfRemoveItem(item);
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- askIfRemoveItem(): void {
|
|
|
+ openItem(item: any) {
|
|
|
+ this.navCtrl.push(ProductDetailsPage, item);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ askIfRemoveItem(item): void {
|
|
|
this.alertCtrl.create({
|
|
|
title: "Confirmar",
|
|
|
message: "Desea borrar este producto?",
|
|
@@ -70,13 +114,14 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
|
|
|
{
|
|
|
text: "Cancelar",
|
|
|
handler: () => {
|
|
|
- this.toggleDelete(-1);
|
|
|
+ console.log("Canceled");
|
|
|
+
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
text: "Aceptar",
|
|
|
handler: () => {
|
|
|
- this.removeItem();
|
|
|
+ this.removeItem(item);
|
|
|
}
|
|
|
}
|
|
|
]
|
|
@@ -86,13 +131,11 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- removeItem() {
|
|
|
- let item = this.elements[this.selectedIndex];
|
|
|
+ removeItem(item: any) {
|
|
|
item.doc_state = "deleted";
|
|
|
- this.toggleDelete(-1);
|
|
|
|
|
|
this.dataProvider.delete("product", item).then(result => {
|
|
|
- this.elements.splice(this.selectedIndex, 1);
|
|
|
+ this.remove(item);
|
|
|
}).catch(() => {
|
|
|
this.toastCtrl.create({
|
|
|
message: "No se pudo eliminar el producto",
|