diff --git a/platform/features/clock/src/controllers/ClockController.js b/platform/features/clock/src/controllers/ClockController.js index 02b32cfc4f..3c7dc7b216 100644 --- a/platform/features/clock/src/controllers/ClockController.js +++ b/platform/features/clock/src/controllers/ClockController.js @@ -67,7 +67,7 @@ define([ timeFormat = self.use24 ? baseFormat.replace('hh', "HH") : baseFormat; // If wrong timezone is provided, the UTC will be used - zoneName = momentTimezone.tz.names().includes(model.timezone) ? + zoneName = momentTimezone.tz.names().includes(model.timezone) ? model.timezone : "UTC"; update(); } diff --git a/platform/forms/src/controllers/AutocompleteController.js b/platform/forms/src/controllers/AutocompleteController.js index efba33b742..46423ba728 100644 --- a/platform/forms/src/controllers/AutocompleteController.js +++ b/platform/forms/src/controllers/AutocompleteController.js @@ -39,18 +39,24 @@ define( }, autocompleteInputElement = $element[0].getElementsByClassName('autocompleteInput')[0]; - if($scope.options[0].name) { + if ($scope.options[0].name) { // If "options" include name, value pair - $scope.optionNames = $scope.options.map(function(opt) { + $scope.optionNames = $scope.options.map(function (opt) { return opt.name; - }) + }); } else { // If options is only an array of string. $scope.optionNames = $scope.options; } + function fillInputWithIndexedOption() { + if ($scope.filteredOptions[$scope.optionIndex]) { + $scope.ngModel[$scope.field] = $scope.filteredOptions[$scope.optionIndex].name; + } + } + function decrementOptionIndex() { - if($scope.optionIndex === 0) { + if ($scope.optionIndex === 0) { $scope.optionIndex = $scope.filteredOptions.length; } $scope.optionIndex--; @@ -58,7 +64,7 @@ define( } function incrementOptionIndex() { - if($scope.optionIndex === $scope.filteredOptions.length-1) { + if ($scope.optionIndex === $scope.filteredOptions.length - 1) { $scope.optionIndex = -1; } $scope.optionIndex++; @@ -70,22 +76,16 @@ define( $scope.ngModel[$scope.field] = string; } - function fillInputWithIndexedOption() { - if($scope.filteredOptions[$scope.optionIndex]) { - $scope.ngModel[$scope.field] = $scope.filteredOptions[$scope.optionIndex].name; - } - } - function showOptions(string) { $scope.hideOptions = false; $scope.filterOptions(string); $scope.optionIndex = 0; } - $scope.keyDown = function($event) { - if($scope.filteredOptions) { + $scope.keyDown = function ($event) { + if ($scope.filteredOptions) { var keyCode = $event.keyCode; - switch(keyCode) { + switch (keyCode) { case key.down: incrementOptionIndex(); break; @@ -94,45 +94,45 @@ define( decrementOptionIndex(); break; case key.enter: - if($scope.filteredOptions[$scope.optionIndex]) { + if ($scope.filteredOptions[$scope.optionIndex]) { fillInputWithString($scope.filteredOptions[$scope.optionIndex].name); } } } - } + }; - $scope.filterOptions = function(string) { + $scope.filterOptions = function (string) { $scope.hideOptions = false; - $scope.filteredOptions = $scope.optionNames.filter(function(option) { + $scope.filteredOptions = $scope.optionNames.filter(function (option) { return option.toLowerCase().indexOf(string.toLowerCase()) >= 0; - }).map(function(option, index) { + }).map(function (option, index) { return { optionId: index, name: option - } + }; }); - } + }; - $scope.inputClicked = function() { + $scope.inputClicked = function () { autocompleteInputElement.select(); showOptions(autocompleteInputElement.value); - } + }; - $scope.arrowClicked = function() { + $scope.arrowClicked = function () { autocompleteInputElement.select(); showOptions(''); - } - - $scope.fillInput = function(string) { - fillInputWithString(string); - } + }; - $scope.optionMouseover = function(optionId) { + $scope.fillInput = function (string) { + fillInputWithString(string); + }; + + $scope.optionMouseover = function (optionId) { $scope.optionIndex = optionId; - } + }; } return AutocompleteController; } -); \ No newline at end of file +); diff --git a/platform/forms/test/controllers/AutocompleteControllerSpec.js b/platform/forms/test/controllers/AutocompleteControllerSpec.js index 7de87a2b6d..4c884fe116 100644 --- a/platform/forms/test/controllers/AutocompleteControllerSpec.js +++ b/platform/forms/test/controllers/AutocompleteControllerSpec.js @@ -41,18 +41,18 @@ define( it("filters options by returning array containing optionId and name", function () { mockScope.filterOptions('Asia'); - var filteredOptions = [ { optionId : 0, name : 'Asia/Dhaka' }, - { optionId : 1, name : 'Asia/Shanghai' } ]; + var filteredOptions = [{ optionId : 0, name : 'Asia/Dhaka' }, + { optionId : 1, name : 'Asia/Shanghai' }]; expect(mockScope.filteredOptions).toEqual(filteredOptions); }); - + it("fills input with given string", function () { var str = "UTC"; mockScope.fillInput(str); expect(mockScope.hideOptions).toEqual(true); expect(mockScope.ngModel[4]).toEqual(str); }); - + it("sets a new optionIndex on mouse hover", function () { mockScope.optionMouseover(1); expect(mockScope.optionIndex).toEqual(1);