'+M.util.get_string('actionchoice','moodle',file.name)+'';content+='';for(var i=0;i';content+='
'}
content+='
';var Y=this.Y;var self=this;var panel=new M.core.dialogue({bodyContent:content,width:'350px',modal:!0,visible:!1,render:!0,align:{node:null,points:[Y.WidgetPositionAlign.CC,Y.WidgetPositionAlign.CC]}});panel.show();panel.after("visibleChange",function(e){if(!panel.get('visible')){panel.destroy(!0);self.check_upload_queue()}});panel.addButton({label:M.util.get_string('upload','moodle'),action:function(e){e.preventDefault();var module=!1;var div=Y.one('#dndupload_handlers'+uploadid);div.all('input').each(function(input){if(input.get('checked')){module=input.get('value')}});if(!module){return}
panel.hide();self.lastselected[extension]=module;self.upload_file(file,section,sectionnumber,module)},section:Y.WidgetStdMod.FOOTER});panel.addButton({label:M.util.get_string('cancel','moodle'),action:function(e){e.preventDefault();panel.hide()},section:Y.WidgetStdMod.FOOTER})},check_upload_queue:function(){this.uploaddialog=!1;if(this.uploadqueue.length==0){return}
var details=this.uploadqueue.shift();if(details.isfile){this.file_handler_dialog(details.handlers,details.extension,details.file,details.section,details.sectionnumber)}else{this.handle_item(details.type,details.contents,details.section,details.sectionnumber)}},upload_file:function(file,section,sectionnumber,module){var xhr=new XMLHttpRequest();var self=this;if(this.maxbytes>0&&file.size>this.maxbytes){new M.core.alert({message:M.util.get_string('namedfiletoolarge','moodle',{filename:file.name})});return}
var resel=this.add_resource_element(file.name,section,module);xhr.upload.addEventListener('progress',function(e){if(e.lengthComputable){var percentage=Math.round((e.loaded*100)/e.total);resel.progress.style.width=percentage+'%'}},!1);xhr.onreadystatechange=function(){if(xhr.readyState==1){this.originalUnloadEvent=window.onbeforeunload;self.reportUploadDirtyState(!0)}
if(xhr.readyState==4){if(xhr.status==200){var result=JSON.parse(xhr.responseText);if(result){if(result.error==0){resel.li.outerHTML=result.fullcontent;if(self.Y.UA.gecko>0){resel.li.outerHTML=unescape(resel.li.outerHTML)}
self.add_editing(result.elementid);require(['core/event','jquery'],function(event,$){event.notifyFilterContentUpdated($(result.fullcontent))})}else{resel.parent.removeChild(resel.li);new M.core.alert({message:result.error})}}}else{new M.core.alert({message:M.util.get_string('servererror','moodle')})}
self.reportUploadDirtyState(!1)}};var formData=new FormData();try{formData.append('repo_upload_file',file)}catch(e){resel.parent.removeChild(resel.li);new M.core.alert({message:M.util.get_string('filereaderror','moodle',file.name)});return}
formData.append('sesskey',M.cfg.sesskey);formData.append('course',this.courseid);formData.append('section',sectionnumber);formData.append('module',module);formData.append('type','Files');var reader=new FileReader();reader.onload=function(){xhr.open("POST",self.url,!0);xhr.send(formData)};reader.onerror=function(){resel.parent.removeChild(resel.li);new M.core.alert({message:M.util.get_string('filereaderror','moodle',file.name)})};if(file.size>0){reader.readAsText(file.slice(0,5))}else{reader.readAsText(file)}},handle_item:function(type,contents,section,sectionnumber){if(type.handlers.length==0){return}
if(type.handlers.length==1&&type.handlers[0].noname){this.upload_item('',type.type,contents,section,sectionnumber,type.handlers[0].module);this.check_upload_queue();return}
if(this.uploaddialog){var details=new Object();details.isfile=!1;details.type=type;details.contents=contents;details.section=section;details.setcionnumber=sectionnumber;this.uploadqueue.push(details);return}
this.uploaddialog=!0;var timestamp=new Date().getTime();var uploadid=Math.round(Math.random()*100000)+'-'+timestamp;var nameid='dndupload_handler_name'+uploadid;var content='';if(type.handlers.length>1){content+=''+type.handlermessage+'
';content+='';var sel=type.handlers[0].module;for(var i=0;i';content+='
'}
content+='
'}
var disabled=(type.handlers[0].noname)?' disabled = "disabled" ':'';content+='';content+=' ';var Y=this.Y;var self=this;var panel=new M.core.dialogue({bodyContent:content,width:'350px',modal:!0,visible:!0,render:!0,align:{node:null,points:[Y.WidgetPositionAlign.CC,Y.WidgetPositionAlign.CC]}});panel.after("visibleChange",function(e){if(!panel.get('visible')){panel.destroy(!0);self.check_upload_queue()}});var namefield=Y.one('#'+nameid);var submit=function(e){e.preventDefault();var name=Y.Lang.trim(namefield.get('value'));var module=!1;var noname=!1;if(type.handlers.length>1){var div=Y.one('#dndupload_handlers'+uploadid);div.all('input').each(function(input){if(input.get('checked')){var idx=input.get('value');module=type.handlers[idx].module;noname=type.handlers[idx].noname}});if(!module){return}}else{module=type.handlers[0].module;noname=type.handlers[0].noname}
if(name==''&&!noname){return}
if(noname){name=''}
panel.hide();self.upload_item(name,type.type,contents,section,sectionnumber,module)};panel.addButton({label:M.util.get_string('upload','moodle'),action:submit,section:Y.WidgetStdMod.FOOTER,name:'submit'});panel.addButton({label:M.util.get_string('cancel','moodle'),action:function(e){e.preventDefault();panel.hide()},section:Y.WidgetStdMod.FOOTER});var submitbutton=panel.getButton('submit').button;namefield.on('key',submit,'enter');namefield.after('keyup',function(){if(Y.Lang.trim(namefield.get('value'))==''){submitbutton.disable()}else{submitbutton.enable()}});for(i=0;i0){resel.li.outerHTML=unescape(resel.li.outerHTML)}
self.add_editing(result.elementid)}else{resel.parent.removeChild(resel.li);new M.core.alert({message:result.error})}}}else{new M.core.alert({message:M.util.get_string('servererror','moodle')})}
self.reportUploadDirtyState(!1)}};var formData=new FormData();formData.append('contents',contents);formData.append('displayname',name);formData.append('sesskey',M.cfg.sesskey);formData.append('course',this.courseid);formData.append('section',sectionnumber);formData.append('type',type);formData.append('module',module);xhr.open("POST",this.url,!0);xhr.send(formData)},add_editing:function(elementid){var node=Y.one('#'+elementid);YUI().use('moodle-course-coursebase',function(Y){Y.log("Invoking setup_for_resource",'debug','coursedndupload');M.course.coursebase.invoke_function('setup_for_resource',node)});if(M.core.actionmenu&&M.core.actionmenu.newDOMNode){M.core.actionmenu.newDOMNode(node)}},reportUploadDirtyState:function(enable){if(!enable){window.onbeforeunload=this.originalUnloadEvent}else{window.onbeforeunload=function(e){var warningMessage=M.util.get_string('changesmadereallygoaway','moodle');if(e){e.returnValue=warningMessage}
return warningMessage}}}}