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

function ChangeName(option) {
    this.markControl = option.markControl;
    this.url = option.url;
    this.context = option.markControl.context;
    this.userName = option.markControl.container.header.find('#mark-user-name');

    this.popover = getDom(this.popover_dom, this.markControl);
    this.popover.input = this.popover.find('input.user-input');
    this.popover.message = this.popover.find('i.wrong');
    this.popover.submitButton = this.popover.find('a.btn');
    this.popover.cancelButton = this.popover.find('p.image-close');
    this.popover.appendTo(this.markControl.container);

    var self = this;

    this.markControl.container.header.find('a.useinfo').click(function() {
        self.toggle(true);
    });
    this.popover.cancelButton.click(function() {
        self.toggle(false);
    });
    this.popover.submitButton.click(function() {
        var text = self.popover.input.val();
        if (text.length == 0) {
            self.popover.message.html('姓名不能为空');
        } else if (text.length > 8) {
            self.popover.message.html('长度不能超过8个字');
        } else {
            $.post(self.url, {
                name: text
            }, function(result) {
                if (result.success == true) {
                    self.userName.html(result.name);
                    self.toggle(false);
                } else {
                    self.popover.message.html('姓名修改失败，请稍后重试');
                }
            }).error(function() {
                self.popover.message.html('网络通信错误，请稍后重试');
            });
        }
    });
}

ChangeName.prototype.toggle = function(enable) {
    if (enable == true) {
        this.enable = true;
        this.popover.input.val('');
        this.popover.message.html('');
        this.popover.show();
        this.context.listenKeyboard = false;
    } else {
        this.enable = false;
        this.popover.hide();
        this.context.listenKeyboard = true;
    }
}

ChangeName.prototype.popover_dom = '<div class="message-popover" style="display:none"><div class="popover-header">\
<p class="title">评卷员更名</p><p class="image-close"><img src="{staticServer}/mark-new/images/images-close.png" /></p></div>\
<div class="popover-cont"><input type="text" class="user-input" placeholder="请输入您的姓名" />\
<i class="wrong"></i></div>\
<a href="#" class="btn btn-large btn-info text-c">确定</a>\
</div>';