/*
 * Copyright 2002-2006 Jahia Ltd
 *
 * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (JCDDL), 
 * Version 1.0 (the "License"), or (at your option) any later version; you may 
 * not use this file except in compliance with the License. You should have 
 * received a copy of the License along with this program; if not, you may obtain 
 * a copy of the License at 
 *
 *  http://www.jahia.org/license/
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
/**
 * Represents a DwtListView Item
 *
 * @param id        Id of the item (row index)
 * @param attrs     Attributes for each column
 * @param values    Values for each column (order is important regarding to attributes)
 * @param hidden    Whether this item is hidden or visible
 * @param regroup   Integer[] indicating how many values should be put under the same column header
 */
function ListItem(id, attrs, values, hidden, regroup) {
    this._id = id;
    this._hidden = (hidden ? hidden : false);
    this._regroup = (regroup ? regroup : [1]);
    this._values = values;
    this._enabled = true;
    for (var i = 0; i < attrs.length; i++) {
        this.setValue(attrs[i][0], values[i]);
    }
}

ListItem.prototype.toString =
function() {
    return "ListItem " + this._id;
}

ListItem.prototype.getID =
function() {
    return this._id;
}

ListItem.prototype.setValue =
function(attrId, value) {
    this[attrId] = value;
}

ListItem.prototype.getValue =
function(attrId) {
    return this[attrId];
}

ListItem.prototype.getValues =
function() {
    return this._values;
}

ListItem.prototype.clear =
function() {
    for (var i in this) {
        this[i] = null;
    }
}

ListItem.prototype.hide =
function() {
    this._hidden = true;
}

ListItem.prototype.show =
function() {
    this._hidden = false;
}

ListItem.prototype.disable =
function() {
    this._enabled = false;
}

ListItem.prototype.enable =
function() {
    this._enabled = true;
}

ListItem.prototype.isHidden =
function() {
    return this._hidden;
}

ListItem.prototype.getRegroup =
function() {
    return this._regroup;
}

ListItem.prototype.invertCheckboxValue =
function (colName) {
    var values = this.getValue(colName);
    if (values[1] != null) {
        values[1] = ! values[1];
    }
    delete values;
}