var DetailCtrl = function(NotesSvc, $scope, $state, $ionicHistory, $ionicPopup) {
    this.note = {};

    this.getNote = function() {
        if ($state.params.id) {
            this.note = NotesSvc.getNote($state.params.id);
        }
    };

    this.retour = function() {
        $ionicHistory.goBack();
    };

    this.save = function(form) {
        if(form.$valid) {
            $state.go('home');
        }
    };

    this.sendMail = function() {
        var self = this;
        $scope.data = {};
        var myPopup = $ionicPopup.show({
            template: '<ion-list><ion-checkbox ng-model="data.sendCC">Envoyer copie</ion-checkbox><ion-checkbox ng-model="data.joinSignature">Joindre ma signature</ion-checkbox></ion-list>',
            title: "Envoyer par mail",
            subTitle: self.note.titre,
            scope: $scope,
            buttons: [
            { text: 'Annuler' },
            {
                text: 'Envoyer',
                type: 'button-positive',
                onTap: function(e) {
                    console.log('Mail envoyé');
                    console.log('Copie : ' + $scope.data.sendCC);
                    console.log('Signature : ' + $scope.data.joinSignature);
                }
            }
            ]
        });
    };

    var self = this;
    $scope.$on("$ionicView.afterEnter", function(event, data){
        self.getNote();
    });
};