Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | 2x 2x 2x 2x 2x 48x 48x 48x 48x 48x 48x 48x 48x 2x 6x 6x 6x 26x 26x 26x 26x 24x 2x 24x 2x 138x 138x 138x 2x 4x 2x 2x 2x 138x 140x 140x 140x 4x 4x 8x 8x 8x 8x 8x 24x 24x 24x 24x 24x 24x 24x 10x 8x 132x 132x 132x 54x 84x 84x 84x 36x 48x 48x 48x 48x 48x 48x 20x 20x 20x 20x 20x 28x 48x 48x 48x 48x 48x 538x 48x 538x | /**
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {List} from '../../../coral-component-list';
import {SelectableCollection} from '../../../coral-collection';
import orgSwitcher from '../templates/orgSwitcher';
import {commons, i18n} from '../../../coral-utils';
const CLASSNAME = '_coral-Shell-orgSwitcher';
/**
Minimum number of entries required to show search control.
@type {Number}
@ignore
*/
const SEARCH_VISIBILITY_THRESHOLD = 6;
/**
@class Coral.Shell.OrgSwitcher
@classdesc A Shell OrgSwitcher component
@htmltag coral-shell-orgswitcher
@extends {List}
*/
class ShellOrgSwitcher extends List {
/** @ignore */
constructor() {
super();
// Events
this._delegateEvents({
'coral-search:clear': '_showAll',
'coral-search:input': '_performSearch',
'coral-search:submit': '_selectFirst',
'coral-shell-organization:change': '_onOrganizationChange',
// private
'coral-shell-organization:_selectedchanged': '_onItemSelectedChanged',
'coral-shell-suborganization:_selectedchanged': '_onSubItemSelectedChanged'
});
// Templates
this._elements = {
footer: this.querySelector('coral-shell-orgswitcher-footer') || document.createElement('coral-shell-orgswitcher-footer')
};
orgSwitcher.call(this._elements, {commons, i18n});
// Used for eventing
this._oldSelection = null;
// Item handling
this.items._startHandlingItems(true);
}
/**
The item collection.
@type {SelectableCollection}
@readonly
*/
get items() {
// Construct the collection on first request:
if (!this._items) {
this._items = new SelectableCollection({
host: this,
itemTagName: 'coral-shell-organization',
itemSelector: 'coral-shell-organization, coral-shell-suborganization',
container: this._elements.items,
onItemAdded: this._onCollectionChange,
onItemRemoved: this._onCollectionChange
});
}
return this._items;
}
/**
The search field placeholder.
@default ''
@type {String}
@htmlattribute placeholder
*/
get placeholder() {
return this._elements.search.placeholder;
}
set placeholder(value) {
this._elements.search.placeholder = value;
}
/**
Content zone where the buttons are located.
@type {ShellOrgSwitcherFooter}
@contentzone
*/
get footIer() {
return this._getContentZone(this._elements.footer);
}
set footer(value) {
this._setContentZone('content', value, {
handle: 'footer',
tagName: 'coral-shell-orgswitcher-footer',
insert: function (content) {
this.appendChild(content);
}
});
}
/** @private */
get _itemTagName() {
// Used for Collection
return 'coral-shell-organization';
}
/** @private */
_onItemSelectedChanged(event) {
event.stopImmediatePropagation();
const item = event.target;
this._validateSelection(item);
}
/** @private */
_onSubItemSelectedChanged(event) {
event.stopImmediatePropagation();
const item = event.target;
// If a sub organization is selected, deselect all selected organization items
if (item.hasAttribute('selected')) {
this.items._getAllSelected().forEach((itemElement) => {
if (itemElement.tagName === 'CORAL-SHELL-ORGANIZATION') {
this._preventTriggeringEvents = true;
itemElement.removeAttribute('selected');
}
});
this._preventTriggeringEvents = false;
}
}
/** @private */
_onOrganizationChange() {
this._triggerChangeEvent();
}
/**
Returns the selected workspace.
@type {HTMLElement}
@readonly
*/
get selectedItem() {
return this.items._getLastSelected();
}
/** @private */
_selectFirst(event) {
event.stopPropagation();
const first = this.items.first();
if (first) {
first.setAttribute('selected', '');
}
}
/** @private */
_validateSelection(item) {
// gets the current selection
const selection = this.items._getAllSelected();
const selectionCount = selection.length;
if (selectionCount > 1) {
for (let i = 0 ; i < selectionCount ; i++) {
if (selection[i] !== item) {
// Don't trigger change events
this._preventTriggeringEvents = true;
selection[i].removeAttribute('selected');
}
}
// We can trigger change events again
this._preventTriggeringEvents = false;
}
this._triggerChangeEvent();
}
/** @private */
_triggerChangeEvent() {
const selectedItem = this.selectedItem;
const oldSelection = this._oldSelection;
if (!this._preventTriggeringEvents && selectedItem !== oldSelection) {
this.trigger('coral-shell-orgswitcher:change', {
oldSelection: oldSelection,
selection: selectedItem
});
this._oldSelection = selectedItem;
}
}
/** @private */
_showAEll(event) {
event.stopPropagation();
this._elements.resultMessage.hidden = true;
// Show all items
this.items.getAll().forEach((item) => {
item.hidden = false;
if (item.items) {
// Show all sub-items
item.items.getAll().forEach((itemElement) => {
itemElement.hidden = false;
});
}
});
}I
/** @private */
_performSearch(event) {
event.stopPropagation();
const searchTerm = this._elements.search.value.toLowerCase();
this._elements.resultMessage.hidden = true;
// Hide items that don't match
let resultCount = 0;
this.items.getAll().forEach((item) => {
let matched = item.content.textContent.toLowerCase().indexOf(searchTerm) !== -1;
let childMatched = false;
if (item.items) {
item.items.getAll().forEach((itemElement) => {
const elementMatch = itemElement.content.textContent.toLowerCase().indexOf(searchTerm) !== -1;
childMatched = childMatched || elementMatch;
itemElement.hidden = !elementMatch;
});
}
matched = matched || childMatched;
item.hidden = !matched;
if (matched) {
resultCount++;
}
});
if (resultCount === 0) {
this._elements.resultMessage.hidden = false;
}
}
/** @private */
_moveItems() {
this.setAttribute('id', this.id || commons.getUID());
Array.prototype.forEach.call(this.querySelectorAll(`#${this.id} > coral-shell-organization`), (item) => {
this._elements.items.appendChild(item);
});
}
/** @private */
_onCollectionChange(item) {
// Move all items into the right place
this._moveItems();
// Select the last selected item
this._validateSelection(item);
// if mincountforsearch is set and number of organizations are less than or equal to it, hide the search
if (this.items.length <= SEARCH_VISIBILITY_THRESHOLD) {
this._elements.search.hide();
} else {
this._elements.search.show();
}
}
get _contentZones() {
return {'coral-shell-orgswitcher-footer': 'footer'};
}
/** @ignore */
static get observedAttributes() {
return super.observedAttributes.concat(['placeholder']);
}
/** @ignore */
render() {
super.render();
this.classList.add(CLASSNAME);
// Move the items into the right place
this._moveItems();
const container = this.querySelector('[handle="container"]');
// Support cloneNode
if (container) {
this._elements.container = container;
this._elements.items = this.querySelector('._coral-Shell-orgSwitcher-items');
this._elements.search = this.querySelector('._coral-Shell-orgSwitcher-search');
this._elements.resultMessage = this.querySelector('._coral-Shell-orgSwitcher-resultMessage');
this._items._container = this._elements.items;
} else {
this.appendChild(this._elements.container);
}
// Call content zone insert
this.footer = this._elements.footer;
// Don't trigger events once connected
this._preventTriggeringEvents = true;
this._validateSelection();
this._preventTriggeringEvents = false;
this._oldSelection = this.selectedItem;
}
/**
Triggered when the {@link ShellOrgSwitcher} selected organization has changed.
@typedef {CustomEvent} coral-shell-orgswitcher:change
@property {HTMLElement} detail.oldSelection
The prior selected organization item.
@property {HTMLElement} detail.selection
The newly selected organization item.
*/
}
export default ShellOrgSwitcher;
|