<commit_before>(function() {
  'use strict';
  angular.module('civic.search')
    .controller('SearchController', SearchController);

  // @ngInject
  function SearchController($scope, $state, $stateParams, $log, $location, _, Search) {
    var vm = $scope.vm = {};

    // function assignment
    vm.onSubmit = onSubmit;
    vm.options = {};
    vm.searchResults = [];
    vm.showEvidenceGrid = false;

    init();

    vm.originalFields = angular.copy(vm.fields);

    // function definition
    function onSubmit() {
      $log.debug(JSON.stringify(vm.model));
      //vm.searchResults = Search.post(vm.model);
      //vm.showEvidenceGrid = true;
      Search.post(vm.model)
        .then(function(response) {
          vm.searchResults = response.results;
          vm.showEvidenceGrid = true;
          if(_.has(response, 'token') && !_.isNull(response.token)) {
            $state.transitionTo('search', { token: response.token}, {notify: false});
          }
        });
    }

    vm.buttonLabel = 'Search Evidence Items';

    function init() {
      if(_.has($stateParams, 'token') && !_.isEmpty($stateParams.token)){
        Search.get($stateParams.token)
          .then(function(response) {
            vm.model.operator = response.params.operator;
            vm.model.queries= response.params.queries;
            vm.searchResults = response.results;
            vm.showEvidenceGrid = true;
          });
      } else {
        vm.model = {
          operator: 'AND',
          queries: [
            {
              field: '',
              condition: {
                name: undefined,
                parameters: []
              }
            }
          ]
        };
      }

      vm.operatorField = [
        {
          key: 'operator',
          type: 'select',
          defaultValue: 'AND',
          templateOptions: {
            label: '',
            options: [
              { value: 'AND', name: 'all' },
              { value: 'OR', name: 'any' }
            ]
          }
        }
      ];

      vm.fields = [
        {
          type: 'queryRow',
          key: 'queries',
          templateOptions: {
            rowFields: [
              {
                key: 'field',
                type: 'select',
                templateOptions: {
                  label: '',
                  required: true,
                  options: [
                    { value: '', name: 'Please select a field' },
                    { value: 'description', name: 'Description' },
                    { value: 'disease_doid', name: 'Disease DOID' },
                    { value: 'disease_name', name: 'Disease Name' },
                    { value: 'drug_id', name: 'Drug PubChem ID' },
                    { value: 'drug_name', name: 'Drug Name' },
                    { value: 'evidence_level', name: 'Evidence Level' },
                    { value: 'gene_name', name: 'Gene Name' },
                    { value: 'pubmed_id', name: 'Pubmed ID' },
                    { value: 'rating', name: 'Rating' },
                    { value: 'suggested_changes_count', name: 'Suggested Revisions' },
                    { value: 'status', name: 'Status' },
                    { value: 'variant_name', name: 'Variant Name' }
                  ],
                  onChange: function(value, options, scope) {
                    scope.model.condition = {
                      name: undefined,
                      parameters: []
                    };
                  }
                }
              }
            ],
            conditionFields: {
              pubmed_id: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-md',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]', // pubmed id
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              rating: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'is_greater_than_or_equal_to',
                  templateOptions: {
                    required: true,
                    label: '',
                    options: [
                      { value: 'is_greater_than_or_equal_to', name: 'is greater than or equal to' },
                      { value: 'is_greater_than', name: 'is greater than' },
                      { value: 'is_less_than', name: 'is less than' },
                      { value: 'is_less_than_or_equal_to', name: 'is less than or equal to' },
                      { value: 'is_equal_to', name: 'is equal to' },
                      { value: 'is_in_the_range', name: 'is in the range'}
                    ],
                    onChange: function(value, options, scope) {
                      _.pullAt(scope.model.parameters, 1,2);
                    }
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'rating',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                },
                {
                  template: 'to',
                  className: 'inline-field',
                  hideExpression: 'model.name != "is_in_the_range"'
                },
                {
                  key: 'parameters[1]',
                  type: 'rating',
                  className: 'inline-field',
                  hideExpression: 'model.name != "is_in_the_range"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              description: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'},
                      {value: 'is_empty', name: 'is empty'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  hideExpression: 'model.name === "is_empty"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              disease_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'},
                      {value: 'is_empty', name: 'is empty'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  hideExpression: 'model.name === "is_empty"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              disease_doid: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-small',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'},
                      {value: 'is_empty', name: 'is empty'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  hideExpression: 'model.name === "is_empty"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              drug_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'},

                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              drug_id: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-small',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              evidence_level: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'is_above',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is_equal_to', name: 'is'},
                      {value: 'is_above', name: 'is above'},
                      {value: 'is_below', name: 'is below'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'C',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      { value: 'A', name: 'A - Validated'},
                      { value: 'B', name: 'B - Clinical'},
                      { value: 'C', name: 'C - Preclinical'},
                      { value: 'D', name: 'D - Case Study'},
                      { value: 'E', name: 'E - Inferential'}
                    ]
                  }
                }
              ],
              status: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-small',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'submitted',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      { value: 'submitted', name: 'Submitted'},
                      { value: 'accepted', name: 'Accepted'},
                      { value: 'rejected', name: 'Rejected'}
                    ]
                  }
                }
              ],
              suggested_changes_count: [
                {
                  template: 'with status',
                  className: 'inline-field'
                },
                {
                  key: 'parameters[0]', // status
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'new',
                  templateOptions: {
                    required: true,
                    label: '',
                    options: [
                      { value: 'new', name: 'new' },
                      { value: 'applied', name: 'applied' },
                      { value: 'rejected', name: 'rejected' }
                    ]
                  }
                },
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'is_greater_than_or_equal_to',
                  templateOptions: {
                    required: true,
                    label: '',
                    options: [
                      { value: 'is_greater_than_or_equal_to', name: 'is greater than or equal to' },
                      { value: 'is_greater_than', name: 'is greater than' },
                      { value: 'is_less_than', name: 'is less than' },
                      { value: 'is_less_than_or_equal_to', name: 'is less than or equal to' },
                      { value: 'is_equal_to', name: 'is equal to' },
                      { value: 'is_in_the_range', name: 'is in the range'}
                    ],
                    onChange: function(value, options, scope) {
                      _.pullAt(scope.model.parameters, 1,2);
                    }
                  }
                },
                {
                  key: 'parameters[1]', // from value
                  type: 'input',
                  className: 'inline-field inline-field-xs',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                },
                {
                  template: 'to',
                  className: 'inline-field',
                  hideExpression: 'model.name.length > 0 && model.name !== "is_in_the_range"'
                },
                {
                  key: 'parameters[2]', // to value
                  type: 'input',
                  className: 'inline-field inline-field-xs',
                  hideExpression: 'model.name.length > 0 && model.name !== "is_in_the_range"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              gene_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              variant_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ]
            }
          }
        }
      ];
    }
  }
})();
<commit_msg>support for searching submitter in advanced search<commit_after>(function() {
  'use strict';
  angular.module('civic.search')
    .controller('SearchController', SearchController);

  // @ngInject
  function SearchController($scope, $state, $stateParams, $log, $location, _, Search) {
    var vm = $scope.vm = {};

    // function assignment
    vm.onSubmit = onSubmit;
    vm.options = {};
    vm.searchResults = [];
    vm.showEvidenceGrid = false;

    init();

    vm.originalFields = angular.copy(vm.fields);

    // function definition
    function onSubmit() {
      $log.debug(JSON.stringify(vm.model));
      //vm.searchResults = Search.post(vm.model);
      //vm.showEvidenceGrid = true;
      Search.post(vm.model)
        .then(function(response) {
          vm.searchResults = response.results;
          vm.showEvidenceGrid = true;
          if(_.has(response, 'token') && !_.isNull(response.token)) {
            $state.transitionTo('search', { token: response.token}, {notify: false});
          }
        });
    }

    vm.buttonLabel = 'Search Evidence Items';

    function init() {
      if(_.has($stateParams, 'token') && !_.isEmpty($stateParams.token)){
        Search.get($stateParams.token)
          .then(function(response) {
            vm.model.operator = response.params.operator;
            vm.model.queries= response.params.queries;
            vm.searchResults = response.results;
            vm.showEvidenceGrid = true;
          });
      } else {
        vm.model = {
          operator: 'AND',
          queries: [
            {
              field: '',
              condition: {
                name: undefined,
                parameters: []
              }
            }
          ]
        };
      }

      vm.operatorField = [
        {
          key: 'operator',
          type: 'select',
          defaultValue: 'AND',
          templateOptions: {
            label: '',
            options: [
              { value: 'AND', name: 'all' },
              { value: 'OR', name: 'any' }
            ]
          }
        }
      ];

      vm.fields = [
        {
          type: 'queryRow',
          key: 'queries',
          templateOptions: {
            rowFields: [
              {
                key: 'field',
                type: 'select',
                templateOptions: {
                  label: '',
                  required: true,
                  options: [
                    { value: '', name: 'Please select a field' },
                    { value: 'description', name: 'Description' },
                    { value: 'disease_doid', name: 'Disease DOID' },
                    { value: 'disease_name', name: 'Disease Name' },
                    { value: 'drug_id', name: 'Drug PubChem ID' },
                    { value: 'drug_name', name: 'Drug Name' },
                    { value: 'evidence_level', name: 'Evidence Level' },
                    { value: 'gene_name', name: 'Gene Name' },
                    { value: 'pubmed_id', name: 'Pubmed ID' },
                    { value: 'rating', name: 'Rating' },
                    { value: 'suggested_changes_count', name: 'Suggested Revisions' },
                    { value: 'status', name: 'Status' },
                    { value: 'variant_name', name: 'Variant Name' },
                    { value: 'submitter', name: 'Submitter' }
                  ],
                  onChange: function(value, options, scope) {
                    scope.model.condition = {
                      name: undefined,
                      parameters: []
                    };
                  }
                }
              }
            ],
            conditionFields: {
              pubmed_id: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-md',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]', // pubmed id
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              rating: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'is_greater_than_or_equal_to',
                  templateOptions: {
                    required: true,
                    label: '',
                    options: [
                      { value: 'is_greater_than_or_equal_to', name: 'is greater than or equal to' },
                      { value: 'is_greater_than', name: 'is greater than' },
                      { value: 'is_less_than', name: 'is less than' },
                      { value: 'is_less_than_or_equal_to', name: 'is less than or equal to' },
                      { value: 'is_equal_to', name: 'is equal to' },
                      { value: 'is_in_the_range', name: 'is in the range'}
                    ],
                    onChange: function(value, options, scope) {
                      _.pullAt(scope.model.parameters, 1,2);
                    }
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'rating',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                },
                {
                  template: 'to',
                  className: 'inline-field',
                  hideExpression: 'model.name != "is_in_the_range"'
                },
                {
                  key: 'parameters[1]',
                  type: 'rating',
                  className: 'inline-field',
                  hideExpression: 'model.name != "is_in_the_range"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              description: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'},
                      {value: 'is_empty', name: 'is empty'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  hideExpression: 'model.name === "is_empty"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              disease_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'},
                      {value: 'is_empty', name: 'is empty'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  hideExpression: 'model.name === "is_empty"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              disease_doid: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-small',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'},
                      {value: 'is_empty', name: 'is empty'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  hideExpression: 'model.name === "is_empty"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              drug_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'},

                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              drug_id: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-small',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              evidence_level: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'is_above',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is_equal_to', name: 'is'},
                      {value: 'is_above', name: 'is above'},
                      {value: 'is_below', name: 'is below'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'C',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      { value: 'A', name: 'A - Validated'},
                      { value: 'B', name: 'B - Clinical'},
                      { value: 'C', name: 'C - Preclinical'},
                      { value: 'D', name: 'D - Case Study'},
                      { value: 'E', name: 'E - Inferential'}
                    ]
                  }
                }
              ],
              status: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field inline-field-small',
                  defaultValue: 'is',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'is_not', name: 'is not'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'submitted',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      { value: 'submitted', name: 'Submitted'},
                      { value: 'accepted', name: 'Accepted'},
                      { value: 'rejected', name: 'Rejected'}
                    ]
                  }
                }
              ],
              suggested_changes_count: [
                {
                  template: 'with status',
                  className: 'inline-field'
                },
                {
                  key: 'parameters[0]', // status
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'new',
                  templateOptions: {
                    required: true,
                    label: '',
                    options: [
                      { value: 'new', name: 'new' },
                      { value: 'applied', name: 'applied' },
                      { value: 'rejected', name: 'rejected' }
                    ]
                  }
                },
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'is_greater_than_or_equal_to',
                  templateOptions: {
                    required: true,
                    label: '',
                    options: [
                      { value: 'is_greater_than_or_equal_to', name: 'is greater than or equal to' },
                      { value: 'is_greater_than', name: 'is greater than' },
                      { value: 'is_less_than', name: 'is less than' },
                      { value: 'is_less_than_or_equal_to', name: 'is less than or equal to' },
                      { value: 'is_equal_to', name: 'is equal to' },
                      { value: 'is_in_the_range', name: 'is in the range'}
                    ],
                    onChange: function(value, options, scope) {
                      _.pullAt(scope.model.parameters, 1,2);
                    }
                  }
                },
                {
                  key: 'parameters[1]', // from value
                  type: 'input',
                  className: 'inline-field inline-field-xs',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                },
                {
                  template: 'to',
                  className: 'inline-field',
                  hideExpression: 'model.name.length > 0 && model.name !== "is_in_the_range"'
                },
                {
                  key: 'parameters[2]', // to value
                  type: 'input',
                  className: 'inline-field inline-field-xs',
                  hideExpression: 'model.name.length > 0 && model.name !== "is_in_the_range"',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              gene_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              variant_name: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'is', name: 'is'},
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                      {value: 'does_not_contain', name: 'does not contain'}
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ],
              submitter: [
                {
                  key: 'name',
                  type: 'select',
                  className: 'inline-field',
                  defaultValue: 'contains',
                  templateOptions: {
                    label: '',
                    required: true,
                    options: [
                      {value: 'contains', name: 'contains'},
                      {value: 'begins_with', name: 'begins with'},
                    ]
                  }
                },
                {
                  key: 'parameters[0]',
                  type: 'input',
                  className: 'inline-field',
                  templateOptions: {
                    label: '',
                    required: true
                  }
                }
              ]
            }
          }
        }
      ];
    }
  }
})();
<|endoftext|>


<commit_before>/**
@Name: sb.flashGate
@Description: Used to include swf for surebert communicate with flash player for sound, multi-file/progress upload and storage.  If you want to use one of these functions on page load, (e.g. play music) make sure to wrap it in the function sb_onFlashGateLoaded so that it fires once sb.flashGate has loaded.
@Author: Paul Visco
@Version: 4.2 02/12/06 09/03/08
#############################
*/
sb.include('swf');
sb.flashGate = new sb.swf({
	src : sb.base+"/FlashGate.swf",
	//src : '${swf}.swf?d='+Math.random(),
	width : 1,
	height : 1,
	bgColor : '#FF0000',
	id : 'Flashgate',
	wmode: 'transparent',
	flashvars : {
		debug : true
	}
});

sb.flashGate.debug = 0;

sb.flashGateContainer = new sb.element({
	tag : 'x',
	styles : {
		display : 'block',
		position : 'absolute',
		left : '-200px',
		top : '-200px'
	}
});

var sb_onFlashGateLoaded = [];

sb.dom.onReady({
	id : 'body',
	onReady : function(){
		sb.flashGateContainer.appendToTop('body');
		sb.flashGate.embed(sb.flashGateContainer);
		sb_onFlashGateLoaded.forEach(function(v){
			if(typeof v == 'function'){
				v();
			}
		})
	},
	tries : 600,
	ontimeout : function(){
		if(sb.flashGate.debug){
			throw('Cannot append flashGate to browser');
		}
	}
});

/**
 * @Name sb_onFlashGateLoad
 * @Description: Used Internally
 */
sb_onFlashGateLoad = function(){

	if(sb_onFlashGateLoaded && sb_onFlashGateLoaded.forEach ){
		sb_onFlashGateLoaded.forEach(function(v){
			if(typeof v == 'function'){
				v();
			}
		});
	}

};<commit_msg>added new sb_FlashGateSrc var to change location if desired<commit_after>/**
@Name: sb.flashGate
@Description: Used to include swf for surebert communicate with flash player for sound, multi-file/progress upload and storage.  If you want to use one of these functions on page load, (e.g. play music) make sure to wrap it in the function sb_onFlashGateLoaded so that it fires once sb.flashGate has loaded.
@Author: Paul Visco
@Version: 4.2 02/12/06 09/03/08
#############################
*/
sb.include('swf');

sb.flashGate = new sb.swf({
	src : sb_FlashGateSrc || sb.base+"/FlashGate.swf",
	//src : '${swf}.swf?d='+Math.random(),
	width : 1,
	height : 1,
	bgColor : '#FF0000',
	id : 'Flashgate',
	wmode: 'transparent',
	flashvars : {
		debug : true
	}
});

sb.flashGate.debug = 0;

sb.flashGateContainer = new sb.element({
	tag : 'x',
	styles : {
		display : 'block',
		position : 'absolute',
		left : '-200px',
		top : '-200px'
	}
});

var sb_onFlashGateLoaded = [];

sb.dom.onReady({
	id : 'body',
	onReady : function(){
		sb.flashGateContainer.appendToTop('body');
		sb.flashGate.embed(sb.flashGateContainer);
		sb_onFlashGateLoaded.forEach(function(v){
			if(typeof v == 'function'){
				v();
			}
		})
	},
	tries : 600,
	ontimeout : function(){
		if(sb.flashGate.debug){
			throw('Cannot append flashGate to browser');
		}
	}
});

/**
 * @Name sb_onFlashGateLoad
 * @Description: Used Internally
 */
sb_onFlashGateLoad = function(){

	if(sb_onFlashGateLoaded && sb_onFlashGateLoaded.forEach ){
		sb_onFlashGateLoaded.forEach(function(v){
			if(typeof v == 'function'){
				v();
			}
		});
	}

};<|endoftext|>


<commit_before>YUI.add('aui-datatable-tests', function(Y) {

    var suite = new Y.Test.Suite('aui-datatable');

    var data = [
        {
            active: 'no',
            address: '3271 Another Ave',
            amount: 3,
            city: 'New York',
            colors: ['red', 'blue'],
            date: '2013-01-01',
            fruit: ['apple'],
            name: 'Joan B. Jones',
            state: 'AL'
        },
        {
            active: 'maybe',
            address: '9996 Random Road',
            amount: 0,
            city: 'Los Angeles',
            colors: ['green'],
            date: '2013-01-01',
            fruit: ['cherry'],
            name: 'Bob C. Uncle',
            state: 'CA'
        },
        {
            active: 'yes',
            address: '1623 Some Street',
            amount: 5,
            city: 'San Francisco',
            colors: ['red'],
            date: '',
            fruit: ['cherry'],
            name: 'John D. Smith',
            state: 'CA'
        },
        {
            active: 'no',
            address: '3217 Another Ave',
            amount: 3,
            city: 'New York',
            colors: ['red', 'blue'],
            date: '2013-01-06',
            fruit: ['apple', 'cherry'],
            name: 'Joan E. Jones',
            state: 'KY'
        }
    ];

    new Y.DataTable({
        boundingBox: '#simple',
        columns: [
            {
                editor: new Y.TextAreaCellEditor({
                    on: {
                        cancel: function(event) {
                            console.log('cancel', event);
                        },
                        save: function(event) {
                            console.log('save', event.newVal);
                        }
                    },
                    validator: {
                        rules: {
                            value: {
                                required: true
                            }
                        }
                    }
                }),
                key: 'name',
                sortable: true
            },
            {
                editor: new Y.TextAreaCellEditor(),
                key: 'address'
            },
            {
                editor: new Y.TextAreaCellEditor(),
                key: 'city'
            },
            {
                editor: new Y.DropDownCellEditor({
                    editable: true,
                    options: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID',
                        'IL', 'IN', 'IA', 'KS', 'KY', 'LA']
                }),
                key: 'state'
            },
            'amount',
            {
                editor: new Y.RadioCellEditor({
                    editable: true,
                    options: {
                        yes: 'Yes',
                        no: 'No',
                        maybe: 'Maybe'
                    }
                }),
                key: 'active'
            },
            {
                editor: new Y.CheckboxCellEditor({
                    editable: true,
                    multiple: true,
                    options: {
                        red: 'Red',
                        green: 'Green',
                        blue: 'Blue'
                    }
                }),
                key: 'colors'
            },
            {
                editor: new Y.DropDownCellEditor({
                    editable: true,
                    multiple: true,
                    options: {
                        apple: 'Apple',
                        banana: 'Banana',
                        cherry: 'Cherry',
                        kiwi: 'Kiwi'
                    }
                }),
                key: 'fruit',
                sortable: true
            },
            {
                editor: new Y.DateCellEditor({
                    calendar: {
                        selectionMode: 'multiple',
                        showNextMonth: true,
                        showPrevMonth: true,
                        width: '400px'
                    }
                }),
                key: 'date',
                sortable: true
            }
        ],
        data: data,
        editEvent: 'dblclick',
        plugins: [
            {
                fn: Y.Plugin.DataTableHighlight
            }
        ]
    }).render();

    function assertHighlightPosition(tableData) {
        var lowerXLimit,
            lowerYLimit,
            overlayActiveBorderWidth,
            overlayActiveBottomWidth,
            overlayActiveChildren,
            overlayActiveLeftHeight,
            overlayActiveNode,
            overlayActiveRightHeight,
            overlayActiveTopWidth,
            overlaySelectionNode,
            tableDataHeight,
            tableDataWidth,
            upperXLimit,
            upperYLimit;

        overlayActiveNode = Y.one('.table-highlight-overlay-active');
        overlayActiveChildren = overlayActiveNode.get('children');
        overlaySelectionNode = overlayActiveNode ? overlayActiveNode.next('.table-highlight-overlay') : null;

        lowerXLimit = tableData.getX() >= (overlayActiveNode.getX() - 1);
        lowerYLimit = tableData.getY() >= (overlayActiveNode.getY() - 1);

        overlayActiveBorderWidth = overlayActiveChildren.item(0).get('offsetHeight');
        overlayActiveBottomWidth = overlayActiveChildren.item(2).get('offsetWidth');

        overlayActiveLeftHeight = overlayActiveChildren.item(3).get('offsetHeight') + overlayActiveBorderWidth;
        overlayActiveRightHeight = overlayActiveChildren.item(1).get('offsetHeight') + overlayActiveBorderWidth;

        overlayActiveTopWidth = overlayActiveChildren.item(0).get('offsetWidth');

        tableDataHeight = tableData.get('offsetHeight');
        tableDataWidth = tableData.get('offsetWidth');

        upperXLimit = tableData.getX() <= (overlayActiveNode.getX() + 1);
        upperYLimit = tableData.getY() <= (overlayActiveNode.getY() + 1);

        Y.Assert.isTrue(
            (lowerXLimit && upperXLimit),
            'X Position of 	 and highlight are not the similar.');

        Y.Assert.isTrue(
            (lowerYLimit && upperYLimit),
            'Y Position of 	 and highlight are not the similar.');

        Y.Assert.areSame(
            tableDataWidth,
            overlayActiveBottomWidth,
            'Hightlight bottom border width ' + overlayActiveBottomWidth + ' is not same width as table data ' +
            tableDataWidth + '.');

        Y.Assert.areSame(
            tableDataWidth,
            overlayActiveTopWidth,
            'Hightlight top border width ' + overlayActiveTopWidth + ' is not same width as table data ' +
            tableDataWidth + '.');

        Y.Assert.areSame(
            tableDataHeight,
            overlayActiveLeftHeight,
            'Hightlight left border height ' + overlayActiveLeftHeight + ' is not same height as table data ' +
            tableDataHeight + '.');

        Y.Assert.areSame(
            tableDataHeight,
            overlayActiveRightHeight,
            'Hightlight right border height ' + overlayActiveRightHeight + ' is not same height as table data ' +
            tableDataHeight + '.');
    }

    suite.add(new Y.Test.Case({
        name: 'Datatable Highlight',
        'table-cell should be highlighted on click': function() {
            var test = this,
                tableData;

            tableData = Y.one('tr.table-odd td.table-col-amount');

            tableData.once('mousedown', function(event) {
                setTimeout(function() {
                    test.resume(function() {
                        assertHighlightPosition(event.currentTarget);
                    });
                }, 800);
            });

            setTimeout(function() {
                tableData.simulate('mousedown');
                tableData.simulate('mouseup');
            }, 0);

            test.wait(1000);
        },

        'table-cell should still be highlighted when table is scrolled horizontally': function() {
            var test = this,
                datatableContainer,
                datatableContent,
                tableData;

            datatableContainer = Y.one('#simple');
            datatableContent = datatableContainer.one('.table-content');
            tableData = Y.one('tr.table-odd td.table-col-amount');

            datatableContainer.setStyle('width', '300px');
            datatableContent.setStyle('overflow', 'auto');

            tableData.once('mousedown', function(event) {
                setTimeout(function() {
                    test.resume(function() {
                        assertHighlightPosition(event.currentTarget);
                    });
                }, 800);
            });

            setTimeout(function() {
                tableData.simulate('mousedown');
                tableData.simulate('mouseup');
                datatableContent.set('scrollLeft', 200);
            }, 0);

            test.wait(1000);
        }
    }));

    suite.add(new Y.Test.Case({
        name: 'Datatable',

        init: function() {
            var data = [
                {
                    active: 'no',
                    address: '3271 Another Ave',
                    amount: 3,
                    city: 'New York',
                    colors: ['red','blue'],
                    date: '2013-01-01',
                    fruit: ['apple'],
                    name: 'Joan B. Jones',
                    state: 'AL'
                },
                {
                    active: 'maybe',
                    address: '9996 Random Road',
                    amount: 0,
                    city: 'Los Angeles',
                    colors: ['green'],
                    date: '2013-01-01',
                    fruit: ['cherry'],
                    name: 'Bob C. Uncle',
                    state: 'CA'
                },
                {
                    active: 'yes',
                    address: '1623 Some Street',
                    amount: 5,
                    city: 'San Francisco',
                    colors: ['red'],
                    date: '',
                    fruit: ['cherry'],
                    name: 'John D. Smith',
                    state: 'CA'
                },
                {
                    active: 'no',
                    address: '3217 Another Ave',
                    amount: 3,
                    city: 'New York',
                    colors: ['red','blue'],
                    date: '2013-01-06',
                    fruit: ['apple','cherry'],
                    name: 'Joan E. Jones',
                    state: 'KY'
                }
            ];

            this._dataTable = new Y.DataTable({
                cssClass: 'table-striped',
                boundingBox: '#datatable',
                columns: [
                    {
                        key: 'name',
                        sortable: true,
                        editor: new Y.TextAreaCellEditor({
                            on: {
                                save: function(event) {
                                    console.log('save', event.newVal);
                                },
                                cancel: function(event) {
                                    console.log('cancel', event);
                                }
                            },
                            validator: {
                                rules: {
                                    value: {
                                        required: true
                                    }
                                }
                            }
                        })
                    },
                    {
                        key: 'address',
                        editor: new Y.TextAreaCellEditor()
                    },
                    {
                        key: 'city',
                        editor: new Y.TextAreaCellEditor()
                    },
                    {
                        key: 'state',
                        editor: new Y.DropDownCellEditor({
                            editable: true,
                            options: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA']
                        })
                    },
                    'amount',
                    {
                        key:'active',
                        editor: new Y.RadioCellEditor({
                            editable: true,
                            options: {
                                yes: 'Yes',
                                no: 'No',
                                maybe: 'Maybe'
                            }
                        })
                    },
                    {
                        key:'colors',
                        editor: new Y.CheckboxCellEditor({
                            editable: true,
                            multiple: true,
                            options: {
                                red: 'Red',
                                green: 'Green',
                                blue: 'Blue'
                            }
                        })
                    },
                    {
                        key: 'fruit',
                        sortable: true,
                        editor: new Y.DropDownCellEditor({
                            editable: true,
                            multiple: true,
                            options: {
                                apple: 'Apple',
                                cherry: 'Cherry',
                                banana: 'Banana',
                                kiwi: 'Kiwi'
                            }
                        })
                    },
                    {
                        key: 'date',
                        sortable: true,
                        editor: new Y.DateCellEditor({
                            calendar: {
                                width:'400px',
                                showPrevMonth: true,
                                showNextMonth: true,
                                selectionMode: 'multiple'
                            }
                        })
                    }
                ],
                data: data,
                editEvent: 'dblclick',
                plugins: [
                    {
                        fn: Y.Plugin.DataTableHighlight
                    }
                ]
            }).render();
        },

        'navigate on arrow keys': function() {
            var dataTable = this._dataTable,
                activeCoords,
                boundingBox = dataTable.get('boundingBox'),
                cellCoords = {
                    topLeft: [0, 0],
                    topRight: [0, 1],
                    bottomLeft: [1, 0],
                    bottomRight: [1, 1]
                };

            dataTable.focus();
            dataTable.set('activeCoord', cellCoords.topLeft);
            dataTable.set('selection', cellCoords.topLeft);

            //simulate right arrow key press

            boundingBox.simulate('keydown', { keyCode: 39 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.topRight, activeCoords, 'Right arrow should have moved selection.');

            //simulate down arrow key press

            boundingBox.simulate('keydown', { keyCode: 40 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.bottomRight, activeCoords, 'Down arrow should have moved selection.');

            //simulate left arrow key press

            boundingBox.simulate('keydown', { keyCode: 37 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.bottomLeft, activeCoords, 'Left arrow should have moved selection.');

            //simulate up arrow key press

            boundingBox.simulate('keydown', { keyCode: 38 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.topLeft, activeCoords, 'Up arrow should have moved selection.');
        },

        'open editor on double click': function() {
            var dataTable = this._dataTable,
                firstCell = dataTable.getCell([0, 0]);

            firstCell.simulate('dblclick');

            var editorNode = Y.one('.basecelleditor');

            Y.Assert.isNotNull(editorNode, 'The editor should have been opened.');
        },

        'cancel cell editor': function() {
            var cell = this._dataTable.getCell([0, 0]),
                newVal = 'Testing editor node save.',
                originalVal = cell.html();

            cell.simulate('dblclick');

            var editorNode = Y.one('.basecelleditor'),
                cancelBtn = editorNode.all('button').item(1),
                textArea = editorNode.one('textarea');

            textArea.val(newVal);

            cancelBtn.focus().simulate('click');

            Y.Assert.areEqual(cell.html(), originalVal);
        },

        'save cell edit': function() {
            var cell = this._dataTable.getCell([0, 0]),
                newVal = 'Testing editor node save.';

            cell.simulate('dblclick');

            var editorNode = Y.one('.basecelleditor'),
                textArea = editorNode.one('textarea'),
                saveBtn = editorNode.all('button').item(0);

            textArea.val(newVal);

            saveBtn.focus().simulate('click');

            Y.Assert.areEqual(cell.html(), newVal);
        },

        'fields sorted on caret click': function() {
            var sortableHeader = Y.one('.table-sortable-column'),
                colId = sortableHeader.getData('yui3-col-id'),
                prevCellHtml,
                sortedCorrectly = true;

            sortableHeader.simulate('click');

            var sortBy = sortableHeader.get('aria-sort');

            Y.all('.table-cell.table-col-' + colId).each(
                function(item) {
                    if (prevCellHtml) {
                        if (sortBy === 'ascending') {
                            sortedCorrectly = prevCellHtml <= item.html();
                        }
                        else {
                            sortedCorrectly = prevCellHtml >= item.html();
                        }
                    }

                    prevCellHtml = item.html();
                }
            );

            Y.Assert.isTrue(sortedCorrectly, 'Items are not sorted correctly.');
        }
    }));

    Y.Test.Runner.add(suite);

}, '', {
    requires: ['aui-datatable', 'node', 'node-event-simulate', 'test']
});
<commit_msg>AUI-1288 - reduce a property lookup<commit_after>YUI.add('aui-datatable-tests', function(Y) {

    var suite = new Y.Test.Suite('aui-datatable');

    var data = [
        {
            active: 'no',
            address: '3271 Another Ave',
            amount: 3,
            city: 'New York',
            colors: ['red', 'blue'],
            date: '2013-01-01',
            fruit: ['apple'],
            name: 'Joan B. Jones',
            state: 'AL'
        },
        {
            active: 'maybe',
            address: '9996 Random Road',
            amount: 0,
            city: 'Los Angeles',
            colors: ['green'],
            date: '2013-01-01',
            fruit: ['cherry'],
            name: 'Bob C. Uncle',
            state: 'CA'
        },
        {
            active: 'yes',
            address: '1623 Some Street',
            amount: 5,
            city: 'San Francisco',
            colors: ['red'],
            date: '',
            fruit: ['cherry'],
            name: 'John D. Smith',
            state: 'CA'
        },
        {
            active: 'no',
            address: '3217 Another Ave',
            amount: 3,
            city: 'New York',
            colors: ['red', 'blue'],
            date: '2013-01-06',
            fruit: ['apple', 'cherry'],
            name: 'Joan E. Jones',
            state: 'KY'
        }
    ];

    new Y.DataTable({
        boundingBox: '#simple',
        columns: [
            {
                editor: new Y.TextAreaCellEditor({
                    on: {
                        cancel: function(event) {
                            console.log('cancel', event);
                        },
                        save: function(event) {
                            console.log('save', event.newVal);
                        }
                    },
                    validator: {
                        rules: {
                            value: {
                                required: true
                            }
                        }
                    }
                }),
                key: 'name',
                sortable: true
            },
            {
                editor: new Y.TextAreaCellEditor(),
                key: 'address'
            },
            {
                editor: new Y.TextAreaCellEditor(),
                key: 'city'
            },
            {
                editor: new Y.DropDownCellEditor({
                    editable: true,
                    options: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID',
                        'IL', 'IN', 'IA', 'KS', 'KY', 'LA']
                }),
                key: 'state'
            },
            'amount',
            {
                editor: new Y.RadioCellEditor({
                    editable: true,
                    options: {
                        yes: 'Yes',
                        no: 'No',
                        maybe: 'Maybe'
                    }
                }),
                key: 'active'
            },
            {
                editor: new Y.CheckboxCellEditor({
                    editable: true,
                    multiple: true,
                    options: {
                        red: 'Red',
                        green: 'Green',
                        blue: 'Blue'
                    }
                }),
                key: 'colors'
            },
            {
                editor: new Y.DropDownCellEditor({
                    editable: true,
                    multiple: true,
                    options: {
                        apple: 'Apple',
                        banana: 'Banana',
                        cherry: 'Cherry',
                        kiwi: 'Kiwi'
                    }
                }),
                key: 'fruit',
                sortable: true
            },
            {
                editor: new Y.DateCellEditor({
                    calendar: {
                        selectionMode: 'multiple',
                        showNextMonth: true,
                        showPrevMonth: true,
                        width: '400px'
                    }
                }),
                key: 'date',
                sortable: true
            }
        ],
        data: data,
        editEvent: 'dblclick',
        plugins: [
            {
                fn: Y.Plugin.DataTableHighlight
            }
        ]
    }).render();

    function assertHighlightPosition(tableData) {
        var lowerXLimit,
            lowerYLimit,
            overlayActiveBorderWidth,
            overlayActiveBottomWidth,
            overlayActiveChildren,
            overlayActiveLeftHeight,
            overlayActiveNode,
            overlayActiveRightHeight,
            overlayActiveTopWidth,
            overlaySelectionNode,
            tableDataHeight,
            tableDataWidth,
            upperXLimit,
            upperYLimit;

        overlayActiveNode = Y.one('.table-highlight-overlay-active');
        overlayActiveChildren = overlayActiveNode.get('children');
        overlaySelectionNode = overlayActiveNode ? overlayActiveNode.next('.table-highlight-overlay') : null;

        lowerXLimit = tableData.getX() >= (overlayActiveNode.getX() - 1);
        lowerYLimit = tableData.getY() >= (overlayActiveNode.getY() - 1);

        overlayActiveBorderWidth = overlayActiveChildren.item(0).get('offsetHeight');
        overlayActiveBottomWidth = overlayActiveChildren.item(2).get('offsetWidth');

        overlayActiveLeftHeight = overlayActiveChildren.item(3).get('offsetHeight') + overlayActiveBorderWidth;
        overlayActiveRightHeight = overlayActiveChildren.item(1).get('offsetHeight') + overlayActiveBorderWidth;

        overlayActiveTopWidth = overlayActiveChildren.item(0).get('offsetWidth');

        tableDataHeight = tableData.get('offsetHeight');
        tableDataWidth = tableData.get('offsetWidth');

        upperXLimit = tableData.getX() <= (overlayActiveNode.getX() + 1);
        upperYLimit = tableData.getY() <= (overlayActiveNode.getY() + 1);

        Y.Assert.isTrue(
            (lowerXLimit && upperXLimit),
            'X Position of 	 and highlight are not the similar.');

        Y.Assert.isTrue(
            (lowerYLimit && upperYLimit),
            'Y Position of 	 and highlight are not the similar.');

        Y.Assert.areSame(
            tableDataWidth,
            overlayActiveBottomWidth,
            'Hightlight bottom border width ' + overlayActiveBottomWidth + ' is not same width as table data ' +
            tableDataWidth + '.');

        Y.Assert.areSame(
            tableDataWidth,
            overlayActiveTopWidth,
            'Hightlight top border width ' + overlayActiveTopWidth + ' is not same width as table data ' +
            tableDataWidth + '.');

        Y.Assert.areSame(
            tableDataHeight,
            overlayActiveLeftHeight,
            'Hightlight left border height ' + overlayActiveLeftHeight + ' is not same height as table data ' +
            tableDataHeight + '.');

        Y.Assert.areSame(
            tableDataHeight,
            overlayActiveRightHeight,
            'Hightlight right border height ' + overlayActiveRightHeight + ' is not same height as table data ' +
            tableDataHeight + '.');
    }

    suite.add(new Y.Test.Case({
        name: 'Datatable Highlight',
        'table-cell should be highlighted on click': function() {
            var test = this,
                tableData;

            tableData = Y.one('tr.table-odd td.table-col-amount');

            tableData.once('mousedown', function(event) {
                setTimeout(function() {
                    test.resume(function() {
                        assertHighlightPosition(event.currentTarget);
                    });
                }, 800);
            });

            setTimeout(function() {
                tableData.simulate('mousedown');
                tableData.simulate('mouseup');
            }, 0);

            test.wait(1000);
        },

        'table-cell should still be highlighted when table is scrolled horizontally': function() {
            var test = this,
                datatableContainer,
                datatableContent,
                tableData;

            datatableContainer = Y.one('#simple');
            datatableContent = datatableContainer.one('.table-content');
            tableData = Y.one('tr.table-odd td.table-col-amount');

            datatableContainer.setStyle('width', '300px');
            datatableContent.setStyle('overflow', 'auto');

            tableData.once('mousedown', function(event) {
                setTimeout(function() {
                    test.resume(function() {
                        assertHighlightPosition(event.currentTarget);
                    });
                }, 800);
            });

            setTimeout(function() {
                tableData.simulate('mousedown');
                tableData.simulate('mouseup');
                datatableContent.set('scrollLeft', 200);
            }, 0);

            test.wait(1000);
        }
    }));

    suite.add(new Y.Test.Case({
        name: 'Datatable',

        init: function() {
            var data = [
                {
                    active: 'no',
                    address: '3271 Another Ave',
                    amount: 3,
                    city: 'New York',
                    colors: ['red','blue'],
                    date: '2013-01-01',
                    fruit: ['apple'],
                    name: 'Joan B. Jones',
                    state: 'AL'
                },
                {
                    active: 'maybe',
                    address: '9996 Random Road',
                    amount: 0,
                    city: 'Los Angeles',
                    colors: ['green'],
                    date: '2013-01-01',
                    fruit: ['cherry'],
                    name: 'Bob C. Uncle',
                    state: 'CA'
                },
                {
                    active: 'yes',
                    address: '1623 Some Street',
                    amount: 5,
                    city: 'San Francisco',
                    colors: ['red'],
                    date: '',
                    fruit: ['cherry'],
                    name: 'John D. Smith',
                    state: 'CA'
                },
                {
                    active: 'no',
                    address: '3217 Another Ave',
                    amount: 3,
                    city: 'New York',
                    colors: ['red','blue'],
                    date: '2013-01-06',
                    fruit: ['apple','cherry'],
                    name: 'Joan E. Jones',
                    state: 'KY'
                }
            ];

            this._dataTable = new Y.DataTable({
                cssClass: 'table-striped',
                boundingBox: '#datatable',
                columns: [
                    {
                        key: 'name',
                        sortable: true,
                        editor: new Y.TextAreaCellEditor({
                            on: {
                                save: function(event) {
                                    console.log('save', event.newVal);
                                },
                                cancel: function(event) {
                                    console.log('cancel', event);
                                }
                            },
                            validator: {
                                rules: {
                                    value: {
                                        required: true
                                    }
                                }
                            }
                        })
                    },
                    {
                        key: 'address',
                        editor: new Y.TextAreaCellEditor()
                    },
                    {
                        key: 'city',
                        editor: new Y.TextAreaCellEditor()
                    },
                    {
                        key: 'state',
                        editor: new Y.DropDownCellEditor({
                            editable: true,
                            options: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA']
                        })
                    },
                    'amount',
                    {
                        key:'active',
                        editor: new Y.RadioCellEditor({
                            editable: true,
                            options: {
                                yes: 'Yes',
                                no: 'No',
                                maybe: 'Maybe'
                            }
                        })
                    },
                    {
                        key:'colors',
                        editor: new Y.CheckboxCellEditor({
                            editable: true,
                            multiple: true,
                            options: {
                                red: 'Red',
                                green: 'Green',
                                blue: 'Blue'
                            }
                        })
                    },
                    {
                        key: 'fruit',
                        sortable: true,
                        editor: new Y.DropDownCellEditor({
                            editable: true,
                            multiple: true,
                            options: {
                                apple: 'Apple',
                                cherry: 'Cherry',
                                banana: 'Banana',
                                kiwi: 'Kiwi'
                            }
                        })
                    },
                    {
                        key: 'date',
                        sortable: true,
                        editor: new Y.DateCellEditor({
                            calendar: {
                                width:'400px',
                                showPrevMonth: true,
                                showNextMonth: true,
                                selectionMode: 'multiple'
                            }
                        })
                    }
                ],
                data: data,
                editEvent: 'dblclick',
                plugins: [
                    {
                        fn: Y.Plugin.DataTableHighlight
                    }
                ]
            }).render();
        },

        'navigate on arrow keys': function() {
            var dataTable = this._dataTable,
                activeCoords,
                boundingBox = dataTable.get('boundingBox'),
                cellCoords = {
                    topLeft: [0, 0],
                    topRight: [0, 1],
                    bottomLeft: [1, 0],
                    bottomRight: [1, 1]
                };

            dataTable.focus();
            dataTable.set('activeCoord', cellCoords.topLeft);
            dataTable.set('selection', cellCoords.topLeft);

            //simulate right arrow key press

            boundingBox.simulate('keydown', { keyCode: 39 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.topRight, activeCoords, 'Right arrow should have moved selection.');

            //simulate down arrow key press

            boundingBox.simulate('keydown', { keyCode: 40 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.bottomRight, activeCoords, 'Down arrow should have moved selection.');

            //simulate left arrow key press

            boundingBox.simulate('keydown', { keyCode: 37 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.bottomLeft, activeCoords, 'Left arrow should have moved selection.');

            //simulate up arrow key press

            boundingBox.simulate('keydown', { keyCode: 38 });
            activeCoords = dataTable.get('activeCoord');

            Y.ArrayAssert.itemsAreSame(cellCoords.topLeft, activeCoords, 'Up arrow should have moved selection.');
        },

        'open editor on double click': function() {
            var dataTable = this._dataTable,
                firstCell = dataTable.getCell([0, 0]);

            firstCell.simulate('dblclick');

            var editorNode = Y.one('.basecelleditor');

            Y.Assert.isNotNull(editorNode, 'The editor should have been opened.');
        },

        'cancel cell editor': function() {
            var cell = this._dataTable.getCell([0, 0]),
                newVal = 'Testing editor node save.',
                originalVal = cell.html();

            cell.simulate('dblclick');

            var editorNode = Y.one('.basecelleditor'),
                cancelBtn = editorNode.all('button').item(1),
                textArea = editorNode.one('textarea');

            textArea.val(newVal);

            cancelBtn.focus().simulate('click');

            Y.Assert.areEqual(cell.html(), originalVal);
        },

        'save cell edit': function() {
            var cell = this._dataTable.getCell([0, 0]),
                newVal = 'Testing editor node save.';

            cell.simulate('dblclick');

            var editorNode = Y.one('.basecelleditor'),
                textArea = editorNode.one('textarea'),
                saveBtn = editorNode.all('button').item(0);

            textArea.val(newVal);

            saveBtn.focus().simulate('click');

            Y.Assert.areEqual(cell.html(), newVal);
        },

        'fields sorted on caret click': function() {
            var sortableHeader = Y.one('.table-sortable-column'),
                colId = sortableHeader.getData('yui3-col-id'),
                prevCellHtml,
                sortedCorrectly = true;

            sortableHeader.simulate('click');

            var sortBy = sortableHeader.get('aria-sort');

            Y.all('.table-cell.table-col-' + colId).each(
                function(item) {
                    var html = item.html();

                    if (prevCellHtml) {
                        if (sortBy === 'ascending') {
                            sortedCorrectly = prevCellHtml <= html;
                        }
                        else {
                            sortedCorrectly = prevCellHtml >= html;
                        }
                    }

                    prevCellHtml = html;
                }
            );

            Y.Assert.isTrue(sortedCorrectly, 'Items are not sorted correctly.');
        }
    }));

    Y.Test.Runner.add(suite);

}, '', {
    requires: ['aui-datatable', 'node', 'node-event-simulate', 'test']
});
<|endoftext|>


<commit_before>// Description:
//   Youtube Feeds
//
// Dependencies:
//   None
//
// Configuration:
//   None
//
//// Commands:
//   hubot yf add <username>
//   hubot yf remove <username>
//   hubot yf list
//
// Author:
//   Eluinhost

var VideoFetcher = require('./lib/video-fetcher.js');
var LatestVideos = require('./lib/latest-videos.js');
var NotificationList = require('./lib/notification-list.js');

module.exports = function(robot) {

    var notificationList = new NotificationList(robot.brain, new LatestVideos(robot.brain, new VideoFetcher(robot)));

    var checkForUpdates = function() {
        notificationList.getNewNotifications().then(function(data) {
            data.forEach(
                /**
                 * @param {Object} element
                 * @param {string} element.username
                 * @param {string} element.channels
                 * @param {{id: string, link: string}[]} element.videos
                 */
                function success(element) {
                    element.videos.forEach(
                        /**
                         * @param {Object} video
                         * @param {string} video.id
                         * @param {string} video.link
                         */
                        function(video) {
                            element.channels.forEach(function(channel) {
                                robot.messageRoom(channel, element.username + ' has uploaded a video: ' + video.link);
                            });
                        }
                    );
                }
            );
        })
    };
    setInterval(checkForUpdates, 1024 * 60 * 5);

    robot.respond(/yf add (.*?)$/i, function(msg) {
        var name = msg.match[1];
        if(notificationList.addNotificationsFor(name, msg.message.room)) {
            msg.reply('Added notifications for: ' + name);
        } else {
            msg.reply(name + ' is already set for notifications in this channel');
        }
    });

    robot.respond(/yf remove (.*?)$/i, function(msg) {
        var name = msg.match[1];
        if(notificationList.removeNotificationsFor(name, msg.message.room)) {
            msg.reply('Removed notifications for: ' + name);
        } else {
            msg.reply(name + ' is not set for notifications in this channel');
        }
    });

    robot.respond(/yf list$/i, function(msg) {
        if(notificationList.notifications.length === 0) {
            msg.reply('No notifications are set for this channel');
            return;
        }
        var userList = notificationList.notifications.map(function(element) {
            return element.username;
        }).join(', ');

        msg.reply('Notifications for this channel: ' + userList);
    });
};<commit_msg>feat: check for updates on startup and add command for checking for updates<commit_after>// Description:
//   Youtube Feeds
//
// Dependencies:
//   None
//
// Configuration:
//   None
//
//// Commands:
//   hubot yf add <username>
//   hubot yf remove <username>
//   hubot yf list
//
// Author:
//   Eluinhost

var VideoFetcher = require('./lib/video-fetcher.js');
var LatestVideos = require('./lib/latest-videos.js');
var NotificationList = require('./lib/notification-list.js');

module.exports = function(robot) {

    var notificationList = new NotificationList(robot.brain, new LatestVideos(robot.brain, new VideoFetcher(robot)));

    var checkForUpdates = function() {
        notificationList.getNewNotifications().then(function(data) {
            data.forEach(
                /**
                 * @param {Object} element
                 * @param {string} element.username
                 * @param {string} element.channels
                 * @param {{id: string, link: string}[]} element.videos
                 */
                function success(element) {
                    element.videos.forEach(
                        /**
                         * @param {Object} video
                         * @param {string} video.id
                         * @param {string} video.link
                         */
                        function(video) {
                            element.channels.forEach(function(channel) {
                                robot.messageRoom(channel, element.username + ' has uploaded a video: ' + video.link);
                            });
                        }
                    );
                }
            );
        })
    };
    checkForUpdates();
    setInterval(checkForUpdates, 1024 * 60 * 5);

    robot.respond(/yf add (.*?)$/i, function(msg) {
        var name = msg.match[1];
        if(notificationList.addNotificationsFor(name, msg.message.room)) {
            msg.reply('Added notifications for: ' + name);
        } else {
            msg.reply(name + ' is already set for notifications in this channel');
        }
    });

    robot.respond(/yf remove (.*?)$/i, function(msg) {
        var name = msg.match[1];
        if(notificationList.removeNotificationsFor(name, msg.message.room)) {
            msg.reply('Removed notifications for: ' + name);
        } else {
            msg.reply(name + ' is not set for notifications in this channel');
        }
    });

    robot.respond(/yf list$/i, function(msg) {
        if(notificationList.notifications.length === 0) {
            msg.reply('No notifications are set for this channel');
            return;
        }
        var userList = notificationList.notifications.map(function(element) {
            return element.username;
        }).join(', ');

        msg.reply('Notifications for this channel: ' + userList);
    });

    robot.respond(/yf check$/i, function(msg) {
        checkForUpdates();
    });
};<|endoftext|>


<commit_before>/*
  Handles alerts shown to the user.
*/
(function() {
  'use strict';

  angular
    .module('vtPortal')
    .factory('AlertService', AlertService);

  AlertService.$inject = ['$rootScope', '$timeout'];

  function AlertService($rootScope, $timeout) {
    var service = {};

    service.success = success;
    service.menuSuccess = menuSuccess;
    service.error = error;
    service.menuError = menuError;
    service.clearAlertMessage = clearAlertMessage;
    service.clearMenuAlertMessage = clearMenuAlertMessage;
    service.clearAlertMessageAndDigest = clearAlertMessageAndDigest;
    service.clearMenuAlertMessageAndDigest = clearMenuAlertMessageAndDigest;

    return service;

    function clearAlertMessage() {
      var alert = $rootScope.alert;
      if (alert) {
        delete $rootScope.alert;
      }
    }

    function clearAlertMessageAndDigest() {
      var alert = $rootScope.alert;
      if (alert) {
        $rootScope.$apply(function() {
          clearAlertMessage();
        });
      }
    }

    function success(message, heading, timeout) {
      var timeoutValue = 4000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.alert = {
        message: message,
        heading: heading,
        type: 'success'
      };

      $timeout(clearAlertMessage, timeoutValue);
    }

    function error(message, heading, timeout) { // jshint ignore:line
      var timeoutValue = 10000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.alert = {
        message: message,
        heading: heading,
        type: 'error'
      };

      $timeout(clearAlertMessage, timeoutValue);
    }

    function clearMenuAlertMessage() {
      var menuAlert = $rootScope.menuAlert;
      if (menuAlert) {
        delete $rootScope.menuAlert;
      }
    }

    function clearMenuAlertMessageAndDigest() {
      var menuAlert = $rootScope.menuAlert;
      if (menuAlert) {
        $rootScope.$apply(function() {
          clearMenuAlertMessage();
        });
      }
    }

    function menuSuccess(message, heading, timeout) {
      var timeoutValue = 4000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.menuAlert = {
        message: message,
        heading: heading,
        type: 'success'
      };

      $timeout(clearMenuAlertMessage, timeoutValue);
    }

    function menuError(message, heading, timeout) { // jshint ignore:line
      var timeoutValue = 10000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.menuAlert = {
        message: message,
        heading: heading,
        type: 'error'
      };

      $timeout(clearMenuAlertMessage, timeoutValue);
    }

  }

})();
<commit_msg>Added better way of displaying a "please login again" message. Useful for new community forum if the users session expires<commit_after>/*
  Handles alerts shown to the user.
*/
(function() {
  'use strict';

  angular
    .module('vtPortal')
    .factory('AlertService', AlertService);

  AlertService.$inject = ['$rootScope', '$timeout'];

  function AlertService($rootScope, $timeout) {
    var service = {};

    service.success = success;
    service.menuSuccess = menuSuccess;
    service.error = error;
    service.errorWithStatus = errorWithStatus;
    service.menuError = menuError;
    service.clearAlertMessage = clearAlertMessage;
    service.clearMenuAlertMessage = clearMenuAlertMessage;
    service.clearAlertMessageAndDigest = clearAlertMessageAndDigest;
    service.clearMenuAlertMessageAndDigest = clearMenuAlertMessageAndDigest;

    return service;

    function clearAlertMessage() {
      var alert = $rootScope.alert;
      if (alert) {
        delete $rootScope.alert;
      }
    }

    function clearAlertMessageAndDigest() {
      var alert = $rootScope.alert;
      if (alert) {
        $rootScope.$apply(function() {
          clearAlertMessage();
        });
      }
    }

    function success(message, heading, timeout) {
      var timeoutValue = 4000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.alert = {
        message: message,
        heading: heading,
        type: 'success'
      };

      $timeout(clearAlertMessage, timeoutValue);
    }

    function errorWithStatus(status, message, heading, timeout) {

      // Handle 401 errors with better error message
      if (status != null && status === 401) {
        message = message + '. Var vänlig logga in igen';
      }

      error(message, heading, timeout);

    }

    function error(message, heading, timeout) { // jshint ignore:line
      var timeoutValue = 10000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.alert = {
        message: message,
        heading: heading,
        type: 'error'
      };

      $timeout(clearAlertMessage, timeoutValue);
    }

    function clearMenuAlertMessage() {
      var menuAlert = $rootScope.menuAlert;
      if (menuAlert) {
        delete $rootScope.menuAlert;
      }
    }

    function clearMenuAlertMessageAndDigest() {
      var menuAlert = $rootScope.menuAlert;
      if (menuAlert) {
        $rootScope.$apply(function() {
          clearMenuAlertMessage();
        });
      }
    }

    function menuSuccess(message, heading, timeout) {
      var timeoutValue = 4000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.menuAlert = {
        message: message,
        heading: heading,
        type: 'success'
      };

      $timeout(clearMenuAlertMessage, timeoutValue);
    }

    function menuError(message, heading, timeout) { // jshint ignore:line
      var timeoutValue = 10000;
      if (timeout != null) { // jshint ignore:line
        timeoutValue = timeout;
      }

      $rootScope.menuAlert = {
        message: message,
        heading: heading,
        type: 'error'
      };

      $timeout(clearMenuAlertMessage, timeoutValue);
    }

  }

})();
<|endoftext|>