product-details.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Component } from '@angular/core';
  2. import { NavController, NavParams } from 'ionic-angular';
  3. import { Product } from '../../models/product'
  4. import { DataProvider } from '../../providers/data-provider'
  5. @Component({
  6. selector: 'page-product-details',
  7. providers: [DataProvider],
  8. templateUrl: 'product-details.html'
  9. })
  10. export class ProductDetailsPage {
  11. product = {
  12. name: "",
  13. type: 0,
  14. salePrice: 0,
  15. ean13: "",
  16. reference: "",
  17. costPrice: 0,
  18. quantity: 0,
  19. salesCount: 0,
  20. active: true
  21. }
  22. constructor(
  23. public navCtrl: NavController,
  24. public params: NavParams,
  25. public data: DataProvider
  26. ) { }
  27. /**
  28. *
  29. */
  30. private isValidForm() {
  31. if (!this.product.name) {
  32. return false;
  33. }
  34. return true;
  35. }
  36. /**
  37. *
  38. */
  39. save(): void {
  40. if (!this.isValidForm()) {
  41. return;
  42. }
  43. this.data.save('product', this.product).then(result => {
  44. this.params.data.push(result.products[0]);
  45. this.navCtrl.pop(this);
  46. });
  47. }
  48. }