//Copyright 2007 Roman Ardern-Corris
//Licenced to 3legs.com


function ligoButton (paramsObj) {
    //Constructor

    //all parameters are passed in JSON notation

    //Attributes
    this.Dataset;       //Instance of a ligoDataset
    this.div;           //The name of the target div
    this.name;          //Name of the button
    this.label;         //label for button
    this.uri;
    this.id;


    //Finish the init by applying the passed in values
    this._init(paramsObj);

}

//#####################################################################################################################

ligoButton.prototype._init = function (paramsObj) {
    if (paramsObj.Dataset) { this.Dataset = paramsObj.Dataset; }
    if (paramsObj.div) { this.div = paramsObj.div; }
    if (paramsObj.name) { this.instanceName = paramsObj.name; }
    if (paramsObj.label) { this.label = paramsObj.label; }
    if (paramsObj.uri) { this.uri = paramsObj.uri; }

    this.Dataset.addDependant(this);

}

//#####################################################################################################################

ligoButton.prototype.button_html = function () {

    var out_html = '<a id="' + this.id +'" href="' + this.uri + '">' + this.label + '</a>';

    return(out_html);

}

//#####################################################################################################################

ligoButton.prototype.before_render = function () {
    //Abstract
}

//#####################################################################################################################

ligoButton.prototype.render = function () {

    this.before_render();

    document.getElementById(this.div).innerHTML = this.button_html();

}

//#####################################################################################################################

ligoButton.prototype.onDS_currentRowChange = function (source) {
    //this occurs when the master dataset has changed its row
    //This is not when we change current row (that can be done in setCurrentRow() )

    //We basically want to repopulate this dataset with data as would be returned from our URI
    //but we want to pass into that remote function the current row of the master dataset as a JSON object

    this.refresh();

}

//#####################################################################################################################

ligoButton.prototype.refresh = function () {
    this.render();
}

//#####################################################################################################################
