nicer all/none buttons
This commit is contained in:
parent
c4c5e1d0d8
commit
a117c78a98
3 changed files with 44 additions and 11 deletions
|
@ -2323,7 +2323,8 @@ and it won't be important on password protected instances */
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
.setDesc,
|
.setDesc,
|
||||||
.selectAll {
|
.selectAll,
|
||||||
|
.selectNone {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
font-family: 'din-medium', helvetica, sans-serif;
|
font-family: 'din-medium', helvetica, sans-serif;
|
||||||
color: #424242;
|
color: #424242;
|
||||||
|
@ -2333,9 +2334,15 @@ and it won't be important on password protected instances */
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.selectAll {
|
.selectAll,
|
||||||
|
.selectNone {
|
||||||
float: right;
|
float: right;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&.selected {
|
||||||
|
color: #00bcd4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
& > ul {
|
& > ul {
|
||||||
|
|
|
@ -92,7 +92,8 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<div id="metacodeSwitchTabsCustom">
|
<div id="metacodeSwitchTabsCustom">
|
||||||
<div class="setDesc">Choose Your Metacodes</div>
|
<div class="setDesc">Choose Your Metacodes</div>
|
||||||
<div class="selectAll">Select all</div> <%# hidden by default %>
|
<div class="selectNone">NONE</div>
|
||||||
|
<div class="selectAll">ALL</div>
|
||||||
<% @list = '' %>
|
<% @list = '' %>
|
||||||
<% metacodesInUse = user_metacodes() %>
|
<% metacodesInUse = user_metacodes() %>
|
||||||
<% Metacode.order("name").all.each_with_index do |m, index| %>
|
<% Metacode.order("name").all.each_with_index do |m, index| %>
|
||||||
|
|
|
@ -28,7 +28,8 @@ const Create = {
|
||||||
}).addClass('ui-tabs-vertical ui-helper-clearfix')
|
}).addClass('ui-tabs-vertical ui-helper-clearfix')
|
||||||
$('#metacodeSwitchTabs .ui-tabs-nav li').removeClass('ui-corner-top').addClass('ui-corner-left')
|
$('#metacodeSwitchTabs .ui-tabs-nav li').removeClass('ui-corner-top').addClass('ui-corner-left')
|
||||||
$('.customMetacodeList li').click(self.toggleMetacodeSelected) // within the custom metacode set tab
|
$('.customMetacodeList li').click(self.toggleMetacodeSelected) // within the custom metacode set tab
|
||||||
$('.selectAll').click(self.metacodeSelectorToggleSelectAll)
|
$('.selectAll').click(self.metacodeSelectorSelectAll)
|
||||||
|
$('.selectNone').click(self.metacodeSelectorSelectNone)
|
||||||
},
|
},
|
||||||
toggleMetacodeSelected: function() {
|
toggleMetacodeSelected: function() {
|
||||||
var self = Create
|
var self = Create
|
||||||
|
@ -44,6 +45,33 @@ const Create = {
|
||||||
self.newSelectedMetacodes.push($(this).attr('id'))
|
self.newSelectedMetacodes.push($(this).attr('id'))
|
||||||
self.newSelectedMetacodeNames.push($(this).attr('data-name'))
|
self.newSelectedMetacodeNames.push($(this).attr('data-name'))
|
||||||
}
|
}
|
||||||
|
self.updateSelectAllColors()
|
||||||
|
},
|
||||||
|
updateSelectAllColors: function() {
|
||||||
|
$('.selectAll, .selectNone').removeClass('selected')
|
||||||
|
if (Create.metacodeSelectorAreAllSelected()) {
|
||||||
|
$('.selectAll').addClass('selected')
|
||||||
|
} else if (Create.metacodeSelectorAreNoneSelected()) {
|
||||||
|
$('.selectNone').addClass('selected')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
metacodeSelectorSelectAll: function() {
|
||||||
|
$('.customMetacodeList li.toggledOff').each(Create.toggleMetacodeSelected)
|
||||||
|
Create.updateSelectAllColors()
|
||||||
|
},
|
||||||
|
metacodeSelectorSelectNone: function() {
|
||||||
|
$('.customMetacodeList li').not('.toggledOff').each(Create.toggleMetacodeSelected)
|
||||||
|
Create.updateSelectAllColors()
|
||||||
|
},
|
||||||
|
metacodeSelectorAreAllSelected: function() {
|
||||||
|
return $('.customMetacodeList li').toArray()
|
||||||
|
.map(li => !$(li).is('.toggledOff')) // note the ! on this line
|
||||||
|
.reduce((curr, prev) => curr && prev)
|
||||||
|
},
|
||||||
|
metacodeSelectorAreNoneSelected: function() {
|
||||||
|
return $('.customMetacodeList li').toArray()
|
||||||
|
.map(li => $(li).is('.toggledOff'))
|
||||||
|
.reduce((curr, prev) => curr && prev)
|
||||||
},
|
},
|
||||||
metacodeSelectorToggleSelectAll: function() {
|
metacodeSelectorToggleSelectAll: function() {
|
||||||
// should be called when Create.isSwitchingSet is true and .customMetacodeList is visible
|
// should be called when Create.isSwitchingSet is true and .customMetacodeList is visible
|
||||||
|
@ -51,14 +79,11 @@ const Create = {
|
||||||
if (!$('.customMetacodeList').is(':visible')) return
|
if (!$('.customMetacodeList').is(':visible')) return
|
||||||
|
|
||||||
// If all are selected, then select none. Otherwise, select all.
|
// If all are selected, then select none. Otherwise, select all.
|
||||||
const anyToggledOff = $('.customMetacodeList li').toArray()
|
if (Create.metacodeSelectorAreAllSelected()) {
|
||||||
.map(li => $(li).is('.toggledOff'))
|
Create.metacodeSelectorSelectNone()
|
||||||
.reduce((curr, prev) => curr || prev)
|
|
||||||
if (anyToggledOff) {
|
|
||||||
$('.customMetacodeList li.toggledOff').each(Create.toggleMetacodeSelected)
|
|
||||||
} else {
|
} else {
|
||||||
// this should be every single one
|
// if some, but not all, are selected, it still runs this function
|
||||||
$('.customMetacodeList li').not('.toggledOff').each(Create.toggleMetacodeSelected)
|
Create.metacodeSelectorSelectAll()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateMetacodeSet: function(set, index, custom) {
|
updateMetacodeSet: function(set, index, custom) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue