'use strict';
/*
*   Author: Pavel Bely
*   Mail: poul-white@yandex.ru
*
*   Item controller with directive
*/

import app from '../../modules/app';
import markup from './item.html';
import {
    updateContent,
    remove
} from '../../redux/actions';

class ItemController {
    constructor($ngRedux, {$parent}) 

    mapDispatchToThis(dispatch) {
        return {
            deleteHandle: (column, id) => dispatch(remove(column, id)),
            updateData: (column, id, text) => dispatch(updateContent(column, id, text))
        };
    }
}

app.directive('appItem', ['dndService', function(dndService) {
    return {
        restrict: 'A',
        controller: ['$ngRedux', '$scope', ItemController],
        controllerAs: 'task',
        link: dndService('item'),
        template: markup,
        scope: {}
    };
}]);

{
        this.column = $parent.$parent.column.name;
        this.id = $parent.task.id;
        this.text = $parent.task.content;
        $ngRedux.connect(this.mapStateToThis,this.mapDispatchToThis)(this);
    }