﻿function ListViewRepeaterControl(id, itemName, collection) {
    this._columnCount = 2;
    this._columnBreakTemplate = '</tr><tr>';
    RepeaterControl.call(this, id, itemName, collection);
}

ListViewRepeaterControl.prototype = new RepeaterControl();

ListViewRepeaterControl.prototype.SetColumnCount = function(cols) {
    this._columnCount = cols;
}

ListViewRepeaterControl.prototype.GetColumnCount = function() {
    return this._columnCount;
}

ListViewRepeaterControl.prototype.SetColumnBreakTemplate = function(cols) {
    this._columnBreakTemplate = cols;
}

ListViewRepeaterControl.prototype.GetColumnBreakTemplate = function() {
    return this._columnBreakTemplate;
}

ListViewRepeaterControl.prototype.getHTML = function () {

    var outHtml = '';
    var last = this._end;
    if (last > this.getCount()) {
        last = this.getCount();
    }

    var k = 0;

    //for (var i in this._Collection) {
    for (var i = this._start; i < last; i++) {
        if ((i >= this._start) && (i < this._end)) {
            if (k % this.GetColumnCount() == 0) {
                outHtml += this.GetColumnBreakTemplate();
            }
            var id = this._ItemName;
            var myControl = new Control(id);
            myControl.setParent(this);
            myControl.setTemplate(this._template);
            myControl.setAttribute(id, this._Collection[i]);
            myControl.setAttribute('RowNumber', i);
            outHtml += myControl.getHTML();
            k++;
        }
        if ((this._end - i) > 1) {
            if (this._callback != null) {
                this._callback(this);
                if (this.isLoading()) return 'Loading ...'; // change this to mask outHtml with special div tag with loading message.
                return outHtml;
            }
        }
    }

    return outHtml;
}


