forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitselect.js
More file actions
50 lines (43 loc) · 1.51 KB
/
unitselect.js
File metadata and controls
50 lines (43 loc) · 1.51 KB
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
44
45
46
47
48
49
50
gg.directive('unitselect', [function() {
return {
restrict: 'E',
transclude: true,
replace: true,
scope: {
selected: '=name',
race: '=race'
},
link: function(scope, element, attrs) {
scope.$watch('units', function(units) {
if (units.length > 0) {
scope.select = $(element).select2({
placeholder: 'unit',
allowClear: true,
containerCssClass: 's2units'
});
scope.$watch('selected', function(v) {
if(v) {
// console.log("Hi DJ!", $(element).children('.s2units'));
$(element).parent().children('.s2units').select2('val', scope.selected);
}
});
}
});
scope.$watch('race', function(race) {
// console.log("race!", race, scope.race);
if (_.isUndefined(race) || _.isNull(race) || race == '') {
scope.units = _.keys(Sc2.armyUnits['HotS']);
} else {
raceunits = _.filter(_.pairs(Sc2.armyUnits['HotS']), function(unit) { return unit[1][4] == race });
scope.units = _.map(raceunits, function(unit) { return unit[0] });
}
});
scope.units = _.keys(Sc2.armyUnits['HotS']);
},
template:
'<select ng-model="selected">' +
'<option></option>' +
'<option ng-repeat="unit in units" value="{{ unit }}" ng-selected="(selected == unit)">{{ unit }}</option>' +
'</select>'
}
}]);