starter.factory('Task', function ($http, $q, $resource, cfg, global, formatFilter, showPopup, Tool) {

    function check(task_item) {
        console.log(task_item)
        if (task_item.content == null || task_item.content == '') {
            showPopup.PopupWindow(0, '请输入任务详情', false);
            return false;
        } else if (task_item.task_members.length == 0) {
            showPopup.PopupWindow(0, '请选择负责人', false);
            return false;
        } else {
            return true;
        }
    }

    return {
        task: function (url) {
            return url == null ? $resource(formatFilter('{0}task/task/:id/', cfg.api), null, {update: {method: 'PUT'}}) : $resource(url)
        },
        taskchild: $resource(formatFilter('{0}task/task/:id/children/', cfg.api)),
        taskmember: $resource(formatFilter('{0}task/member/', cfg.api)),
        taskcomment: function (url) {
            return url == null ? $resource(formatFilter('{0}task/comment/:id/', cfg.api)) : $resource(url)
        },
        taskhistory: function (url) {
            return url == null ? $resource(formatFilter('{0}task/history/', cfg.api)) : $resource(url)
        },
        taskfile: $resource(formatFilter('{0}task/file/', cfg.api)),
        taskcommentfile: $resource(formatFilter('{0}task/commentfile/', cfg.api)),
        taskpreferences: $resource(formatFilter('{0}preferences/', cfg.api)),
        taskdetail: {},
        check: function (task_item) {
            return check(task_item);
        }
    }
});
