芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/moodledata/localcache/js/893a0bdbf40d79f80668ab707bb2dfd79867aed5
M.core_user=M.core_user||{};M.core_user.user_selectors=[];M.core_user.get_user_selector=function(name){return this.user_selectors[name]||null};M.core_user.init_user_selector=function(Y,name,hash,extrafields,lastsearch){var user_selector={name:name,extrafields:extrafields,querydelay:0.5,searchfield:Y.one('#'+name+'_searchtext'),clearbutton:null,listbox:Y.one('#'+name),timeoutid:null,iotransactions:{},lastsearch:lastsearch,selectionempty:!0,init:function(){var searchbutton=Y.one('#'+this.name+'_searchbutton');this.searchfield.insert(Y.Node.create('
'+searchbutton.get('value')+'
'),this.searchfield);searchbutton.remove();this.searchfield.on('keyup',this.handle_keyup,this);this.listbox.on('keyup',this.handle_selection_change,this);this.listbox.on('click',this.handle_selection_change,this);this.listbox.on('change',this.handle_selection_change,this);Y.one('#userselector_searchanywhereid').on('click',this.handle_searchanywhere_change,this);this.selectionempty=this.is_selection_empty();var clearbtn=Y.one('#'+this.name+'_clearbutton');this.clearbutton=Y.Node.create('
');clearbtn.replace(Y.Node.getDOMNode(this.clearbutton));this.clearbutton.set('id',this.name+"_clearbutton");this.clearbutton.on('click',this.handle_clear,this);this.clearbutton.set('disabled',(this.get_search_text()==''));this.send_query(!1)},handle_keyup:function(e){this.cancel_timeout();this.timeoutid=Y.later(this.querydelay*1000,e,function(obj){obj.send_query(!1)},this);this.clearbutton.set('disabled',(this.get_search_text()==''));if(e.keyCode==13){e.halt()}},handle_selection_change:function(){var isselectionempty=this.is_selection_empty();if(isselectionempty!==this.selectionempty){this.fire('user_selector:selectionchanged',isselectionempty)} this.selectionempty=isselectionempty},handle_searchanywhere_change:function(){if(this.lastsearch!=''&&this.get_search_text()!=''){this.send_query(!0)}},handle_clear:function(){this.searchfield.set('value','');this.clearbutton.set('disabled',!0);this.send_query(!1)},send_query:function(forceresearch){this.cancel_timeout();var value=this.get_search_text();this.searchfield.set('class','');if(this.lastsearch==value&&!forceresearch){return} Y.Object.each(this.iotransactions,function(trans){trans.abort()});var iotrans=Y.io(M.cfg.wwwroot+'/user/selector/search.php',{method:'POST',data:'selectorid='+hash+'&sesskey='+M.cfg.sesskey+'&search='+value+'&userselector_searchanywhere='+this.get_option('searchanywhere'),on:{complete:this.handle_response},context:this});this.iotransactions[iotrans.id]=iotrans;this.lastsearch=value;this.listbox.setStyle('background','url('+M.util.image_url('i/loading','moodle')+') no-repeat center center')},handle_response:function(requestid,response){try{delete this.iotransactions[requestid];if(!Y.Object.isEmpty(this.iotransactions)){return} this.listbox.setStyle('background','');var data=Y.JSON.parse(response.responseText);if(data.error){this.searchfield.addClass('error');return new M.core.ajaxException(data)} this.output_options(data);if(typeof data.userSummaries!=="undefined"){userSummaries=data.userSummaries}}catch(e){this.listbox.setStyle('background','');this.searchfield.addClass('error');return new M.core.exception(e)}},output_options:function(data){var selectedusers={};this.listbox.all('optgroup').each(function(optgroup){optgroup.all('option').each(function(option){if(option.get('selected')){selectedusers[option.get('value')]={id:option.get('value'),name:option.get('innerText')||option.get('textContent'),disabled:option.get('disabled')}} option.remove()},this);optgroup.remove()},this);var count=0;for(var key in data.results){var groupdata=data.results[key];this.output_group(groupdata.name,groupdata.users,selectedusers,!0);count ++} if(!count){var searchstr=(this.lastsearch!='')?this.insert_search_into_str(M.util.get_string('nomatchingusers','moodle'),this.lastsearch):M.util.get_string('none','moodle');this.output_group(searchstr,{},selectedusers,!0)} if(this.get_option('preserveselected')&&selectedusers){this.output_group(this.insert_search_into_str(M.util.get_string('previouslyselectedusers','moodle'),this.lastsearch),selectedusers,!0,!1)} this.handle_selection_change()},output_group:function(groupname,users,selectedusers,processsingle){var optgroup=Y.Node.create('
');this.listbox.append(optgroup);var count=0;for(var key in users){var user=users[key];var option=Y.Node.create('
'+user.name+'
');if(user.disabled){option.setAttribute('disabled','disabled')}else if(selectedusers===!0||selectedusers[user.id]){option.setAttribute('selected','selected');delete selectedusers[user.id]} optgroup.append(option);if(user.infobelow){extraoption=Y.Node.create('
');extraoption.appendChild(document.createTextNode(user.infobelow));optgroup.append(extraoption)} count ++} if(count>0){optgroup.set('label',groupname+' ('+count+')');if(processsingle&&count===1&&this.get_option('autoselectunique')&&option.get('disabled')==!1){option.setAttribute('selected','selected')}}else{optgroup.set('label',groupname);optgroup.append(Y.Node.create('
\u00A0
'))}},insert_search_into_str:function(str,search){return str.replace("%%SEARCHTERM%%",search)},get_search_text:function(){return this.searchfield.get('value').toString().replace(/^ +| +$/,'')},is_selection_empty:function(){var selection=!1;this.listbox.all('option').each(function(){if(this.get('selected')){selection=!0}});return!(selection)},cancel_timeout:function(){if(this.timeoutid){clearTimeout(this.timeoutid);this.timeoutid=null}},get_option:function(name){var checkbox=Y.one('#userselector_'+name+'id');if(checkbox){return(checkbox.get('checked'))}else{return!1}}};Y.augment(user_selector,Y.EventTarget,null,null,{});user_selector.init();this.user_selectors[name]=user_selector;return user_selector};M.core_user.init_user_selector_options_tracker=function(Y){var user_selector_options_tracker={init:function(){var settings=['userselector_preserveselected','userselector_autoselectunique','userselector_searchanywhere'];for(var s in settings){var setting=settings[s];Y.one('#'+setting+'id').on('click',this.set_user_preference,this,setting)}},set_user_preference:function(e,name){M.util.set_user_preference(name,Y.one('#'+name+'id').get('checked'))}};user_selector_options_tracker.init();return user_selector_options_tracker}