//#region доп. поле - чекбокс
function FieldCheckboxItemData(observer, id) {
    var args = [];
    args.push(observer);
    args.push({
        group: 'fieldcheckbox',
        name: id,
        selector: '#' + id,
    });
    FieldItemData.apply(this, args);
}
FieldCheckboxItemData.prototype = Object.create(FieldItemData.prototype);
FieldCheckboxItemData.prototype.GetCurrentVal = function () {
    return $(this._options.selector).is(':checked').toString();
}
//функция подсветки блока
FieldCheckboxItemData.prototype.Highlight = function () {
    $(this._options.selector).closest('label').addClass('taskFormHub-highlightBlock');
}

//функция убирает подсветку блока
FieldCheckboxItemData.prototype.Unhighlight = function () {
    $(this._options.selector).closest('label').removeClass('taskFormHub-highlightBlock');
}
FieldCheckboxItemData.prototype.GetSelectorType = function () {
    return 'checkbox';
}
//создать сообщение что нет конфликта и обновить блок данными
FieldCheckboxItemData.prototype.AppendNotConflict = function (submitData) {
    var $notconflictMessage = $(this.tmpl_notconflictMessageBase({ blockName: this._options.name }));

    //добавить новую инфу
    $(this._options.selector).closest('label').append($notconflictMessage);

    this.AppendNotConflictUpdate(submitData);
}
//обновить блок
FieldCheckboxItemData.prototype.AppendNotConflictUpdate = function (submitData) {
    if (submitData == '') {
        $(this._options.selector).prop('checked', false);
    }
    else {
        $(this._options.selector).prop('checked', true);
    }

    this.SetOldValue();
    this.SendBlockChange();
}
FieldCheckboxItemData.prototype.GetSubmitVal = function (submitData) {
    if (submitData == '')
        return 'false';
    else
        return 'true';
}

FieldCheckboxItemData.prototype.AppendConflict2 = function ($conflictMessage) {
    //добавить новую инфу
    $(this._options.selector).closest('label').append($conflictMessage);
}

FieldCheckboxItemData.prototype.ConflictDialogContent = function (selectorType, submitData) {
    var that = this;

    var c =
    '<div>\
        <label>\
            <input type="radio" name="conflictradioresolve-' + that._options.name + '" value="1" checked />' + TaskFormHubResources.ConflictDialogContent_UseOldValue + '\
        </label>';
    c += '<label>'
    if (this.GetCurrentVal() == 'true') {
        c += '<input type="checkbox" name="conflictradioresolve-' + that._options.name + '-value1" checked />';
    }
    else {
        c += '<input type="checkbox" name="conflictradioresolve-' + that._options.name + '-value1" />';
    }
    c += this.GetBlockTitle();
    c += '</label>'
    c +=
    '</div><hr>\
    <div>\
        <label>\
            <input type="radio" name="conflictradioresolve-' + that._options.name + '" value="0" />' + TaskFormHubResources.ConflictDialogContent_UseNewValue + '\
        </label>';
    c += '<label>'
    if (submitData == '' || submitData == 'false') {
        c += '<input type="checkbox" name="conflictradioresolve-' + that._options.name + '-value0" disabled />';
    }
    else {
        c += '<input type="checkbox" name="conflictradioresolve-' + that._options.name + '-value0" disabled checked />';
    }
    c += this.GetBlockTitle();
    c += '</label>'
    c += '</div>';

    return $(c);

}

FieldCheckboxItemData.prototype.ConflictDialogOkCallback = function () {
    var selectorType = this.GetSelectorType();

    var $content = GLOBAL_taskFormHubDialog.getContent();
    var checkedVal = $content.find('[name="conflictradioresolve-' + this._options.name + '"]:checked').val();
    var checked = $content.find('[name="conflictradioresolve-' + this._options.name + '-value' + checkedVal + '"]').is(':checked');
    $(this._options.selector).prop('checked', checked).trigger('change');
    if (checkedVal == 0) {
        this.SetOldValue();
        this.SendBlockChange();
    }

    //удаляем инфу о конфликте
    this.isConflict = false;
    this.$conflictMessageElement = undefined;
    $(this._options.selector).siblings('[conflict-block="' + this._options.name + '"]').remove();

    GLOBAL_taskFormHubDialog.closeDialog();
}

//#endregion