123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import { Component } from '@angular/core';
- import { NavController, NavParams, ActionSheetController } from 'ionic-angular';
- // import { Product } from '../../models/product'
- import { DataProvider } from '../../providers/data-provider'
- import { CameraProvider } from '../../providers/camera-provider';
- import { PreferencesProvider } from '../../providers/preferences-provider';
- @Component({
- selector: 'page-product-details',
- providers: [CameraProvider],
- templateUrl: 'product-details.html'
- })
- export class ProductDetailsPage {
- product = {
- company_id: 0,
- default_code: false,
- description: false,
- ean13: false,
- image_medium: null,
- image_small: null,
- name: null,
- list_price: 1,
- purchase_ok: true,
- qty_available: 0,
- rental: false,
- sale_ok: true,
- standard_price: 0,
- type: "product",
- remote_id: 0,
- doc_state: "created"
- }
- constructor(
- public navCtrl: NavController,
- public params: NavParams,
- public data: DataProvider,
- public actionSheetCtrl: ActionSheetController,
- private cameraProvider: CameraProvider,
- private preferencesPreferences: PreferencesProvider
- ) {
- this.initialize();
- }
- /**
- *
- */
- private initialize() {
- if (!(this.params.data instanceof Array)) {
- this.product = this.params.data;
- this.product.doc_state = "updated";
- }
- }
- /**
- *
- */
- private isValidForm() {
- if (!this.product.name) {
- return false;
- }
- return true;
- }
- /**
- *
- */
- showPhotoOptions() {
- this.actionSheetCtrl.create({
- title: "Tomar una foto",
- buttons: [
- {
- text: "Desde la cámara",
- icon: "camera",
- handler: () => {
- this.takePicture("camera");
- }
- },
- {
- text: "Desde la galería",
- icon: "images",
- handler: () => {
- this.takePicture("album");
- }
- },
- {
- text: "Cancelar",
- role: "cancel"
- }
- ]
- }).present();
- }
- /**
- *
- */
- takePicture(source: string): void {
- this.cameraProvider.getPicture(source).then(i => {
- this.product.image_medium = i;
- this.product.image_small = i;
- }).catch(e => {
- console.log(e);
- });
- }
- /**
- *
- */
- save(): void {
- if (!this.isValidForm()) {
- return;
- }
- this.product.company_id = this.preferencesPreferences.getCompany();
-
- this.data.save('product', this.product).then(result => {
- if (this.params.data instanceof Array) {
- this.params.data.push(result.products[0]);
- }
-
- this.navCtrl.pop(this);
- }).catch(e => {
- console.log(e);
- });
-
- }
- }
|