//#region Трудозатраты
function ExpenseItemData(observer) {
    var that = this;

    this.removedExpenses = [];
    this.expenseIsEditing = false;

    var args = [];
    args.push(observer);
    args.push({
        group: 'taskexpenses',
        name: 'taskexpenses',
        selector: '#expenses',
        useDefaultEvent: false,
        initConflictAfterSubmit: {
            compareEqualsCurrentWithSubmitValue: false,
            canConflict: false
        },
    });
    ItemData.apply(this, args);
}
ExpenseItemData.prototype = Object.create(ItemData.prototype);

ExpenseItemData.prototype.InitTaskRightsDisplayType = function () {
    this.taskRightsDisplayType = ItemDataHelper.TaskRightsDisplayType[$('#expensestaskrightsdisplaytype').attr(ItemData.taskRightsDisplayTypeKey)] || ItemDataHelper.TaskRightsDisplayType.None;
}

ExpenseItemData.prototype.GetBlockTitle = function () {
    return $('[expensetitle]').clone().children().remove().end().text();
}
ExpenseItemData.prototype.GetCurrentVal = function () {
    return this.expenseIsEditing || this.removedExpenses.length > 0;
}
//part2 - пользовательская
ExpenseItemData.prototype.Append2 = function (userConnectionId, userId, userName, data, existUserConnectionId) {
    var $parent = $('[expensetitle]').parent();
    $parent.find('span.taskFormHub-blockInfo').remove();
    var $span = this.GetSpanTemplate(userConnectionId, userId);
    $parent.append($span);
    this.Highlight();
}
//удалить инфу о всех юзерах которые изменили блок
//вызывает при дисконекте
ExpenseItemData.prototype.ResetAll = function () {
    this.usersEditThisBlock = [];
    var $parent = $('[expensetitle]').parent();
    //удалить текущий span
    $parent.find('span.taskFormHub-blockInfo').remove();
    this.Unhighlight();
}
//part2 - пользовательская
ExpenseItemData.prototype.Reset2 = function (userConnectionId, userId, userName) {
    var $parent = $('[expensetitle]').parent();
    //удалить текущий span
    $parent.find('span.taskFormHub-blockInfo').remove();
    //если есть еще пользователи которые редактируют блок
    if (this.usersEditThisBlock.length > 0 && this.TaskRightsDisplayType() != ItemDataHelper.TaskRightsDisplayType.None) {
        //сделать новый span
        var $span = this.GetSpanTemplate(userConnectionId, userId);
        $parent.append($span);
        //подстветить
        this.Highlight();
    }
    else {
        this.Unhighlight();
    }
}

ExpenseItemData.prototype.GetSendBlockChangeData = function () {
    return {
        expenseIsEditing: this.expenseIsEditing,
        removedExpenses: this.removedExpenses
    }
}

ExpenseItemData.prototype.addExpenses = function () {
    this.expenseIsEditing = true;
    addExpenses();
    this.SendBlockChange();
}
ExpenseItemData.prototype.cancelAddExpenses = function () {
    this.expenseIsEditing = false;
    cancelAddExpenses();
    this.SendBlockChange();
}
ExpenseItemData.prototype.removeExpenses = function (id) {
    var that = this;
    var defResult = removeExpenses(id);
    defResult.then(function (ok) {
        if (ok) {
            that.removedExpenses.push(id);
            that.SendBlockChange();
        }
    });
}
//#endregion