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

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

    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);
                }
            }
            ]
        });
    };

    this.evaluation = {
        iconOn : 'ion-ios-star',
        iconOff : 'ion-ios-star-outline',
        iconOnColor: 'rgb(200, 200, 100)',
        iconOffColor:  'rgb(200, 100, 100)',
        rating:  5,
        minRating:1,
        callback: function(rating) {
          self.ratingsCallback(rating);
        }
      };

      this.ratingsCallback = function(rating) {
        this.note.evaluation = rating;
        console.log('Nouvelle note : ', rating);
      };

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