﻿//// GridToolBar Class -------------------------------------------

//Properties
GridToolBar.prototype.divToolbar;
GridToolBar.prototype.imgIncludeFilter;
GridToolBar.prototype.imgExcludeFilter;
GridToolBar.prototype.imgCustomFilter;
GridToolBar.prototype.imgCustomSort;
GridToolBar.prototype.imgHideShowColumns;
GridToolBar.prototype.imgCalculatedColumn;
GridToolBar.prototype.imgRefresh;
GridToolBar.prototype.imgExportExcel; //right now has an <a> tag, no onclick
GridToolBar.prototype.imgExportAdwords;

GridToolBar.prototype.grid;
GridToolBar.prototype.dialogIncludeFilter;
GridToolBar.prototype.dialogExcludeFilter;
GridToolBar.prototype.dialogCustomFilter;
GridToolBar.prototype.dialogCustomSort;
//GridToolBar.prototype.dialogHideShowColumns; //may not be needed, built into grid already
GridToolBar.prototype.dialogCalculatedColumn;
//refresh shouldn't need a dialog
//no dialog for excel export (dialog made by returning request with appropriate mime type)
GridToolBar.prototype.dialogExportAdwords;

//Event Handlers

GridToolBar.prototype.showIncludeFilter = function (event)
{
    this.dialogIncludeFilter.show();
}

GridToolBar.prototype.showExcludeFilter = function (event)
{
    this.dialogExcludeFilter.show();
}

GridToolBar.prototype.showCustomFilter = function (event)
{
    this.dialogCustomFilter.show();
}

GridToolBar.prototype.showCustomSort = function (event)
{
    this.dialogCustomSort.show();
}

GridToolBar.prototype.showHideShowColumns = function (event)
{
    alert('NOT IMPLEMENTED');
}

GridToolBar.prototype.showCalculatedColumn = function (event)
{
    this.dialogCalculatedColumn.show();
}

GridToolBar.prototype.runRefresh = function (event)
{
    alert('NOT IMPLEMENTED');
}

GridToolBar.prototype.showExportAdwords = function (event)
{
    var keywordArray = this.grid.getCheckedRows();
    this.dialogExportAdwords.show(keywordArray);
}

// GridToolBar object constructor
//note: could find the img and span tags from the div id, then constructor would just have one arg
function GridToolBar(divToolbarId, grid
                    , imgIncludeFilterId, dialogIncludeFilter
                    , imgExcludeFilterId, dialogExcludeFilter
                    , imgCustomFilterId, dialogCustomFilter
                    , imgCustomSortId, dialogCustomSort
                    , imgHideShowColumnsId
                    , imgCalculatedColumnId, dialogCalculatedColumn
                    , imgRefreshId
                    , imgExportAdwordsId, dialogExportAdwords)
{
    this.divToolbar = elm(divToolbarId);
    this.imgIncludeFilter = elm(imgIncludeFilterId);
    this.imgExcludeFilter = elm(imgExcludeFilterId);
    this.imgCustomFilter = elm(imgCustomFilterId);
    this.imgCustomSort = elm(imgCustomSortId);
    this.imgHideShowColumns = elm(imgHideShowColumnsId);
    this.imgCalculatedColumn = elm(imgCalculatedColumnId);
    this.imgRefresh = elm(imgRefreshId);
    this.imgExportAdwords = elm(imgExportAdwordsId);

    this.grid = grid;
    this.dialogIncludeFilter = dialogIncludeFilter;
    this.dialogExcludeFilter = dialogExcludeFilter;
    this.dialogCustomFilter = dialogCustomFilter;
    this.dialogCustomSort = dialogCustomSort;
    this.dialogCalculatedColumn = dialogCalculatedColumn;
    this.dialogExportAdwords = dialogExportAdwords;
    
    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.imgIncludeFilter.addEventListener('click', function(event) {currObj.showIncludeFilter(event); }, false);
            currObj.imgExcludeFilter.addEventListener('click', function(event) {currObj.showExcludeFilter(event); }, false);
//            currObj.imgCustomFilter.addEventListener('click', function(event) {currObj.showCustomFilter(event); }, false);
//            currObj.imgCustomSort.addEventListener('click', function(event) {currObj.showCustomSort(event); }, false);
//            currObj.imgHideShowColumns.addEventListener('click', function(event) {currObj.showHideShowColumns(event); }, false);
//            currObj.imgCalculatedColumn.addEventListener('click', function(event) {currObj.showCalculatedColumn(event); }, false);
//            currObj.imgRefresh.addEventListener('click', function(event) {currObj.runRefresh(event); }, false);
            currObj.imgExportAdwords.addEventListener('click', function(event) {currObj.showExportAdwords(event); }, false);
        }
        else if(document.attachEvent) // IE
        {
            currObj.imgIncludeFilter.attachEvent('onclick', function(event) {currObj.showIncludeFilter(event); }, false);
            currObj.imgExcludeFilter.attachEvent('onclick', function(event) {currObj.showExcludeFilter(event); }, false);
//            currObj.imgCustomFilter.attachEvent('onclick', function(event) {currObj.showCustomFilter(event); }, false);
//            currObj.imgCustomSort.attachEvent('onclick', function(event) {currObj.showCustomSort(event); }, false);
//            currObj.imgHideShowColumns.attachEvent('onclick', function(event) {currObj.showHideShowColumns(event); }, false);
//            currObj.imgCalculatedColumn.attachEvent('onclick', function(event) {currObj.showCalculatedColumn(event); }, false);
//            currObj.imgRefresh.attachEvent('onclick', function(event) {currObj.runRefresh(event); }, false);
            currObj.imgExportAdwords.attachEvent('onclick', function(event) {currObj.showExportAdwords(event); }, false);
        }
    };
    assignEventHandlers(this);
}

//// End of GridToolBar Class -------------------------------------------