//切换分组模块
var switch_group = function(option, success) {
    var object = new SwitchGroup(option);
    success();
    return object;
}

function SwitchGroup(option) {
    this.markControl = option.markControl;
    this.url = option.url;
    this.groups =JSON.parse(option.groups);
    this.popover = getDom(this.popover_dom, this.markControl);
    this.popover.cancelButton = this.popover.find('p.image-close');
    this.popover.submitButton = this.popover.find('a.btn');
    this.popover.appendTo(this.markControl.container);
    $("#groupForm").attr("action", this.url);

    var self = this;
    if(this.groups.length > 0){
    	for (var i = 0; i < this.groups.length; i++) {
    		var name = getDom("<option value="+this.groups[i].id+">分组序号:"+this.groups[i].groupNumber+"</option>").appendTo(self.popover.find('#groupSelect'));
    	}
    }
    
    
    this.markControl.container.header.find('#switch-group-button').click(function() {
        self.toggle(true);
    });
    this.popover.cancelButton.click(function() {
        self.toggle(false);
    });
    this.popover.submitButton.click(function() {
    	var markerId= self.popover.find('#groupSelect').val();
    	if(markerId==0){
    		return;
    	}
    	$("#groupForm").submit();
    });
}

SwitchGroup.prototype.toggle = function(enable) {
    if (enable == true) {
        this.enable = true;
        this.popover.show();
    } else {
        this.enable = false;
        this.popover.hide();
    }
}

SwitchGroup.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"><form id="groupForm" method="post"><select name="markerId" id="groupSelect"><option value="0">请选择</option></select></form></div>\
<a href="#" class="btn btn-small btn-info " id="groupFormSubmit" data-i18n-text="mark.change.confirm">确定</a>\
</div>';