{"size": 1560, "ext": "js", "max_stars_repo_path": "app/users/user-item.component.js", "max_stars_repo_name": "remarcmij/hyf-todos-es6", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/users/user-item.component.js", "max_issues_repo_name": "remarcmij/hyf-todos-es6", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/users/user-item.component.js", "max_forks_repo_name": "remarcmij/hyf-todos-es6", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.5737704918, "max_line_length": 72, "alphanum_fraction": 0.5064102564}
'use strict';
import angular from 'angular';

const template = require('./user-item.component.html');

class UserItemController {

    static get $inject() {
        return ['$mdDialog', '$state', 'backendService'];
    }

    constructor ($mdDialog, $state, backendService) {
        this.$mdDialog = $mdDialog;
        this.$state = $state;
        this.backendService = backendService;
    }

    editUser(ev) {
        let prompt = this.$mdDialog.prompt()
            .title('Change user name')
            // .textContent('Please enter the user\'s name')
            .placeholder('name')
            .ariaLabel('User name')
            .initialValue(this.user.name)
            .targetEvent(ev)
            .ok('Update')
            .cancel('Cancel');

        this.$mdDialog.show(prompt)
            .then(name => {
                name = name.trim();
                if (name && name !== this.user.name) {
                    console.log('Updating user name: ' + name);
                    this.user.name = name
                    this.backendService.updateUser(this.user)
                }
            })
            .catch(() => console.log('Change user name was cancelled'));
    }

    deleteUser(ev) {
        this.onDelete({id: this.user._id, ev: ev});
    }

    showTodos() {
        this.$state.go('userTodos', {id: this.user._id});
    }
}

angular.module('app')
    .component('hyfUserItem', {
        template,
        bindings: {
            user: '<',
            onDelete: '&'
        },
        controller: UserItemController
    });


