var AutocompleteSearch = new Class({ Implements: [Options, Events], options: { 'inputBox': "", // represents the name of the inputbox element on the page. 'delimiterCodes': [Utils.keyCode.TAB, Utils.keyCode.ENTER, Utils.keyCode.COMMA], 'criteria': "", // represents the search string 'listContainer': {}, // represents the list container element on the page. 'searchMethod': "", //string representing the api method to run see createAPIMethod() for valid options. 'maxcount': 50, 'page': 1, 'qType': null, //This is a integer *or* null representing the range of the search we should be performing (see MemberQueryFactory.cs) 'groupId': "", //'GUID' 'parent': "", // String representing the href of the parent scope to sreach within 'application': null, // Integer representing the application filter type 'highlight': true, 'allowNavigation': false, 'suppressDropdownLoader': false, 'onSelect': function() {}, 'onComplete': function() {} }, initialize: function(options) { this.isParentGone = false; this.setOptions(options); if (!this.options.inputBox || !$(this.options.inputBox)) { return null; } }, request: function(criteria) { this.apiStarted = true; var self = this; Utils.debounce( function() { self.callAPI(criteria); }, 200 ); }, callAPI: function(criteria) { //don't call the API if queryparams is null this.createQueryParams(criteria); if ( this.queryParams == null ) { return null; } else { //don't call the API if API Method is null this.createAPIMethod(); if ( this.apiMethod == null ) { return null; } else { var self = this; this.autocompleteapi = new ApiClient({ 'apimethod': this.apiMethod, 'method': 'get', 'queryparams': this.queryParams, onRequest:function ( instance ) { self.fireEvent('apiStarted'); }, onSuccess:function ( text, xml ) { if (!self.isParentGone) { self.returnstring = text; self.returnxml = xml; self.createObjectList(); self.isNewSearch = true; self.fireEvent('apiFinished', [criteria, true]); } }, onFailure:function ( text, xml) { if (!self.isParentGone) { self.returnstring = text; self.fireEvent('apiFinished', [criteria, false]); } }, onComplete: function() { self.apiStarted = false; } }); } } } });/* Description: This is the base AutocompleteSearchDisplay class it contains functions that are common to displaying all types of objects. If there is something unique to a particular type of object you should subclass this and create a new specialized display class that inherits these common functions. */ var AutocompleteSearchDisplay = new Class({ Implements: [Options, Events], options: { 'inputBox': "", // represents the name of the inputbox element on the page. 'delimiterCodes': [Utils.keyCode.TAB, Utils.keyCode.ENTER, Utils.keyCode.COMMA], 'criteria': "", // represents the search string 'listContainer': {}, // Represents the list container element on the page. 'searchMethod': "", // String representing the api method to run see createAPIMethod() for valid options. 'maxcount': 50, 'page': 1, 'qType': null, // This is a integer *or* null representing the range of the search we should be performing (see MemberDismaxQueryFactory.cs) 'groupId': "", // 'GUID' 'parent': "", // String representing the href of the parent scope to sreach within 'application': null, // Integer representing the application filter type 'highlight': true, 'allowNavigation': false, 'suppressDropdownLoader': false, 'onSelect': null, 'onComplete': function() { }, 'autohighlightfirst': false }, initialize: function(options) { this.isParentGone = false; this.modOverlay = null; this.setOptions(options); if (!this.options.inputBox || !$(this.options.inputBox)) { return null; } if (this.options.allowNavigation) { if (this.options.searchMethod.toString().toLowerCase() === "adminsearch") { this.options.onSelect = (function(selectedLink) { var memberString = "members?action=view&namespace=" + selectedLink.namespace; var goToObject = new URI(memberString); goToObject.go(); }); } else { this.options.onSelect = (function(selectedLink) { var bgImage = self.inputBoxElement.getParent('span').getStyle('background-image'); if (bgImage && bgImage.ciContains('ig-search.png')) { self.inputBoxElement.getParent('span').setStyle('background-image', bgImage.replace('ig-search.png', 'ig-loader-small.gif')); self.inputBoxElement.getParent('span').setStyle('background-position', '5px center'); } if (selectedLink.name) { self.inputBoxElement.set('value', selectedLink.name); } else if (selectedLink.plainTitle) { self.inputBoxElement.set('value', selectedLink.plainTitle); } self.inputBoxElement.disabled = true; var goToObject = new URI(selectedLink.originalHref); goToObject.go(); }); } } this.addEvent('onSelect', function(selectedLink) { this.options.onSelect(selectedLink) }); if (!this.options.onSelect) { this.options.onSelect = (function() { self.firstMatch = false; return false; }); } this.listenToInputBox(); this.attachEvents(); this.suppressMouseEvents = false; var self = this; document.addEvent('click', function(event) { if (event && event.target) { if ((event.target.getParents('.ig-suggestions-dropdown').length == 0) && (event.target != self.inputBoxElement)) { self.hideList(true); } } }); }, listenToInputBox: function() { var self = this; this.inputBoxElement = $(this.options.inputBox); this.inputBoxElement.addEvents({ 'keydown': function(event) { switch (event.code) { case Utils.keyCode.UP: self.hilightPrevious(); event.stop(); break; case Utils.keyCode.DOWN: self.hilightNext(); event.stop(); break; case Utils.keyCode.ESC: self.escaped = true; self.hideList(true); event.stop(); self.inputBoxElement.focus(); break; case Utils.keyCode.TAB: self.handleTab(event); break; case Utils.keyCode.ENTER: self.escaped = false; if (self.firstMatch && self.acList) { event.preventDefault(); var highlightedElem = self.acList.getElement('.hilighted'); if (self.acList.getElement('.hilighted')) { if (highlightedElem.content) { self.fireEvent('onSelect', highlightedElem.content); } else if (highlightedElem.user) { self.fireEvent('onSelect', highlightedElem.user); } if (self.acList) self.acList.getElement('.hilighted').acsObject = ""; } self.hideList(true); if (!self.options.nofocus) { self.inputBoxElement.focus(); } } break; default: if (self.options.delimiterCodes.contains(event.code)) { if ((event.code == Utils.keyCode.TAB && this.value == '') || !self.acList || (event.code == Utils.keyCode.ENTER && self.acList.getElement('.ig-recepient-notfound'))) { break; } } break; } }, 'keyup': function(event) { switch (event.code) { case Utils.keyCode.LEFT: case Utils.keyCode.RIGHT: case Utils.keyCode.UP: case Utils.keyCode.DOWN: case Utils.keyCode.TAB: case Utils.keyCode.ENTER: case Utils.keyCode.COMMA: case Utils.keyCode.ESC: break; default: if (!self.escaped) { // calls an API to get the autocomplete list of names if (!this.value) { self.hideList(true); return false; } self.getResults(this.value); } break; } }, 'blur': function() { self.escaped = false; } }); }, handleTab: function(event) { this.switchList(); if (event) { event.stop(); } }, attachEvents: function() { var self = this; document.addEvent('modalClose', function() { if ($(self.loader)) { $(self.loader).destroy(); self.loader = null; } if ($(self.modOverlay)) { $(self.modOverlay).destroy(); self.hideList(true); } self.hideList(true); }); }, addEventsToACS: function(acsObject) { var self = this; acsObject.addEvent('apiStarted', function() { var userList = $('js-accessUserList'); if (userList) { //remove the spinner if it's present already if ($(self.modOverlay)) { $(self.modOverlay).destroy(); self.hideList(true); } // Curtain and spinner over whole item self.modOverlay_height = userList.getHeight(); self.modOverlay = new Element('div', { 'class': 'ig-curtain' }); new Element('div', { 'class': 'ig-curtain-overlay', 'style': 'height: ' + self.modOverlay_height + 'px;' }).inject(self.modOverlay); new Element('div', { 'class': 'ig-loader-large', 'style': 'height: ' + self.modOverlay_height + 'px;' }).inject(self.modOverlay); // If its a comment page use different parent div self.modOverlay.inject(userList, 'top'); } else { if ($(self.modOverlay)) { $(self.modOverlay).destroy(); self.hideList(true); } } if (!self.acList && !self.loader && !self.options.suppressDropdownLoader) { //remove the spinner if it's present already if ($(self.loader)) { $(self.loader).destroy(); self.hideList(true); } var inputBoxCoordinates = self.inputBoxElement.getCoordinates(); self.loader = new Element('div', { 'class': 'ig-suggestions-dropdown ig-autocomplete' + self.options.inputBox }).adopt( new Element('ul').adopt( new Element('li', { 'class': '' }).adopt( new Element('div', { 'class': 'ig-loader-medium' } ) ) )).setStyles({ 'top': inputBoxCoordinates.bottom, 'left': inputBoxCoordinates.left, 'width': inputBoxCoordinates.width }).inject(document.body); } else { if ($(self.loader)) { $(self.loader).destroy(); self.hideList(true); } } }); acsObject.addEvent('apiFinished', function(criteria, wasSuccessful) { if (wasSuccessful) { self.infoRetrieved(criteria); } else { self.displayResults(criteria); } }); }, closeList: function() { //this function is to be used from the parent modal object to indicate it is closing //to avoid some timing holes that cause display issues. this.isParentGone = true; this.hideList(true); }, hideList: function(forceHide) { // don't need the autocomplete list anymore! if (this.firstMatch) { this.firstMatch.dispose(); } if (this.acList && (!this.options.listContainer || forceHide)) { if (!$(this.options.listContainer)) { this.acList.dispose(); this.acList = null; } else { this.acList.set('html', ''); } } }, hilightElement: function(elem) { $$('li.hilighted').removeClass('hilighted'); if (elem.tagName.toLowerCase() != 'li') { elem = elem.getParent('li'); } elem.addClass('hilighted'); }, hilightPrevious: function() { if (this.acList) { var hilighted = this.acList.getElement('.hilighted'); if (hilighted) { var previous = hilighted.getPrevious('li'); if (previous) { hilighted.removeClass('hilighted'); previous.addClass('hilighted'); if ((this.options.inputBox != "globalsearchtext") && (!this.options.inputBox.ciContains("ig-search"))) { this.scroll(this.acList, previous, -1); } } } } }, hilightNext: function() { var firstTimeThrough = false; if (this.acList) { if (!this.firstMatch) { firstTimeThrough = true; this.firstMatch = this.acList.getElement('li'); if (!this.firstMatch) { //if there was nothing found let the user know nameList.adopt(new Element('li', { 'html': window.translations('comps-message-No_matches_found'), 'class': 'ig-recepient-notfound' }) ); } else { // hilight the first match this.firstMatch.addClass('hilighted'); } } if (!firstTimeThrough) { var hilighted = this.acList.getElement('.hilighted'); if (hilighted) { var next = hilighted.getNext('li'); if (next) { hilighted.removeClass('hilighted'); next.addClass('hilighted'); if ((this.options.inputBox != "globalsearchtext") && (!this.options.inputBox.ciContains("ig-search"))) { this.scroll(this.acList, next, 1); } } } } firstTimeThrough = false; } }, scroll: function(list, item, direction) { this.suppressMouseEvents = true; var itemCoordinates = item.getCoordinates(); var position = Math.round((itemCoordinates.bottom - this.listTop) / this.itemHeight); if (direction > 0 && position > (this.itemsPerPage - this.scrollBuffer)) { var scrollTo = list.getScroll().y + this.itemHeight * (position - this.itemsPerPage + this.scrollBuffer); list.scrollTo(0, scrollTo); } else if (direction < 0 && position - 1 < this.scrollBuffer) { var scrollTo = list.getScroll().y + this.itemHeight * (position - 1 - this.scrollBuffer); list.scrollTo(0, scrollTo); } }, gethilightedUser: function() { var user = null; if (this.acList) { var hilighted = this.acList.getElement('.hilighted'); if (hilighted) { user = hilighted.user; } } return user; }, switchList: function() { if (this.acList) { var highlighted = this.acList.getElement('.hilighted'); if (highlighted) { var contentParent = this.acList.getElement('div.ig-suggestion-contentList'); var userParent = this.acList.getElement('div.ig-suggestion-userList'); var contentArray = contentParent.getElements('.js-ACS-item'); var userArray = userParent.getElements('.js-ACS-item'); var otherListItem = null var count = 0; if (highlighted.getParent('div.ig-suggestion-contentList')) { while (!contentArray[count].hasClass('hilighted') && count < contentArray.length) { count++; } otherListItem = $(userArray[count]); if (otherListItem) { highlighted.removeClass('hilighted'); otherListItem.addClass('hilighted'); } } else { count = 0; while (!userArray[count].hasClass('hilighted') && count < userArray.length) { count++; } otherListItem = $(contentArray[count]); if (otherListItem) { highlighted.removeClass('hilighted'); otherListItem.addClass('hilighted'); } } } } } }); var AutocompleteSolrUserSearch = new Class({ Extends: AutocompleteSearch, Implements: [Options, Events], createAPIMethod: function() { this.apiMethod = 'search/members'; }, createQueryParams: function(criteria) { //Don't make the API call until the user has entered at least two characters to begin the search if ( !criteria || criteria.length < 2 ) { return null; } this.queryParams = { 'qType': this.options.qType, 'q': criteria, 'rows': this.options.maxcount, 'page': this.options.page, 'parent': this.options.parent, 'groupId': this.options.groupId, 'hl': this.options.highlight }; }, createObjectList: function() { if (this.returnstring) { this.returnjson = JSON.decode(this.returnstring, true); } else { return null; } this.userList = []; var self = this; if (this.returnjson.response && this.returnjson.response.value && this.returnjson.response.value.count != 0) { this.returnjson.response.value.hit.each(function(item) { var user = { 'hasPhoto': item.hasImage, 'originalHref': "/.profile/" + item.namespace, 'firstName': item.name.firstName, 'lastName': item.name.lastName, 'userTo': (item.Id) ? item.Id.replace(/<.*?>/g, '') : item.id.replace(/<.*?>/g, ''), 'name': item.name.fullName, 'namespace': item.namespace, 'email': item.email }; //Highlights if (item.Highlights) { for ( var i = 0; i < item.Highlights.length; i++) { if (item.Highlights[i].Key.toString().toLowerCase() == 'first_name') { user.highlightedFirstName = item.Highlights[i].Value[0]; } else if (item.Highlights[i].Key.toString().toLowerCase() == 'last_name') { user.highlightedLastName = item.Highlights[i].Value[0]; } else if (item.Highlights[i].Key.toString().toLowerCase() == 'namespace') { user.highlightedNameSpace = Utils.htmldecode(item.Highlights[i].Value[0]); } else if (item.Highlights[i].Key.toString().toLowerCase() == 'email_private') { user.highlightedEmail = item.Highlights[i].Value[0]; } } } self.userList.push(user); }); } else { return null; } } }); /* Description: This subclass of the AutocompleteSearchDisplay contains functions that are specific to displaying users in the various fields that autocomplete users (e.g. the "to" field in sending messages). */ var AutocompleteSearchDisplayUser = new Class({ Extends: AutocompleteSearchDisplay, Implements: [Options, Events], getResults: function(criteria) { //create a new instance of the autocompleteSolrUserSearch if we don't have one already if (!this.autocompleteSolrUser ) { this.autocompleteSolrUser = new AutocompleteSolrUserSearch(this.options); this.addEventsToACS(this.autocompleteSolrUser); } this.isParentGone = false; this.autocompleteSolrUser.request(criteria); }, handleTab: function(event) { if (event) { event.preventDefault(); } }, infoRetrieved: function(criteria) { if ( !criteria || criteria.length < 2 ) { //remove the spinner if it's present already if (this.modOverlay && $(this.modOverlay)) { $(this.modOverlay).destroy(); } if (this.loader && $(this.loader)) { $(this.loader).destroy(); } return null; } if (this.autocompleteSolrUser.userList) { this.displayResults(criteria); } }, displayResults: function(criteria) { this.hideList(true); if (!this.isParentGone) { var nameList = new Element('ul'); var self = this; this.autocompleteSolrUser.userList.each(function(user) { //Display highlights if we have them, if not display the plain ones if (user.highlightedFirstName) { user.htmlFirstName = user.highlightedFirstName; } else { user.htmlFirstName = user.firstName; } if (user.highlightedLastName) { user.htmlLastName = user.highlightedLastName; } else { user.htmlLastName = user.lastName; } if (user.highlightedNameSpace) { user.htmlNameSpace = '@' + user.highlightedNameSpace; } else if (user.namespace){ user.htmlNameSpace = '@' + user.namespace; } else { user.htmlNameSpace = "" } if (user.highlightedEmail) { user.htmlEmail = user.highlightedEmail; } else if (user.email) { user.htmlEmail = user.email; } else { user.htmlEmail = ""; } if (user.hasPhoto) { var thumbPath = '/download-profile/{'+user.userTo+'}/profile/small'; var thumbClass = ''; } else { var thumbPath='/cmedia/img/none.gif;v0'; var thumbClass = 'ig-thumbnail-32-none'; } // The element that displays the user's image. var imageElem = new Element ('span', { 'class':'ig-user-thumbnail thumbnail thumbnail-crsmall ig-left' }).adopt( new Element('span', { 'class':'ig-thumbnail-padding' }).adopt( new Element('img', { 'class':thumbClass, 'src':thumbPath, 'alt':user.name }) ) ); // And then there's this guy. He holds all the elements we just created, plus the name/email/namespace elements var elem = new Element('li', { 'class':'ig-member', 'title': user.name }).adopt( new Element('div', { 'class':'ig-container' }).adopt( imageElem, // Here's then namespace element. new Element('div', { 'class':'ig-member-info' }).adopt( new Element('span', { 'class':'small ig-medium_font ig-nowrap ig-mediummarginleft ig-nomarginbottom ig-right', 'html':user.htmlNameSpace }), new Element('a', { 'id':'js-user_' + user.userTo, 'title':user.name, 'html':user.htmlFirstName + ' ' + user.htmlLastName }), new Element ('div').adopt( new Element ('span', { 'class':'small ig-nowrap ig-nomarginbottom ig-medium_font', 'title':user.email, 'html':user.htmlEmail }) ) ) ) ).addEvents({ 'click': function(event) { // add this element var elem = $(event.target); if (elem.tagName.toLowerCase() != 'li') { elem = elem.getParent('li'); } self.fireEvent('onSelect', user); self.hideList(true); }, 'mousemove':function(event) { if (self.suppressMouseEvents) { self.suppressMouseEvents = false; self.hilightElement($(event.target)); } }, 'mouseenter':function(event) { if (!self.suppressMouseEvents) { self.hilightElement($(event.target)); } } }); elem.user = user; nameList.adopt(elem); }); if (!this.options.allowNavigation) { if (this.autocompleteSolrUser.userList.length <= 0) { // if there was nothing found let the user know nameList.adopt( new Element('li', { 'html': window.translations('comps-message-No_matches_found'), 'class': 'ig-recepient-notfound ig-smallpadding small ig-nomarginbottom ig-light_font' }) ); } else if (this.options.autohighlightfirst) { // hilight the first match this.firstMatch = nameList.getElement('li'); if (this.firstMatch) { this.firstMatch.addClass('hilighted'); } } } else { if (this.autocompleteSolrUser.userList.length <= 0) { // if there was nothing found let the user know nameList.adopt( new Element('li', { 'html': window.translations('comps-message-No_matches_found'), 'class': 'ig-recepient-notfound ig-smallpadding small ig-nomarginbottom ig-light_font' }) ); } } // show the menu var inputBoxCoordinates = $(this.options.inputBox).getParent().getCoordinates(); var inputBoxWidth = inputBoxCoordinates.width - 4; //Manage Members displays this a little too small. if (inputBoxWidth < 200) { inputBoxWidth = 250; } // If the contain which holds the list exists, then adopt it // Otherwise, create a new container if ($(this.options.listContainer)) { this.acList = $(this.options.listContainer).adopt(nameList); } else { this.acList = new Element('div', { 'class': 'ig-suggestions-dropdown' }).adopt(nameList).setStyles({ 'top': inputBoxCoordinates.bottom, 'left': inputBoxCoordinates.left, 'width': inputBoxWidth }).inject(document.body); } if (this.firstMatch) { this.scrollBuffer = 1; this.listCoordinates = this.acList.getCoordinates(); this.listDimensions = this.acList.getComputedSize(); this.listTop = this.listCoordinates.top + this.listDimensions['border-top-width']; this.itemHeight = this.firstMatch.getCoordinates().height; this.itemsPerPage = Math.round(this.listDimensions.height / this.itemHeight); } self.fireEvent('onComplete'); if ($(self.loader)) { $(self.loader).destroy(); } if (this.modOverlay) { $(this.modOverlay).destroy(); } } } }); window.addEvent('domready', function() { if (Igloo.asset_AutocompleteSearchDisplayUser) { Object.each(Igloo.asset_AutocompleteSearchDisplayUser, function(object, id) { var autocomplete = new AutocompleteSearchDisplayUser(object); }); } }); var AutocompleteSolrContentSearch = new Class({ Extends: AutocompleteSearch, Implements: [Options, Events], createAPIMethod: function() { this.apiMethod = 'search/content'; }, createQueryParams: function(criteria) { //Don't make the API call until the user has entered at least two characters to begin the search if ( !criteria || criteria.length < 2 ) { return null; } this.queryParams = { 'qType': this.options.qType, 'q': criteria, 'rows': this.options.maxcount, 'page': this.options.page, 'parent': this.options.parent, 'application': this.options.application, 'hl': this.options.highlight }; }, createObjectList: function( criteria ) { if (this.returnstring) { this.returnjson = JSON.decode(this.returnstring, true); } else { return null; } this.contentList = []; var self = this; if (this.returnjson.response && this.returnjson.response.value && this.returnjson.response.value.count != 0) { this.returnjson.response.value.hit.each(function(item) { //determine the content type var contentType = Igloo.cSearchType[item.ApplicationType].toLowerCase(); var content = { 'href': item.Href, 'originalHref': item.Href, //making a second copy that will be using for the navigation link. 'id': item.ObjectId, 'type': 'app-' + contentType, 'mimeType': item.FileFormat.MimeType, 'fileExtension':item.FileFormat.Extension, 'plainTitle': item.Title, 'plainContent': item.Content, 'description': item.Description }; //Highlights if (item.Highlights){ for ( var i = 0; i < item.Highlights.length; i++) { if (item.Highlights[i].Key.toString().toLowerCase() == 'title') { content.highlightedTitle = item.Highlights[i].Value[0]; } else if (item.Highlights[i].Key.toString().toLowerCase() == 'content') { content.highlightedContent = item.Highlights[i].Value[0]; }else if (item.Highlights[i].Key.toString().toLowerCase() == 'description') { content.highlightedDescription = item.Highlights[i].Value[0]; }else if (item.Highlights[i].Key.toString().toLowerCase() == 'href') { content.highlightedHref = item.Highlights[i].Value[0]; } } } self.contentList.push(content); }); } else { return null; } } }); /* Description: This subclass of the AutocompleteSearchDisplay class handle finding content items to link in the links widget. */ var AutocompleteSearchDisplayContent = new Class({ Extends: AutocompleteSearchDisplay, Implements: [Options, Events], getResults: function(criteria) { //set a custom max count for search widget if (this.options.inputBox.toString().ciContains("ig-search")) { this.options.maxcount = 10; } //create a new instance of the AutocompleteContentSearch if we don't have one already if (!this.autocompleteContent) { this.autocompleteContent = new AutocompleteSolrContentSearch(this.options); this.addEventsToACS(this.autocompleteContent); } this.autocompleteContent.request(criteria); }, infoRetrieved: function(criteria) { if (!criteria || criteria.length < 2) { //remove the spinner if it's present already if (this.modOverlay && $(this.modOverlay)) { $(this.modOverlay).destroy(); } if (this.loader && $(this.loader)) { $(this.loader).destroy(); } return null; } if (this.autocompleteContent.contentList) { this.displayResults(criteria); } }, displayResults: function(criteria) { this.hideList(true); var nameList = new Element('ul'); var self = this; this.autocompleteContent.contentList.each(function(content) { // Quick fix till we have time to properly update type sent back from platform if (content.type == 'app-calendar') { content.type = 'app-event'; } else if (content.type == 'app-document' && !content.mimeType) { content.type = 'mime-folder'; } else if (content.type == 'app-pages') { content.type = 'app-page'; } if (content.mimeType) { content.fileExtension = content.fileExtension.replace('.', ''); content.type = Igloo.mimeTypeMap[content.fileExtension]; } //Display highlights if we have them, if not display the plain ones if (content.highlightedTitle) { content.title = content.highlightedTitle; } else { content.title = content.plainTitle; } if (content.highlightedHref) { content.href = content.highlightedHref; } else { content.href = content.originalHref; } var html = new Element('a', { 'id': 'js-objectcontent_' + content.id, 'html': content.title }); var elem = new Element('li', { 'class': 'ig-type ig-truncate' }).adopt( new Element('span', { 'class': 'ig-thumbnail' }).adopt( new Element('span', { 'class': content.type + ' icon-32' }) ), html, new Element('span', { 'class': 'js-objectcontent', 'html': content.href }) ).addEvents({ 'click': function(event) { // add this element var elem = $(event.target); if (elem.tagName.toLowerCase() != 'li') { elem = elem.getParent('li'); } self.fireEvent('onSelect', content); self.hideList(true); }, 'mousemove': function(event) { if (self.suppressMouseEvents) { self.suppressMouseEvents = false; self.hilightElement($(event.target)); } }, 'mouseenter': function(event) { if (!self.suppressMouseEvents) { self.hilightElement($(event.target)); } } }); elem.content = content; nameList.adopt(elem); }); if (!this.options.allowNavigation) { if (this.autocompleteContent.contentList.length <= 0) { // if there was nothing found let the user know nameList.adopt( new Element('div', { 'html': window.translations('comps-message-No_matches_found'), 'class': 'ig-recepient-notfound ig-smallpadding small ig-nomarginbottom ig-light_font' }) ); } else if (this.options.autohighlightfirst) { // hilight the first match this.firstMatch = nameList.getElement('li'); this.firstMatch.addClass('hilighted'); } } else { if (this.autocompleteContent.contentList.length <= 0) { // if there was nothing found let the user know nameList.adopt( new Element('li', { 'html': window.translations('comps-message-No_matches_found'), 'class': 'ig-recepient-notfound ig-smallpadding small ig-nomarginbottom ig-light_font' }) ); } else if (this.options.autohighlightfirst) { this.firstMatch = nameList.getElement('li'); this.firstMatch.addClass('hilighted'); } } // show the menu var inputBoxCoordinates = $(this.options.inputBox).getParent().getCoordinates(); var inputBoxWidth = inputBoxCoordinates.width - 4; // If the container which holds the list exists, then adopt it // Otherwise, create a new container if ($(this.options.listContainer)) { this.acList = $(this.options.listContainer).adopt(nameList); } else { this.acList = new Element('div', { 'class': 'ig-suggestions-dropdown' }).adopt(nameList).setStyles({ 'top': inputBoxCoordinates.bottom, 'left': inputBoxCoordinates.left, 'width': inputBoxWidth }).inject(document.body); } if (this.firstMatch) { this.scrollBuffer = 1; this.listCoordinates = this.acList.getCoordinates(); this.listDimensions = this.acList.getComputedSize(); this.listTop = this.listCoordinates.top + this.listDimensions['border-top-width']; this.itemHeight = this.firstMatch.getCoordinates().height; this.itemsPerPage = Math.round(this.listDimensions.height / this.itemHeight); } this.fireEvent('onComplete'); if ($(self.loader)) { $(self.loader).destroy(); } if (this.modOverlay) { $(this.modOverlay).destroy(); } } }); window.addEvent('domready', function() { if (Igloo.asset_AutocompleteSearchDisplayContent) { Object.each(Igloo.asset_AutocompleteSearchDisplayContent, function(object, id) { var autocomplete = new AutocompleteSearchDisplayContent(object); }); } }); window.addEvent('bootstrap4finished', function() { if (window.dependents['AutocompleteSearchDisplayContent']) { // the old bootstrap4 attaches dataobj as a string, not a Hash // bootstrap4velo attaches the dataobj as a Hash, not a string. wheeee! window.dependents['AutocompleteSearchDisplayContent'].each(function(elem) { var autocomplete = new AutocompleteSearchDisplayContent(elem.dataobj.AutocompleteSearchDisplayContent); }); } });/* Description: This subclass of the AutocompleteSearchDisplay class is used with our search feature to display a list of users and content items at the same time. */ var AutocompleteSearchDisplayUserContent = new Class({ Extends: AutocompleteSearchDisplay, Implements: [Options, Events], getResults: function(criteria) { //create a new instance of the autocompleteSolrContentSearch if we don't have one already if (!this.autocompleteSolrContent) { this.options.maxcount = 10; this.autocompleteSolrContent = new AutocompleteSolrContentSearch(this.options); this.addEventsToACS(this.autocompleteSolrContent); } //create a new instance of the autocompleteSolrUserSearch if we don't have one already if (!this.autocompleteSolrUser) { this.options.maxcount = 2; this.autocompleteSolrUser = new AutocompleteSolrUserSearch(this.options); this.addEventsToACS(this.autocompleteSolrUser); } this.autocompleteSolrUser.request(criteria); this.autocompleteSolrContent.request(criteria); }, infoRetrieved: function(criteria) { if (!criteria || criteria.length < 2) { return null; } if (!this.autocompleteSolrUser.isNewSearch || !this.autocompleteSolrContent.isNewSearch) { if (!this.autocompleteSolrUser.isNewSearch) { this.autocompleteSolrUser.request(criteria); } else if (!this.autocompleteSolrContent.isNewSearch) { this.autocompleteSolrContent.request(criteria); } } else { this.displayResults(criteria); } }, displayResults: function(criteria) { this.hideList(true); var nameList = new Element('div'); var displayList = new Element('ul'); var self = this; this.autocompleteSolrUser.userList.each(function(user) { //Display highlights if we have them, if not display the plain ones if (user.highlightedFirstName) { user.htmlFirstName = user.highlightedFirstName; } else { user.htmlFirstName = user.firstName; } if (user.highlightedLastName) { user.htmlLastName = user.highlightedLastName; } else { user.htmlLastName = user.lastName; } if (user.highlightedNameSpace) { user.htmlNameSpace = '@' + user.highlightedNameSpace; } else if (user.namespace) { user.htmlNameSpace = '@' + user.namespace; } else { user.htmlNameSpace = "" } if (user.highlightedEmail) { user.htmlEmail = user.highlightedEmail; } else if (user.email) { user.htmlEmail = user.email; } else { user.htmlEmail = ""; } if (user.hasPhoto) { var thumbPath = '/download-profile/{' + user.userTo + '}/profile/small'; var thumbClass = ''; } else { var thumbPath = '/cmedia/img/none.gif;v0'; var thumbClass = 'ig-thumbnail-32-none'; } // The element that displays the user's image. var imageElem = new Element('span', { 'class': 'ig-user-thumbnail thumbnail thumbnail-crsmall ig-left' }).adopt( new Element('span', { 'class': 'ig-thumbnail-padding' }).adopt( new Element('img', { 'class': thumbClass, 'src': thumbPath, 'alt': user.name }) ) ); // And then there's this guy. He holds all the elements we just created, plus the name/email/namespace elements var elem = new Element('li', { 'class': 'ig-member', 'title': user.name }).adopt( new Element('div', { 'class': 'ig-container' }).adopt( imageElem, // Here's then namespace element. new Element('div', { 'class': 'ig-member-info' }).adopt( new Element('span', { 'class': 'small ig-medium_font ig-nowrap ig-mediummarginleft ig-nomarginbottom ig-right', 'html': user.htmlNameSpace }), new Element('a', { 'id': 'js-user_' + user.userTo, 'title': user.name, 'html': user.htmlFirstName + ' ' + user.htmlLastName }), new Element('div').adopt( new Element('span', { 'class': 'small ig-nowrap ig-nomarginbottom ig-medium_font', 'title': user.email, 'html': user.htmlEmail }) ) ) ) ).addEvents({ 'click': function(event) { // add this element var elem = $(event.target); if (elem.tagName.toLowerCase() != 'li') { elem = elem.getParent('li'); } self.fireEvent('onSelect', user); self.hideList(true); }, 'mousemove': function(event) { if (self.suppressMouseEvents) { self.suppressMouseEvents = false; self.hilightElement($(event.target)); } }, 'mouseenter': function(event) { if (!self.suppressMouseEvents) { self.hilightElement($(event.target)); } } }); elem.user = user; displayList.adopt(elem); }); this.autocompleteSolrContent.contentList.each(function(content) { // Quick fix till we have time to properly update type sent back from platform if (content.type == 'app-calendar') { content.type = 'app-event'; } else if (content.type == 'app-document') { content.type = 'mime-folder'; } else if (content.type == 'app-pages') { content.type = 'app-page'; } if (content.mimeType) { content.fileExtension = content.fileExtension.replace('.', ''); content.type = Igloo.mimeTypeMap[content.fileExtension]; } //Display highlights if we have them, if not display the plain one if (content.highlightedTitle) { content.title = content.highlightedTitle; } else { content.title = content.plainTitle; } if (content.highlightedHref) { content.href = content.highlightedHref; } else { content.href = content.originalHref; } var elem = new Element('li', { 'class': 'js-ACS-item ig-type ig-nominwidth ig-nomargin ig-truncate' }).adopt( new Element('a', { 'id': 'js-objectcontent_' + content.id }).adopt( new Element('span', { 'class': 'ig-thumbnail' }).adopt( new Element('span', { 'class': content.type + ' icon-32' }) ), new Element('span', { 'html': content.title }) ), new Element('span', { 'class': 'js-objectcontent', 'html': content.href }) ).addEvents({ 'click': function(event) { // add this element var elem = $(event.target); if (elem.tagName.toLowerCase() != 'li') { elem = elem.getParent('li'); } self.fireEvent('select', content); self.hideList(true); }, 'mousemove': function(event) { if (self.suppressMouseEvents) { self.suppressMouseEvents = false; self.hilightElement($(event.target)); } }, 'mouseenter': function(event) { if (!self.suppressMouseEvents) { self.hilightElement($(event.target)); } } }); elem.content = content; displayList.adopt(elem); }); nameList.adopt(displayList); if (this.autocompleteSolrUser.userList.length <= 0 && this.autocompleteSolrContent.contentList <= 0) { //if there was nothing found let the user know nameList.adopt( new Element('div', { 'html': window.translations('comps-message-No_matches_found'), 'class': 'ig-recepient-notfound ig-smallpadding small ig-nomarginbottom ig-light_font' }) ); } else if (this.options.autohighlightfirst) { this.firstMatch = nameList.getElement('li'); this.firstMatch.addClass('hilighted'); } // show the menu var inputBoxCoordinates = $(this.options.inputBox).getParent().getCoordinates(); var inputBoxWidth = inputBoxCoordinates.width - 4; // If the container which holds the list exists, then adopt it // Otherwise, create a new container if ($(this.options.listContainer)) { this.acList = $(this.options.listContainer).adopt(nameList); } else { this.acList = new Element('div', { 'class': 'ig-suggestions-dropdown ig-autocomplete' + this.options.inputBox }).adopt(nameList).setStyles({ 'top': inputBoxCoordinates.bottom, 'left': inputBoxCoordinates.left, 'width': inputBoxWidth }).inject(document.body); } if (this.firstMatch) { this.scrollBuffer = 1; this.listCoordinates = this.acList.getCoordinates(); this.listDimensions = this.acList.getComputedSize(); this.listTop = this.listCoordinates.top + this.listDimensions['border-top-width']; this.itemHeight = this.firstMatch.getCoordinates().height; this.itemsPerPage = Math.round(this.listDimensions.height / this.itemHeight); } this.autocompleteSolrUser.isNewSearch = false; this.autocompleteSolrContent.isNewSearch = false; this.fireEvent('onComplete'); } }); window.addEvent('domready', function() { if (Igloo.asset_AutocompleteSearchDisplayUserContent) { Object.each(Igloo.asset_AutocompleteSearchDisplayUserContent, function(object, id) { var autocomplete = new AutocompleteSearchDisplayUserContent(object); }); } }); window.addEvent('bootstrap4finished', function() { if (window.dependents['AutocompleteSearchDisplayUserContent']) { // the old bootstrap4 attaches dataobj as a string, not a Hash // bootstrap4velo attaches the dataobj as a Hash, not a string. wheeee! window.dependents['AutocompleteSearchDisplayUserContent'].each(function(elem) { var autocomplete = new AutocompleteSearchDisplayUserContent(elem.dataobj.AutocompleteSearchDisplayUserContent); }); } });var AutocompleteUserSearch = new Class({ Extends: AutocompleteSearch, Implements: [Options, Events], createAPIMethod: function() { //translate passed in option into the correct API method to run. this.apimethod = ''; if ( this.options.searchMethod.toString().toLowerCase() == 'personasmall' ) { this.apiMethod = 'users/searchByNameAsPersonaSmall'; } else { this.apiMethod = 'users/searchByName'; } }, createPostData: function(criteria) { //Don't make the API call until the user has entered at least two characters to begin the search if ( !criteria || criteria.length < 2 ) { return null; } this.postData = { 'criteria': criteria, 'groupId': this.options.groupId, 'page': this.options.page, 'itemsperpage': this.options.maxcount }; }, createObjectList: function() { if (this.returnstring) { this.returnjson = JSON.decode(this.returnstring, true); } else { return null; } var user; this.userList = []; var self = this; this.returnjson.response.items.each(function(item) { user = {}; user.hasPhoto = ( item.hasPhoto ) ? true : false; user.href = item.href; user.name = ( item.Name ) ? item.Name.firstName.trim() + ' ' + item.Name.lastName.trim() : item.name.firstName.trim()+ ' ' + item.name.lastName.trim(); user.type = item.__type.contains('PersonaForSearch') ? 'member' : 'group'; user.userTo = (item.Id) ? item.Id.replace(/<.*?>/g, '') : item.id.replace(/<.*?>/g, ''); self.userList.push(user); }); } }); var AutocompleteContentSearch = new Class({ Extends: AutocompleteSearch, Implements: [Options, Events], createAPIMethod: function() { this.apiMethod = 'objects/smart_search'; }, createQueryParams: function(criteria) { //Don't make the API call until the user has entered at least two characters to begin the search if ( !criteria || criteria.length < 2 ) { return null; } this.queryParams = { 'criteria': criteria, 'maxcount': this.options.maxcount, 'startindex': this.options.page }; }, createObjectList: function( criteria ) { if (this.returnstring) { this.returnjson = JSON.decode(this.returnstring, true); } else { return null; } var content; this.contentList = []; var self = this; this.returnjson.response.items.each(function(item) { //get the object type var link_apptype = item.__type.toLowerCase(); var type = link_apptype.split(":"); content = { 'href':item.href, 'title':item.title, 'id':item.id, 'type':type[0] }; self.contentList.push(content); }); } });