Elgg
Version 5.0
|
Go to the source code of this file.
Functions | |
define (['jquery', 'elgg', 'elgg/Ajax', 'jquery-ui/widgets/autocomplete', 'jquery.ui.autocomplete.html'], function($, elgg, Ajax){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.matchOn=data.matchOn|| 'users';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;}var ajax=new Ajax();ajax.path(UserPicker.handler,{data:{term:Autocomplete.term, match_on:UserPicker.getSearchType(), name:UserPicker.name}, method: 'GET', 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(event.isDefaultPrevented()){return;}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(){if(this.$wrapper.has('[type="checkbox"][name="match_on"]:checked').length){return $('[type="checkbox"][name=match_on]:checked', this.$wrapper).val();}return this.matchOn;}};UserPicker.setup=function(selector){$(selector).each(function(){if(!$(this).data('initialized')){new UserPicker(this);$(this).data('initialized', 1);}});};return UserPicker;}) | |
elgg/UserPicker More... | |
define | ( | function($, elgg, Ajax){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.matchOn=data.matchOn|| 'users';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;}var ajax=new Ajax();ajax.path(UserPicker.handler,{data:{term:Autocomplete.term, match_on:UserPicker.getSearchType(), name:UserPicker.name}, method: 'GET', 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(event.isDefaultPrevented()){return;}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(){if(this.$wrapper.has('[type="checkbox"][name="match_on"]:checked').length){return $('[type="checkbox"][name=match_on]:checked', this.$wrapper).val();}return this.matchOn;}};UserPicker.setup=function(selector){$(selector).each(function(){if(!$(this).data('initialized')){new UserPicker(this);$(this).data('initialized', 1);}});};return UserPicker;} | ) |
elgg/UserPicker
function($,elgg,Ajax){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.matchOn=data.matchOn|| 'users';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;}var ajax=new Ajax();ajax.path(UserPicker.handler,{data:{term:Autocomplete.term, match_on:UserPicker.getSearchType(), name:UserPicker.name}, method: 'GET', 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(event.isDefaultPrevented()){return;}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(){if(this.$wrapper.has('[type="checkbox"][name="match_on"]:checked').length){return $('[type="checkbox"][name=match_on]:checked', this.$wrapper).val();}return this.matchOn;}};UserPicker.setup=function(selector){.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
{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
{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
{String} | selector |