﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("MXA.FP.View.WorkshopView");

MXA.FP.View.WorkshopView = function (element) {

    MXA.FP.View.WorkshopView.initializeBase(this, [element]);
    this.addCssClass('WorkshopView');

    this._extraInfoContainer = document.createElement('div');
    this._extraInfoContainer.className = 'wvExtraInfoContainer';

    this._dateText = document.createElement('div');
    this._dateText.className = 'wvDate';

    this._amountOfSeatsText = document.createElement('div');
    this._amountOfSeatsText.className = 'wvAmountOfSeats';

    this._extraInfoContainer.appendChild(this._dateText);
    this._extraInfoContainer.appendChild(this._amountOfSeatsText);

    element.appendChild(this._extraInfoContainer);

}

MXA.FP.View.WorkshopView.prototype =
{
    initialize: function () {
        MXA.FP.View.WorkshopView.callBaseMethod(this, 'initialize');
    },

    dispose: function () {
        MXA.FP.View.WorkshopView.callBaseMethod(this, 'dispose');
    },

    get_formTitle: function () {
        return 'inschrijven?';
    },

    initializeCollection: function (container) {
        var datasource = this.get_datasource();
        var element = document.createElement('div');
        container.appendChild(element);
        var template = $create(MXA.FP.Template.WorkshopTemplate, null, null, null, element);
        template._owner = this;
        template.set_datasource(datasource);
        return template;
    },

    get_datasource: function () {
        if (document.datasource.workshops != null) {
            return document.datasource.workshops.workshop;
        }
        return null;
    },

    databindItem: function () {
        MXA.FP.View.WorkshopView.callBaseMethod(this, 'databindItem');
        var ds = this.get_datasource();
        if (ds == null) {
            return;
        }
        var source = ds[this._selectedIndex];
        if (source.date == null) {
            this._dateText.innerHTML = 'Datum niet bekend';
        }
        else {
            this._dateText.innerHTML = source.date;
        }
        if (source.seatsavailable == 0) {
            this._amountOfSeatsText.innerHTML = 'vol';
            this._extraInfoContainer.className = 'wvExtraInfoContainer full';
        } else {
            this._amountOfSeatsText.innerHTML = 'Nog ' + source.seatsavailable + ' plaatsen';
            this._extraInfoContainer.className = 'wvExtraInfoContainer';
        }
        Cufon.replace([this._dateText, this._amountOfSeatsText]);
    },


    showIndex: function (index) {
        MXA.FP.View.WorkshopView.callBaseMethod(this, 'showIndex', [index]);
        var _this = this;
        $(_this._extraInfoContainer).animate({ opacity: 0 }, document.datasource.animation.speed.productOut, function () {
            $(_this._extraInfoContainer).animate({ opacity: 1 }, document.datasource.animation.speed.productIn);
        });
    }

}

MXA.FP.View.WorkshopView.registerClass('MXA.FP.View.WorkshopView', MXA.FP.View.ProductBaseView);
