Elgg  Version 3.0
Functions
UserPicker.js File Reference

Go to the source code of this file.

Functions

 define (function(require){var $=require('jquery');var elgg=require('elgg');var spinner=require('elgg/spinner');require('jquery.ui.autocomplete.html');function UserPicker(wrapper){this.$wrapper=$(wrapper);this.$input=$('.elgg-input-user-picker', wrapper);this.$ul=$('.elgg-user-picker-list', wrapper);var UserPicker=this, data=this.$wrapper.data();this.name=data.name|| 'members';this.handler=data.handler|| 'livesearch';this.limit=data.limit||0;this.minLength=data.minLength||2;this.isSealed=false;this.$input.autocomplete({source:function(request, response){var Autocomplete=this;if(UserPicker.isSealed){return;}elgg.get(UserPicker.handler,{beforeSend:spinner.start, complete:spinner.stop, data:{term:Autocomplete.term, match_on:UserPicker.getSearchType(), name:UserPicker.name}, dataType: 'json', success:function(data){response(data);}});}, minLength:UserPicker.minLength, html:"html", select:function(event, ui){UserPicker.addUser(event, ui.item.guid, ui.item.html);}, messages:{noResults: '', results:function(){}}});this.$wrapper.on('click', '.elgg-autocomplete-item-remove', function(event){UserPicker.removeUser(event);});this.enforceLimit();}UserPicker.prototype={addUser:function(event, guid, html){if(!$('li[data-guid="' + guid + '"]', this.$ul).length){this.$ul.append(html);}this.$input.val('');this.enforceLimit();event.preventDefault();}, removeUser:function(event){$(event.target).closest('.elgg-user-picker-list > li').remove();this.enforceLimit();event.preventDefault();}, enforceLimit:function(){if(this.limit){if($('li[data-guid]', this.$ul).length >=this.limit){if(!this.isSealed){this.seal();}}else{if(this.isSealed){this.unseal();}}}}, seal:function(){this.$input.prop('disabled', true);this.$wrapper.addClass('elgg-state-disabled');this.isSealed=true;}, unseal:function(){this.$input.prop('disabled', false);this.$wrapper.removeClass('elgg-state-disabled');this.isSealed=false;}, getSearchType:function(){var defaultType= 'users';if(this.$wrapper.has('[type="hidden"][name="match_on"]').length){defaultType=$('[type="hidden"][name="match_on"]', this.$wrapper).val();}if(this.$wrapper.has('[type="checkbox"][name="match_on"]:checked').length){return $('[type="checkbox"][name=match_on]:checked', this.$wrapper).val();}return defaultType;}};UserPicker.setup=function(selector){elgg.register_hook_handler('init', 'system', function(){$(selector).each(function(){if(!$(this).data('initialized')){new UserPicker(this);$(this).data('initialized', 1);}});});};return UserPicker;})
 elgg/UserPicker More...
 

Function Documentation

define ( function(require){var $=require('jquery');var elgg=require('elgg');var spinner=require('elgg/spinner');require('jquery.ui.autocomplete.html');function UserPicker(wrapper){this.$wrapper=$(wrapper);this.$input=$('.elgg-input-user-picker', wrapper);this.$ul=$('.elgg-user-picker-list', wrapper);var UserPicker=this, data=this.$wrapper.data();this.name=data.name|| 'members';this.handler=data.handler|| 'livesearch';this.limit=data.limit||0;this.minLength=data.minLength||2;this.isSealed=false;this.$input.autocomplete({source:function(request, response){var Autocomplete=this;if(UserPicker.isSealed){return;}elgg.get(UserPicker.handler,{beforeSend:spinner.start, complete:spinner.stop, data:{term:Autocomplete.term, match_on:UserPicker.getSearchType(), name:UserPicker.name}, dataType: 'json', success:function(data){response(data);}});}, minLength:UserPicker.minLength, html:"html", select:function(event, ui){UserPicker.addUser(event, ui.item.guid, ui.item.html);}, messages:{noResults: '', results:function(){}}});this.$wrapper.on('click', '.elgg-autocomplete-item-remove', function(event){UserPicker.removeUser(event);});this.enforceLimit();}UserPicker.prototype={addUser:function(event, guid, html){if(!$('li[data-guid="' + guid + '"]', this.$ul).length){this.$ul.append(html);}this.$input.val('');this.enforceLimit();event.preventDefault();}, removeUser:function(event){$(event.target).closest('.elgg-user-picker-list > li').remove();this.enforceLimit();event.preventDefault();}, enforceLimit:function(){if(this.limit){if($('li[data-guid]', this.$ul).length >=this.limit){if(!this.isSealed){this.seal();}}else{if(this.isSealed){this.unseal();}}}}, seal:function(){this.$input.prop('disabled', true);this.$wrapper.addClass('elgg-state-disabled');this.isSealed=true;}, unseal:function(){this.$input.prop('disabled', false);this.$wrapper.removeClass('elgg-state-disabled');this.isSealed=false;}, getSearchType:function(){var defaultType= 'users';if(this.$wrapper.has('[type="hidden"][name="match_on"]').length){defaultType=$('[type="hidden"][name="match_on"]', this.$wrapper).val();}if(this.$wrapper.has('[type="checkbox"][name="match_on"]:checked').length){return $('[type="checkbox"][name=match_on]:checked', this.$wrapper).val();}return defaultType;}};UserPicker.setup=function(selector){elgg.register_hook_handler('init', 'system', function(){$(selector).each(function(){if(!$(this).data('initialized')){new UserPicker(this);$(this).data('initialized', 1);}});});};return UserPicker;}  )

elgg/UserPicker

Parameters
function(require){var$=require('jquery');var elgg=require('elgg');var spinner=require('elgg/spinner');require('jquery.ui.autocomplete.html');function UserPicker(wrapper){this.$wrapper=;this.$input=$('.elgg-input-user-picker', wrapper);this.$ul=$('.elgg-user-picker-list', wrapper);var UserPicker=this, data=this.$wrapper.data();this.name=data.name|| 'members';this.handler=data.handler|| 'livesearch';this.limit=data.limit||0;this.minLength=data.minLength||2;this.isSealed=false;this.$input.autocomplete({source:function(request, response){var Autocomplete=this;if(UserPicker.isSealed){return;}elgg.get(UserPicker.handler,{beforeSend:spinner.start, complete:spinner.stop, data:{term:Autocomplete.term, match_on:UserPicker.getSearchType(), name:UserPicker.name}, dataType: 'json', success:function(data){response(data);}});}, minLength:UserPicker.minLength, html:"html", select:function(event, ui){UserPicker.addUser(event, ui.item.guid, ui.item.html);}, messages:{noResults: '', results:function(){}}});this.$wrapper.on('click', '.elgg-autocomplete-item-remove', function(event){UserPicker.removeUser(event);});this.enforceLimit();}UserPicker.prototype={addUser:function(event, guid, html){if(!$('li[data-guid="' + guid + '"]', this.$ul).length){this.$ul.append(html);}this.$input.val('');this.enforceLimit();event.preventDefault();}, removeUser:function(event){$(event.target).closest('.elgg-user-picker-list > li').remove();this.enforceLimit();event.preventDefault();}, enforceLimit:function(){if(this.limit){if($('li[data-guid]', this.$ul).length >=this.limit){if(!this.isSealed){this.seal();}}else{if(this.isSealed){this.unseal();}}}}, seal:function(){this.$input.prop('disabled', true);this.$wrapper.addClass('elgg-state-disabled');this.isSealed=true;}, unseal:function(){this.$input.prop('disabled', false);this.$wrapper.removeClass('elgg-state-disabled');this.isSealed=false;}, getSearchType:function(){var defaultType= 'users';if(this.$wrapper.has('[type="hidden"][name="match_on"]').length){defaultType=$('[type="hidden"][name="match_on"]', this.$wrapper).val();}if(this.$wrapper.has('[type="checkbox"][name="match_on"]:checked').length){return $('[type="checkbox"][name=match_on]:checked', this.$wrapper).val();}return defaultType;}};UserPicker.setup=function(selector){elgg.register_hook_handler('init', 'system', function(){.each(function(){if(!.data('initialized')){new UserPicker(this);.data('initialized', 1);}});});};return UserPicker;}
{HTMLElement}wrapper outer div module:elgg/UserPicker

Adds a user to the select user list

Parameters
{Object}event
{Number}guid GUID of autocomplete item selected by user
{String}html HTML for autocomplete item selected by user

Removes a user from the select user list

Parameters
{Object}event

Make sure user can't add more than limit

Don't allow user to add users

Allow user to add users

Get search type

Parameters
{String}selector