<commit_before>(function(){

    xtag.register('widget-Filter', {
        extends: 'div',
        lifecycle: {
            created: function() {
                var spawnCondition, filterTitle, currentFilter,
                    controlWrap = document.createElement('form'),
                    controlRows = [],
                    encodedFilter = document.createElement('input'),
                    applyFilter = document.createElement('input'),
                    filterNameLabel = document.createElement('label'),
                    filterName = document.createElement('input'),
                    saveFilter = document.createElement('button'),
                    chooseFilterLabel = document.createElement('label'),
                    chooseFilter = document.createElement('select'),
                    loadFilter = document.createElement('button'),
                    deleteFilter = document.createElement('button'),
                    loadTarget = document.createElement('input'),
                    deleteTarget = document.createElement('input'),
                    saveLoadFilter = document.createElement('button');

                this.filterConditions = [];
                this.nRows = [];
                this.detectors = ['DANTE', 'DESCANT', 'GRIFFIN', 'PACES', 'SCEPTAR', 'ZDS'];
                this.detectorCodes = ['DA', 'DS', 'GR', 'PA', 'SE', 'ZD'],
                this.filterOptions = ['Singles', 'Coincidences', 'Prescale'];
                this.filterCodes = ['S', 'C', 'P'];

                filterTitle = document.createElement('h1');
                filterTitle.innerHTML = 'Filter Control';
                this.appendChild(filterTitle);
                currentFilter = document.createElement('h3');
                currentFilter.setAttribute('id', 'currentFilter');
                this.appendChild(currentFilter);

                this.conditionWrap = document.createElement('div');
                this.conditionWrap.setAttribute('id', 'conditionWrap');
                this.appendChild(this.conditionWrap);

                this.spawnFilterCondition();

                spawnCondition = document.createElement('button');
                spawnCondition.innerHTML = 'OR new condition';
                spawnCondition.setAttribute('class', 'stdin');
                spawnCondition.onclick = this.spawnFilterCondition.bind(this);
                this.appendChild(spawnCondition);

                controlWrap.setAttribute('class', 'filterControl summary');
                controlWrap.setAttribute('id', 'filterDefinitionForm');
                controlWrap.setAttribute('method', 'POST');
                controlWrap.setAttribute('action', 'registerFilter');
                this.appendChild(controlWrap);

                controlRows[0] = document.createElement('span')
                controlWrap.appendChild(controlRows[0]);

                encodedFilter.setAttribute('type', 'text');
                encodedFilter.setAttribute('id', 'encodedFilter');
                encodedFilter.setAttribute('style', 'display:none');
                encodedFilter.setAttribute('name', 'filterString');
                controlRows[0].appendChild(encodedFilter);

                applyFilter.setAttribute('type', 'checkbox');
                applyFilter.setAttribute('id', 'applyFilter');
                applyFilter.setAttribute('style', 'display:none');
                applyFilter.setAttribute('name', 'applyFilter');
                controlRows[0].appendChild(applyFilter);

                filterNameLabel.innerHTML = 'Filter Name:';
                filterName.setAttribute('class', 'stdin');
                filterName.setAttribute('type', 'text');
                filterName.setAttribute('id', 'filterName');
                filterName.setAttribute('name', 'filterName');
                filterName.setAttribute('pattern',"[^\s]");
                filterName.setAttribute('required', true);
                controlRows[0].appendChild(filterNameLabel);
                controlRows[0].appendChild(filterName);

                saveFilter.setAttribute('class', 'stdin');
                saveFilter.innerHTML = 'Save Filter Definition';
                saveFilter.onclick = this.registerNewFilter.bind(this);
                controlRows[0].appendChild(saveFilter);

                saveLoadFilter.setAttribute('class', 'stdin');
                saveLoadFilter.innerHTML = 'Save & Apply Filter Definition';
                saveLoadFilter.onclick = function(){
                    this.registerNewFilter();
                    document.getElementById('applyFilter').checked = true;
                }.bind(this);
                controlRows[0].appendChild(saveLoadFilter);

                controlRows[1] = document.createElement('span');
                controlWrap.appendChild(controlRows[1]);

                chooseFilterLabel.innerHTML = 'Load / Delete Filter:'
                controlRows[1].appendChild(chooseFilterLabel);
                chooseFilter.setAttribute('class', 'stdin');
                chooseFilter.setAttribute('id', 'filterList');
                controlRows[1].appendChild(chooseFilter);

                loadTarget.setAttribute('type', 'text');
                loadTarget.setAttribute('name', 'loadTarget');
                loadTarget.setAttribute('id', 'loadTarget');
                loadTarget.setAttribute('value', 'null');
                loadTarget.setAttribute('style', 'display:none');
                controlRows[1].appendChild(loadTarget);
                loadFilter.setAttribute('class', 'stdin');
                loadFilter.innerHTML = 'Load'
                loadFilter.onclick = function(){
                    document.getElementById('loadTarget').value = selected('filterList')
                }
                controlRows[1].appendChild(loadFilter);

                deleteTarget.setAttribute('type', 'text');
                deleteTarget.setAttribute('name', 'deleteTarget');
                deleteTarget.setAttribute('id', 'deleteTarget');
                deleteTarget.setAttribute('value', 'null');
                deleteTarget.setAttribute('style', 'display:none');
                controlRows[1].appendChild(deleteTarget);
                deleteFilter.setAttribute('class', 'stdin');
                deleteFilter.innerHTML = 'Delete'
                deleteFilter.onclick = function(){
                    document.getElementById('deleteTarget').value = selected('filterList')
                }
                controlRows[1].appendChild(deleteFilter);

                XHR('http://'+this.MIDAS+'/?cmd=jcopy&odb=/Filter&encoding=json-nokeys', this.registerFilterODB.bind(this));
            },
            inserted: function() {},
            removed: function() {},
            attributeChanged: function() {}
        },
        events: {

        },
        accessors: {
            'MIDAS':{
                attribute: {} //this just needs to be declared
            }
        },
        methods: {
            'spawnFilterCondition' : function(){
                var newCondition = document.createElement('div'),
                    leftTab = document.createElement('div'),
                    filterContent = document.createElement('div'),
                    conditionTable = document.createElement('table'),
                    addNewRow = document.createElement('button'),
                    deleteCondition = document.createElement('button'),
                    index = this.filterConditions.length;

                newCondition.setAttribute('id', 'filterCondition' + index);
                newCondition.setAttribute('class', 'filterCondition');
                this.conditionWrap.appendChild(newCondition);

                leftTab.setAttribute('id', 'leftTab' + index);
                leftTab.setAttribute('class', 'leftTab');
                leftTab.innerHTML = 'OR';
                newCondition.appendChild(leftTab);

                filterContent.setAttribute('id', 'filterContent' + index);
                filterContent.setAttribute('class', 'filterContent');
                newCondition.appendChild(filterContent)

                conditionTable.setAttribute('id', 'filterTable'+index);
                conditionTable.setAttribute('class', 'filterTable');
                filterContent.appendChild(conditionTable);

                addNewRow.setAttribute('id', 'addNewRow' + index);
                addNewRow.setAttribute('class', 'stdin lightButton');
                addNewRow.innerHTML = 'AND new condition';
                addNewRow.onclick = this.addNewRow.bind(this, index);
                filterContent.appendChild(addNewRow);

                deleteCondition.setAttribute('id', 'deleteCondition' + index);
                deleteCondition.setAttribute('class', 'stdin lightButton');
                deleteCondition.innerHTML = 'Delete This Block';
                deleteCondition.onclick = this.deleteOrBlock.bind(this, index);
                filterContent.appendChild(deleteCondition);

                this.nRows[index] = 0;
                addNewRow.onclick();

                this.filterConditions.push(newCondition);
            },

            'addNewRow' : function(index){
                var row, cell,
                    detectorSelect, detectorOption,
                    filterSelect, filterOption,
                    optionConfigWrap, optionConfigLabel, optionConfigInput,
                    deleteRow,
                    i,
                    rowIndex = this.nRows[index]

                row = document.createElement('tr');
                row.setAttribute('id', 'filterRow' + index + rowIndex);
                document.getElementById('filterTable' + index).appendChild(row);

                cell = document.createElement('td');
                cell.innerHTML = 'AND';
                row.appendChild(cell);

                cell = document.createElement('td');
                row.appendChild(cell);
                detectorSelect = document.createElement('select');
                detectorSelect.setAttribute('id', 'detectorSelect'+index+rowIndex);
                detectorSelect.setAttribute('class', 'stdin');
                for(i=0; i<this.detectors.length; i++){
                    detectorOption = document.createElement('option');
                    detectorOption.value = this.detectorCodes[i];
                    detectorOption.innerHTML = this.detectors[i];
                    detectorSelect.appendChild(detectorOption);
                }
                cell.appendChild(detectorSelect);

                cell = document.createElement('td');
                row.appendChild(cell);
                filterSelect = document.createElement('select');
                filterSelect.setAttribute('id', 'filterType'+index+rowIndex)
                filterSelect.setAttribute('class', 'stdin');
                filterSelect.onchange = function(idCode){
                    var filterType = selected('filterType'+idCode);

                    this.manageInputCell(filterType, idCode);

                }.bind(this, ''+index+rowIndex);
                for(i=0; i<this.filterOptions.length; i++){
                    filterOption = document.createElement('option');
                    filterOption.value = this.filterCodes[i];
                    filterOption.innerHTML = this.filterOptions[i];
                    filterSelect.appendChild(filterOption);
                }
                cell.appendChild(filterSelect);

                cell = document.createElement('td');
                row.appendChild(cell);
                optionConfigWrap = document.createElement('div');
                optionConfigWrap.setAttribute('id', 'optionConfigWrap'+index+rowIndex);
                optionConfigWrap.setAttribute('class', 'optionConfigWrap hiddenConfig');
                cell.appendChild(optionConfigWrap);
                optionConfigLabel = document.createElement('label');
                optionConfigLabel.setAttribute('id', 'optionConfigLabel'+index+rowIndex);
                optionConfigWrap.appendChild(optionConfigLabel);
                optionConfigInput = document.createElement('input');
                optionConfigInput.setAttribute('id', 'optionConfigInput'+index+rowIndex);
                optionConfigInput.setAttribute('class', 'stdin');
                optionConfigInput.setAttribute('type', 'number');
                optionConfigInput.setAttribute('step', 1);
                optionConfigInput.setAttribute('min', 0);
                optionConfigWrap.appendChild(optionConfigInput);

                cell = document.createElement('td');
                row.appendChild(cell);
                deleteRow = document.createElement('button');
                deleteRow.innerHTML = 'Remove';
                deleteRow.setAttribute('class', 'stdin');
                deleteRow.onclick = this.deleteRow.bind(this, index, ''+index+rowIndex);
                cell.appendChild(deleteRow);

                this.nRows[index]++;

            },

            'manageInputCell' : function(filterType, idCode){

                if(filterType == 'S'){
                    document.getElementById('optionConfigWrap'+idCode).setAttribute('class', 'optionConfigWrap hiddenConfig');
                } else if(filterType == 'C'){
                    document.getElementById('optionConfigWrap'+idCode).setAttribute('class', 'optionConfigWrap');
                    document.getElementById('optionConfigLabel'+idCode).innerHTML = 'Multiplicity: ';
                    document.getElementById('optionConfigInput'+idCode).setAttribute('value', 2);
                } else if(filterType == 'P'){
                    document.getElementById('optionConfigWrap'+idCode).setAttribute('class', 'optionConfigWrap');
                    document.getElementById('optionConfigLabel'+idCode).innerHTML = 'Factor: ';
                    document.getElementById('optionConfigInput'+idCode).setAttribute('value', 10);
                }
            },

            'deleteOrBlock' : function(index){
                var block = document.getElementById('filterCondition' + index);
                this.conditionWrap.removeChild(block);
            },

            'deleteRow' : function(index, idCode){
                var row = document.getElementById('filterRow'+idCode);
                document.getElementById('filterTable'+index).removeChild(row);

            },

            'registerNewFilter' : function(){
                var filterConditions = this.querySelectorAll('div.filterCondition'),
                    tableRows,
                    selects,
                    detector, filter, scale, condition,
                    encoded = [],
                    i,j;

                for(i=0; i<filterConditions.length; i++){
                    tableRows = filterConditions[i].querySelectorAll('tr');
                    if(!tableRows || tableRows.length == 0) continue;
                    encoded[i] = [];

                    for(j=0; j<tableRows.length; j++){
                        selects = tableRows[j].querySelectorAll('select');

                        detector = selected(selects[0].id);
                        filter = selected(selects[1].id);
                        scale = parseInt(tableRows[j].querySelectorAll('input')[0].value, 10);
                        if(!scale) scale = 1;

                        condition = detector + '-' + filter + '-' + scale;

                        encoded[i][j] = condition;

                    }
                }

                document.getElementById('encodedFilter').value = JSON.stringify(encoded);
            },

            'registerFilterODB' : function(responseText){
                var data = JSON.parse(responseText),
                    currentName = data.Current,
                    currentFilter = data.Filters[currentName],
                    filterSelect = document.getElementById('filterList'),
                    filterOptions, key;

                this.filterRecord = data;

                this.loadFilter(currentFilter);
                document.getElementById('filterName').value = currentName;
                document.getElementById('currentFilter').innerHTML = 'Current Active Filter: ' + currentName;

                for(key in data.Filters){
                    filterOptions = document.createElement('option');
                    filterOptions.innerHTML = key;
                    filterOptions.value = key;
                    filterSelect.appendChild(filterOptions);

                }

                filterSelect.value = currentName;
            },

            'loadFilter' : function(currentFilter){

            }

        }
    });

})();<commit_msg>messing around with regex<commit_after>(function(){

    xtag.register('widget-Filter', {
        extends: 'div',
        lifecycle: {
            created: function() {
                var spawnCondition, filterTitle, currentFilter,
                    controlWrap = document.createElement('form'),
                    controlRows = [],
                    encodedFilter = document.createElement('input'),
                    applyFilter = document.createElement('input'),
                    filterNameLabel = document.createElement('label'),
                    filterName = document.createElement('input'),
                    saveFilter = document.createElement('button'),
                    chooseFilterLabel = document.createElement('label'),
                    chooseFilter = document.createElement('select'),
                    loadFilter = document.createElement('button'),
                    deleteFilter = document.createElement('button'),
                    loadTarget = document.createElement('input'),
                    deleteTarget = document.createElement('input'),
                    saveLoadFilter = document.createElement('button');

                this.filterConditions = [];
                this.nRows = [];
                this.detectors = ['DANTE', 'DESCANT', 'GRIFFIN', 'PACES', 'SCEPTAR', 'ZDS'];
                this.detectorCodes = ['DA', 'DS', 'GR', 'PA', 'SE', 'ZD'],
                this.filterOptions = ['Singles', 'Coincidences', 'Prescale'];
                this.filterCodes = ['S', 'C', 'P'];

                filterTitle = document.createElement('h1');
                filterTitle.innerHTML = 'Filter Control';
                this.appendChild(filterTitle);
                currentFilter = document.createElement('h3');
                currentFilter.setAttribute('id', 'currentFilter');
                this.appendChild(currentFilter);

                this.conditionWrap = document.createElement('div');
                this.conditionWrap.setAttribute('id', 'conditionWrap');
                this.appendChild(this.conditionWrap);

                this.spawnFilterCondition();

                spawnCondition = document.createElement('button');
                spawnCondition.innerHTML = 'OR new condition';
                spawnCondition.setAttribute('class', 'stdin');
                spawnCondition.onclick = this.spawnFilterCondition.bind(this);
                this.appendChild(spawnCondition);

                controlWrap.setAttribute('class', 'filterControl summary');
                controlWrap.setAttribute('id', 'filterDefinitionForm');
                controlWrap.setAttribute('method', 'POST');
                controlWrap.setAttribute('action', 'registerFilter');
                this.appendChild(controlWrap);

                controlRows[0] = document.createElement('span')
                controlWrap.appendChild(controlRows[0]);

                encodedFilter.setAttribute('type', 'text');
                encodedFilter.setAttribute('id', 'encodedFilter');
                encodedFilter.setAttribute('style', 'display:none');
                encodedFilter.setAttribute('name', 'filterString');
                controlRows[0].appendChild(encodedFilter);

                applyFilter.setAttribute('type', 'checkbox');
                applyFilter.setAttribute('id', 'applyFilter');
                applyFilter.setAttribute('style', 'display:none');
                applyFilter.setAttribute('name', 'applyFilter');
                controlRows[0].appendChild(applyFilter);

                filterNameLabel.innerHTML = 'Filter Name:';
                filterName.setAttribute('class', 'stdin');
                filterName.setAttribute('type', 'text');
                filterName.setAttribute('id', 'filterName');
                filterName.setAttribute('name', 'filterName');
                filterName.setAttribute('pattern',"(?=.*[a-zA-Z])(?=.*[\d\W])[\S]*$");
                filterName.setAttribute('required', true);
                controlRows[0].appendChild(filterNameLabel);
                controlRows[0].appendChild(filterName);

                saveFilter.setAttribute('class', 'stdin');
                saveFilter.innerHTML = 'Save Filter Definition';
                saveFilter.onclick = this.registerNewFilter.bind(this);
                controlRows[0].appendChild(saveFilter);

                saveLoadFilter.setAttribute('class', 'stdin');
                saveLoadFilter.innerHTML = 'Save & Apply Filter Definition';
                saveLoadFilter.onclick = function(){
                    this.registerNewFilter();
                    document.getElementById('applyFilter').checked = true;
                }.bind(this);
                controlRows[0].appendChild(saveLoadFilter);

                controlRows[1] = document.createElement('span');
                controlWrap.appendChild(controlRows[1]);

                chooseFilterLabel.innerHTML = 'Load / Delete Filter:'
                controlRows[1].appendChild(chooseFilterLabel);
                chooseFilter.setAttribute('class', 'stdin');
                chooseFilter.setAttribute('id', 'filterList');
                controlRows[1].appendChild(chooseFilter);

                loadTarget.setAttribute('type', 'text');
                loadTarget.setAttribute('name', 'loadTarget');
                loadTarget.setAttribute('id', 'loadTarget');
                loadTarget.setAttribute('value', 'null');
                loadTarget.setAttribute('style', 'display:none');
                controlRows[1].appendChild(loadTarget);
                loadFilter.setAttribute('class', 'stdin');
                loadFilter.innerHTML = 'Load'
                loadFilter.onclick = function(){
                    document.getElementById('loadTarget').value = selected('filterList')
                }
                controlRows[1].appendChild(loadFilter);

                deleteTarget.setAttribute('type', 'text');
                deleteTarget.setAttribute('name', 'deleteTarget');
                deleteTarget.setAttribute('id', 'deleteTarget');
                deleteTarget.setAttribute('value', 'null');
                deleteTarget.setAttribute('style', 'display:none');
                controlRows[1].appendChild(deleteTarget);
                deleteFilter.setAttribute('class', 'stdin');
                deleteFilter.innerHTML = 'Delete'
                deleteFilter.onclick = function(){
                    document.getElementById('deleteTarget').value = selected('filterList')
                }
                controlRows[1].appendChild(deleteFilter);

                XHR('http://'+this.MIDAS+'/?cmd=jcopy&odb=/Filter&encoding=json-nokeys', this.registerFilterODB.bind(this));
            },
            inserted: function() {},
            removed: function() {},
            attributeChanged: function() {}
        },
        events: {

        },
        accessors: {
            'MIDAS':{
                attribute: {} //this just needs to be declared
            }
        },
        methods: {
            'spawnFilterCondition' : function(){
                var newCondition = document.createElement('div'),
                    leftTab = document.createElement('div'),
                    filterContent = document.createElement('div'),
                    conditionTable = document.createElement('table'),
                    addNewRow = document.createElement('button'),
                    deleteCondition = document.createElement('button'),
                    index = this.filterConditions.length;

                newCondition.setAttribute('id', 'filterCondition' + index);
                newCondition.setAttribute('class', 'filterCondition');
                this.conditionWrap.appendChild(newCondition);

                leftTab.setAttribute('id', 'leftTab' + index);
                leftTab.setAttribute('class', 'leftTab');
                leftTab.innerHTML = 'OR';
                newCondition.appendChild(leftTab);

                filterContent.setAttribute('id', 'filterContent' + index);
                filterContent.setAttribute('class', 'filterContent');
                newCondition.appendChild(filterContent)

                conditionTable.setAttribute('id', 'filterTable'+index);
                conditionTable.setAttribute('class', 'filterTable');
                filterContent.appendChild(conditionTable);

                addNewRow.setAttribute('id', 'addNewRow' + index);
                addNewRow.setAttribute('class', 'stdin lightButton');
                addNewRow.innerHTML = 'AND new condition';
                addNewRow.onclick = this.addNewRow.bind(this, index);
                filterContent.appendChild(addNewRow);

                deleteCondition.setAttribute('id', 'deleteCondition' + index);
                deleteCondition.setAttribute('class', 'stdin lightButton');
                deleteCondition.innerHTML = 'Delete This Block';
                deleteCondition.onclick = this.deleteOrBlock.bind(this, index);
                filterContent.appendChild(deleteCondition);

                this.nRows[index] = 0;
                addNewRow.onclick();

                this.filterConditions.push(newCondition);
            },

            'addNewRow' : function(index){
                var row, cell,
                    detectorSelect, detectorOption,
                    filterSelect, filterOption,
                    optionConfigWrap, optionConfigLabel, optionConfigInput,
                    deleteRow,
                    i,
                    rowIndex = this.nRows[index]

                row = document.createElement('tr');
                row.setAttribute('id', 'filterRow' + index + rowIndex);
                document.getElementById('filterTable' + index).appendChild(row);

                cell = document.createElement('td');
                cell.innerHTML = 'AND';
                row.appendChild(cell);

                cell = document.createElement('td');
                row.appendChild(cell);
                detectorSelect = document.createElement('select');
                detectorSelect.setAttribute('id', 'detectorSelect'+index+rowIndex);
                detectorSelect.setAttribute('class', 'stdin');
                for(i=0; i<this.detectors.length; i++){
                    detectorOption = document.createElement('option');
                    detectorOption.value = this.detectorCodes[i];
                    detectorOption.innerHTML = this.detectors[i];
                    detectorSelect.appendChild(detectorOption);
                }
                cell.appendChild(detectorSelect);

                cell = document.createElement('td');
                row.appendChild(cell);
                filterSelect = document.createElement('select');
                filterSelect.setAttribute('id', 'filterType'+index+rowIndex)
                filterSelect.setAttribute('class', 'stdin');
                filterSelect.onchange = function(idCode){
                    var filterType = selected('filterType'+idCode);

                    this.manageInputCell(filterType, idCode);

                }.bind(this, ''+index+rowIndex);
                for(i=0; i<this.filterOptions.length; i++){
                    filterOption = document.createElement('option');
                    filterOption.value = this.filterCodes[i];
                    filterOption.innerHTML = this.filterOptions[i];
                    filterSelect.appendChild(filterOption);
                }
                cell.appendChild(filterSelect);

                cell = document.createElement('td');
                row.appendChild(cell);
                optionConfigWrap = document.createElement('div');
                optionConfigWrap.setAttribute('id', 'optionConfigWrap'+index+rowIndex);
                optionConfigWrap.setAttribute('class', 'optionConfigWrap hiddenConfig');
                cell.appendChild(optionConfigWrap);
                optionConfigLabel = document.createElement('label');
                optionConfigLabel.setAttribute('id', 'optionConfigLabel'+index+rowIndex);
                optionConfigWrap.appendChild(optionConfigLabel);
                optionConfigInput = document.createElement('input');
                optionConfigInput.setAttribute('id', 'optionConfigInput'+index+rowIndex);
                optionConfigInput.setAttribute('class', 'stdin');
                optionConfigInput.setAttribute('type', 'number');
                optionConfigInput.setAttribute('step', 1);
                optionConfigInput.setAttribute('min', 0);
                optionConfigWrap.appendChild(optionConfigInput);

                cell = document.createElement('td');
                row.appendChild(cell);
                deleteRow = document.createElement('button');
                deleteRow.innerHTML = 'Remove';
                deleteRow.setAttribute('class', 'stdin');
                deleteRow.onclick = this.deleteRow.bind(this, index, ''+index+rowIndex);
                cell.appendChild(deleteRow);

                this.nRows[index]++;

            },

            'manageInputCell' : function(filterType, idCode){

                if(filterType == 'S'){
                    document.getElementById('optionConfigWrap'+idCode).setAttribute('class', 'optionConfigWrap hiddenConfig');
                } else if(filterType == 'C'){
                    document.getElementById('optionConfigWrap'+idCode).setAttribute('class', 'optionConfigWrap');
                    document.getElementById('optionConfigLabel'+idCode).innerHTML = 'Multiplicity: ';
                    document.getElementById('optionConfigInput'+idCode).setAttribute('value', 2);
                } else if(filterType == 'P'){
                    document.getElementById('optionConfigWrap'+idCode).setAttribute('class', 'optionConfigWrap');
                    document.getElementById('optionConfigLabel'+idCode).innerHTML = 'Factor: ';
                    document.getElementById('optionConfigInput'+idCode).setAttribute('value', 10);
                }
            },

            'deleteOrBlock' : function(index){
                var block = document.getElementById('filterCondition' + index);
                this.conditionWrap.removeChild(block);
            },

            'deleteRow' : function(index, idCode){
                var row = document.getElementById('filterRow'+idCode);
                document.getElementById('filterTable'+index).removeChild(row);

            },

            'registerNewFilter' : function(){
                var filterConditions = this.querySelectorAll('div.filterCondition'),
                    tableRows,
                    selects,
                    detector, filter, scale, condition,
                    encoded = [],
                    i,j;

                for(i=0; i<filterConditions.length; i++){
                    tableRows = filterConditions[i].querySelectorAll('tr');
                    if(!tableRows || tableRows.length == 0) continue;
                    encoded[i] = [];

                    for(j=0; j<tableRows.length; j++){
                        selects = tableRows[j].querySelectorAll('select');

                        detector = selected(selects[0].id);
                        filter = selected(selects[1].id);
                        scale = parseInt(tableRows[j].querySelectorAll('input')[0].value, 10);
                        if(!scale) scale = 1;

                        condition = detector + '-' + filter + '-' + scale;

                        encoded[i][j] = condition;

                    }
                }

                document.getElementById('encodedFilter').value = JSON.stringify(encoded);
            },

            'registerFilterODB' : function(responseText){
                var data = JSON.parse(responseText),
                    currentName = data.Current,
                    currentFilter = data.Filters[currentName],
                    filterSelect = document.getElementById('filterList'),
                    filterOptions, key;

                this.filterRecord = data;

                this.loadFilter(currentFilter);
                document.getElementById('filterName').value = currentName;
                document.getElementById('currentFilter').innerHTML = 'Current Active Filter: ' + currentName;

                for(key in data.Filters){
                    filterOptions = document.createElement('option');
                    filterOptions.innerHTML = key;
                    filterOptions.value = key;
                    filterSelect.appendChild(filterOptions);

                }

                filterSelect.value = currentName;
            },

            'loadFilter' : function(currentFilter){

            }

        }
    });

})();<|endoftext|>


<commit_before>var verify = require("../utils/verify");
var KNOWN_MODULE_TYPES = {
  "core": true,
  "core-extension": true,
  "extension": true
};

/**
 * @class Component
 * Represents a component to be built.
 *
 * @param {!Object} configuration The configuration of the component.
 *  @property {!Object} grunt Instance of grunt to use in the component.
 *  @property {!String} name  The name of the component.
 *  @property {?String} colour  The colour of the component.
 *
 *  @property {?Object} targets Target definition object.
 *    @property {?Array.<String>} deps List of project dependencies.
 *
 *  @property {?String} module-type Type of component being defined:
 *    * core: module is always enabled and has no init function [default].
 *    * core-extension: module is always enabled and has an init function.
 *    * extension: module has an init function and can be disabled.
 */
var Component = module.exports = function Component(configuration) {
  // Verify configuration.
  verify.notNullObject(configuration, "Invalid component configuration");
  verify.notNullObject(configuration.grunt, "Grunt instance not valid");
  verify.notEmptyString(configuration.name, "Missing component name");
  verify.notNullObjectIfDefined(
      configuration.targets,
      "If defined, the target property must be an object."
  );
  verify.optionalColour(
      configuration.colour,
      "If defined, the colour property must be an hex colour prefixed by an #."
  );
  verify.optionalNotEmptyString(
      configuration["module-type"],
      "If defined, the module-type property must be a string."
  );
  verify.optionalArray(
      configuration.inject,
      "Invalid injection list. Array of string required.",
      verify.notEmptyString
  );

  // Store it in the new instance.
  this._colour = configuration.colour;
  this._grunt  = configuration.grunt;
  this._inject = configuration.inject || [];
  this._name   = configuration.name;
  this._module_type = configuration["module-type"] || "core";
  this._enabled = true;
  this._targets = {};

  // Validate mode.
  if (!KNOWN_MODULE_TYPES[this._module_type]) {
    throw new Error("Unrecognised module type '" + this._module_type + "'");
  }

  // Process targets.
  if (configuration.targets) {
    this._process_targets(configuration);
  }
};

/**
 * Parses a dependency name for a target.
 * @param {!String} name   The dependency name to parse.
 * @param {!String} target The target that the name is resolved for.
 * @returns {!Object} A {name: !String, target: !String} object.
 */
Component.parseDependencyName = function parseDependencyName(name, target) {
  verify.notEmptyString(name, "The dependency name must be a string");
  verify.notEmptyString(
      target, "The name of the current target must be a string"
  );
  var parts = name.split("@");

  // Target missing from name.
  if (parts.length === 1) {
    return {
      name: name,
      target: target
    };
  }

  // Both target and name are specified.
  if (parts.length === 2) {
    return {
      name: parts[1],
      target: parts[0]
    };
  }

  throw new Error("Cannot parse malformed dependency '" + name + "'");
};

/**
 * Checks the given list of dependencies for conflicts and duplicates.
 * @param {!Array} dependencies
 * @returns {!Array}
 */
Component.checkDependenciesList = function checkDependenciesList(
    dependencies
) {
  verify.array(dependencies, "An array of dependencies is required");

  // Check for ambiguous dependencies.
  var components = {};
  dependencies.forEach(function(dep) {
    if (dep.name in components && components[dep.name] !== dep.target) {
      throw new Error("Ambiguous dependency for component '" + dep.name + "'");
    }
    components[dep.name] = dep.target;
  });

  // Rebuild result array.
  var added  = {};
  return dependencies.filter(function(dep) {
    var ignore = dep.name in added;
    added[dep.name] = true;
    return !ignore;
  });
};

/**
 * Processes a component configuration to extract targets information.
 * @param {!Object} config The configuration to process.
 */
Component.prototype._process_targets = function _process_targets(config) {
  var targets = Object.keys(config.targets);
  var nameParser = function(target) {
    return function(name) {
      return Component.parseDependencyName(name, target);
    };
  };

  for (var idx=0; idx < targets.length; idx++) {
    var name   = targets[idx];
    var target = config.targets[name];

    // Verify target structure.
    verify.notNullObject(target, "Target definitions must be objects.");
    verify.optionalArray(
        target.deps,
        "If defined, the deps property of target '" + name +
        "' must be an array"
    );

    // Process dependneces.
    var global_deps = config.deps || [];
    var target_deps = target.deps || [];
    var deps = [];
    deps.push.apply(deps, global_deps);
    deps.push.apply(deps, target_deps);
    deps = deps.map(nameParser(name));
    deps = Component.checkDependenciesList(deps);

    // Build result.
    this._targets[name] = {
      deps: deps
    };
  }
};

/**
 * Adds a dependency to all the targets of the component.
 * @param {!String} name The name of the dependency to add.
 */
Component.prototype.addDependency = function addDependency(name) {
  var _this   = this;
  var targets = Object.keys(this._targets);

  targets.forEach(function(target) {
    var deps = [];
    var parsed_name = Component.parseDependencyName(name, target);

    deps.push.apply(deps, _this._targets[target].deps);
    deps.push(parsed_name);

    deps = Component.checkDependenciesList(deps);
    _this._targets[target].deps = deps;
  });
};

/** @returns {bool} True if the component can be disabled. */
Component.prototype.canDisable = function canDisable() {
  return this._module_type === "extension";
};

/** @returns {!String} The colour of the component. */
Component.prototype.colour = function colour() {
  if (!this._colour) {
    this._colour = "#" + Math.floor(Math.random() * 16777215).toString(16);
  }
  return this._colour;
};

/**
 * Returns the list of dependencies for a target.
 * @param {!Strng} name The target to look for.
 * @returns {!Array} List of objects describing targets.
 */
Component.prototype.dependencies = function dependencies(name) {
  verify.notEmptyString(name, "Target name must be a string");
  if (!(name in this._targets)) {
    throw new Error("Missing target '" + name + "' for '" + this._name + "'");
  }

  var target = this._targets[name];
  return target.deps;
};

/**
 * Disables an optional component.
 * Calls to this method have no effect if the component cannot be diasabled.
 * @returns {!Boolean} true if the component was disabled by this call.
 */
Component.prototype.disable = function disable() {
  var enabled = this._enabled;
  this._enabled = false;
  return enabled;
};

/**
 * @returns {!Boolean} true if the component is currently enabled.
 */
Component.prototype.enabled = function enabled() {
  return (
      this._module_type === "core" ||
      this._module_type === "core-extension" ||
      this._enabled
  );
};

/**
 * Returns the path to run the clean task against
 * @param {!String} target The target to get the path for.
 * @returns {!String|!Array.<!String>} Path or paths to clear.
 */
Component.prototype.getCleanPath = function getCleanPath(target) {
  throw new Error("Method not implemented");
};

/**
 * Returns a list of C/C++ header files exposed by this component.
 * @param {!String} target The target to get the headers for.
 * @returns {!Array.<!String>} Headers file exposed.
 */
Component.prototype.getCppHeaders = function getCppHeaders(target) {
  return [];
};

/**
 * Returns a list of C/C++ dynamic libraries needed by this component.
 * @param {!String} target The target to get the dynamic libraries for.
 * @returns {!Array.<!String>} Static libraries exposed.
 */
Component.prototype.getDynamicLibs = function getDynamicLibs(target) {
  return [];
};

/** @returns {!String} The type of component. */
Component.prototype.getModuleType = function getModuleType() {
  return this._module_type;
};

/**
 * Returns a list of partial grunt file mappings.
 *
 * These mappings are used by NodeJS components to copy the needed files
 * into their destination directoryes.
 * As such, the mappings will have a source but should not have a dest
 * attribute, which will be set by the component that includes this.
 *
 * @param {!String} target The target to get the deps for.
 * @returns {!Array} An array of grunt file mappings without a dest attribute.
 */
Component.prototype.getNodeJsDependencies = function getNodeJsDependencies(
    target
) {
  return [];
};

/**
 * Returns the path to the output to the item build by this component.
 *
 * @param {!String} target The target to get the output path for.
 * @returns {!String|!Object}
 *     Path or to the item build by this target or object describing
 *     the files built by this target.
 *
 *     If this method returns an object,
 *     the object has the following properties:
 *
 *       * cwd: the `cwd` option to `grunt.file.copy`.
 *       * expand: the `expand` option to `grunt.file.copy`.
 *       * src: the `src` option to `grunt.file.copy`, this is mandatory.
 */
Component.prototype.getOutput = function getOutput(target) {
  throw new Error("Method not implemented");
};

/**
 * Returns a list of C/C++ static libraries exposed by this component.
 * @param {!String} target The target to get the static libraries for.
 * @returns {!Array.<!String>} Static libraries exposed.
 */
Component.prototype.getStaticLibs = function getStaticLibs(target) {
  return [];
};

/**
 * Returns a graph description for the component.
 *
 * The graph desctiption has the following format:
 *   * nodes: map from node ID to node description
 *     * label:  string describing the label.
 *     * colour: string with the colour of the node.
 *   * edges: list of directed edges mapping node ids.
 *
 * @param {!Object} components The components registry.
 * @param {!String} target     The build target to generate the graph for.
 * @returns {!Object} Direct dependencies graph for this component.
 */
Component.prototype.graph = function graph(components, target) {
  var deps  = this.dependencies(target);
  var graph = {
    nodes: {},
    edges: []
  };

  // Conver deps in components.
  deps = deps.map(function(dep) {
    return {
      instance: components.get(dep.name),
      target:   dep.target
    }
  });

  // Build the nodes map.
  graph.nodes[this.name()] = {
    colour: this.colour(),
    label:  this.name()
  };

  deps.forEach(function(dep) {
    var name = dep.instance.name();
    graph.nodes[name] = {
      colour: dep.instance.colour(),
      label:  name
    };
  });

  // Build the edges list.
  var _this = this;
  deps.forEach(function(dep) {
    graph.edges.push({
      colour: _this.colour(),
      from: dep.instance.name(),
      to:   _this.name()
    });
  });

  // Done.
  return graph;
};

/**
 * Handles the configuration and enqueuing of analysis tasks.
 * @param {!Components} components Collection of components in the system.
 */
Component.prototype.handleAnalysis = function handleAnalysis(components) {
  throw new Error("Method not implemented");
};

/**
 * Handles the configuration and enqueuing of a target.
 * @param {!String} target The target to handle.
 * @param {!Components} components Collection of components in the system.
 */
Component.prototype.handleTarget = function handleTarget(target, components) {
  throw new Error("Method not implemented");
};

/** @returns {bool} True if the component has an init function. */
Component.prototype.hasModuleInit = function hasModuleInit() {
  return (
      this._module_type === "core-extension" ||
      this._module_type === "extension"
  );
};

/**
 * Checks if a target is available.
 * @param {!String} target The target to check
 * @returns {!Boolean} True if the target is configured.
 */
Component.prototype.hasTarget = function hasTarget(target) {
  verify.notEmptyString(target, "Target to check for must be a string");
  return target in this._targets;
};

/** @returns {!Array.<String>} the list of components to be injected into. */
Component.prototype.listInjections = function listInjections() {
  return this._inject;
};

/** @returns {!String} The name of the component. */
Component.prototype.name = function name() {
  return this._name;
};

/** @returns {!Array} The list of targets defined for the component. */
Component.prototype.targets = function targets() {
  return Object.keys(this._targets).sort();
};
<commit_msg>Revert back to . as separator.<commit_after>var verify = require("../utils/verify");
var KNOWN_MODULE_TYPES = {
  "core": true,
  "core-extension": true,
  "extension": true
};

/**
 * @class Component
 * Represents a component to be built.
 *
 * @param {!Object} configuration The configuration of the component.
 *  @property {!Object} grunt Instance of grunt to use in the component.
 *  @property {!String} name  The name of the component.
 *  @property {?String} colour  The colour of the component.
 *
 *  @property {?Object} targets Target definition object.
 *    @property {?Array.<String>} deps List of project dependencies.
 *
 *  @property {?String} module-type Type of component being defined:
 *    * core: module is always enabled and has no init function [default].
 *    * core-extension: module is always enabled and has an init function.
 *    * extension: module has an init function and can be disabled.
 */
var Component = module.exports = function Component(configuration) {
  // Verify configuration.
  verify.notNullObject(configuration, "Invalid component configuration");
  verify.notNullObject(configuration.grunt, "Grunt instance not valid");
  verify.notEmptyString(configuration.name, "Missing component name");
  verify.notNullObjectIfDefined(
      configuration.targets,
      "If defined, the target property must be an object."
  );
  verify.optionalColour(
      configuration.colour,
      "If defined, the colour property must be an hex colour prefixed by an #."
  );
  verify.optionalNotEmptyString(
      configuration["module-type"],
      "If defined, the module-type property must be a string."
  );
  verify.optionalArray(
      configuration.inject,
      "Invalid injection list. Array of string required.",
      verify.notEmptyString
  );

  // Store it in the new instance.
  this._colour = configuration.colour;
  this._grunt  = configuration.grunt;
  this._inject = configuration.inject || [];
  this._name   = configuration.name;
  this._module_type = configuration["module-type"] || "core";
  this._enabled = true;
  this._targets = {};

  // Validate mode.
  if (!KNOWN_MODULE_TYPES[this._module_type]) {
    throw new Error("Unrecognised module type '" + this._module_type + "'");
  }

  // Process targets.
  if (configuration.targets) {
    this._process_targets(configuration);
  }
};

/**
 * Parses a dependency name for a target.
 * @param {!String} name   The dependency name to parse.
 * @param {!String} target The target that the name is resolved for.
 * @returns {!Object} A {name: !String, target: !String} object.
 */
Component.parseDependencyName = function parseDependencyName(name, target) {
  verify.notEmptyString(name, "The dependency name must be a string");
  verify.notEmptyString(
      target, "The name of the current target must be a string"
  );
  var parts = name.split(".");

  // Target missing from name.
  if (parts.length === 1) {
    return {
      name: name,
      target: target
    };
  }

  // Both target and name are specified.
  if (parts.length === 2) {
    return {
      name: parts[1],
      target: parts[0]
    };
  }

  throw new Error("Cannot parse malformed dependency '" + name + "'");
};

/**
 * Checks the given list of dependencies for conflicts and duplicates.
 * @param {!Array} dependencies
 * @returns {!Array}
 */
Component.checkDependenciesList = function checkDependenciesList(
    dependencies
) {
  verify.array(dependencies, "An array of dependencies is required");

  // Check for ambiguous dependencies.
  var components = {};
  dependencies.forEach(function(dep) {
    if (dep.name in components && components[dep.name] !== dep.target) {
      throw new Error("Ambiguous dependency for component '" + dep.name + "'");
    }
    components[dep.name] = dep.target;
  });

  // Rebuild result array.
  var added  = {};
  return dependencies.filter(function(dep) {
    var ignore = dep.name in added;
    added[dep.name] = true;
    return !ignore;
  });
};

/**
 * Processes a component configuration to extract targets information.
 * @param {!Object} config The configuration to process.
 */
Component.prototype._process_targets = function _process_targets(config) {
  var targets = Object.keys(config.targets);
  var nameParser = function(target) {
    return function(name) {
      return Component.parseDependencyName(name, target);
    };
  };

  for (var idx=0; idx < targets.length; idx++) {
    var name   = targets[idx];
    var target = config.targets[name];

    // Verify target structure.
    verify.notNullObject(target, "Target definitions must be objects.");
    verify.optionalArray(
        target.deps,
        "If defined, the deps property of target '" + name +
        "' must be an array"
    );

    // Process dependneces.
    var global_deps = config.deps || [];
    var target_deps = target.deps || [];
    var deps = [];
    deps.push.apply(deps, global_deps);
    deps.push.apply(deps, target_deps);
    deps = deps.map(nameParser(name));
    deps = Component.checkDependenciesList(deps);

    // Build result.
    this._targets[name] = {
      deps: deps
    };
  }
};

/**
 * Adds a dependency to all the targets of the component.
 * @param {!String} name The name of the dependency to add.
 */
Component.prototype.addDependency = function addDependency(name) {
  var _this   = this;
  var targets = Object.keys(this._targets);

  targets.forEach(function(target) {
    var deps = [];
    var parsed_name = Component.parseDependencyName(name, target);

    deps.push.apply(deps, _this._targets[target].deps);
    deps.push(parsed_name);

    deps = Component.checkDependenciesList(deps);
    _this._targets[target].deps = deps;
  });
};

/** @returns {bool} True if the component can be disabled. */
Component.prototype.canDisable = function canDisable() {
  return this._module_type === "extension";
};

/** @returns {!String} The colour of the component. */
Component.prototype.colour = function colour() {
  if (!this._colour) {
    this._colour = "#" + Math.floor(Math.random() * 16777215).toString(16);
  }
  return this._colour;
};

/**
 * Returns the list of dependencies for a target.
 * @param {!Strng} name The target to look for.
 * @returns {!Array} List of objects describing targets.
 */
Component.prototype.dependencies = function dependencies(name) {
  verify.notEmptyString(name, "Target name must be a string");
  if (!(name in this._targets)) {
    throw new Error("Missing target '" + name + "' for '" + this._name + "'");
  }

  var target = this._targets[name];
  return target.deps;
};

/**
 * Disables an optional component.
 * Calls to this method have no effect if the component cannot be diasabled.
 * @returns {!Boolean} true if the component was disabled by this call.
 */
Component.prototype.disable = function disable() {
  var enabled = this._enabled;
  this._enabled = false;
  return enabled;
};

/**
 * @returns {!Boolean} true if the component is currently enabled.
 */
Component.prototype.enabled = function enabled() {
  return (
      this._module_type === "core" ||
      this._module_type === "core-extension" ||
      this._enabled
  );
};

/**
 * Returns the path to run the clean task against
 * @param {!String} target The target to get the path for.
 * @returns {!String|!Array.<!String>} Path or paths to clear.
 */
Component.prototype.getCleanPath = function getCleanPath(target) {
  throw new Error("Method not implemented");
};

/**
 * Returns a list of C/C++ header files exposed by this component.
 * @param {!String} target The target to get the headers for.
 * @returns {!Array.<!String>} Headers file exposed.
 */
Component.prototype.getCppHeaders = function getCppHeaders(target) {
  return [];
};

/**
 * Returns a list of C/C++ dynamic libraries needed by this component.
 * @param {!String} target The target to get the dynamic libraries for.
 * @returns {!Array.<!String>} Static libraries exposed.
 */
Component.prototype.getDynamicLibs = function getDynamicLibs(target) {
  return [];
};

/** @returns {!String} The type of component. */
Component.prototype.getModuleType = function getModuleType() {
  return this._module_type;
};

/**
 * Returns a list of partial grunt file mappings.
 *
 * These mappings are used by NodeJS components to copy the needed files
 * into their destination directoryes.
 * As such, the mappings will have a source but should not have a dest
 * attribute, which will be set by the component that includes this.
 *
 * @param {!String} target The target to get the deps for.
 * @returns {!Array} An array of grunt file mappings without a dest attribute.
 */
Component.prototype.getNodeJsDependencies = function getNodeJsDependencies(
    target
) {
  return [];
};

/**
 * Returns the path to the output to the item build by this component.
 *
 * @param {!String} target The target to get the output path for.
 * @returns {!String|!Object}
 *     Path or to the item build by this target or object describing
 *     the files built by this target.
 *
 *     If this method returns an object,
 *     the object has the following properties:
 *
 *       * cwd: the `cwd` option to `grunt.file.copy`.
 *       * expand: the `expand` option to `grunt.file.copy`.
 *       * src: the `src` option to `grunt.file.copy`, this is mandatory.
 */
Component.prototype.getOutput = function getOutput(target) {
  throw new Error("Method not implemented");
};

/**
 * Returns a list of C/C++ static libraries exposed by this component.
 * @param {!String} target The target to get the static libraries for.
 * @returns {!Array.<!String>} Static libraries exposed.
 */
Component.prototype.getStaticLibs = function getStaticLibs(target) {
  return [];
};

/**
 * Returns a graph description for the component.
 *
 * The graph desctiption has the following format:
 *   * nodes: map from node ID to node description
 *     * label:  string describing the label.
 *     * colour: string with the colour of the node.
 *   * edges: list of directed edges mapping node ids.
 *
 * @param {!Object} components The components registry.
 * @param {!String} target     The build target to generate the graph for.
 * @returns {!Object} Direct dependencies graph for this component.
 */
Component.prototype.graph = function graph(components, target) {
  var deps  = this.dependencies(target);
  var graph = {
    nodes: {},
    edges: []
  };

  // Conver deps in components.
  deps = deps.map(function(dep) {
    return {
      instance: components.get(dep.name),
      target:   dep.target
    }
  });

  // Build the nodes map.
  graph.nodes[this.name()] = {
    colour: this.colour(),
    label:  this.name()
  };

  deps.forEach(function(dep) {
    var name = dep.instance.name();
    graph.nodes[name] = {
      colour: dep.instance.colour(),
      label:  name
    };
  });

  // Build the edges list.
  var _this = this;
  deps.forEach(function(dep) {
    graph.edges.push({
      colour: _this.colour(),
      from: dep.instance.name(),
      to:   _this.name()
    });
  });

  // Done.
  return graph;
};

/**
 * Handles the configuration and enqueuing of analysis tasks.
 * @param {!Components} components Collection of components in the system.
 */
Component.prototype.handleAnalysis = function handleAnalysis(components) {
  throw new Error("Method not implemented");
};

/**
 * Handles the configuration and enqueuing of a target.
 * @param {!String} target The target to handle.
 * @param {!Components} components Collection of components in the system.
 */
Component.prototype.handleTarget = function handleTarget(target, components) {
  throw new Error("Method not implemented");
};

/** @returns {bool} True if the component has an init function. */
Component.prototype.hasModuleInit = function hasModuleInit() {
  return (
      this._module_type === "core-extension" ||
      this._module_type === "extension"
  );
};

/**
 * Checks if a target is available.
 * @param {!String} target The target to check
 * @returns {!Boolean} True if the target is configured.
 */
Component.prototype.hasTarget = function hasTarget(target) {
  verify.notEmptyString(target, "Target to check for must be a string");
  return target in this._targets;
};

/** @returns {!Array.<String>} the list of components to be injected into. */
Component.prototype.listInjections = function listInjections() {
  return this._inject;
};

/** @returns {!String} The name of the component. */
Component.prototype.name = function name() {
  return this._name;
};

/** @returns {!Array} The list of targets defined for the component. */
Component.prototype.targets = function targets() {
  return Object.keys(this._targets).sort();
};
<|endoftext|>


<commit_before>angular.module('npact')
  .factory('Track', function($log,  $q, $timeout, $http,
                      Fetcher, ExtractParser, TrackBinSearchIndex, npactConstants) {
    'use strict';

    var ITrackIndex = TrackBinSearchIndex;
    function Track(filename, data, type, name) {
      // console.log('new Track ',name, data, type ,filename);
      if(!name && !type){
        if(filename.search('profiles')>=0){
          name="Hits";
          type='hits';
        }
        else if(filename.search('modified')>=0){
          name="Modified ORFs";
          type='extracts';
        }
        else if(filename.search('newcds')>=0){
          name="New ORFs";
          type='extracts';
        }
        else if(filename.search('genes')>=0){
          name="Input CDSs";
          type='extracts';
        }
        else{
          name = filename;
          type = 'extracts';
        }
      }
      this.active = true;
      this.filename = filename;
      this.name = name;
      this.type = type;
      if(!_.includes(['extracts', 'hits'], type)) {
        throw new Error("Unknown track type: ", type);
        //console.log("Unknown track type: ", type);
      }
      var trackStyle = npactConstants.trackStyle[type] || {};
      this.style = _.defaults(trackStyle, npactConstants.trackStyle['default']);
      this.data = null;
      this.index = null;
      this.loading = this.loadData(data);
      this.reindex();
    }

    Track.prototype.id = function () {
      var fn = _.last(this.filename.split('/'));
      return _.takeRight(fn.split('.'),2)[0];
    };

    Track.prototype.loadData = function(data) {
      var self = this;
      // console.log(data);
      if(typeof(data) === 'string') { // trackfile to parse
        return (
          self.loading = ExtractParser.parseAsync(data)
            .then(function (data) {
              $log.log("Finished parsing", self.name, ", found ", data.length);
              self.data = [];
              self.metadata = {};
              _.each(data, function(v, k) {
                if(v.type === 'CDS') self.data.push(v);
                else if(v.type === 'META') self.metadata[k]=v;
              });
              self.loading = false;
              return data;
            })
            .catch(function(e) { $log.log('Track.loadData failed', name, e); throw e; }));
      }
      else { // data must be parsed (probably json version of this object)
        if(Array.isArray(data))
          self.data = data;
        else if(data.cds)
          self.data = data.cds;
        else if(data.data)
          self.data = data.data;
        return null;
      }
    };

    Track.prototype.indexData = function(data) {
      return (
        this.indexing = $timeout(_.bind(function () {
          this.indexing = false;
          return (this.index = ITrackIndex(data));
        }, this))
          .catch(function(e) { $log.log('Track.indexData failed', name, e); throw e; }));
    };

    Track.prototype.reindex = function () {
      if(this.loading) {
        this.loading.then(_.bind(this.indexData, this));
      }
      else if(this.indexing) {
        this.indexing.then(_.bind(this.indexData, this, this.data));
      }
      else {
        this.indexData(this.data);
      }
   };
    Track.prototype.slice = function(opts) {
      if(this.indexing) {
        return this.indexing.then(function (index) {
          return index(opts);
        });
      }
      else {
        return this.index(opts);
      }
    };

    Track.prototype.findByName = function(substr) {
      var doFind = function () {
        if(!this.data) return [];
        var searcher = new RegExp(substr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
        return _.filter(this.data, function(orf) {
          return searcher.test(orf.name);
        });
      };
      return (this.loading ? this.loading.then : $timeout)(_.bind(doFind, this));
    };

    Track.prototype.add = function (entry) {
      if(this.loading) {
        throw new Error("Shouldn't be able to add to a track that doesn't exist");
      }
      this.data.push(entry);
      this.reindex();
    };

    Track.prototype.remove = function (entry) {
      if(this.loading) {
        throw new Error("Shouldn't be able to remove from a track before the track exists");
      }
      this.data = _.without(this.data, entry);
      this.reindex();
    };

    Track.prototype.save = function () {
      var track = this;
      delete Track.loadedTracks[track.filename];  //this is no longer a valid repr of the url.

      return $http({
        method: 'POST',
        url: Fetcher.buildUrl('save_track'),
        data: { track: _.pick(this, ['filename', 'name', 'type', 'active', 'data', 'metadata']) },
        headers: {'Content-Type': 'application/json'}
      })
        .then(function (res) {
          var tr = _.create(Track.prototype, track);
          tr.filename = res.data.filename;
          Track.loadedTracks[tr.filename] = $q.when(tr);
          return tr;
        });
    };

    /// Static methods on Track.
    Track.loadedTracks = {};

    Track.fetchAllTracks = function(paths){
      return $q.all(_.map(paths, Track.fetchTrack));
    };

    Track.fetchTrack = function(filename){
      console.log('fetchTrack ', filename);
      var tr = Track.loadedTracks[filename];
      if(!tr) {
        tr = Track.loadedTracks[filename] = Fetcher.pollThenFetch(filename)
          .then(function(data) { return new Track(filename, data); });
      }
      return tr;
    };
    return Track;
  })

  .factory('TrackRTreeIndex', function($log, Utils, Err, $q, $timeout) {
    'use strict';
    function TrackRTreeIndex(data) {
      var index = RTree();
      var indexReady = Utils.forEachAsync(data, function(d) {
          index.insert({ x: d.start, y: 0,
                         w: d.end - d.start, h: 5},
                       d);
      });
      return function(opts) {
        return $timeout(function() {
          return indexReady.then(function() {
            return index.bbox(opts.startBase, 0, opts.endBase, 5);
          });
        });
      };
    }
    return TrackRTreeIndex;
  })

  .factory('TrackNaiveIndex', function(Utils, $log, Err, $q, $timeout) {
    'use strict';
    return function(data) {
      return function(opts) {
        var minIdx = null, maxIdx;
        return Utils.forEachAsync(data, function(dataPoint, idx) {
          // extract starts in this range?
          var startsInRange = dataPoint.start >= opts.startBase &&
                dataPoint.start < opts.endBase,
              // extract ends in this range?
              endsInRange = dataPoint.end > opts.startBase &&
                dataPoint.end <= opts.endBase;
          if(startsInRange || endsInRange){
            if(minIdx === null) { minIdx = idx; }
            maxIdx = idx;
          }
        }).then(function() {
          return minIdx === null ? [] : data.slice(minIdx, maxIdx+1);
        });
      };
    };
  })
  .factory('TrackBinSearchIndex', function($log, Utils, Err, $q, $timeout) {
    'use strict';
    return function(data) {
      var byStart = _.sortBy(data, 'start');
      var byEnd = _(byStart).map(function(d, idx) {
                return {end: d.end, idx: idx};
      }).sortBy('end').value();

      return function(opts) {
        return $timeout(function() {
          var min = opts.startBase, max = opts.endBase;
          if(isNaN(min) || isNaN(max)) {
            throw new Error("Invalid start or end coordinate");
          }
          //Is the max coord larger than the start of any?
          var rightIdx = _.sortedIndex(byStart, {start: max}, 'start');
          //Is the min coord smaller than the end of any (with reference back to item)
          var leftPointerIdx = _.sortedLastIndex(byEnd, {end: min}, 'end'),
              leftIdx = rightIdx;
          //Because the byEnd array isn't necessarilty sorted by start
          //walk it to the right and if any of the entries reference
          //one that is less than our current left idx then update the
          //lefidx
          while(leftPointerIdx < byEnd.length) {
            leftIdx = Math.min(leftIdx, byEnd[leftPointerIdx].idx);
            //if the end coordinate is past the max then we're done
            if(byEnd[leftPointerIdx].end >= max) break;
            leftPointerIdx++;
          }
          return _.slice(byStart, leftIdx, rightIdx);
        });
      };
    };
  })
;
<commit_msg>Apparently slices can now happen while loading<commit_after>angular.module('npact')
  .factory('Track', function($log,  $q, $timeout, $http,
                      Fetcher, ExtractParser, TrackBinSearchIndex, npactConstants) {
    'use strict';

    var ITrackIndex = TrackBinSearchIndex;
    function Track(filename, data, type, name) {
      // console.log('new Track ',name, data, type ,filename);
      if(!name && !type){
        if(filename.search('profiles')>=0){
          name="Hits";
          type='hits';
        }
        else if(filename.search('modified')>=0){
          name="Modified ORFs";
          type='extracts';
        }
        else if(filename.search('newcds')>=0){
          name="New ORFs";
          type='extracts';
        }
        else if(filename.search('genes')>=0){
          name="Input CDSs";
          type='extracts';
        }
        else{
          name = filename;
          type = 'extracts';
        }
      }
      this.active = true;
      this.filename = filename;
      this.name = name;
      this.type = type;
      if(!_.includes(['extracts', 'hits'], type)) {
        throw new Error("Unknown track type: ", type);
        //console.log("Unknown track type: ", type);
      }
      var trackStyle = npactConstants.trackStyle[type] || {};
      this.style = _.defaults(trackStyle, npactConstants.trackStyle['default']);
      this.data = null;
      this.index = null;
      this.loading = this.loadData(data);
      this.reindex();
    }

    Track.prototype.id = function () {
      var fn = _.last(this.filename.split('/'));
      return _.takeRight(fn.split('.'),2)[0];
    };

    Track.prototype.loadData = function(data) {
      var self = this;
      // console.log(data);
      if(typeof(data) === 'string') { // trackfile to parse
        return (
          self.loading = ExtractParser.parseAsync(data)
            .then(function (data) {
              $log.log("Finished parsing", self.name, ", found ", data.length);
              self.data = [];
              self.metadata = {};
              _.each(data, function(v, k) {
                if(v.type === 'CDS') self.data.push(v);
                else if(v.type === 'META') self.metadata[k]=v;
              });
              self.loading = false;
              return data;
            })
            .catch(function(e) { $log.log('Track.loadData failed', name, e); throw e; }));
      }
      else { // data must be parsed (probably json version of this object)
        if(Array.isArray(data))
          self.data = data;
        else if(data.cds)
          self.data = data.cds;
        else if(data.data)
          self.data = data.data;
        return null;
      }
    };

    Track.prototype.indexData = function(data) {
      return (
        this.indexing = $timeout(_.bind(function () {
          this.indexing = false;
          return (this.index = ITrackIndex(data));
        }, this))
          .catch(function(e) { $log.log('Track.indexData failed', name, e); throw e; }));
    };

    Track.prototype.reindex = function () {
      if(this.loading) {
        this.loading.then(_.bind(this.indexData, this));
      }
      else if(this.indexing) {
        this.indexing.then(_.bind(this.indexData, this, this.data));
      }
      else {
        this.indexData(this.data);
      }
   };
    Track.prototype.slice = function(opts) {
      if(this.loading) {
        return this.loading.then(_.bind(function () {
          return this.slice(opts);
        }, this));
      }
      if(this.indexing) {
        return this.indexing.then(function (index) {
          return index(opts);
        });
      }
      else {
        return this.index(opts);
      }
    };

    Track.prototype.findByName = function(substr) {
      var doFind = function () {
        if(!this.data) return [];
        var searcher = new RegExp(substr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
        return _.filter(this.data, function(orf) {
          return searcher.test(orf.name);
        });
      };
      return (this.loading ? this.loading.then : $timeout)(_.bind(doFind, this));
    };

    Track.prototype.add = function (entry) {
      if(this.loading) {
        throw new Error("Shouldn't be able to add to a track that doesn't exist");
      }
      this.data.push(entry);
      this.reindex();
    };

    Track.prototype.remove = function (entry) {
      if(this.loading) {
        throw new Error("Shouldn't be able to remove from a track before the track exists");
      }
      this.data = _.without(this.data, entry);
      this.reindex();
    };

    Track.prototype.save = function () {
      var track = this;
      delete Track.loadedTracks[track.filename];  //this is no longer a valid repr of the url.

      return $http({
        method: 'POST',
        url: Fetcher.buildUrl('save_track'),
        data: { track: _.pick(this, ['filename', 'name', 'type', 'active', 'data', 'metadata']) },
        headers: {'Content-Type': 'application/json'}
      })
        .then(function (res) {
          var tr = _.create(Track.prototype, track);
          tr.filename = res.data.filename;
          Track.loadedTracks[tr.filename] = $q.when(tr);
          return tr;
        });
    };

    /// Static methods on Track.
    Track.loadedTracks = {};

    Track.fetchAllTracks = function(paths){
      return $q.all(_.map(paths, Track.fetchTrack));
    };

    Track.fetchTrack = function(filename){
      console.log('fetchTrack ', filename);
      var tr = Track.loadedTracks[filename];
      if(!tr) {
        tr = Track.loadedTracks[filename] = Fetcher.pollThenFetch(filename)
          .then(function(data) { return new Track(filename, data); });
      }
      return tr;
    };
    return Track;
  })

  .factory('TrackRTreeIndex', function($log, Utils, Err, $q, $timeout) {
    'use strict';
    function TrackRTreeIndex(data) {
      var index = RTree();
      var indexReady = Utils.forEachAsync(data, function(d) {
          index.insert({ x: d.start, y: 0,
                         w: d.end - d.start, h: 5},
                       d);
      });
      return function(opts) {
        return $timeout(function() {
          return indexReady.then(function() {
            return index.bbox(opts.startBase, 0, opts.endBase, 5);
          });
        });
      };
    }
    return TrackRTreeIndex;
  })

  .factory('TrackNaiveIndex', function(Utils, $log, Err, $q, $timeout) {
    'use strict';
    return function(data) {
      return function(opts) {
        var minIdx = null, maxIdx;
        return Utils.forEachAsync(data, function(dataPoint, idx) {
          // extract starts in this range?
          var startsInRange = dataPoint.start >= opts.startBase &&
                dataPoint.start < opts.endBase,
              // extract ends in this range?
              endsInRange = dataPoint.end > opts.startBase &&
                dataPoint.end <= opts.endBase;
          if(startsInRange || endsInRange){
            if(minIdx === null) { minIdx = idx; }
            maxIdx = idx;
          }
        }).then(function() {
          return minIdx === null ? [] : data.slice(minIdx, maxIdx+1);
        });
      };
    };
  })
  .factory('TrackBinSearchIndex', function($log, Utils, Err, $q, $timeout) {
    'use strict';
    return function(data) {
      var byStart = _.sortBy(data, 'start');
      var byEnd = _(byStart).map(function(d, idx) {
                return {end: d.end, idx: idx};
      }).sortBy('end').value();

      return function(opts) {
        return $timeout(function() {
          var min = opts.startBase, max = opts.endBase;
          if(isNaN(min) || isNaN(max)) {
            throw new Error("Invalid start or end coordinate");
          }
          //Is the max coord larger than the start of any?
          var rightIdx = _.sortedIndex(byStart, {start: max}, 'start');
          //Is the min coord smaller than the end of any (with reference back to item)
          var leftPointerIdx = _.sortedLastIndex(byEnd, {end: min}, 'end'),
              leftIdx = rightIdx;
          //Because the byEnd array isn't necessarilty sorted by start
          //walk it to the right and if any of the entries reference
          //one that is less than our current left idx then update the
          //lefidx
          while(leftPointerIdx < byEnd.length) {
            leftIdx = Math.min(leftIdx, byEnd[leftPointerIdx].idx);
            //if the end coordinate is past the max then we're done
            if(byEnd[leftPointerIdx].end >= max) break;
            leftPointerIdx++;
          }
          return _.slice(byStart, leftIdx, rightIdx);
        });
      };
    };
  })
;
<|endoftext|>


<commit_before>/*
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

google.container = {};

////////////////////////////////////////////////////////////////////////////////
// Externs from container.js
////////////////////////////////////////////////////////////////////////////////

google.container.ContainerConfig = {};

google.container.ContainerRender = {};

/**
 * @param {Object} config
 * @constructor
 */
google.container.Container = function(config) {};

/**
 * @param {Object=} opt_config
 */
google.container.Container.prototype.onConstructed = function(opt_config) {};

/**
 * Create a new gadget site.
 * @param {Element} gadgetEl
 * @param {Element=} opt_bufferEl
 * @return {google.container.GadgetSite}
 */
google.container.Container.prototype.newGadgetSite = function(gadgetEl,
    opt_bufferEl) {};

/**
 * @param {string} id
 * @return {google.container.GadgetSite}
 * @nosideeffects
 */
google.container.Container.prototype.getGadgetSite = function(id) {};

/**
 * @param {string} id
 * @return {google.container.GadgetHolder}
 * @nosideeffects
 */
google.container.Container.prototype.getGadgetHolder = function(id) {};

/**
 * @param {google.container.GadgetSite} site
 * @param {string} gadgetUrl
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 * @param {Function=} opt_callback
 */
google.container.Container.prototype.navigateGadget = function(
    site, gadgetUrl, gadgetParams, renderParams, opt_callback) {};

/**
 * @param {google.container.GadgetSite} site
 */
google.container.Container.prototype.closeGadget = function(site) {};

/**
 * @param {Object} request
 */
google.container.Container.prototype.preloadGadgets = function(request) {};

/**
 * @param {string} url
 * @param {function(Object)=} opt_callback
 */
google.container.Container.prototype.getGadgetMetadata = function(url,
    opt_callback) {};

////////////////////////////////////////////////////////////////////////////////
// Externs from gadget_site.js
////////////////////////////////////////////////////////////////////////////////

/**
 * @param {google.container.Service} service
 * @param {Element} gadgetEl
 * @param {Element=} opt_bufferEl
 * @constructor
 */
google.container.GadgetSite = function(service, gadgetEl, opt_bufferEl) {};

google.container.GadgetSite.prototype.onConstructed = function() {};

/**
 * @param {number} height
 */
google.container.GadgetSite.prototype.setHeight = function(height) {};

/**
 * @param {number} width
 */
google.container.GadgetSite.prototype.setWidth = function(width) {};

/**
 * @param {number} value
 */
google.container.GadgetSite.prototype.setParentId = function(value) {};

/**
 * @return {number}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getId = function() {};

/**
 * @return {google.container.GadgetHolder}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getActiveGadgetHolder = function() {};

/**
 * @param {string} name
 * @param {Object=} opt_gadgetInfo
 * @return {Object}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getFeature = function(name,
    opt_gadgetInfo) {};

/**
 * @param {string} id
 * @return {google.container.GadgetHolder}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getGadgetHolder = function(id) {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getParentId = function() {};

/**
 * @param {string} gadgetUrl
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 * @param {Function=} opt_callback
 */
google.container.GadgetSite.prototype.navigateTo = function(gadgetUrl,
    gadgetParams, renderParams, opt_callback) {};

/**
 * @param {Object} gadgetInfo
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 */
google.container.GadgetSite.prototype.render = function(
    gadgetInfo, gadgetParams, renderParams) {};

/**
 * @param {string} serviceName
 * @param {Function} callback
 * @param {...number} var_args
 */
google.container.GadgetSite.prototype.rpcCall = function(serviceName, callback,
    var_args) {};

google.container.GadgetSite.prototype.close = function() {};

////////////////////////////////////////////////////////////////////////////////
// Externs from gadget_holder.js
////////////////////////////////////////////////////////////////////////////////

/**
 * @param {number} siteId
 * @param {Element} el
 * @constructor
 */
google.container.GadgetHolder = function(siteId, el) {};

google.container.GadgetHolder.prototype.onConstructed = function() {};

/**
 * @return {Element}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getElement = function() {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getIframeId = function() {};

/**
 * @return {Object}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getGadgetInfo = function() {};

google.container.GadgetHolder.prototype.dispose = function() {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getUrl = function() {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getView = function() {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getIframeElement = function() {};

/**
 * @param {string} value
 */
google.container.GadgetHolder.prototype.setSecurityToken = function(value) {};

/**
 * @param {Object} gadgetInfo
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 */
google.container.GadgetHolder.prototype.render = function(gadgetInfo,
    gadgetParams, renderParams) {};

////////////////////////////////////////////////////////////////////////////////
// Externs from service.js
////////////////////////////////////////////////////////////////////////////////

google.container.ServiceConfig = {};

/**
 * @param {Object=} opt_config
 * @constructor
 */
google.container.Service = function(opt_config) {};

/**
 * @param {Object} request
 * @param {function(Object)=} opt_callback
 */
google.container.Service.prototype.getGadgetMetadata = function(request,
    opt_callback) {};

/**
 * @param {Object} request
 * @param {function(Object)=} opt_callback
 */
google.container.Service.prototype.getGadgetToken = function(request,
    opt_callback) {};

/**
 * @param {string} url
 * @return {Object}
 */
google.container.Service.prototype.getCachedGadgetMetadata = function(url) {};

/**
 * @param {string} url
 * @return {Object}
 */
google.container.Service.prototype.getCachedGadgetToken = function(url) {};
<commit_msg><commit_after>/*
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

google.container = {};

////////////////////////////////////////////////////////////////////////////////
// Externs from container.js
////////////////////////////////////////////////////////////////////////////////

google.container.ContainerConfig = {};

google.container.ContainerRender = {};

/**
 * @param {Object} config
 * @constructor
 */
google.container.Container = function(config) {};

/**
 * @param {Object=} opt_config
 */
google.container.Container.prototype.onConstructed = function(opt_config) {};

/**
 * Create a new gadget site.
 * @param {Element} gadgetEl
 * @param {Element=} opt_bufferEl
 * @return {google.container.GadgetSite}
 */
google.container.Container.prototype.newGadgetSite = function(gadgetEl,
    opt_bufferEl) {};

/**
 * @param {string} id
 * @return {google.container.GadgetSite}
 * @nosideeffects
 */
google.container.Container.prototype.getGadgetSite = function(id) {};

/**
 * @param {string} id
 * @return {google.container.GadgetHolder}
 * @nosideeffects
 */
google.container.Container.prototype.getGadgetHolder = function(id) {};

/**
 * @param {google.container.GadgetSite} site
 * @param {string} gadgetUrl
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 * @param {Function=} opt_callback
 */
google.container.Container.prototype.navigateGadget = function(
    site, gadgetUrl, gadgetParams, renderParams, opt_callback) {};

/**
 * @param {google.container.GadgetSite} site
 */
google.container.Container.prototype.closeGadget = function(site) {};

/**
 * @param {Object} request
 */
google.container.Container.prototype.preloadGadgets = function(request) {};

/**
 * @param {string} url
 * @param {function(Object)=} opt_callback
 */
google.container.Container.prototype.getGadgetMetadata = function(url,
    opt_callback) {};

////////////////////////////////////////////////////////////////////////////////
// Externs from gadget_site.js
////////////////////////////////////////////////////////////////////////////////

/**
 * @param {google.container.Service} service
 * @param {Element} gadgetEl
 * @param {Element=} opt_bufferEl
 * @constructor
 */
google.container.GadgetSite = function(service, gadgetEl, opt_bufferEl) {};

google.container.GadgetSite.prototype.onConstructed = function() {};

/**
 * @param {number} height
 */
google.container.GadgetSite.prototype.setHeight = function(height) {};

/**
 * @param {number} width
 */
google.container.GadgetSite.prototype.setWidth = function(width) {};

/**
 * @param {number} value
 */
google.container.GadgetSite.prototype.setParentId = function(value) {};

/**
 * @return {number}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getId = function() {};

/**
 * @return {google.container.GadgetHolder}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getActiveGadgetHolder = function() {};

/**
 * @param {string} name
 * @param {Object=} opt_gadgetInfo
 * @return {Object}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getFeature = function(name,
    opt_gadgetInfo) {};

/**
 * @param {string} id
 * @return {google.container.GadgetHolder}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getGadgetHolder = function(id) {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetSite.prototype.getParentId = function() {};

/**
 * @param {string} gadgetUrl
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 * @param {Function=} opt_callback
 */
google.container.GadgetSite.prototype.navigateTo = function(gadgetUrl,
    gadgetParams, renderParams, opt_callback) {};

/**
 * @param {Object} gadgetInfo
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 */
google.container.GadgetSite.prototype.render = function(
    gadgetInfo, gadgetParams, renderParams) {};

/**
 * @param {string} serviceName
 * @param {Function} callback
 * @param {...number} var_args
 */
google.container.GadgetSite.prototype.rpcCall = function(serviceName, callback,
    var_args) {};

google.container.GadgetSite.prototype.close = function() {};

////////////////////////////////////////////////////////////////////////////////
// Externs from gadget_holder.js
////////////////////////////////////////////////////////////////////////////////

/**
 * @param {number} siteId
 * @param {Element} el
 * @constructor
 */
google.container.GadgetHolder = function(siteId, el) {};

google.container.GadgetHolder.prototype.onConstructed = function() {};

/**
 * @return {Element}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getElement = function() {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getIframeId = function() {};

/**
 * @return {Object}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getGadgetInfo = function() {};

google.container.GadgetHolder.prototype.dispose = function() {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getUrl = function() {};

/**
 * @return {string}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getView = function() {};

/**
 * @return {Element}
 * @nosideeffects
 */
google.container.GadgetHolder.prototype.getIframeElement = function() {};

/**
 * @param {string} value
 */
google.container.GadgetHolder.prototype.setSecurityToken = function(value) {};

/**
 * @param {Object} gadgetInfo
 * @param {Object} gadgetParams
 * @param {Object} renderParams
 */
google.container.GadgetHolder.prototype.render = function(gadgetInfo,
    gadgetParams, renderParams) {};

////////////////////////////////////////////////////////////////////////////////
// Externs from service.js
////////////////////////////////////////////////////////////////////////////////

google.container.ServiceConfig = {};

/**
 * @param {Object=} opt_config
 * @constructor
 */
google.container.Service = function(opt_config) {};

/**
 * @param {Object} request
 * @param {function(Object)=} opt_callback
 */
google.container.Service.prototype.getGadgetMetadata = function(request,
    opt_callback) {};

/**
 * @param {Object} request
 * @param {function(Object)=} opt_callback
 */
google.container.Service.prototype.getGadgetToken = function(request,
    opt_callback) {};

/**
 * @param {string} url
 * @return {Object}
 */
google.container.Service.prototype.getCachedGadgetMetadata = function(url) {};

/**
 * @param {string} url
 * @return {Object}
 */
google.container.Service.prototype.getCachedGadgetToken = function(url) {};
<|endoftext|>