UNPKG

pip-webui

Version:

HTML5 UI for LOB applications

63 lines (53 loc) 2.37 kB
/** * @file Dropdown control * @copyright Digital Living Software Corp. 2014-2016 * */ /* global _, angular */ (function () { 'use strict'; var thisModule = angular.module("pipDropdown", ['pipAssert', 'pipNav.Templates']); thisModule.directive('pipDropdown', function ($mdMedia, pipAssert) { return { restrict: 'E', scope: { ngDisabled: '&', actions: '=pipActions', showDropdown: '&pipShow', activeIndex: '=pipActiveIndex', select: '=pipDropdownSelect' }, templateUrl: 'dropdown/dropdown.html', controller: function ($scope, $element, $attrs, localStorageService) { $scope.class = ($attrs.class || '') + ' md-' + localStorageService.get('theme') + '-theme'; pipAssert.isArray($scope.actions, 'pipDropdown: pip-actions attribute should take an array, but take ' + typeof $scope.actions); $scope.$mdMedia = $mdMedia; $scope.actions = ($scope.actions && _.isArray($scope.actions)) ? $scope.actions : []; $scope.activeIndex = $scope.activeIndex || 0; $scope.disabled = function () { if ($scope.ngDisabled()) { return $scope.ngDisabled(); } else { return false; } }; $scope.onSelect = function (index) { $scope.activeIndex = index; if ($scope.select) { $scope.select($scope.actions[index], $scope.activeIndex); } }; $scope.show = function () { if ($scope.showDropdown()) { return $scope.showDropdown(); } else { return true; } }; } }; } ); })();