more select bug fixes

This commit is contained in:
Colin McLeod
2015-05-04 21:21:16 -07:00
parent c24ac043ac
commit 90cd35bfc3
2 changed files with 8 additions and 6 deletions

View File

@@ -2,13 +2,13 @@ angular.module('app').directive('componentSelect', function() {
// Generting the HTML in this manner is MUCH faster than using an angular template. // Generting the HTML in this manner is MUCH faster than using an angular template.
function appendGroup(list, opts, cid, mass) { function appendGroup(list, opts, cid, mass, wrap) {
var prevClass = null, prevRating = null; var prevClass = null, prevRating = null;
for (var i = 0; i < opts.length; i++) { for (var i = 0; i < opts.length; i++) {
var o = opts[i]; var o = opts[i];
var id = o.id || (o.class + o.rating); // Common components' ID is their class and rating var id = o.id || (o.class + o.rating); // Common components' ID is their class and rating
list.push('<li class="', o.name? 'lc' : 'c'); list.push('<li class="', o.name? 'lc' : 'c');
if(o.class != prevClass && o.rating != prevRating) list.push(' cl'); if(wrap && o.class != prevClass) list.push(' cl');
if (cid == o.id) list.push(' active'); if (cid == o.id) list.push(' active');
list.push((o.maxmass && mass > o.maxmass)? ' disabled"' : '" cpid="', id, '">', o.class, o.rating); list.push((o.maxmass && mass > o.maxmass)? ' disabled"' : '" cpid="', id, '">', o.class, o.rating);
if(o.mode) { if(o.mode) {
@@ -30,7 +30,8 @@ angular.module('app').directive('componentSelect', function() {
opts: '=', // Component Options object opts: '=', // Component Options object
groups: '=', // Groups of Component Options groups: '=', // Groups of Component Options
mass: '=', // Current ship unladen mass mass: '=', // Current ship unladen mass
s: '=' // Current Slot s: '=', // Current Slot
wrap: '@' // Wrap on class
}, },
link: function(scope, element) { link: function(scope, element) {
var list = []; var list = [];
@@ -39,6 +40,7 @@ angular.module('app').directive('componentSelect', function() {
var opts = scope.opts; var opts = scope.opts;
var groups = scope.groups; var groups = scope.groups;
var mass = scope.mass || 0; var mass = scope.mass || 0;
var wrap = scope.wrap;
if(groups) { if(groups) {
// At present time slots with grouped options (Hardpoints and Internal) can be empty // At present time slots with grouped options (Hardpoints and Internal) can be empty
@@ -47,12 +49,12 @@ angular.module('app').directive('componentSelect', function() {
var grp = groups[g]; var grp = groups[g];
var grpCode = grp[Object.keys(grp)[0]].grp; // Nasty operation to get the grp property of the first/any single component var grpCode = grp[Object.keys(grp)[0]].grp; // Nasty operation to get the grp property of the first/any single component
list.push('<div id="', grpCode ,'" class="select-group">', g, '</div><ul>'); list.push('<div id="', grpCode ,'" class="select-group">', g, '</div><ul>');
appendGroup(list, grp, cid, mass); appendGroup(list, grp, cid, mass, wrap);
list.push('</ul>'); list.push('</ul>');
} }
} else { } else {
list.push('<ul>'); list.push('<ul>');
appendGroup(list, opts, cid, mass); appendGroup(list, opts, cid, mass, wrap);
list.push('</ul>'); list.push('</ul>');
} }

View File

@@ -49,7 +49,7 @@
<div class="l">Max: {{th.c.maxmass}} <u>T</u></div> <div class="l">Max: {{th.c.maxmass}} <u>T</u></div>
<div class="r">{{th.c.mass}} <u>T</u></div> <div class="r">{{th.c.mass}} <u>T</u></div>
</div> </div>
<div component-select class="select" s="th" mass="ship.unladenMass" opts="availCS.common[1]" ng-if="selectedSlot==th" ng-click="select('c',th,$event)"></div> <div component-select class="select" s="th" mass="ship.unladenMass" wrap="true" opts="availCS.common[1]" ng-if="selectedSlot==th" ng-click="select('c',th,$event)"></div>
</div> </div>
<div class="slot" ng-click="selectSlot($event, fsd)" ng-class="{selected: selectedSlot==fsd}"> <div class="slot" ng-click="selectSlot($event, fsd)" ng-class="{selected: selectedSlot==fsd}">
<div class="details"> <div class="details">