//评卷状态模块
var header_mark_status = function (option, success) {
    var object = new HeaderMarkStatus(option);
    success();
    return object;
}

function HeaderMarkStatus(option) {
    this.markControl = option.markControl;
    this.title = option.title;
    this.init();
    this.markControl.on('task.get.before', this, function (event, context, statusInfo) {
        this.secretArea.hide();
        this.blockTitle.html('正在领取任务');
    });
    this.markControl.on('task.get.success', this, function (event, context, eventObject) {
        var task = context.task;
        //状态栏区域
        this.blockTitle.html('');

        this.secretArea.show();
        this.topStatus.find('#secret-number').html(task.studentNumber);
    });
    this.markControl.on('task.get.none', this, function (event, context, status) {
        this.secretArea.hide();
        this.blockTitle.html('');
    });
    this.markControl.on('mark.status.change', this, function (event, context, status) {
        this.render(status);
    });
}

HeaderMarkStatus.prototype.init = function () {
    this.progress = getDom(this.progress_dom, this.markControl).prependTo(this.markControl.container.header);
    this.topStatus = getDom(this.top_status_dom, this.markControl).prependTo(this.markControl.container.header);
    this.secretArea = this.topStatus.find('#secret-area');
    this.secretArea.hide();
    this.progress.hide();

    this.blockTitle = this.topStatus.find('#block-title');
    this.topStatus.find('#status-title').html(this.title);
}

HeaderMarkStatus.prototype.render = function (status) {
    if (status != undefined && status.valid === true) {
        this.progress.show();
        //进度信息区域
        var totalCount = status.totalCount;
        var markedCount = status.markedCount;
        var leftCount = totalCount > markedCount ? (totalCount - markedCount) : 0;
        var markedPercent = totalCount > 0 ? new Number((totalCount - leftCount) * 100 / totalCount).toFixed(0) : 0;
        if (markedPercent == '100' && leftCount > 0) {
            markedPercent = '99';
        } else if (markedPercent == '0' && markedCount > 0) {
            markedPercent = '1';
        }
        this.progress.find('#total-count').html(totalCount);
        this.progress.find('#marked-count').html(markedCount);
        //this.progress.find('#todo-count').html(leftCount);
        //this.progress.find('#marked-percent').html(markedPercent.toString() + '%');
    }
}

HeaderMarkStatus.prototype.top_status_dom = '<p class="text">\
<i id="status-title"></i>\
<i id="block-title"></i>\
<i id="secret-area"><em id="secret-number"></em></i>\
</p>';

HeaderMarkStatus.prototype.progress_dom = '<p class="text">\
<i>待处理<em id="total-count"></em></i>\
<i>已处理<em id="marked-count"></em></i>\
</p>';