﻿//// GridDialogIncludeExcludeFilter Class -------------------------------------------

//Properties
GridDialogIncludeExcludeFilter.prototype.divDialog;
GridDialogIncludeExcludeFilter.prototype.ddlColumn;
GridDialogIncludeExcludeFilter.prototype.txtareaList;
GridDialogIncludeExcludeFilter.prototype.btnFilter;
GridDialogIncludeExcludeFilter.prototype.btnClose;
GridDialogIncludeExcludeFilter.prototype.imgClose;

GridDialogIncludeExcludeFilter.prototype.parentGrid;
GridDialogIncludeExcludeFilter.prototype.originalMarginTop;
GridDialogIncludeExcludeFilter.prototype.type;

//Event Handlers

GridDialogIncludeExcludeFilter.prototype.filterClick = function (event)
{
    var lines = this.txtareaList.value.replace('\r', '');
//    var lines = this.txtareaList.value.split('\n');
//    var cleanedLines = new Array();
//    for (var i=0; i < lines.length; i++)
//    {
//        lines[i] = lines[i].replace('\r', '');
//        lines[i] = trim(lines[i]);
//        if(lines[i] != '')
//        {
//            cleanedLines.push(lines[i]);
//        }
//    }
    var colName = this.ddlColumn.options[this.ddlColumn.selectedIndex].text;
    this.parentGrid.addIncludeExcludeFilter(colName, lines, this.type);
    this.hide();
}

GridDialogIncludeExcludeFilter.prototype.closeClick = function (event)
{
    this.hide();
}

GridDialogIncludeExcludeFilter.prototype.show = function()
{
    this.divDialog.style.marginTop = getNewMarginTop(this.originalMarginTop); //account for scrolling that may have happened
    this.divDialog.style.visibility = 'visible';
    $(this.txtareaList).focus();
}

GridDialogIncludeExcludeFilter.prototype.hide = function()
{
    this.divDialog.style.visibility = 'hidden';
}

// GridDialogIncludeExcludeFilter object constructor
function GridDialogIncludeExcludeFilter(parentGrid, divDialogId, ddlColumnId, txtareaListId
                                  , btnFilterId, btnCloseId, imgCloseId, type)
{
    this.divDialog = elm(divDialogId);
    this.ddlColumn = elm(ddlColumnId);
    this.txtareaList = elm(txtareaListId);
    this.btnFilter = elm(btnFilterId);
    this.btnClose = elm(btnCloseId);
    this.imgClose = elm(imgCloseId);
    
    this.parentGrid = parentGrid;
    this.originalMarginTop = pixelsToNum(getStyle(this.divDialog).marginTop);
    this.type = type;
    
    function assignEventHandlers(currObj) // Creates a new closure so that inside each event handler "this" means the GridDialogGoogleExport object, not the event target
    {
        if(document.addEventListener)
        {
            currObj.btnFilter.addEventListener('click', function(event) {currObj.filterClick(event); }, false);
            currObj.btnClose.addEventListener('click', function(event) {currObj.closeClick(event); }, false);
            currObj.imgClose.addEventListener('click', function(event) {currObj.closeClick(event); }, false);
        }
        else if(document.attachEvent) // IE
        {
            currObj.btnFilter.attachEvent('onclick', function(event) {currObj.filterClick(event); }, false);
            currObj.btnClose.attachEvent('onclick', function(event) {currObj.closeClick(event); }, false);
            currObj.imgClose.attachEvent('onclick', function(event) {currObj.closeClick(event); }, false);
        }
    };
    assignEventHandlers(this);
}

//// End of GridDialogIncludeExcludeFilter Class -------------------------------------------
