Last active
August 29, 2015 13:56
-
-
Save shawn-simon/9282648 to your computer and use it in GitHub Desktop.
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
.controller('ComparisonCtrl', ['$scope', '$rootScope', function($scope, $rootScope) { | |
var get_content_value_set = function() | |
{ | |
return $scope.events[$scope.event.key].segments[$scope.segment_index].conditions[$scope.condition.key].content_value_set; | |
} | |
var clear_empty_sets = function() | |
{ | |
if (find_comparison_set_by_value('').set != null) | |
{ | |
$scope.events[$scope.event.key].segments[$scope.segment_index].conditions[$scope.condition.key].content_value_set = []; | |
} | |
} | |
var find_comparison_set_by_value = function(value) | |
{ | |
var index = -1; | |
var found_set = null; | |
$.each(get_content_value_set(), function(i, set) | |
{ | |
if (set[0] == value) { | |
found_set = set; | |
index = i; | |
} | |
}); | |
return {index: index, set: found_set}; | |
} | |
clear_empty_sets(); | |
var set_result = find_comparison_set_by_value($scope.comparsion_value.id) | |
$scope.comparison_checked = set_result.set != null; | |
$scope.get_set_index = function() { | |
return find_comparison_set_by_value($scope.comparsion_value.id).index; | |
} | |
$scope.$on('update_index_needed', function() { | |
$scope.set_index = $scope.get_set_index(); | |
}) | |
$scope.comparison_check_changed = function() { | |
if ($scope.comparison_checked) | |
{ | |
var current_length = get_content_value_set().length; | |
$scope.set_index = current_length; | |
get_content_value_set().push([$scope.comparsion_value.id,'','']) | |
} | |
else | |
{ | |
var set_result = find_comparison_set_by_value($scope.comparsion_value.id); | |
if (set_result.set != null) | |
{ | |
get_content_value_set().splice(set_result.index, 1) | |
$rootScope.$broadcast('update_index_needed') | |
} | |
} | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment