11import { Component } from '@angular/core' ;
2- import { ModalController , ViewController } from 'ionic-angular' ;
2+ import { AlertController , ModalController , Platform , ViewController } from 'ionic-angular' ;
33import { NewLocationMessageComponent } from './location-message' ;
44import { MessageType } from 'api/models' ;
55import { PictureService } from '../../services/picture' ;
@@ -12,16 +12,26 @@ export class MessagesAttachmentsComponent {
1212 constructor (
1313 private viewCtrl : ViewController ,
1414 private modelCtrl : ModalController ,
15- private pictureService : PictureService
15+ private pictureService : PictureService ,
16+ private platform : Platform ,
17+ private alertCtrl : AlertController
1618 ) { }
1719
18- sendPicture ( ) : void {
19- this . pictureService . select ( ) . then ( ( file : File ) => {
20- this . viewCtrl . dismiss ( {
21- messageType : MessageType . PICTURE ,
22- selectedPicture : file
20+ sendPicture ( camera : boolean ) : void {
21+ if ( camera && ! this . platform . is ( 'cordova' ) ) {
22+ return console . warn ( 'Device must run cordova in order to take pictures' ) ;
23+ }
24+
25+ this . pictureService . getPicture ( camera , false )
26+ . then ( ( blob : File ) => {
27+ this . viewCtrl . dismiss ( {
28+ messageType : MessageType . PICTURE ,
29+ selectedPicture : blob
30+ } ) ;
31+ } )
32+ . catch ( ( e ) => {
33+ this . handleError ( e ) ;
2334 } ) ;
24- } ) ;
2535 }
2636
2737 sendLocation ( ) : void {
@@ -41,4 +51,16 @@ export class MessagesAttachmentsComponent {
4151
4252 locationModal . present ( ) ;
4353 }
54+
55+ handleError ( e : Error ) : void {
56+ console . error ( e ) ;
57+
58+ const alert = this . alertCtrl . create ( {
59+ title : 'Oops!' ,
60+ message : e . message ,
61+ buttons : [ 'OK' ]
62+ } ) ;
63+
64+ alert . present ( ) ;
65+ }
4466}
0 commit comments