mention-input.ctrl.js 1.75 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
commonModule.controller('mentionInputController', ['$scope', '$q', '$log', '$interval', '$timeout', '$translate',
    function ($scope, $q, $log, $interval, $timeout, $translate) {
        'use strict';

        $log.debug('mentionInputController.ctor()...');

        var searchKeyValue = function (term) {
            var searchedList = [];
            if (!_.isEmpty($scope.keyValueList)) {
                searchedList = _.filter($scope.keyValueList, function (tag) {
                    return tag
                        && (tag.code.toUpperCase().indexOf(term.toUpperCase()) >= 0
                        || $scope.showName && tag.name && tag.name.toUpperCase().indexOf(term.toUpperCase()) >= 0);
                });
            }

            $scope.searchedKeyValueList = searchedList;
            return $q.when(searchedList);
        };

        var searchFormula = function (term) {
            var searchedList = [];
            if (!_.isEmpty($scope.formulaList)) {
                searchedList = _.filter($scope.formulaList, function (tag) {
                    return tag && tag.code.toUpperCase().indexOf(term.toUpperCase()) >= 0;
                });
            }

            $scope.searchedFormulaList = searchedList;
            return $q.when(searchedList);
        };

        (function initialize() {
            $log.debug('mentionInputController.initialize()...');

            // keyValueList is the list of all candidate mention items, searchedKeyValueList is the list filtered by 
            $scope.searchedKeyValueList = angular.copy($scope.keyValueList);
            $scope.searchKeyValue = searchKeyValue;
            $scope.searchedFormulaList = angular.copy($scope.formulaList);
            $scope.searchFormula = searchFormula;
        })();
    }
]);