﻿function CreateLightboxModal()
{
    this.width = 489;
    this.height = 420;
    this.dialogType = "createLightboxModal";
    this.success = {};

    this._getContents = function()
    {
        context = this;
        Core.GetHtml("/createlightbox/index", null, false, function(data)
        {
            context.content = data;
            context._show();
            $('#LightboxName').focus();

            $("#CreateLightbox #Cancel").click(function()
            {
                context.close();
            });

            $("#CreateLightbox #Create").click(function()
            {
                context._createLightbox();
            });
        });
    }

    this._createLightbox = function()
    {
        var name = $('#LightboxName').val();
        var client = $('#Client').val();
        var project = $('#Project').val();
        var notes = $('#Notes').val();
        var context = this;

        $.ajax({
            url: "/createlightbox/CreateLightbox",
            type: "POST",
            data: { 'lightboxname': name,
                'client': client,
                'project': project,
                'notes': notes
            },

            success: function(status)
            {
                if ($.isJson(status))
                {
                    context.success(status);
                }
                else
                {
                    context.dialogContent.html(status);
                    context.border.height(context.dialog.height() + 52);

                    $("#CreateLightbox #Cancel").click(function()
                    {
                        context.close();
                    });

                    $("#CreateLightbox #Create").click(function()
                    {
                        context._createLightbox();
                    });
                }
            }
        });
    }
}

CreateLightboxModal.prototype = new ModalDialog();
CreateLightboxModal.constructor = CreateLightboxModal;
CreateLightboxModal.parent = ModalDialog.prototype;

CreateLightboxModal.prototype.display = function()
{
    this._getContents();
}

function CreateLightboxPreviewModal()
{
    this.dialogType = "CreateLightboxPreviewModal";

    this.success = function(id)
    {
        Lightbox.SetCurrentLightbox(id);
        LightboxPreview.InitializeResults(id);
        context.close();
    }
}

CreateLightboxPreviewModal.prototype = new CreateLightboxModal();
CreateLightboxPreviewModal.constructor = CreateLightboxPreviewModal;
CreateLightboxPreviewModal.parent = CreateLightboxModal.prototype;

CreateLightboxPreviewModal.prototype.display = function()
{
    this._getContents();
}

function CreateLightboxDetailModal()
{
    this.dialogType = "CreateLightboxDetailModal";

    this.success = function(id)
    {
        document.location = "/lightboxes/" + id;
    }
}

CreateLightboxDetailModal.prototype = new CreateLightboxModal();
CreateLightboxDetailModal.constructor = CreateLightboxDetailModal;
CreateLightboxDetailModal.parent = CreateLightboxModal.prototype;

CreateLightboxDetailModal.prototype.display = function()
{
    this._getContents();
}

function ShareLightboxModal(contentProvider)
{
    this.width = 489;
    this.dialogType = "shareLightbox";
    this.contentProvider = contentProvider;
    var thisContext = this;

    this._getContents = function(lightboxId)
    {
        $(document).unbind("CloseSharedLightbox");
        $(document).bind("CloseSharedLightbox", function()
        {
            thisContext.close();
        });

        thisContext.content = thisContext.contentProvider.getContents().outerHtml();
        thisContext._show();
        Core.GetHtml("/lightboxes/share/" + lightboxId, null, false, function(data)
        {
            var result = $.evalJson(data);
            thisContext.contentProvider.init(result);
            thisContext.border.height(thisContext.dialog.height() + 52);
        });
    }
}

ShareLightboxModal.prototype = new ModalDialog();
ShareLightboxModal.constructor = ShareLightboxModal;
ShareLightboxModal.parent = ModalDialog.prototype;

ShareLightboxModal.prototype.display = function(lightboxId)
{
    this._getContents(lightboxId);
}

ShareLightboxModal.prototype.onBeforeClose = function()
{
    this.contentProvider.reset();
};