Created
May 20, 2014 15:57
-
-
Save coderberry/63dd66f860608e87e023 to your computer and use it in GitHub Desktop.
partners_ctrl.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = angular.module('app', []); | |
| app.controller('PartnersCtrl', ['$scope', function($scope) { | |
| $scope.partnerLevels = window.ENV['PARTNER_LEVELS']; | |
| $scope.partners = window.ENV['PARTNERS']; | |
| $scope.partnerTypes = window.ENV['PARTNER_TYPES']; | |
| $scope.markets = window.ENV['MARKETS']; | |
| $scope.solutionCategories = window.ENV['SOLUTION_CATEGORIES']; | |
| $scope.currentPartnerType = null; | |
| $scope.currentMarket = null; | |
| $scope.currentSolutionCategory = null; | |
| $scope.filterText = ''; | |
| $scope.partersForPartnerLevel = function(partnerLevel) { | |
| var partners = _.filter($scope.partners, function(partner) { | |
| return (partner.partner_level == partnerLevel.id); | |
| }); | |
| return partners; | |
| }; | |
| $scope.hasFilters = function() { | |
| return ( | |
| ($scope.currentPartnerType != null) || | |
| ($scope.currentMarket != null) || | |
| ($scope.currentSolutionCategory != null) || | |
| ($scope.filterText != '') | |
| ); | |
| } | |
| $scope.resetFilters = function() { | |
| $scope.currentPartnerType = null; | |
| $scope.currentMarket = null; | |
| $scope.currentSolutionCategory = null; | |
| $scope.filterText = ''; | |
| }; | |
| $scope.selectPartnerType = function(partnerType) { | |
| if (partnerType === undefined) { | |
| $scope.currentPartnerType = null; | |
| } else { | |
| $scope.currentPartnerType = partnerType; | |
| } | |
| Foundation.libs.dropdown.closeall(); | |
| }; | |
| $scope.selectMarket = function(market) { | |
| if (market === undefined) { | |
| $scope.currentMarket = null; | |
| } else { | |
| $scope.currentMarket = market; | |
| } | |
| Foundation.libs.dropdown.closeall(); | |
| }; | |
| $scope.selectSolutionCategory = function(solutionCategory) { | |
| if (solutionCategory === undefined) { | |
| $scope.currentSolutionCategory = null; | |
| } else { | |
| $scope.currentSolutionCategory = solutionCategory; | |
| } | |
| Foundation.libs.dropdown.closeall(); | |
| }; | |
| $scope.customCriteriaFilter = function(partner) { | |
| if ($scope.hasFilters()) { | |
| var matches = []; | |
| if ($scope.filterText.length > 0) { | |
| console.log(partner.name); | |
| if (partner.name.match(new RegExp($scope.filterText, 'gi'))) { | |
| matches.push(true); | |
| } else { | |
| matches.push(false); | |
| } | |
| } | |
| // partner type | |
| if ($scope.currentPartnerType != null) { | |
| if (partner.partner_type == $scope.currentPartnerType.id) { | |
| matches.push(true); | |
| } else { | |
| matches.push(false); | |
| } | |
| } | |
| // solution category | |
| if ($scope.currentSolutionCategory != null) { | |
| if (_.contains(partner.solution_category_ids, $scope.currentSolutionCategory.id)) { | |
| matches.push(true); | |
| } else { | |
| matches.push(false); | |
| } | |
| } | |
| // markets | |
| if ($scope.currentMarket != null) { | |
| if (_.contains(partner.market_ids, $scope.currentMarket.id)) { | |
| matches.push(true); | |
| } else { | |
| matches.push(false); | |
| } | |
| } | |
| if (!_.contains(matches, false)) { | |
| return partner; | |
| } else { | |
| return false; | |
| } | |
| } else { | |
| return partner; | |
| } | |
| }; | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment