
/**
 * 修改位置
 */
var modifyPosition = function () {
    var positions = '';
    var indexs = $('#portlet').portlet('index');
    //这里获取的x、y坐标和add接口新增时所给的坐标是相反的............
    for(index in indexs) {
        if (index != 'undefined') {
            positions += '|' + index + ',' + indexs[index]['y'] + ',' + indexs[index]['x'];
        }
    }
    var positionUrl = $('#portlet').data('positionUrl');
    $.getJSON(positionUrl, {positions:positions}, function (json) {
    });
}

/**
 * 删除组件
 */
var removePortlet = function (portlet) {
    var removePortletUrl = $('#portlet').data('removePortletUrl');
    $.getJSON(removePortletUrl, {portlet:portlet}, function (json) {
        if (json.status == 1) {
            modifyPosition();
        }
        else {
            alert(json.info);
        }
    });
}

$(function () {

    //放置两个占位符......
	$('#portlet').portlet({
		sortable: true,
        singleView: false,
		//removeItem: function() {
        //    modifyPosition();
		//},
        events: {
            drag: {
                stop: function(event, ui) {
                    modifyPosition();
                }
            }
        },
            columns: [{
				width: "70%",
				portlets: [{
                    attrs: {'style':'display:none;'},
						title: '',
						content: {
							type: 'text',
							text: ''
                        }
					}]
                }, {
				width: "30%",
				portlets: [{
                    attrs: {'style':'display:none;'},
						title: '',
						content: {
							type: 'text',
							text: ''
						}
                    }]
			}]
	});

});
