/*
 * Copyright (c) 2012-2014 Kaarle Ritvanen
 * See LICENSE file for license details
 */

define(
    ["aconf/dom", "aconf/widget/combobox", "jquery", "underscore"],
    function(dom, Base, $, _) {
	return Base.extend({
	    init: function(
		data, name, meta, level, editable, removable
	    ) {
		this.field = Base.createEl();
		return Base.init.call(
		    this,
		    data,
		    name,
		    meta,
		    level,
		    editable,
		    removable
		);
	    },
	    
	    staticRender: function(value, meta) {
		return $("<td>").html(dom.objectRef(value).text(value));
	    },
	    
	    statusEl: function() { return this.el.find("select"); },

	    createEl: function() { return $("<div>"); },
	    
	    render: function(value, meta) {
		Base.render.call(this, value, meta);
		
		this.el.html(this.field);
		this.el.append(" ");
		
		var link = $("<div>");
		var update = _.bind(function() {
		    link.html(dom.objectRef(this.get()));
		}, this);
		this.el.append(link);
		
		this.field.change(update);
		update();
	    }
	});
    }
);
