From e99376493ed18de9fb3efb72ecee2cc7d5073542 Mon Sep 17 00:00:00 2001 From: Anders Rasmussen Date: Thu, 23 Mar 2023 10:24:16 +0100 Subject: [PATCH 1/3] Updated version.php --- version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.php b/version.php index 20369d9..2c5d150 100644 --- a/version.php +++ b/version.php @@ -27,6 +27,6 @@ /** @var object $plugin */ $plugin->component = 'block_sharing_cart'; $plugin->version = 2023032300; -$plugin->requires = 2021051704; // Moodle 3.11.4 +$plugin->requires = 2022112800; // Moodle 4.1.0 $plugin->release = '4.1, release 1'; $plugin->maturity = MATURITY_STABLE; From 2cb73b3036091022d097f69abfa09af7042de310 Mon Sep 17 00:00:00 2001 From: Sven Bachmann Date: Fri, 7 Jul 2023 12:33:54 +0200 Subject: [PATCH 2/3] Return to original URL when inserting items & general code cleanup --- README.md | 2 + amd/build/script.min.js | 2 +- amd/build/script.min.js.map | 2 +- amd/src/script.js | 45 +- block_sharing_cart.php | 2 +- classes/section_title_form.php | 53 +- restore.php | 103 ++- script.js | 1236 -------------------------------- settings.php | 2 +- version.php | 6 +- 10 files changed, 92 insertions(+), 1361 deletions(-) delete mode 100644 script.js diff --git a/README.md b/README.md index 038f3ca..a660a6e 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Warning: PHP versions 7.2 and older are deprecated, and will cause problems, unr Change Log ---------- +* 4.1, release 2 2023.07.05 + * Return to original URL when inserting items & general code cleanup * 4.1, release 1 2023.03.23 * Changed section copy button design * Tested in Boost Union theme diff --git a/amd/build/script.min.js b/amd/build/script.min.js index 5a7be53..5b7c78f 100644 --- a/amd/build/script.min.js +++ b/amd/build/script.min.js @@ -5,6 +5,6 @@ * @copyright 2017 (C) VERSION2, INC. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("block_sharing_cart/script",["jquery","core/modal_factory","core/modal_events"],(function($,ModalFactory,ModalEvents){return{init:function(addMethod){$(document).ready((function(){let isDragging=!1;function str(identifier){return M.str.block_sharing_cart[identifier]||M.str.moodle[identifier]}function get_action_url(name,args){var url=M.cfg.wwwroot+"/blocks/sharing_cart/"+name+".php";if(args){var q=[];for(var k in args)q.push(k+"="+encodeURIComponent(args[k]));url+="?"+q.join("&")}return url}function remove_basket(){if("drag_and_drop"===addMethod&&!isDragging){const footerIconContainer=document.getElementById("page-footer").querySelector('div[data-region="footer-container-popover"]'),sharingCartBasket=document.querySelector("button.sharing_cart_basket");sharingCartBasket&&(null==footerIconContainer||footerIconContainer.removeChild(sharingCartBasket),sharingCartBasket.classList.remove("shake_basket"))}}function confirm_modal(obj){obj.checkbox&&(obj.body+='"),ModalFactory.create({type:ModalFactory.types.SAVE_CANCEL,title:obj.title,body:obj.body}).done((function(modal){let is_submitted=!1;modal.setSaveButtonText(obj.save_button),modal.getRoot().on(ModalEvents.save,(function(e){var response={checkbox:$(e.target).find(".modal-checkbox").is(":checked")};obj.next(response),is_submitted=!0})),modal.getRoot().on(ModalEvents.cancel,(function(){remove_basket()})),modal.getRoot().on(ModalEvents.hidden,(function(){$("body").removeClass("modal-open"),is_submitted||remove_basket()})),modal.show()}))}function in_place_edit_section_name($section){var sectionName="",$inPlaceEditable=$section.find("h3.sectionname .inplaceeditable");return $inPlaceEditable.length&&(sectionName=$inPlaceEditable.data("value")),sectionName}function on_backup_modal(post_data,title_str,body_str,isSection){$.post(get_action_url("rest"),post_data,(function(response){!function(response){var checkbox=!1;"1"===response&&(checkbox=!0),confirm_modal({title:title_str,body:body_str,save_button:str("modal_confirm_backup"),checkbox:checkbox,next:function(data){!0===isSection?function(sectionId,sectionNumber,courseId,userdata){var $commands=$("span.inplaceeditable[data-itemtype=sectionname][data-itemid="+sectionId+"]"),$section=$commands.closest("li.section.main"),sectionName=$section.attr("aria-label")||$section.find(".sectionname").text().trim();null===sectionName&&(sectionName=String($("#region-main .section_action_menu[data-sectionid='"+sectionId+"']").parent().parent().find("h3.sectionname").text()));var inPlaceEditSectionName=in_place_edit_section_name($section);sectionName=""!==inPlaceEditSectionName?inPlaceEditSectionName:sectionName;var $spinner=add_spinner(),$node_spinner=add_node_spinner($commands);$.post(get_action_url("rest"),{action:"backup_section",sectionid:sectionId,sectionnumber:sectionNumber,courseid:courseId,sectionname:sectionName,userdata:userdata,sesskey:M.cfg.sesskey},(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide(),$node_spinner.hide(),remove_basket()}))}(post_data.sectionid,post_data.sectionnumber,post_data.courseid,data.checkbox):function(cmid,userdata){var $commands=$("#module-"+cmid+" .actions");$commands.length||($commands=$('[data-owner="#module-'+cmid+'"]'));var $spinner=add_spinner(),$node_spinner=add_node_spinner($commands);$.post(get_action_url("rest"),{action:"backup",cmid:cmid,userdata:userdata,sesskey:M.cfg.sesskey,courseid:course.id},(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$node_spinner.hide(),$spinner.hide(),remove_basket()}))}(post_data.cmid,data.checkbox),function(){if("drag_and_drop"===addMethod){const sharingCartBasket=document.querySelector("button.sharing_cart_basket");null==sharingCartBasket||sharingCartBasket.classList.add("shake_basket")}}()}})}(response)}),"text").fail((function(response){show_error(response)}))}var icon={backup:{css:"editing_backup",iconClass:"fa fa-frown-o"},movedir:{css:"editing_right",iconClass:"fa fa-arrow-right"},move:{css:"editing_move_",iconClass:"fa fa-arrows-v"},edit:{css:"editing_update",iconClass:"fa fa-pencil"},cancel:{css:"editing_cancel",iconClass:"fa fa-ban"},delete:{css:"editing_update",iconClass:"fa fa-trash"},restore:{css:"editing_restore",iconClass:"fa fa-clone"},"dir-open":{iconClass:"fa fa-folder-open-o"},"dir-closed":{iconClass:"fa fa-folder-o"}},$block=$(".block_sharing_cart"),course=new function(){var body=$("body");this.id=body.attr("class").match(/course-(\d+)/)[1],this.is_frontpage=body.hasClass("pagelayout-frontpage")};function show_error(response){try{var ex=JSON.parse(response.responseText);new M.core.exception({name:str("pluginname")+" - "+str("error"),message:ex.message})}catch(e){new M.core.exception({name:str("pluginname")+" - "+str("error"),message:response.responseText})}}function create_command(name){var iconElement=$("").attr("alt",str(name)).attr("class",icon[name].iconClass);return $('').addClass(icon[name].css).attr("title",str(name)).append(iconElement)}function add_spinner(){var $spinner=$('
');return $("section.block_sharing_cart").append($spinner),$spinner}function add_node_spinner($node){var $node_spinner=$('');return $node.append($node_spinner),$node_spinner}function reload_tree(){$.post(get_action_url("rest"),{action:"render_tree",courseid:course.id},(function(response){$block.find(".tree").replaceWith($(response)),$.init_item_tree()}),"html").fail((function(response){show_error(response)}))}$(document).on("click","a.restore",(function(){add_spinner()}));var directories=new function(){var param,readCookie,KEY="block_sharing_cart-dirs",opens=(param=KEY,readCookie=document.cookie.match("(^|;)\\s*"+param+"\\s*=\\s*([^;]+)"),readCookie?readCookie.pop():"").split(",").map((function(v){return parseInt(v)}));function save(){var expires=new Date;expires.setDate(expires.getDate()+30),function(name,value,expireTimeInMillisecond){var d=new Date;d.setTime(d.getTime()+expireTimeInMillisecond);var expires="expires="+d.toUTCString();document.cookie=name+"="+value+";"+expires}(KEY,opens.join(","),expires)}function open($dir,visible){var iconElement=icon[visible?"dir-open":"dir-closed"].iconClass;$dir.find("> div i.icon").attr("class","icon "+iconElement),$dir.find("> ul.list")[visible?"show":"hide"]()}this.init=function(){var i=0;$block.find("li.directory").each((function(index,dir){var $dir=$(dir);$dir.attr("id","block_sharing_cart-dir-"+i),i>=opens.length?opens.push(0):opens[i]&&open($dir,!0),$dir.find("> div div.toggle-wrapper").css("cursor","pointer").on("click",(function(e){!function(e){var $dir=$(e.target).closest("li.directory"),i=$dir.attr("id").match(/(\d+)$/)[1],v="none"===$dir.find("> ul.list").css("display");open($dir,v),opens[i]=v?1:0,save()}(e)})),i++}))},this.reset=function(){opens=[],this.init(),save()}},move_targets=new function(){var $cancel=null,targets=[];this.hide=function(){if(null!==$cancel){var $commands=$cancel.closest(".commands");$cancel.remove(),$cancel=null,$commands.closest("li.activity").css("opacity",1),$commands.find("a").each((function(){$(this).show()})),$.each(targets,(function(index,$target){$target.remove()})),targets=[]}},this.show=function(item_id){this.hide();var $current=$block.find("#block_sharing_cart-item-"+item_id),$next=$current.next(),$list=$current.closest("ul"),next_id=0;function create_target(item_id,area_to){var $anchor=$('
').addClass("move-"+item_id+"-to-"+area_to).attr("title",str("movehere")).append($("

"+str("clicktomove")+"

").attr("alt",str("movehere"))),$target=$('
  • ').append($anchor);return $anchor.on("click",(function(e){!function(e){var m=$(e.target).closest("a").attr("class").match(/move-(\d+)-to-(\d+)/),item_id=m[1],area_to=m[2],$spinner=add_spinner();$.post(get_action_url("rest"),{action:"move",item_id:item_id,area_to:area_to,sesskey:M.cfg.sesskey},(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide()}))}(e)})),$target}if($next.length&&(next_id=$next.attr("id").match(/item-(\d+)$/)[1]),$list.find("> li.activity").each((function(index,item){var $item=$(item),to=$item.attr("id").match(/item-(\d+)$/)[1];if(to===item_id){($cancel=create_command("cancel")).on("click",(function(){move_targets.hide()}));var $commands=$item.find(".commands");$commands.find("a").each((function(){$(this).hide()})),$commands.append($cancel),$item.css("opacity",.5)}else if(to!==next_id){var $target=create_target(item_id,to);$item.before($target),targets.push($target)}}),this),$next){var $target=create_target(item_id,0);$list.append($target),targets.push($target)}}},restore_targets=new function(){this.is_directory=null;var $clipboard=null,targets=[];function create_target(id,section){var href="",inSection=$("#copy-section-form").data("in-section");href=restore_targets.is_directory?get_action_url("restore",{directory:!0,path:id,course:course.id,section:section,in_section:inSection,sesskey:M.cfg.sesskey}):get_action_url("restore",{directory:!1,id:id,course:course.id,section:section,in_section:inSection,sesskey:M.cfg.sesskey});var $target=$("").attr("class","restore").attr("href",href).attr("title",str("copyhere")).append($('').attr("alt",str("copyhere")).attr("src",M.util.image_url("dropzone_arrow","block_sharing_cart")));return targets.push($target),$target}this.hide=function(){null!==$clipboard&&($clipboard.remove(),$clipboard=null,$.each(targets,(function(index,$target){$target.remove()})),targets=[])},this.show=function(id){this.hide();var $view=$("");if(this.is_directory)$view.html(id).css("display","inline"),$view.prepend($("").addClass("icon").attr("alt",id));else{var $item=$block.find("#block_sharing_cart-item-"+id);($view=$($item.find("div")[0].cloneNode(!0)).css("display","inline")).attr("class",$view.attr("class").replace(/mod-indent-\d+/,"")),$view.find(".commands").remove()}var $cancel=create_command("cancel");if($cancel.on("click",this.hide),($clipboard=$('
    ')).append(str("clipboard")+": ").append($view).append($cancel),course.is_frontpage){var $sitetopic=$(".sitetopic"),$mainmenu=$(".block_site_main_menu");$sitetopic?$sitetopic.find("*").before($clipboard):$mainmenu&&$mainmenu.find(".content").before($clipboard),$mainmenu&&$mainmenu.find(".footer").before(create_target(id,0)),$sitetopic&&$sitetopic.find("ul.section").append(create_target(id,1))}else{var $container=$(".course-content");$container.prepend($clipboard),$container.find(M.course.format.get_section_wrapper(null)).each((function(index,sectionDOM){var $section=$(sectionDOM),section=$section.attr("id").match(/(\d+)$/)[1];$section.find("ul.section").first().append(create_target(id,section))}),this)}}};function init_footer_basket(){let currentDragging;const activities=document.querySelectorAll(".activity.activity-wrapper"),sections=document.querySelectorAll(".course-section-header"),sharingCartBlock=document.querySelector('section[data-block="sharing_cart"]');!function(){var _document$getElements;const courseSectionHeader=null!==(_document$getElements=document.getElementsByClassName("course-section-header")[0])&&void 0!==_document$getElements?_document$getElements:null;courseSectionHeader instanceof HTMLElement&&(courseSectionHeader.classList.add("draggable"),courseSectionHeader.setAttribute("draggable",!0))}();const footerIconContainer=document.getElementById("page-footer").querySelector('div[data-region="footer-container-popover"]');var basket=document.createElement("i");basket.setAttribute("class","fa fa-shopping-basket");var basketButton=document.createElement("button");basketButton.setAttribute("class","btn btn-icon bg-secondary icon-no-margin btn-footer-popover sharing_cart_basket"),basketButton.setAttribute("style","z-index: 1001;"),basketButton.append(basket);var dropAreaText=document.createElement("p");dropAreaText.setAttribute("class","font-weight-bold text-white"),dropAreaText.innerText=str("drop_here");var dropArea=document.createElement("div");function drag_event_listeners(draggable){draggable.addEventListener("dragstart",(e=>{basketButton.classList.remove("shake_basket"),null==footerIconContainer||footerIconContainer.prepend(basketButton),sharingCartBlock.children[0].classList.add("dragging_item"),sharingCartBlock.append(dropArea),currentDragging=e.target,isDragging=!0})),draggable.addEventListener("dragend",(()=>{currentDragging instanceof HTMLElement&&(null==footerIconContainer||footerIconContainer.removeChild(basketButton)),sharingCartBlock.children[0].classList.remove("dragging_item"),sharingCartBlock.removeChild(dropArea),isDragging=!1}))}dropArea.setAttribute("class","h-100 w-100 position-absolute d-flex justify-content-center align-items-center"),dropArea.append(dropAreaText),sections.forEach((section=>{drag_event_listeners(section)})),activities.forEach((activity=>{drag_event_listeners(activity)})),[basketButton,sharingCartBlock].forEach((dropzone=>{dropzone.addEventListener("dragover",(e=>{e.preventDefault(),dropzone.classList.add("drag_over")})),dropzone.addEventListener("dragenter",(e=>{e.preventDefault(),dropzone.classList.add("drag_over")})),dropzone.addEventListener("dragleave",(()=>{dropzone.classList.remove("drag_over")})),dropzone.addEventListener("drop",(()=>{currentDragging instanceof HTMLElement&¤tDragging.querySelector(".add-to-sharing-cart").click(),dropzone.classList.remove("drag_over"),currentDragging=void 0,isDragging=!1}))}))}$.get_plugin_name=function(){var $blockheader=$block.find("h2");return $blockheader.length||($blockheader=$block.find("h3")).length?$blockheader.html():""},$.on_backup=function(e,activityName){on_backup_modal({action:"is_userdata_copyable",cmid:function($backup){var $activity=$backup.closest("li.activity");if($activity.length)return $activity.attr("id").match(/(\d+)$/)[1];var $commands=$backup.closest(".commands"),dataowner=$commands.attr("data-owner");return dataowner.length?dataowner.match(/(\d+)$/)[1]:$commands.find("a.editing_delete").attr("href").match(/delete=(\d+)/)[1]}($(e.target))},activityName,str("confirm_backup"),!1)},$.on_movedir=function(e){var $commands=$(e.target).closest(".commands"),$current_dir=$commands.closest("li.directory"),current_path=$current_dir.length?$current_dir.attr("directory-path"):"/",item_id=$(e.target).closest("li.activity").attr("id").match(/(\d+)$/)[1],dirs=[];$block.find("li.directory").each((function(){dirs.push($(this).attr("directory-path"))}));var $form=$("
    ");function submit(){var folder_to=$form.find('[name="to"]').val(),$spinner=add_spinner();$.post(get_action_url("rest"),{action:"movedir",item_id:item_id,folder_to:folder_to,sesskey:M.cfg.sesskey},(function(){reload_tree(),directories.reset()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide()}))}if($form.attr("action","javascript:void(0)"),$form.submit(submit),0===dirs.length){var $input=$('').val(current_path);setTimeout((function(){$input.focus()}),1),$form.append($input)}else{dirs.unshift("/");for(var $select=$('').val(current_path);$select.remove(),$edit.replaceWith($input),$input.focus()})),$form.append($edit)}var $cancel=create_command("cancel");$cancel.on("click",(function(){$form.remove(),$commands.find("a").show()})),$form.append($cancel),$commands.find("a").each((function(){$(this).hide()})),$commands.append($form)},$.on_move=function(e){var id=$(e.target).closest("li.activity").attr("id").match(/(\d+)$/)[1];move_targets.show(id)},$.on_delete=function(e){var modalBody,item,$item=$(e.target).closest("li"),liText=$item[0].innerText,isDirectory=!1,description_text="";$item.hasClass("directory")?(isDirectory=!0,item=str("folder_string"),description_text=str("delete_folder")):item=str("activity_string"),modalBody='

    '+item+" "+liText+description_text+"

    ",confirm_modal({title:str("confirm_delete"),body:modalBody,save_button:str("modal_confirm_delete"),checkbox:!1,next:function(){var data={};!0===isDirectory?data={action:"delete_directory",path:$item.attr("directory-path"),sesskey:M.cfg.sesskey}:$item.hasClass("activity")&&(data={action:"delete",id:$item.attr("id").match(/(\d+)$/)[1],sesskey:M.cfg.sesskey});var $spinner=add_spinner();$.post(get_action_url("rest"),data,(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide()})),e.stopPropagation()}})},$.on_restore=function(e){var $item=$(e.target).closest("li"),id=null;$item.hasClass("directory")?(id=$item.attr("directory-path"),restore_targets.is_directory=!0):$item.hasClass("activity")&&(id=$item.attr("id").match(/(\d+)$/)[1],restore_targets.is_directory=!1),restore_targets.show(id)},$.on_section_backup=function(sectionId,sectionNumber,courseId,sectionName){on_backup_modal({action:"is_userdata_copyable_section",sectionid:sectionId,sectionnumber:sectionNumber,courseid:courseId},sectionName,'

    '+str("backup_heavy_load_warning_message")+"

    "+str("confirm_backup_section"),!0)},$.init_bulk_delete=function(isspeciallayout){var bulkdelete=$block.find(".editing_bulkdelete");bulkdelete.length&&(isspeciallayout?(bulkdelete.attr("role","menuitem").addClass("dropdown-item menu-action"),bulkdelete.append($("").append(bulkdelete.attr("title"))),$block.find(".menubar .dropdown .dropdown-menu").append(bulkdelete)):$block.find(".header .commands").append(bulkdelete))},$.init_help_icon=function(isspeciallayout){var helpicon=$block.find(".header-commands > .help-icon");isspeciallayout?$block.find(".header-commands").parent().css("display","block"):$block.find(".header .commands").append(helpicon)},$.init_block_header=function(){var isspeciallayout=$block.find(".menubar .dropdown .dropdown-menu").length;$.init_bulk_delete(isspeciallayout),$.init_help_icon(isspeciallayout)},$.init_item_tree=function(){function add_actions(item,actions){var $commands=$(item).find(".commands").first();$.each(actions,(function(index,action){var $command=create_command(action);$command.on("click",(function(e){$["on_"+action](e)})),$commands.append($command)}),this)}var activity_actions=["movedir","move","delete"];course&&activity_actions.push("restore");var directory_actions=["delete","restore"];$block.find("li.activity").each((function(index,item){1!=$(item).attr("data-disable-copy")?add_actions(item,activity_actions):add_actions(item,["movedir","move","delete"])})),$block.find("li.directory").each((function(index,item){add_actions(item,directory_actions)})),directories.init()},$.init_activity_commands=function(){function create_backup_icon(){var $backupIcon=$('
    ').append($('')).attr("title",str("backup"));return"click_to_add"!==addMethod&&$backupIcon.addClass("d-none"),$backupIcon}function add_activity_backup_control($activity){var activityClass=$activity[0].className,modtype=activityClass.substr(activityClass.indexOf("modtype_")+8),activityName=str("activity_string");"label"!==modtype&&(activityName=$(".activity#"+$activity[0].id).find(".mod-indent-outer .activityinstance span.instancename").html());var $backupIcon=create_backup_icon();$backupIcon.on("click",(function(e){$.on_backup(e,activityName)}));var $actionMenuItem=$activity.find(".action-menu.section-cm-edit-actions").parent(".actions");$actionMenuItem.find(".add-to-sharing-cart").length||$actionMenuItem.append($backupIcon)}$(document).ajaxComplete((function(event,xhr,settings){var url=settings.url,lastslashindex=url.lastIndexOf("="),result=url.substring(lastslashindex+1);if("core_course_edit_module"===result||"core_course_get_module"===result){var data=JSON.parse(settings.data),action=data[0].args.action;if("delete"===action)return;setTimeout((function(){var activity_id=data[0].args.id,activity=$("#module-"+activity_id);(add_activity_backup_control(activity),"duplicate"===action)&&add_activity_backup_control(activity.next())}),1)}})),$("body.editing .course-content li.section").each((function(){!function($section){var sectionId=$section.find(".section_action_menu").data("sectionid"),sectionNumber=parseInt(String($section.attr("id")).match(/\d+/)[0]),sectionName=$section.attr("aria-label")||$section.find(".sectionname").text().trim(),isFlexibleCourseFormat=$("body[id$=flexsections]").length;isFlexibleCourseFormat&&null==sectionId&&(sectionId=$section.data("section-id"));var courseId=parseInt(String($("body").attr("class")).match(/course-([0-9]*)( |$)/)[1]),$backupIcon=create_backup_icon();$backupIcon.on("click",(function(){var inPlaceEditSectionName=in_place_edit_section_name($section);sectionName=""!==inPlaceEditSectionName?inPlaceEditSectionName:sectionName,$.on_section_backup(sectionId,sectionNumber,courseId,sectionName)}));var $sectionTitle=$section.find("h3.sectionname").first().find("a").last(),$inPlaceEditable=$section.find("h3.sectionname .inplaceeditable").first();$inPlaceEditable.length&&($sectionTitle=$inPlaceEditable),isFlexibleCourseFormat&&0===sectionNumber?($sectionTitle=$section.find("> .controls")).prepend($backupIcon):$backupIcon.insertAfter($sectionTitle);var $activities=$section.find("li.activity");$($activities).each((function(){add_activity_backup_control($(this))}))}($(this))}))},$.init=function(){M.str.block_sharing_cart.pluginname=this.get_plugin_name(),$.init_block_header(),$.init_item_tree(),$.init_activity_commands(),"drag_and_drop"===addMethod&&init_footer_basket()};var $spinner=$("").addClass("spinner fa fa-3x fa-circle-o-notch fa-spin");$("div#sharing-cart-spinner-modal div.spinner-container").prepend($spinner),$.init()})),$(".copy_section").on("click",(function(){var $section_selected=$(".section-dropdown option:selected"),sectionId=$section_selected.data("section-id"),sectionNumber=$section_selected.data("section-number"),courseId=$section_selected.data("course-id"),sectionName=$section_selected.data("section-name");$.on_section_backup(sectionId,sectionNumber,courseId,sectionName)}))}}})); +define("block_sharing_cart/script",["jquery","core/modal_factory","core/modal_events"],(function($,ModalFactory,ModalEvents){return{init:function(addMethod){$(document).ready((function(){let isDragging=!1;function str(identifier){return M.str.block_sharing_cart[identifier]||M.str.moodle[identifier]}function get_action_url(name,args){var url=M.cfg.wwwroot+"/blocks/sharing_cart/"+name+".php";if(args){var q=[];for(var k in args)q.push(k+"="+encodeURIComponent(args[k]));url+="?"+q.join("&")}return url}function remove_basket(){if("drag_and_drop"===addMethod&&!isDragging){const footerIconContainer=document.getElementById("page-footer").querySelector('div[data-region="footer-container-popover"]'),sharingCartBasket=document.querySelector("button.sharing_cart_basket");sharingCartBasket&&(null==footerIconContainer||footerIconContainer.removeChild(sharingCartBasket),sharingCartBasket.classList.remove("shake_basket"))}}function confirm_modal(obj){obj.checkbox&&(obj.body+='"),ModalFactory.create({type:ModalFactory.types.SAVE_CANCEL,title:obj.title,body:obj.body}).done((function(modal){let is_submitted=!1;modal.setSaveButtonText(obj.save_button),modal.getRoot().on(ModalEvents.save,(function(e){var response={checkbox:$(e.target).find(".modal-checkbox").is(":checked")};obj.next(response),is_submitted=!0})),modal.getRoot().on(ModalEvents.cancel,(function(){remove_basket()})),modal.getRoot().on(ModalEvents.hidden,(function(){$("body").removeClass("modal-open"),is_submitted||remove_basket()})),modal.show()}))}function in_place_edit_section_name($section){var sectionName="",$inPlaceEditable=$section.find("h3.sectionname .inplaceeditable");return $inPlaceEditable.length&&(sectionName=$inPlaceEditable.data("value")),sectionName}function on_backup_modal(post_data,title_str,body_str,isSection){$.post(get_action_url("rest"),post_data,(function(response){!function(response){var checkbox=!1;"1"===response&&(checkbox=!0),confirm_modal({title:title_str,body:body_str,save_button:str("modal_confirm_backup"),checkbox:checkbox,next:function(data){!0===isSection?function(sectionId,sectionNumber,courseId,userdata){var $commands=$("span.inplaceeditable[data-itemtype=sectionname][data-itemid="+sectionId+"]"),$section=$commands.closest("li.section.main"),sectionName=$section.attr("aria-label")||$section.find(".sectionname").text().trim();null===sectionName&&(sectionName=String($("#region-main .section_action_menu[data-sectionid='"+sectionId+"']").parent().parent().find("h3.sectionname").text()));var inPlaceEditSectionName=in_place_edit_section_name($section);sectionName=""!==inPlaceEditSectionName?inPlaceEditSectionName:sectionName;var $spinner=add_spinner(),$node_spinner=add_node_spinner($commands);$.post(get_action_url("rest"),{action:"backup_section",sectionid:sectionId,sectionnumber:sectionNumber,courseid:courseId,sectionname:sectionName,userdata:userdata,sesskey:M.cfg.sesskey},(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide(),$node_spinner.hide(),remove_basket()}))}(post_data.sectionid,post_data.sectionnumber,post_data.courseid,data.checkbox):function(cmid,userdata){var $commands=$("#module-"+cmid+" .actions");$commands.length||($commands=$('[data-owner="#module-'+cmid+'"]'));var $spinner=add_spinner(),$node_spinner=add_node_spinner($commands);$.post(get_action_url("rest"),{action:"backup",cmid:cmid,userdata:userdata,sesskey:M.cfg.sesskey,courseid:course.id},(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$node_spinner.hide(),$spinner.hide(),remove_basket()}))}(post_data.cmid,data.checkbox),function(){if("drag_and_drop"===addMethod){const sharingCartBasket=document.querySelector("button.sharing_cart_basket");null==sharingCartBasket||sharingCartBasket.classList.add("shake_basket")}}()}})}(response)}),"text").fail((function(response){show_error(response)}))}var icon={backup:{css:"editing_backup",iconClass:"fa fa-frown-o"},movedir:{css:"editing_right",iconClass:"fa fa-arrow-right"},move:{css:"editing_move_",iconClass:"fa fa-arrows-v"},edit:{css:"editing_update",iconClass:"fa fa-pencil"},cancel:{css:"editing_cancel",iconClass:"fa fa-ban"},delete:{css:"editing_update",iconClass:"fa fa-trash"},restore:{css:"editing_restore",iconClass:"fa fa-clone"},"dir-open":{iconClass:"fa fa-folder-open-o"},"dir-closed":{iconClass:"fa fa-folder-o"}},$block=$(".block_sharing_cart"),course=new function(){var body=$("body");this.id=body.attr("class").match(/course-(\d+)/)[1],this.is_frontpage=body.hasClass("pagelayout-frontpage")};function show_error(response){try{var ex=JSON.parse(response.responseText);new M.core.exception({name:str("pluginname")+" - "+str("error"),message:ex.message})}catch(e){new M.core.exception({name:str("pluginname")+" - "+str("error"),message:response.responseText})}}function create_command(name){var iconElement=$("").attr("alt",str(name)).attr("class",icon[name].iconClass);return $('').addClass(icon[name].css).attr("title",str(name)).append(iconElement)}function add_spinner(){var $spinner=$('
    ');return $("section.block_sharing_cart").append($spinner),$spinner}function add_node_spinner($node){var $node_spinner=$('');return $node.append($node_spinner),$node_spinner}function reload_tree(){$.post(get_action_url("rest"),{action:"render_tree",courseid:course.id},(function(response){$block.find(".tree").replaceWith($(response)),$.init_item_tree()}),"html").fail((function(response){show_error(response)}))}$(document).on("click","a.restore",(function(){add_spinner()}));var directories=new function(){var param,readCookie,KEY="block_sharing_cart-dirs",opens=(param=KEY,readCookie=document.cookie.match("(^|;)\\s*"+param+"\\s*=\\s*([^;]+)"),readCookie?readCookie.pop():"").split(",").map((function(v){return parseInt(v)}));function save(){var expires=new Date;expires.setDate(expires.getDate()+30),function(name,value,expireTimeInMillisecond){var d=new Date;d.setTime(d.getTime()+expireTimeInMillisecond);var expires="expires="+d.toUTCString();document.cookie=name+"="+value+";"+expires}(KEY,opens.join(","),expires)}function open($dir,visible){var iconElement=icon[visible?"dir-open":"dir-closed"].iconClass;$dir.find("> div i.icon").attr("class","icon "+iconElement),$dir.find("> ul.list")[visible?"show":"hide"]()}this.init=function(){var i=0;$block.find("li.directory").each((function(index,dir){var $dir=$(dir);$dir.attr("id","block_sharing_cart-dir-"+i),i>=opens.length?opens.push(0):opens[i]&&open($dir,!0),$dir.find("> div div.toggle-wrapper").css("cursor","pointer").on("click",(function(e){!function(e){var $dir=$(e.target).closest("li.directory"),i=$dir.attr("id").match(/(\d+)$/)[1],v="none"===$dir.find("> ul.list").css("display");open($dir,v),opens[i]=v?1:0,save()}(e)})),i++}))},this.reset=function(){opens=[],this.init(),save()}},move_targets=new function(){var $cancel=null,targets=[];this.hide=function(){if(null!==$cancel){var $commands=$cancel.closest(".commands");$cancel.remove(),$cancel=null,$commands.closest("li.activity").css("opacity",1),$commands.find("a").each((function(){$(this).show()})),$.each(targets,(function(index,$target){$target.remove()})),targets=[]}},this.show=function(item_id){this.hide();var $current=$block.find("#block_sharing_cart-item-"+item_id),$next=$current.next(),$list=$current.closest("ul"),next_id=0;function create_target(item_id,area_to){var $anchor=$('
    ').addClass("move-"+item_id+"-to-"+area_to).attr("title",str("movehere")).append($("

    "+str("clicktomove")+"

    ").attr("alt",str("movehere"))),$target=$('
  • ').append($anchor);return $anchor.on("click",(function(e){!function(e){var m=$(e.target).closest("a").attr("class").match(/move-(\d+)-to-(\d+)/),item_id=m[1],area_to=m[2],$spinner=add_spinner();$.post(get_action_url("rest"),{action:"move",item_id:item_id,area_to:area_to,sesskey:M.cfg.sesskey},(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide()}))}(e)})),$target}if($next.length&&(next_id=$next.attr("id").match(/item-(\d+)$/)[1]),$list.find("> li.activity").each((function(index,item){var $item=$(item),to=$item.attr("id").match(/item-(\d+)$/)[1];if(to===item_id){($cancel=create_command("cancel")).on("click",(function(){move_targets.hide()}));var $commands=$item.find(".commands");$commands.find("a").each((function(){$(this).hide()})),$commands.append($cancel),$item.css("opacity",.5)}else if(to!==next_id){var $target=create_target(item_id,to);$item.before($target),targets.push($target)}}),this),$next){var $target=create_target(item_id,0);$list.append($target),targets.push($target)}}},restore_targets=new function(){this.is_directory=null;var $clipboard=null,targets=[];function create_target(id,section){const href=get_action_url("restore",{directory:!0===restore_targets.is_directory,target:id,course:course.id,section:section,in_section:$("#copy-section-form").data("in-section"),sesskey:M.cfg.sesskey,returnurl:document.URL});let $target=$("").attr("href",href).attr("title",str("copyhere")).append($('').attr("alt",str("copyhere")).attr("src",M.util.image_url("dropzone_arrow","block_sharing_cart")));return targets.push($target),$target}this.hide=function(){null!==$clipboard&&($clipboard.remove(),$clipboard=null,$.each(targets,(function(index,$target){$target.remove()})),targets=[])},this.show=function(id){this.hide();var $view=$("");if(this.is_directory)$view.html(id).css("display","inline"),$view.prepend($("").addClass("icon").attr("alt",id));else{var $item=$block.find("#block_sharing_cart-item-"+id);($view=$($item.find("div")[0].cloneNode(!0)).css("display","inline")).attr("class",$view.attr("class").replace(/mod-indent-\d+/,"")),$view.find(".commands").remove()}var $cancel=create_command("cancel");if($cancel.on("click",this.hide),($clipboard=$('
    ')).append(str("clipboard")+": ").append($view).append($cancel),course.is_frontpage){var $sitetopic=$(".sitetopic"),$mainmenu=$(".block_site_main_menu");$sitetopic?$sitetopic.find("*").before($clipboard):$mainmenu&&$mainmenu.find(".content").before($clipboard),$mainmenu&&$mainmenu.find(".footer").before(create_target(id,0)),$sitetopic&&$sitetopic.find("ul.section").append(create_target(id,1))}else{var $container=$(".course-content");$container.prepend($clipboard),$container.find(M.course.format.get_section_wrapper(null)).each((function(index,sectionDOM){var $section=$(sectionDOM),section=$section.attr("id").match(/(\d+)$/)[1];$section.find("ul.section").first().append(create_target(id,section))}),this)}}};function init_footer_basket(){let currentDragging;const activities=document.querySelectorAll(".activity.activity-wrapper"),sections=document.querySelectorAll(".course-section-header"),sharingCartBlock=document.querySelector('section[data-block="sharing_cart"]');!function(){var _document$getElements;const courseSectionHeader=null!==(_document$getElements=document.getElementsByClassName("course-section-header")[0])&&void 0!==_document$getElements?_document$getElements:null;courseSectionHeader instanceof HTMLElement&&(courseSectionHeader.classList.add("draggable"),courseSectionHeader.setAttribute("draggable",!0))}();const footerIconContainer=document.getElementById("page-footer").querySelector('div[data-region="footer-container-popover"]');var basket=document.createElement("i");basket.setAttribute("class","fa fa-shopping-basket");var basketButton=document.createElement("button");basketButton.setAttribute("class","btn btn-icon bg-secondary icon-no-margin btn-footer-popover sharing_cart_basket"),basketButton.setAttribute("style","z-index: 1001;"),basketButton.append(basket);var dropAreaText=document.createElement("p");dropAreaText.setAttribute("class","font-weight-bold text-white"),dropAreaText.innerText=str("drop_here");var dropArea=document.createElement("div");function drag_event_listeners(draggable){draggable.addEventListener("dragstart",(e=>{basketButton.classList.remove("shake_basket"),null==footerIconContainer||footerIconContainer.prepend(basketButton),sharingCartBlock.children[0].classList.add("dragging_item"),sharingCartBlock.append(dropArea),currentDragging=e.target,isDragging=!0})),draggable.addEventListener("dragend",(()=>{currentDragging instanceof HTMLElement&&(null==footerIconContainer||footerIconContainer.removeChild(basketButton)),sharingCartBlock.children[0].classList.remove("dragging_item"),sharingCartBlock.removeChild(dropArea),isDragging=!1}))}dropArea.setAttribute("class","h-100 w-100 position-absolute d-flex justify-content-center align-items-center"),dropArea.append(dropAreaText),sections.forEach((section=>{drag_event_listeners(section)})),activities.forEach((activity=>{drag_event_listeners(activity)})),[basketButton,sharingCartBlock].forEach((dropzone=>{dropzone.addEventListener("dragover",(e=>{e.preventDefault(),dropzone.classList.add("drag_over")})),dropzone.addEventListener("dragenter",(e=>{e.preventDefault(),dropzone.classList.add("drag_over")})),dropzone.addEventListener("dragleave",(()=>{dropzone.classList.remove("drag_over")})),dropzone.addEventListener("drop",(()=>{currentDragging instanceof HTMLElement&¤tDragging.querySelector(".add-to-sharing-cart").click(),dropzone.classList.remove("drag_over"),currentDragging=void 0,isDragging=!1}))}))}$.get_plugin_name=function(){var $blockheader=$block.find("h2");return $blockheader.length||($blockheader=$block.find("h3")).length?$blockheader.html():""},$.on_backup=function(e,activityName){on_backup_modal({action:"is_userdata_copyable",cmid:function($backup){var $activity=$backup.closest("li.activity");if($activity.length)return $activity.attr("id").match(/(\d+)$/)[1];var $commands=$backup.closest(".commands"),dataowner=$commands.attr("data-owner");return dataowner.length?dataowner.match(/(\d+)$/)[1]:$commands.find("a.editing_delete").attr("href").match(/delete=(\d+)/)[1]}($(e.target))},activityName,str("confirm_backup"),!1)},$.on_movedir=function(e){var $commands=$(e.target).closest(".commands"),$current_dir=$commands.closest("li.directory"),current_path=$current_dir.length?$current_dir.attr("directory-path"):"/",item_id=$(e.target).closest("li.activity").attr("id").match(/(\d+)$/)[1],dirs=[];$block.find("li.directory").each((function(){dirs.push($(this).attr("directory-path"))}));var $form=$("");function submit(){var folder_to=$form.find('[name="to"]').val(),$spinner=add_spinner();$.post(get_action_url("rest"),{action:"movedir",item_id:item_id,folder_to:folder_to,sesskey:M.cfg.sesskey},(function(){reload_tree(),directories.reset()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide()}))}if($form.attr("action","javascript:void(0)"),$form.submit(submit),0===dirs.length){var $input=$('').val(current_path);setTimeout((function(){$input.focus()}),1),$form.append($input)}else{dirs.unshift("/");for(var $select=$('').val(current_path);$select.remove(),$edit.replaceWith($input),$input.focus()})),$form.append($edit)}var $cancel=create_command("cancel");$cancel.on("click",(function(){$form.remove(),$commands.find("a").show()})),$form.append($cancel),$commands.find("a").each((function(){$(this).hide()})),$commands.append($form)},$.on_move=function(e){var id=$(e.target).closest("li.activity").attr("id").match(/(\d+)$/)[1];move_targets.show(id)},$.on_delete=function(e){var modalBody,item,$item=$(e.target).closest("li"),liText=$item[0].innerText,isDirectory=!1,description_text="";$item.hasClass("directory")?(isDirectory=!0,item=str("folder_string"),description_text=str("delete_folder")):item=str("activity_string"),modalBody='

    '+item+" "+liText+description_text+"

    ",confirm_modal({title:str("confirm_delete"),body:modalBody,save_button:str("modal_confirm_delete"),checkbox:!1,next:function(){var data={};!0===isDirectory?data={action:"delete_directory",path:$item.attr("directory-path"),sesskey:M.cfg.sesskey}:$item.hasClass("activity")&&(data={action:"delete",id:$item.attr("id").match(/(\d+)$/)[1],sesskey:M.cfg.sesskey});var $spinner=add_spinner();$.post(get_action_url("rest"),data,(function(){reload_tree()})).fail((function(response){show_error(response)})).always((function(){$spinner.hide()})),e.stopPropagation()}})},$.on_restore=function(e){var $item=$(e.target).closest("li"),id=null;$item.hasClass("directory")?(id=$item.attr("directory-path"),restore_targets.is_directory=!0):$item.hasClass("activity")&&(id=$item.attr("id").match(/(\d+)$/)[1],restore_targets.is_directory=!1),restore_targets.show(id)},$.on_section_backup=function(sectionId,sectionNumber,courseId,sectionName){on_backup_modal({action:"is_userdata_copyable_section",sectionid:sectionId,sectionnumber:sectionNumber,courseid:courseId},sectionName,'

    '+str("backup_heavy_load_warning_message")+"

    "+str("confirm_backup_section"),!0)},$.init_bulk_delete=function(isspeciallayout){var bulkdelete=$block.find(".editing_bulkdelete");bulkdelete.length&&(isspeciallayout?(bulkdelete.attr("role","menuitem").addClass("dropdown-item menu-action"),bulkdelete.append($("").append(bulkdelete.attr("title"))),$block.find(".menubar .dropdown .dropdown-menu").append(bulkdelete)):$block.find(".header .commands").append(bulkdelete))},$.init_help_icon=function(isspeciallayout){var helpicon=$block.find(".header-commands > .help-icon");isspeciallayout?$block.find(".header-commands").parent().css("display","block"):$block.find(".header .commands").append(helpicon)},$.init_block_header=function(){var isspeciallayout=$block.find(".menubar .dropdown .dropdown-menu").length;$.init_bulk_delete(isspeciallayout),$.init_help_icon(isspeciallayout)},$.init_item_tree=function(){function add_actions(item,actions){var $commands=$(item).find(".commands").first();$.each(actions,(function(index,action){var $command=create_command(action);$command.on("click",(function(e){$["on_"+action](e)})),$commands.append($command)}),this)}var activity_actions=["movedir","move","delete"];course&&activity_actions.push("restore");var directory_actions=["delete","restore"];$block.find("li.activity").each((function(index,item){1!=$(item).attr("data-disable-copy")?add_actions(item,activity_actions):add_actions(item,["movedir","move","delete"])})),$block.find("li.directory").each((function(index,item){add_actions(item,directory_actions)})),directories.init()},$.init_activity_commands=function(){function create_backup_icon(){var $backupIcon=$('
    ').append($('')).attr("title",str("backup"));return"click_to_add"!==addMethod&&$backupIcon.addClass("d-none"),$backupIcon}function add_activity_backup_control($activity){var activityClass=$activity[0].className,modtype=activityClass.substr(activityClass.indexOf("modtype_")+8),activityName=str("activity_string");"label"!==modtype&&(activityName=$(".activity#"+$activity[0].id).find(".mod-indent-outer .activityinstance span.instancename").html());var $backupIcon=create_backup_icon();$backupIcon.on("click",(function(e){$.on_backup(e,activityName)}));var $actionMenuItem=$activity.find(".action-menu.section-cm-edit-actions").parent(".actions");$actionMenuItem.find(".add-to-sharing-cart").length||$actionMenuItem.append($backupIcon)}$(document).ajaxComplete((function(event,xhr,settings){var url=settings.url,lastslashindex=url.lastIndexOf("="),result=url.substring(lastslashindex+1);if("core_course_edit_module"===result||"core_course_get_module"===result){var data=JSON.parse(settings.data),action=data[0].args.action;if("delete"===action)return;setTimeout((function(){var activity_id=data[0].args.id,activity=$("#module-"+activity_id);(add_activity_backup_control(activity),"duplicate"===action)&&add_activity_backup_control(activity.next())}),1)}})),$("body.editing .course-content li.section").each((function(){!function($section){var sectionId=$section.find(".section_action_menu").data("sectionid"),sectionNumber=parseInt(String($section.attr("id")).match(/\d+/)[0]),sectionName=$section.attr("aria-label")||$section.find(".sectionname").text().trim(),isFlexibleCourseFormat=$("body[id$=flexsections]").length;isFlexibleCourseFormat&&null==sectionId&&(sectionId=$section.data("section-id"));var courseId=parseInt(String($("body").attr("class")).match(/course-([0-9]*)( |$)/)[1]),$backupIcon=create_backup_icon();$backupIcon.on("click",(function(){var inPlaceEditSectionName=in_place_edit_section_name($section);sectionName=""!==inPlaceEditSectionName?inPlaceEditSectionName:sectionName,$.on_section_backup(sectionId,sectionNumber,courseId,sectionName)}));var $sectionTitle=$section.find("h3.sectionname").first().find("a").last(),$inPlaceEditable=$section.find("h3.sectionname .inplaceeditable").first();$inPlaceEditable.length&&($sectionTitle=$inPlaceEditable),isFlexibleCourseFormat&&0===sectionNumber?($sectionTitle=$section.find("> .controls")).prepend($backupIcon):$backupIcon.insertAfter($sectionTitle);var $activities=$section.find("li.activity");$($activities).each((function(){add_activity_backup_control($(this))}))}($(this))}))},$.init=function(){M.str.block_sharing_cart.pluginname=this.get_plugin_name(),$.init_block_header(),$.init_item_tree(),$.init_activity_commands(),"drag_and_drop"===addMethod&&init_footer_basket()};var $spinner=$("").addClass("spinner fa fa-3x fa-circle-o-notch fa-spin");$("div#sharing-cart-spinner-modal div.spinner-container").prepend($spinner),$.init()})),$(".copy_section").on("click",(function(){var $section_selected=$(".section-dropdown option:selected"),sectionId=$section_selected.data("section-id"),sectionNumber=$section_selected.data("section-number"),courseId=$section_selected.data("course-id"),sectionName=$section_selected.data("section-name");$.on_section_backup(sectionId,sectionNumber,courseId,sectionName)}))}}})); //# sourceMappingURL=script.min.js.map \ No newline at end of file diff --git a/amd/build/script.min.js.map b/amd/build/script.min.js.map index c21cefd..29db447 100644 --- a/amd/build/script.min.js.map +++ b/amd/build/script.min.js.map @@ -1 +1 @@ -{"version":3,"file":"script.min.js","sources":["../src/script.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Sharing Cart\n *\n * @package block_sharing_cart\n * @copyright 2017 (C) VERSION2, INC.\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/modal_factory', 'core/modal_events'], function($, ModalFactory, ModalEvents) {\n return {\n init: function(addMethod) {\n\n $(document).ready(function() {\n let isDragging = false;\n\n /**\n * Returns a localized string\n *\n * @param {String} identifier\n * @return {String}\n */\n function str(identifier) {\n return M.str.block_sharing_cart[identifier] || M.str.moodle[identifier];\n }\n\n /**\n * Get an action URL\n *\n * @param {String} name The action name\n * @param {Object} [args] The action parameters\n * @return {String}\n */\n function get_action_url(name, args) {\n var url = M.cfg.wwwroot + '/blocks/sharing_cart/' + name + '.php';\n if (args) {\n var q = [];\n for (var k in args) {\n q.push(k + '=' + encodeURIComponent(args[k]));\n }\n url += '?' + q.join('&');\n }\n return url;\n }\n\n /**\n * Shake the basket to indicate cancel/submit\n */\n function shake_basket() {\n if (addMethod === 'drag_and_drop') {\n const sharingCartBasket = document.querySelector('button.sharing_cart_basket');\n sharingCartBasket?.classList.add('shake_basket');\n }\n }\n\n /**\n * Remove the shake effect and basket icon\n */\n function remove_basket() {\n if (addMethod === 'drag_and_drop' && !isDragging) {\n const footer = document.getElementById('page-footer');\n const footerIconContainer = footer.querySelector('div[data-region=\"footer-container-popover\"]');\n const sharingCartBasket = document.querySelector('button.sharing_cart_basket');\n\n if (sharingCartBasket) {\n footerIconContainer?.removeChild(sharingCartBasket);\n sharingCartBasket.classList.remove('shake_basket');\n }\n }\n }\n\n /**\n * Modal called when confirming an action.\n *\n * @param obj\n */\n function confirm_modal(obj) {\n\n // Checkbox for copying userdata confirmation.\n if (obj.checkbox) {\n obj.body +=\n '
    ' +\n '' +\n '' +\n '
    ';\n }\n\n\n ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: obj.title,\n body: obj.body,\n }).done(function(modal) {\n let is_submitted = false;\n modal.setSaveButtonText(obj.save_button);\n\n // On save save check - if checkbox is checked.\n modal.getRoot().on(ModalEvents.save, function(e) {\n\n var response = {\n 'checkbox': $(e.target).find('.modal-checkbox').is(':checked'),\n };\n\n obj.next(response);\n is_submitted = true;\n });\n\n modal.getRoot().on(ModalEvents.cancel, function() {\n remove_basket();\n });\n\n // Remove modal from html.\n modal.getRoot().on(ModalEvents.hidden, function() {\n $('body').removeClass('modal-open');\n\n if (!is_submitted) {\n remove_basket();\n }\n });\n\n modal.show();\n });\n }\n\n /**\n * Get the section name from the section when\n * it's changed with the in place editor\n *\n * @param $section\n * @returns {*}\n */\n function in_place_edit_section_name($section) {\n var sectionName = '';\n var $inPlaceEditable = $section.find('h3.sectionname .inplaceeditable');\n if ($inPlaceEditable.length) {\n sectionName = $inPlaceEditable.data('value');\n }\n return sectionName;\n }\n\n /**\n * @param post_data\n * @param title_str\n * @param body_str\n * @param isSection\n */\n function on_backup_modal(post_data, title_str, body_str, isSection) {\n (function(on_success) {\n $.post(get_action_url('rest'), post_data,\n function(response) {\n on_success(response);\n }, \"text\")\n .fail(function(response) {\n show_error(response);\n });\n })(function(response) {\n var copyable = response === '1';\n var checkbox = false;\n\n if (copyable) {\n checkbox = true;\n }\n\n confirm_modal({\n 'title': title_str,\n 'body': body_str,\n 'save_button': str('modal_confirm_backup'),\n 'checkbox': checkbox,\n 'next': function(data) {\n if (isSection === true) {\n backup_section(post_data.sectionid, post_data.sectionnumber, post_data.courseid, data.checkbox);\n } else {\n backup(post_data.cmid, data.checkbox);\n }\n\n shake_basket();\n }\n });\n });\n }\n\n /** @var {Object} The icon configurations */\n var icon = {\n // Actions\n 'backup': {\n css: 'editing_backup',\n iconClass: 'fa fa-frown-o',\n },\n 'movedir': {\n css: 'editing_right',\n iconClass: 'fa fa-arrow-right',\n },\n 'move': {\n css: 'editing_move_',\n iconClass: 'fa fa-arrows-v',\n },\n 'edit': {\n css: 'editing_update',\n iconClass: 'fa fa-pencil',\n },\n 'cancel': {\n css: 'editing_cancel',\n iconClass: 'fa fa-ban',\n },\n 'delete': {\n css: 'editing_update',\n iconClass: 'fa fa-trash',\n },\n 'restore': {\n css: 'editing_restore',\n iconClass: 'fa fa-clone',\n },\n // Directories\n 'dir-open': {\n iconClass: 'fa fa-folder-open-o'\n },\n 'dir-closed': {\n iconClass: 'fa fa-folder-o'\n },\n };\n\n /** @var {Node} The Sharing Cart block container node */\n var $block = $('.block_sharing_cart');\n\n /** @var {Object} The current course */\n var course = new function() {\n var body = $('body');\n this.id = body.attr('class').match(/course-(\\d+)/)[1];\n this.is_frontpage = body.hasClass('pagelayout-frontpage');\n }();\n\n /**\n * Shows an error message with given Ajax error\n *\n * @param {Object} response The Ajax response\n */\n function show_error(response) {\n try {\n var ex = JSON.parse(response.responseText);\n new M.core.exception({\n name: str('pluginname') + ' - ' + str('error'),\n message: ex.message\n });\n } catch (e) {\n new M.core.exception({\n name: str('pluginname') + ' - ' + str('error'),\n message: response.responseText\n });\n }\n }\n\n /**\n * Check special layout (theme boost)\n *\n * @return {Boolean}\n */\n function verify_layout() {\n var menuelement = $block.find('.menubar .dropdown .dropdown-menu');\n return (menuelement.length);\n }\n\n /**\n * Set Cookie\n * @param name\n * @param value\n * @param expireTimeInMillisecond\n */\n function setCookie(name, value, expireTimeInMillisecond) {\n var d = new Date();\n d.setTime(d.getTime() + expireTimeInMillisecond);\n var expires = 'expires=' + d.toUTCString();\n document.cookie = name + '=' + value + ';' + expires + '';\n }\n\n /**\n * Get Cookie Value\n * @param param\n * @returns {*}\n */\n function getCookieValue(param) {\n var readCookie = document.cookie.match('(^|;)\\\\s*' + param + '\\\\s*=\\\\s*([^;]+)');\n return readCookie ? readCookie.pop() : '';\n }\n\n /**\n * Create a command icon\n *\n * @param {String} name The command name, predefined in icon\n * @param {String} [pix] The icon pix name to override\n */\n function create_command(name) {\n var iconElement = $('')\n .attr('alt', str(name))\n .attr('class', icon[name].iconClass);\n // If (verify_layout()) {\n // iconElement.addClass('iconcustom');\n // }\n\n return $('
    ')\n .addClass(icon[name].css)\n .attr('title', str(name))\n .append(iconElement);\n }\n\n /**\n * Create a spinner\n * @param $node\n * @returns {*|jQuery}\n */\n function add_spinner() {\n var $spinner = ($('
    '));\n $('section.block_sharing_cart').append($spinner);\n return $spinner;\n }\n\n /**\n *\n * @param $node\n * @returns {jQuery.fn.init}\n */\n function add_node_spinner($node) {\n var $node_spinner = $('');\n $node.append($node_spinner);\n return $node_spinner;\n }\n\n $(document).on('click', 'a.restore', function() {\n add_spinner();\n });\n\n /**\n *\n * Reload the Sharing Cart item tree\n */\n function reload_tree() {\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"render_tree\",\n \"courseid\": course.id\n },\n function(response) {\n $block.find(\".tree\").replaceWith($(response));\n $.init_item_tree();\n }, \"html\")\n .fail(function(response) {\n show_error(response);\n });\n }\n\n /**\n * Backup an activity\n *\n * @param {int} cmid\n * @param {Boolean} userdata\n */\n function backup(cmid, userdata) {\n var $commands = $('#module-' + cmid + ' .actions');\n if (!$commands.length) {\n $commands = $('[data-owner=\"#module-' + cmid + '\"]');\n }\n\n var $spinner = add_spinner();\n var $node_spinner = add_node_spinner($commands);\n\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"backup\",\n \"cmid\": cmid,\n \"userdata\": userdata,\n \"sesskey\": M.cfg.sesskey,\n \"courseid\": course.id\n },\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $node_spinner.hide();\n $spinner.hide();\n remove_basket();\n });\n }\n\n /**\n * Backup an activities in a section\n *\n * @param {int} sectionId\n * @param {int} sectionNumber\n * @param {int} courseId\n * @param {Boolean} userdata\n */\n function backup_section(sectionId, sectionNumber, courseId, userdata) {\n var $commands = $('span.inplaceeditable[data-itemtype=sectionname][data-itemid=' + sectionId + ']');\n var $section = $commands.closest(\"li.section.main\");\n var sectionName = $section.attr('aria-label') || $section.find('.sectionname').text().trim();\n\n if (sectionName === null) {\n sectionName = String($('#region-main .section_action_menu[data-sectionid=\\'' + sectionId + '\\']')\n .parent().parent().find('h3.sectionname').text());\n }\n\n var inPlaceEditSectionName = in_place_edit_section_name($section);\n sectionName = (inPlaceEditSectionName !== '') ? inPlaceEditSectionName : sectionName;\n\n var $spinner = add_spinner();\n var $node_spinner = add_node_spinner($commands);\n\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"backup_section\",\n \"sectionid\": sectionId,\n \"sectionnumber\": sectionNumber,\n \"courseid\": courseId,\n \"sectionname\": sectionName,\n \"userdata\": userdata,\n \"sesskey\": M.cfg.sesskey\n },\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n $node_spinner.hide();\n remove_basket();\n });\n }\n\n\n // /////// CLASSES /////////\n\n /**\n * @class Directory states manager\n */\n var directories = new function() {\n var KEY = 'block_sharing_cart-dirs';\n\n var opens = getCookieValue(KEY).split(',').map(function(v) {\n return parseInt(v);\n });\n\n function save() {\n var expires = new Date();\n expires.setDate(expires.getDate() + 30);\n setCookie(KEY, opens.join(','), expires);\n }\n\n function open($dir, visible) {\n var iconIndex = visible ? 'dir-open' : 'dir-closed';\n var iconElement = icon[iconIndex].iconClass;\n $dir.find('> div i.icon').attr('class', 'icon ' + iconElement);\n $dir.find('> ul.list')[visible ? 'show' : 'hide']();\n }\n\n function toggle(e) {\n var $dir = $(e.target).closest('li.directory');\n var i = $dir.attr('id').match(/(\\d+)$/)[1];\n var v = $dir.find('> ul.list').css('display') === 'none';\n\n open($dir, v);\n opens[i] = v ? 1 : 0;\n save();\n }\n\n /**\n * Initialize directory states\n */\n this.init = function() {\n var i = 0;\n $block.find('li.directory').each(function(index, dir) {\n var $dir = $(dir);\n $dir.attr('id', 'block_sharing_cart-dir-' + i);\n if (i >= opens.length) {\n opens.push(0);\n } else if (opens[i]) {\n open($dir, true);\n }\n $dir.find('> div div.toggle-wrapper').css('cursor', 'pointer').on('click', function(e) {\n toggle(e);\n });\n i++;\n });\n };\n\n /**\n * Reset directory states\n */\n this.reset = function() {\n opens = [];\n this.init();\n save();\n };\n }();\n\n /**\n * @class Targets for moving an item directory\n */\n var move_targets = new function() {\n var $cancel = null,\n targets = [];\n\n /**\n * Hide move targets\n */\n this.hide = function() {\n if ($cancel !== null) {\n var $commands = $cancel.closest('.commands');\n $cancel.remove();\n $cancel = null;\n $commands.closest('li.activity').css('opacity', 1.0);\n $commands.find('a').each(function() {\n $(this).show();\n });\n $.each(targets, function(index, $target) {\n $target.remove();\n });\n targets = [];\n }\n };\n\n /**\n * Show move targets for a given item\n *\n * @param {int} id The item ID\n */\n this.show = function(item_id) {\n this.hide();\n\n function move(e) {\n\n var m = $(e.target).closest('a').attr('class').match(/move-(\\d+)-to-(\\d+)/);\n var item_id = m[1],\n area_to = m[2];\n\n var $spinner = add_spinner();\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"move\",\n \"item_id\": item_id,\n \"area_to\": area_to,\n \"sesskey\": M.cfg.sesskey\n },\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n });\n }\n\n var $current = $block.find('#block_sharing_cart-item-' + item_id);\n var $next = $current.next();\n var $list = $current.closest('ul');\n\n var next_id = 0;\n if ($next.length) {\n next_id = $next.attr('id').match(/item-(\\d+)$/)[1];\n }\n\n /**\n *\n * @param item_id\n * @param area_to\n * @returns {jQuery}\n */\n function create_target(item_id, area_to) {\n var $anchor = $('
    ')\n .addClass('move-' + item_id + '-to-' + area_to)\n .attr('title', str('movehere'))\n .append(\n $('

    ' + str('clicktomove') + '

    ')\n .attr('alt', str('movehere'))\n );\n\n var $target = $('
  • ')\n .append($anchor);\n $anchor.on('click', function(e) {\n move(e);\n });\n\n return $target;\n }\n\n $list.find('> li.activity').each(function(index, item) {\n var $item = $(item);\n var to = $item.attr('id').match(/item-(\\d+)$/)[1];\n if (to === item_id) {\n $cancel = create_command('cancel', 't/left');\n $cancel.on('click', function() {\n move_targets.hide();\n });\n var $commands = $item.find('.commands');\n $commands.find('a').each(function() {\n $(this).hide();\n });\n $commands.append($cancel);\n $item.css('opacity', 0.5);\n } else if (to !== next_id) {\n var $target = create_target(item_id, to);\n $item.before($target);\n targets.push($target);\n }\n }, this);\n\n if ($next) {\n var $target = create_target(item_id, 0);\n $list.append($target);\n targets.push($target);\n }\n };\n }();\n\n /**\n * @class Targets for restoring an item\n */\n\n var restore_targets = new function() {\n this.is_directory = null;\n var $clipboard = null,\n targets = [];\n\n /**\n *\n * @param id\n * @param section\n * @returns {jQuery}\n */\n\n\n function create_target(id, section) {\n var href = '';\n\n var inSection = $('#copy-section-form').data('in-section');\n if (restore_targets.is_directory) {\n href = get_action_url('restore', {\n 'directory': true,\n 'path': id,\n 'course': course.id,\n 'section': section,\n 'in_section': inSection,\n 'sesskey': M.cfg.sesskey\n });\n } else {\n href = get_action_url('restore', {\n 'directory': false,\n 'id': id,\n 'course': course.id,\n 'section': section,\n 'in_section': inSection,\n 'sesskey': M.cfg.sesskey\n });\n }\n\n var $target = $('')\n .attr('class', 'restore')\n .attr('href', href)\n .attr('title', str('copyhere'))\n .append(\n $('')\n .attr('alt', str('copyhere'))\n .attr('src', M.util.image_url('dropzone_arrow', 'block_sharing_cart'))\n );\n\n targets.push($target);\n return $target;\n }\n\n /**\n * Hide restore targets\n */\n this.hide = function() {\n if ($clipboard !== null) {\n $clipboard.remove();\n $clipboard = null;\n $.each(targets, function(index, $target) {\n $target.remove();\n });\n targets = [];\n }\n };\n\n /**\n *\n *\n * @param {int} id The item ID\n */\n this.show = function(id) {\n this.hide();\n\n var $view = $(\"\");\n\n if (this.is_directory) {\n $view.html(id).css('display', 'inline');\n $view.prepend(\n $(\"\").addClass(\"icon\")\n .attr(\"alt\", id)\n // .attr(\"src\", M.util.image_url(icon['dir-closed'].pix, null))\n );\n } else {\n var $item = $block.find('#block_sharing_cart-item-' + id);\n $view = $($item.find('div')[0].cloneNode(true)).css('display', 'inline');\n $view.attr('class', $view.attr('class').replace(/mod-indent-\\d+/, ''));\n $view.find('.commands').remove();\n }\n\n var $cancel = create_command('cancel');\n\n $cancel.on('click', this.hide);\n\n $clipboard = $('
    ');\n $clipboard.append(str('clipboard') + \": \").append($view).append($cancel);\n\n if (course.is_frontpage) {\n var $sitetopic = $('.sitetopic');\n var $mainmenu = $('.block_site_main_menu');\n if ($sitetopic) {\n $sitetopic.find('*').before($clipboard);\n } else if ($mainmenu) {\n $mainmenu.find('.content').before($clipboard);\n }\n\n // Mainmenu = section #0, sitetopic = section #1\n if ($mainmenu) {\n $mainmenu.find('.footer').before(create_target(id, 0));\n }\n if ($sitetopic) {\n $sitetopic.find('ul.section').append(create_target(id, 1));\n }\n } else {\n var $container = $('.course-content');\n $container.prepend($clipboard);\n $container.find(M.course.format.get_section_wrapper(null)).each(function(index, sectionDOM) {\n var $section = $(sectionDOM);\n var section = $section.attr('id').match(/(\\d+)$/)[1];\n $section.find('ul.section').first().append(create_target(id, section));\n }, this);\n }\n };\n }();\n\n // /////// INITIALIZATION /////////\n\n /**\n *\n * @returns {string|*}\n */\n $.get_plugin_name = function() {\n var $blockheader = $block.find(\"h2\");\n\n if (!$blockheader.length) {\n $blockheader = $block.find(\"h3\");\n\n if ($blockheader.length) {\n return $blockheader.html();\n }\n } else {\n return $blockheader.html();\n }\n\n return \"\";\n };\n\n /**\n *\n * @param e\n * @param activityName\n */\n $.on_backup = function(e, activityName) {\n var cmid = (function($backup) {\n var $activity = $backup.closest('li.activity');\n if ($activity.length) {\n return $activity.attr('id').match(/(\\d+)$/)[1];\n }\n var $commands = $backup.closest('.commands');\n var dataowner = $commands.attr('data-owner');\n if (dataowner.length) {\n return dataowner.match(/(\\d+)$/)[1];\n }\n return $commands.find('a.editing_delete').attr('href').match(/delete=(\\d+)/)[1];\n })($(e.target));\n\n var data =\n {\n \"action\": \"is_userdata_copyable\",\n \"cmid\": cmid\n };\n\n on_backup_modal(data, activityName, str('confirm_backup'), false);\n };\n\n /**\n * On movedir command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_movedir = function(e) {\n var $commands = $(e.target).closest('.commands');\n\n var $current_dir = $commands.closest('li.directory');\n var current_path = $current_dir.length ? $current_dir.attr('directory-path') : '/';\n\n var item_id = $(e.target).closest('li.activity').attr('id').match(/(\\d+)$/)[1];\n\n var dirs = [];\n $block.find('li.directory').each(function() {\n dirs.push($(this).attr('directory-path'));\n });\n\n var $form = $('');\n // eslint-disable-next-line no-script-url\n $form.attr('action', 'javascript:void(0)');\n\n function submit() {\n var folder_to = $form.find('[name=\"to\"]').val();\n var $spinner = add_spinner();\n $.post(get_action_url('rest'),\n {\n \"action\": \"movedir\",\n \"item_id\": item_id,\n \"folder_to\": folder_to,\n \"sesskey\": M.cfg.sesskey\n },\n function() {\n reload_tree();\n directories.reset();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n });\n }\n\n $form.submit(submit);\n\n if (dirs.length === 0) {\n var $input = $('').val(current_path);\n setTimeout(function() {\n $input.focus();\n }, 1);\n $form.append($input);\n } else {\n dirs.unshift('/');\n\n var $select = $('').val(current_path);\n $select.remove();\n $edit.replaceWith($input);\n $input.focus();\n });\n\n $form.append($edit);\n }\n\n var $cancel = create_command('cancel');\n $cancel.on('click', function() {\n $form.remove();\n $commands.find('a').show();\n });\n $form.append($cancel);\n\n $commands.find('a').each(function() {\n $(this).hide();\n });\n $commands.append($form);\n };\n\n /**\n * On move command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_move = function(e) {\n var $item = $(e.target).closest('li.activity');\n var id = $item.attr('id').match(/(\\d+)$/)[1];\n\n move_targets.show(id);\n };\n\n /**\n * On delete command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_delete = function(e) {\n var $item = $(e.target).closest('li');\n var liText = $item[0].innerText;\n\n var isDirectory = false;\n var modalBody;\n var item;\n var description_text = '';\n\n if ($item.hasClass(\"directory\")) {\n isDirectory = true;\n item = str('folder_string');\n description_text = str('delete_folder');\n } else {\n item = str('activity_string');\n }\n\n modalBody = '

    ' + item + ' ' + liText + description_text + '

    ';\n\n confirm_modal({\n 'title': str('confirm_delete'),\n 'body': modalBody,\n 'save_button': str('modal_confirm_delete'),\n 'checkbox': false,\n 'next': function() {\n\n var data = {};\n\n if (isDirectory === true) {\n data = {\n \"action\": \"delete_directory\",\n \"path\": $item.attr(\"directory-path\"),\n \"sesskey\": M.cfg.sesskey\n };\n } else if ($item.hasClass(\"activity\")) {\n data = {\n \"action\": \"delete\",\n \"id\": $item.attr('id').match(/(\\d+)$/)[1],\n \"sesskey\": M.cfg.sesskey\n };\n }\n\n var $spinner = add_spinner();\n\n $.post(get_action_url(\"rest\"), data,\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n });\n\n e.stopPropagation();\n }\n });\n };\n\n /**\n * On restore command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_restore = function(e) {\n var $item = $(e.target).closest('li');\n var id = null;\n\n if ($item.hasClass(\"directory\")) {\n id = $item.attr(\"directory-path\");\n restore_targets.is_directory = true;\n } else if ($item.hasClass(\"activity\")) {\n id = $item.attr('id').match(/(\\d+)$/)[1];\n restore_targets.is_directory = false;\n }\n\n restore_targets.show(id);\n };\n\n /**\n * On backup the whole section as a folder\n *\n * @param {int} sectionId\n * @param {int} sectionNumber\n * @param {int} courseId\n * @param {string} sectionName\n */\n $.on_section_backup = function(sectionId, sectionNumber, courseId, sectionName) {\n var data =\n {\n \"action\": \"is_userdata_copyable_section\",\n \"sectionid\": sectionId,\n \"sectionnumber\": sectionNumber,\n \"courseid\": courseId,\n };\n\n var body_html = '

    ' + str('backup_heavy_load_warning_message') +\n '

    ' + str('confirm_backup_section');\n\n on_backup_modal(data, sectionName, body_html, true);\n };\n\n /**\n * Initialize the delete bulk\n */\n $.init_bulk_delete = function(isspeciallayout) {\n var bulkdelete = $block.find('.editing_bulkdelete');\n if (bulkdelete.length) {\n if (isspeciallayout) {\n bulkdelete.attr('role', 'menuitem').addClass('dropdown-item menu-action');\n bulkdelete.append($(\"\").append(bulkdelete.attr('title')));\n\n $block.find('.menubar .dropdown .dropdown-menu').append(bulkdelete);\n } else {\n $block.find('.header .commands').append(bulkdelete);\n }\n }\n };\n\n /**\n * Initialize the help icon\n */\n $.init_help_icon = function(isspeciallayout) {\n var helpicon = $block.find('.header-commands > .help-icon');\n\n if (isspeciallayout) {\n $block.find('.header-commands').parent().css('display', 'block');\n } else {\n $block.find('.header .commands').append(helpicon);\n }\n };\n\n /**\n * Initialize the Sharing Cart block header\n */\n $.init_block_header = function() {\n var isspeciallayout = verify_layout();\n $.init_bulk_delete(isspeciallayout);\n $.init_help_icon(isspeciallayout);\n };\n\n /**\n * Initialize the Sharing Cart item tree\n */\n $.init_item_tree = function() {\n function add_actions(item, actions) {\n var $item = $(item);\n var $commands = $item.find('.commands').first();\n\n $.each(actions, function(index, action) {\n var $command = create_command(action);\n $command.on('click', function(e) {\n $['on_' + action](e);\n });\n $commands.append($command);\n }, this);\n }\n\n var activity_actions = ['movedir', 'move', 'delete'];\n if (course) {\n activity_actions.push('restore');\n }\n\n var directory_actions = ['delete', 'restore'];\n\n // Initialize items\n $block.find('li.activity').each(function(index, item) {\n if($(item).attr('data-disable-copy') == 1) {\n add_actions(item, ['movedir', 'move', 'delete']);\n return;\n }\n add_actions(item, activity_actions);\n });\n\n // Initialize directory items\n $block.find('li.directory').each(function(index, item) {\n add_actions(item, directory_actions);\n });\n\n // Initialize directories\n directories.init();\n };\n\n /**\n * Extract html object from area where moodle ajax was called.\n *\n * Call add_activity_backup_control to re append sharing cart icon.\n */\n $.init_activity_commands = function() {\n $(document).ajaxComplete(function(event, xhr, settings) {\n\n var url = settings.url;\n var lastslashindex = url.lastIndexOf('=');\n var result = url.substring(lastslashindex + 1);\n\n if (result === 'core_course_edit_module' || result === 'core_course_get_module') {\n\n var data = JSON.parse(settings.data);\n var action = data[0].args.action;\n\n // Don't try to add icon if activity has been deleted.\n if (action === 'delete') {\n return;\n }\n\n setTimeout(function() {\n var activity_id = data[0].args.id;\n var activity = $('#module-' + activity_id);\n add_activity_backup_control(activity);\n\n if (action === 'duplicate') {\n var duplicated = activity.next();\n add_activity_backup_control(duplicated);\n }\n }, 1);\n }\n });\n\n /**\n * Create the backup icon\n *\n * @returns $backupIcon\n */\n function create_backup_icon() {\n\n var $backupIcon = $('
    ')\n .append($(''))\n .attr('title', str('backup'));\n\n if (addMethod !== 'click_to_add') {\n $backupIcon.addClass('d-none');\n }\n\n return $backupIcon;\n }\n\n /**\n * Add backup control with a click event to an activity\n * Added fix for copying an activity without backup routine\n *\n * @param $activity\n */\n function add_activity_backup_control($activity) {\n\n var activityClass = $activity[0].className;\n\n // Selecting modtype without prefix.\n var modtype = activityClass.substr(activityClass.indexOf('modtype_') + 8);\n\n // Default activity name.\n var activityName = str('activity_string');\n\n // Label is using a different html / css layout, so it's needed to get the name by using another $find.\n if (modtype !== 'label') {\n activityName = $('.activity#' + $activity[0].id)\n .find('.mod-indent-outer .activityinstance span.instancename')\n .html();\n }\n\n var $backupIcon = create_backup_icon();\n\n $backupIcon.on('click', function(e) {\n $.on_backup(e, activityName);\n });\n\n var $actionMenuItem = $activity.find('.action-menu.section-cm-edit-actions').parent('.actions');\n\n if (!$actionMenuItem.find('.add-to-sharing-cart').length) {\n $actionMenuItem.append($backupIcon);\n }\n }\n\n /**\n * Add backup control with a click event to a section\n *\n * @param $section\n */\n function add_section_backup_control($section) {\n\n var sectionId = $section.find('.section_action_menu').data('sectionid');\n var sectionNumber = parseInt(String($section.attr('id')).match(/\\d+/)[0]);\n var sectionName = $section.attr('aria-label') || $section.find('.sectionname').text().trim();\n\n var isFlexibleCourseFormat = $('body[id$=flexsections]').length;\n\n // Extract the section ID from the section if this is a Flexible\n // course format (since this format doesn't have an action menu)\n if (isFlexibleCourseFormat && (typeof sectionId === 'undefined' || sectionId === null)) {\n sectionId = $section.data('section-id');\n }\n\n // A bit unsafe to extract the course ID from the body but it's the best option we got at the moment\n var courseId = parseInt(String($('body').attr('class')).match(/course-([0-9]*)( |$)/)[1]);\n\n var $backupIcon = create_backup_icon();\n\n $backupIcon.on('click', function() {\n var inPlaceEditSectionName = in_place_edit_section_name($section);\n sectionName = (inPlaceEditSectionName !== '') ? inPlaceEditSectionName : sectionName;\n $.on_section_backup(sectionId, sectionNumber, courseId, sectionName);\n });\n\n var $sectionTitle = $section.find('h3.sectionname').first().find('a').last();\n\n var $inPlaceEditable = $section.find('h3.sectionname .inplaceeditable').first();\n if ($inPlaceEditable.length) {\n $sectionTitle = $inPlaceEditable;\n }\n\n // Add the backup icon after the cog wheel if this is a Flexible course format\n if (isFlexibleCourseFormat && sectionNumber === 0) {\n $sectionTitle = $section.find('> .controls');\n $sectionTitle.prepend($backupIcon);\n } else {\n $backupIcon.insertAfter($sectionTitle);\n }\n\n var activitySelector = 'li.activity';\n\n var $activities = $section.find(activitySelector);\n\n $($activities).each(function() {\n add_activity_backup_control($(this));\n });\n }\n\n $(\"body.editing .course-content li.section\").each(function() {\n add_section_backup_control($(this));\n });\n };\n\n /**\n * Initialize the Sharing Cart footer basket for 4.0+.\n */\n function init_footer_basket() {\n let currentDragging;\n const activities = document.querySelectorAll(\".activity.activity-wrapper\");\n const sections = document.querySelectorAll(\".course-section-header\");\n const sharingCartBlock = document.querySelector('section[data-block=\"sharing_cart\"]');\n\n add_draggable_to_first_section();\n\n const footer = document.getElementById('page-footer');\n const footerIconContainer = footer.querySelector('div[data-region=\"footer-container-popover\"]');\n\n var basket = document.createElement('i');\n basket.setAttribute('class', 'fa fa-shopping-basket');\n\n var basketButton = document.createElement('button');\n basketButton.setAttribute('class', 'btn btn-icon bg-secondary icon-no-margin btn-footer-popover sharing_cart_basket');\n basketButton.setAttribute('style', 'z-index: 1001;');\n basketButton.append(basket);\n\n var dropAreaText = document.createElement('p');\n dropAreaText.setAttribute('class', 'font-weight-bold text-white');\n dropAreaText.innerText = str('drop_here');\n\n var dropArea = document.createElement('div');\n dropArea.setAttribute('class',\n 'h-100 w-100 position-absolute d-flex justify-content-center align-items-center');\n dropArea.append(dropAreaText);\n\n sections.forEach(section => {\n drag_event_listeners(section);\n });\n\n activities.forEach(activity => {\n drag_event_listeners(activity);\n });\n\n /**\n * Initialize events for dragging\n * @param {object} draggable\n */\n function drag_event_listeners(draggable) {\n draggable.addEventListener('dragstart', (e) => {\n basketButton.classList.remove('shake_basket');\n\n footerIconContainer?.prepend(basketButton);\n sharingCartBlock.children[0].classList.add('dragging_item');\n sharingCartBlock.append(dropArea);\n currentDragging = e.target;\n isDragging = true;\n });\n\n draggable.addEventListener('dragend', () => {\n if (currentDragging instanceof HTMLElement) {\n footerIconContainer?.removeChild(basketButton);\n }\n\n sharingCartBlock.children[0].classList.remove('dragging_item');\n sharingCartBlock.removeChild(dropArea);\n isDragging = false;\n });\n }\n\n [basketButton, sharingCartBlock].forEach((dropzone) => {\n dropzone.addEventListener(\"dragover\", (e) => {\n e.preventDefault();\n dropzone.classList.add('drag_over');\n });\n\n dropzone.addEventListener(\"dragenter\", (e) => {\n e.preventDefault();\n dropzone.classList.add('drag_over');\n });\n\n dropzone.addEventListener(\"dragleave\", () => {\n dropzone.classList.remove('drag_over');\n });\n\n dropzone.addEventListener(\"drop\", () => {\n if (currentDragging instanceof HTMLElement) {\n currentDragging.querySelector('.add-to-sharing-cart').click();\n }\n\n dropzone.classList.remove('drag_over');\n currentDragging = undefined;\n isDragging = false;\n });\n });\n }\n\n /**\n * Make the first section (General) draggable\n */\n function add_draggable_to_first_section() {\n const courseSectionHeader = document.getElementsByClassName(\"course-section-header\")[0] ?? null;\n\n if (courseSectionHeader instanceof HTMLElement) {\n courseSectionHeader.classList.add('draggable');\n courseSectionHeader.setAttribute('draggable', true);\n }\n }\n\n /**\n * Initialize the Sharing Cart block\n */\n $.init = function() {\n M.str.block_sharing_cart.pluginname = this.get_plugin_name();\n\n // Arrange header icons (bulkdelete, help)\n $.init_block_header();\n $.init_item_tree();\n $.init_activity_commands();\n\n if (addMethod === 'drag_and_drop') {\n init_footer_basket();\n }\n };\n var $spinner = $('').addClass('spinner fa fa-3x fa-circle-o-notch fa-spin');\n $('div#sharing-cart-spinner-modal div.spinner-container').prepend($spinner);\n\n $.init();\n });\n\n $('.copy_section').on('click', function() {\n\n var $section_selected = ($('.section-dropdown option:selected'));\n var sectionId = $section_selected.data('section-id');\n var sectionNumber = $section_selected.data('section-number');\n var courseId = $section_selected.data('course-id');\n var sectionName = $section_selected.data('section-name');\n\n $.on_section_backup(sectionId, sectionNumber, courseId, sectionName);\n });\n }\n };\n});\n"],"names":["define","$","ModalFactory","ModalEvents","init","addMethod","document","ready","isDragging","str","identifier","M","block_sharing_cart","moodle","get_action_url","name","args","url","cfg","wwwroot","q","k","push","encodeURIComponent","join","remove_basket","footerIconContainer","getElementById","querySelector","sharingCartBasket","removeChild","classList","remove","confirm_modal","obj","checkbox","body","create","type","types","SAVE_CANCEL","title","done","modal","is_submitted","setSaveButtonText","save_button","getRoot","on","save","e","response","target","find","is","next","cancel","hidden","removeClass","show","in_place_edit_section_name","$section","sectionName","$inPlaceEditable","length","data","on_backup_modal","post_data","title_str","body_str","isSection","post","sectionId","sectionNumber","courseId","userdata","$commands","closest","attr","text","trim","String","parent","inPlaceEditSectionName","$spinner","add_spinner","$node_spinner","add_node_spinner","sesskey","reload_tree","fail","show_error","always","hide","backup_section","sectionid","sectionnumber","courseid","cmid","course","id","backup","add","shake_basket","on_success","icon","css","iconClass","$block","match","is_frontpage","hasClass","ex","JSON","parse","responseText","core","exception","message","create_command","iconElement","addClass","append","$node","replaceWith","init_item_tree","directories","param","readCookie","KEY","opens","cookie","pop","split","map","v","parseInt","expires","Date","setDate","getDate","value","expireTimeInMillisecond","d","setTime","getTime","toUTCString","setCookie","open","$dir","visible","i","each","index","dir","toggle","reset","move_targets","$cancel","targets","this","$target","item_id","$current","$next","$list","next_id","create_target","area_to","$anchor","m","move","item","$item","to","before","restore_targets","is_directory","$clipboard","section","href","inSection","util","image_url","$view","html","prepend","cloneNode","replace","$sitetopic","$mainmenu","$container","format","get_section_wrapper","sectionDOM","first","init_footer_basket","currentDragging","activities","querySelectorAll","sections","sharingCartBlock","courseSectionHeader","getElementsByClassName","HTMLElement","setAttribute","add_draggable_to_first_section","basket","createElement","basketButton","dropAreaText","innerText","dropArea","drag_event_listeners","draggable","addEventListener","children","forEach","activity","dropzone","preventDefault","click","undefined","get_plugin_name","$blockheader","on_backup","activityName","$backup","$activity","dataowner","on_movedir","$current_dir","current_path","dirs","$form","submit","folder_to","val","$input","setTimeout","focus","unshift","$select","change","$edit","on_move","on_delete","modalBody","liText","isDirectory","description_text","stopPropagation","on_restore","on_section_backup","init_bulk_delete","isspeciallayout","bulkdelete","init_help_icon","helpicon","init_block_header","add_actions","actions","action","$command","activity_actions","directory_actions","init_activity_commands","create_backup_icon","$backupIcon","add_activity_backup_control","activityClass","className","modtype","substr","indexOf","$actionMenuItem","ajaxComplete","event","xhr","settings","lastslashindex","lastIndexOf","result","substring","activity_id","isFlexibleCourseFormat","$sectionTitle","last","insertAfter","$activities","add_section_backup_control","pluginname","$section_selected"],"mappings":";;;;;;;AAuBAA,mCAAO,CAAC,SAAU,qBAAsB,sBAAsB,SAASC,EAAGC,aAAcC,mBAC7E,CACHC,KAAM,SAASC,WAEXJ,EAAEK,UAAUC,OAAM,eACVC,YAAa,WAQRC,IAAIC,mBACFC,EAAEF,IAAIG,mBAAmBF,aAAeC,EAAEF,IAAII,OAAOH,qBAUvDI,eAAeC,KAAMC,UACtBC,IAAMN,EAAEO,IAAIC,QAAU,wBAA0BJ,KAAO,UACvDC,KAAM,KACFI,EAAI,OACH,IAAIC,KAAKL,KACVI,EAAEE,KAAKD,EAAI,IAAME,mBAAmBP,KAAKK,KAE7CJ,KAAO,IAAMG,EAAEI,KAAK,YAEjBP,aAgBFQ,mBACa,kBAAdpB,YAAkCG,WAAY,OAExCkB,oBADSpB,SAASqB,eAAe,eACJC,cAAc,+CAC3CC,kBAAoBvB,SAASsB,cAAc,8BAE7CC,oBACAH,MAAAA,qBAAAA,oBAAqBI,YAAYD,mBACjCA,kBAAkBE,UAAUC,OAAO,2BAUtCC,cAAcC,KAGfA,IAAIC,WACJD,IAAIE,MACA,uJAEiC3B,IAAI,kBAFrC,kBAORP,aAAamC,OAAO,CAChBC,KAAMpC,aAAaqC,MAAMC,YACzBC,MAAOP,IAAIO,MACXL,KAAMF,IAAIE,OACXM,MAAK,SAASC,WACTC,cAAe,EACnBD,MAAME,kBAAkBX,IAAIY,aAG5BH,MAAMI,UAAUC,GAAG7C,YAAY8C,MAAM,SAASC,OAEtCC,SAAW,UACClD,EAAEiD,EAAEE,QAAQC,KAAK,mBAAmBC,GAAG,aAGvDpB,IAAIqB,KAAKJ,UACTP,cAAe,KAGnBD,MAAMI,UAAUC,GAAG7C,YAAYqD,QAAQ,WACnC/B,mBAIJkB,MAAMI,UAAUC,GAAG7C,YAAYsD,QAAQ,WACnCxD,EAAE,QA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W0N,kBAAkBnO,KAAK,aAClCH,YAAcsO,kBAAkBnO,KAAK,gBAEzChE,EAAE4P,kBAAkBrL,UAAWC,cAAeC,SAAUZ"} \ No newline at end of file +{"version":3,"file":"script.min.js","sources":["../src/script.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Sharing Cart\n *\n * @package block_sharing_cart\n * @copyright 2017 (C) VERSION2, INC.\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/modal_factory', 'core/modal_events'], function($, ModalFactory, ModalEvents) {\n return {\n init: function(addMethod) {\n\n $(document).ready(function() {\n let isDragging = false;\n\n /**\n * Returns a localized string\n *\n * @param {String} identifier\n * @return {String}\n */\n function str(identifier) {\n return M.str.block_sharing_cart[identifier] || M.str.moodle[identifier];\n }\n\n /**\n * Get an action URL\n *\n * @param {String} name The action name\n * @param {Object} [args] The action parameters\n * @return {String}\n */\n function get_action_url(name, args) {\n var url = M.cfg.wwwroot + '/blocks/sharing_cart/' + name + '.php';\n if (args) {\n var q = [];\n for (var k in args) {\n q.push(k + '=' + encodeURIComponent(args[k]));\n }\n url += '?' + q.join('&');\n }\n return url;\n }\n\n /**\n * Shake the basket to indicate cancel/submit\n */\n function shake_basket() {\n if (addMethod === 'drag_and_drop') {\n const sharingCartBasket = document.querySelector('button.sharing_cart_basket');\n sharingCartBasket?.classList.add('shake_basket');\n }\n }\n\n /**\n * Remove the shake effect and basket icon\n */\n function remove_basket() {\n if (addMethod === 'drag_and_drop' && !isDragging) {\n const footer = document.getElementById('page-footer');\n const footerIconContainer = footer.querySelector('div[data-region=\"footer-container-popover\"]');\n const sharingCartBasket = document.querySelector('button.sharing_cart_basket');\n\n if (sharingCartBasket) {\n footerIconContainer?.removeChild(sharingCartBasket);\n sharingCartBasket.classList.remove('shake_basket');\n }\n }\n }\n\n /**\n * Modal called when confirming an action.\n *\n * @param obj\n */\n function confirm_modal(obj) {\n\n // Checkbox for copying userdata confirmation.\n if (obj.checkbox) {\n obj.body +=\n '
    ' +\n '' +\n '' +\n '
    ';\n }\n\n\n ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: obj.title,\n body: obj.body,\n }).done(function(modal) {\n let is_submitted = false;\n modal.setSaveButtonText(obj.save_button);\n\n // On save save check - if checkbox is checked.\n modal.getRoot().on(ModalEvents.save, function(e) {\n\n var response = {\n 'checkbox': $(e.target).find('.modal-checkbox').is(':checked'),\n };\n\n obj.next(response);\n is_submitted = true;\n });\n\n modal.getRoot().on(ModalEvents.cancel, function() {\n remove_basket();\n });\n\n // Remove modal from html.\n modal.getRoot().on(ModalEvents.hidden, function() {\n $('body').removeClass('modal-open');\n\n if (!is_submitted) {\n remove_basket();\n }\n });\n\n modal.show();\n });\n }\n\n /**\n * Get the section name from the section when\n * it's changed with the in place editor\n *\n * @param $section\n * @returns {*}\n */\n function in_place_edit_section_name($section) {\n var sectionName = '';\n var $inPlaceEditable = $section.find('h3.sectionname .inplaceeditable');\n if ($inPlaceEditable.length) {\n sectionName = $inPlaceEditable.data('value');\n }\n return sectionName;\n }\n\n /**\n * @param post_data\n * @param title_str\n * @param body_str\n * @param isSection\n */\n function on_backup_modal(post_data, title_str, body_str, isSection) {\n (function(on_success) {\n $.post(get_action_url('rest'), post_data,\n function(response) {\n on_success(response);\n }, \"text\")\n .fail(function(response) {\n show_error(response);\n });\n })(function(response) {\n var copyable = response === '1';\n var checkbox = false;\n\n if (copyable) {\n checkbox = true;\n }\n\n confirm_modal({\n 'title': title_str,\n 'body': body_str,\n 'save_button': str('modal_confirm_backup'),\n 'checkbox': checkbox,\n 'next': function(data) {\n if (isSection === true) {\n backup_section(post_data.sectionid, post_data.sectionnumber, post_data.courseid, data.checkbox);\n } else {\n backup(post_data.cmid, data.checkbox);\n }\n\n shake_basket();\n }\n });\n });\n }\n\n /** @var {Object} The icon configurations */\n var icon = {\n // Actions\n 'backup': {\n css: 'editing_backup',\n iconClass: 'fa fa-frown-o',\n },\n 'movedir': {\n css: 'editing_right',\n iconClass: 'fa fa-arrow-right',\n },\n 'move': {\n css: 'editing_move_',\n iconClass: 'fa fa-arrows-v',\n },\n 'edit': {\n css: 'editing_update',\n iconClass: 'fa fa-pencil',\n },\n 'cancel': {\n css: 'editing_cancel',\n iconClass: 'fa fa-ban',\n },\n 'delete': {\n css: 'editing_update',\n iconClass: 'fa fa-trash',\n },\n 'restore': {\n css: 'editing_restore',\n iconClass: 'fa fa-clone',\n },\n // Directories\n 'dir-open': {\n iconClass: 'fa fa-folder-open-o'\n },\n 'dir-closed': {\n iconClass: 'fa fa-folder-o'\n },\n };\n\n /** @var {Node} The Sharing Cart block container node */\n var $block = $('.block_sharing_cart');\n\n /** @var {Object} The current course */\n var course = new function() {\n var body = $('body');\n this.id = body.attr('class').match(/course-(\\d+)/)[1];\n this.is_frontpage = body.hasClass('pagelayout-frontpage');\n }();\n\n /**\n * Shows an error message with given Ajax error\n *\n * @param {Object} response The Ajax response\n */\n function show_error(response) {\n try {\n var ex = JSON.parse(response.responseText);\n new M.core.exception({\n name: str('pluginname') + ' - ' + str('error'),\n message: ex.message\n });\n } catch (e) {\n new M.core.exception({\n name: str('pluginname') + ' - ' + str('error'),\n message: response.responseText\n });\n }\n }\n\n /**\n * Check special layout (theme boost)\n *\n * @return {Boolean}\n */\n function verify_layout() {\n var menuelement = $block.find('.menubar .dropdown .dropdown-menu');\n return (menuelement.length);\n }\n\n /**\n * Set Cookie\n * @param name\n * @param value\n * @param expireTimeInMillisecond\n */\n function setCookie(name, value, expireTimeInMillisecond) {\n var d = new Date();\n d.setTime(d.getTime() + expireTimeInMillisecond);\n var expires = 'expires=' + d.toUTCString();\n document.cookie = name + '=' + value + ';' + expires + '';\n }\n\n /**\n * Get Cookie Value\n * @param param\n * @returns {*}\n */\n function getCookieValue(param) {\n var readCookie = document.cookie.match('(^|;)\\\\s*' + param + '\\\\s*=\\\\s*([^;]+)');\n return readCookie ? readCookie.pop() : '';\n }\n\n /**\n * Create a command icon\n *\n * @param {String} name The command name, predefined in icon\n * @param {String} [pix] The icon pix name to override\n */\n function create_command(name) {\n var iconElement = $('')\n .attr('alt', str(name))\n .attr('class', icon[name].iconClass);\n // If (verify_layout()) {\n // iconElement.addClass('iconcustom');\n // }\n\n return $('
    ')\n .addClass(icon[name].css)\n .attr('title', str(name))\n .append(iconElement);\n }\n\n /**\n * Create a spinner\n * @param $node\n * @returns {*|jQuery}\n */\n function add_spinner() {\n var $spinner = ($('
    '));\n $('section.block_sharing_cart').append($spinner);\n return $spinner;\n }\n\n /**\n *\n * @param $node\n * @returns {jQuery.fn.init}\n */\n function add_node_spinner($node) {\n var $node_spinner = $('');\n $node.append($node_spinner);\n return $node_spinner;\n }\n\n $(document).on('click', 'a.restore', function() {\n add_spinner();\n });\n\n /**\n *\n * Reload the Sharing Cart item tree\n */\n function reload_tree() {\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"render_tree\",\n \"courseid\": course.id\n },\n function(response) {\n $block.find(\".tree\").replaceWith($(response));\n $.init_item_tree();\n }, \"html\")\n .fail(function(response) {\n show_error(response);\n });\n }\n\n /**\n * Backup an activity\n *\n * @param {int} cmid\n * @param {Boolean} userdata\n */\n function backup(cmid, userdata) {\n var $commands = $('#module-' + cmid + ' .actions');\n if (!$commands.length) {\n $commands = $('[data-owner=\"#module-' + cmid + '\"]');\n }\n\n var $spinner = add_spinner();\n var $node_spinner = add_node_spinner($commands);\n\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"backup\",\n \"cmid\": cmid,\n \"userdata\": userdata,\n \"sesskey\": M.cfg.sesskey,\n \"courseid\": course.id\n },\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $node_spinner.hide();\n $spinner.hide();\n remove_basket();\n });\n }\n\n /**\n * Backup an activities in a section\n *\n * @param {int} sectionId\n * @param {int} sectionNumber\n * @param {int} courseId\n * @param {Boolean} userdata\n */\n function backup_section(sectionId, sectionNumber, courseId, userdata) {\n var $commands = $('span.inplaceeditable[data-itemtype=sectionname][data-itemid=' + sectionId + ']');\n var $section = $commands.closest(\"li.section.main\");\n var sectionName = $section.attr('aria-label') || $section.find('.sectionname').text().trim();\n\n if (sectionName === null) {\n sectionName = String($('#region-main .section_action_menu[data-sectionid=\\'' + sectionId + '\\']')\n .parent().parent().find('h3.sectionname').text());\n }\n\n var inPlaceEditSectionName = in_place_edit_section_name($section);\n sectionName = (inPlaceEditSectionName !== '') ? inPlaceEditSectionName : sectionName;\n\n var $spinner = add_spinner();\n var $node_spinner = add_node_spinner($commands);\n\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"backup_section\",\n \"sectionid\": sectionId,\n \"sectionnumber\": sectionNumber,\n \"courseid\": courseId,\n \"sectionname\": sectionName,\n \"userdata\": userdata,\n \"sesskey\": M.cfg.sesskey\n },\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n $node_spinner.hide();\n remove_basket();\n });\n }\n\n\n // /////// CLASSES /////////\n\n /**\n * @class Directory states manager\n */\n var directories = new function() {\n var KEY = 'block_sharing_cart-dirs';\n\n var opens = getCookieValue(KEY).split(',').map(function(v) {\n return parseInt(v);\n });\n\n function save() {\n var expires = new Date();\n expires.setDate(expires.getDate() + 30);\n setCookie(KEY, opens.join(','), expires);\n }\n\n function open($dir, visible) {\n var iconIndex = visible ? 'dir-open' : 'dir-closed';\n var iconElement = icon[iconIndex].iconClass;\n $dir.find('> div i.icon').attr('class', 'icon ' + iconElement);\n $dir.find('> ul.list')[visible ? 'show' : 'hide']();\n }\n\n function toggle(e) {\n var $dir = $(e.target).closest('li.directory');\n var i = $dir.attr('id').match(/(\\d+)$/)[1];\n var v = $dir.find('> ul.list').css('display') === 'none';\n\n open($dir, v);\n opens[i] = v ? 1 : 0;\n save();\n }\n\n /**\n * Initialize directory states\n */\n this.init = function() {\n var i = 0;\n $block.find('li.directory').each(function(index, dir) {\n var $dir = $(dir);\n $dir.attr('id', 'block_sharing_cart-dir-' + i);\n if (i >= opens.length) {\n opens.push(0);\n } else if (opens[i]) {\n open($dir, true);\n }\n $dir.find('> div div.toggle-wrapper').css('cursor', 'pointer').on('click', function(e) {\n toggle(e);\n });\n i++;\n });\n };\n\n /**\n * Reset directory states\n */\n this.reset = function() {\n opens = [];\n this.init();\n save();\n };\n }();\n\n /**\n * @class Targets for moving an item directory\n */\n var move_targets = new function() {\n var $cancel = null,\n targets = [];\n\n /**\n * Hide move targets\n */\n this.hide = function() {\n if ($cancel !== null) {\n var $commands = $cancel.closest('.commands');\n $cancel.remove();\n $cancel = null;\n $commands.closest('li.activity').css('opacity', 1.0);\n $commands.find('a').each(function() {\n $(this).show();\n });\n $.each(targets, function(index, $target) {\n $target.remove();\n });\n targets = [];\n }\n };\n\n /**\n * Show move targets for a given item\n *\n * @param {int} id The item ID\n */\n this.show = function(item_id) {\n this.hide();\n\n function move(e) {\n\n var m = $(e.target).closest('a').attr('class').match(/move-(\\d+)-to-(\\d+)/);\n var item_id = m[1],\n area_to = m[2];\n\n var $spinner = add_spinner();\n $.post(get_action_url(\"rest\"),\n {\n \"action\": \"move\",\n \"item_id\": item_id,\n \"area_to\": area_to,\n \"sesskey\": M.cfg.sesskey\n },\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n });\n }\n\n var $current = $block.find('#block_sharing_cart-item-' + item_id);\n var $next = $current.next();\n var $list = $current.closest('ul');\n\n var next_id = 0;\n if ($next.length) {\n next_id = $next.attr('id').match(/item-(\\d+)$/)[1];\n }\n\n /**\n *\n * @param item_id\n * @param area_to\n * @returns {jQuery}\n */\n function create_target(item_id, area_to) {\n var $anchor = $('
    ')\n .addClass('move-' + item_id + '-to-' + area_to)\n .attr('title', str('movehere'))\n .append(\n $('

    ' + str('clicktomove') + '

    ')\n .attr('alt', str('movehere'))\n );\n\n var $target = $('
  • ')\n .append($anchor);\n $anchor.on('click', function(e) {\n move(e);\n });\n\n return $target;\n }\n\n $list.find('> li.activity').each(function(index, item) {\n var $item = $(item);\n var to = $item.attr('id').match(/item-(\\d+)$/)[1];\n if (to === item_id) {\n $cancel = create_command('cancel', 't/left');\n $cancel.on('click', function() {\n move_targets.hide();\n });\n var $commands = $item.find('.commands');\n $commands.find('a').each(function() {\n $(this).hide();\n });\n $commands.append($cancel);\n $item.css('opacity', 0.5);\n } else if (to !== next_id) {\n var $target = create_target(item_id, to);\n $item.before($target);\n targets.push($target);\n }\n }, this);\n\n if ($next) {\n var $target = create_target(item_id, 0);\n $list.append($target);\n targets.push($target);\n }\n };\n }();\n\n /**\n * @class Targets for restoring an item\n */\n\n var restore_targets = new function() {\n this.is_directory = null;\n var $clipboard = null,\n targets = [];\n\n /**\n *\n * @param id\n * @param section\n * @returns {jQuery}\n */\n\n function create_target(id, section) {\n const href = get_action_url('restore', {\n 'directory': (restore_targets.is_directory === true),\n 'target': id,\n 'course': course.id,\n 'section': section,\n 'in_section': $('#copy-section-form').data('in-section'),\n 'sesskey': M.cfg.sesskey,\n 'returnurl': document.URL,\n });\n\n let $target = $('').attr('href', href).attr('title', str('copyhere')).append(\n $('').attr('alt', str('copyhere')).attr('src', M.util.image_url('dropzone_arrow', 'block_sharing_cart'))\n );\n\n targets.push($target);\n\n return $target;\n }\n\n /**\n * Hide restore targets\n */\n this.hide = function() {\n if ($clipboard !== null) {\n $clipboard.remove();\n $clipboard = null;\n $.each(targets, function(index, $target) {\n $target.remove();\n });\n targets = [];\n }\n };\n\n /**\n *\n *\n * @param {int} id The item ID\n */\n this.show = function(id) {\n this.hide();\n\n var $view = $(\"\");\n\n if (this.is_directory) {\n $view.html(id).css('display', 'inline');\n $view.prepend(\n $(\"\").addClass(\"icon\")\n .attr(\"alt\", id)\n // .attr(\"src\", M.util.image_url(icon['dir-closed'].pix, null))\n );\n } else {\n var $item = $block.find('#block_sharing_cart-item-' + id);\n $view = $($item.find('div')[0].cloneNode(true)).css('display', 'inline');\n $view.attr('class', $view.attr('class').replace(/mod-indent-\\d+/, ''));\n $view.find('.commands').remove();\n }\n\n var $cancel = create_command('cancel');\n\n $cancel.on('click', this.hide);\n\n $clipboard = $('
    ');\n $clipboard.append(str('clipboard') + \": \").append($view).append($cancel);\n\n if (course.is_frontpage) {\n var $sitetopic = $('.sitetopic');\n var $mainmenu = $('.block_site_main_menu');\n if ($sitetopic) {\n $sitetopic.find('*').before($clipboard);\n } else if ($mainmenu) {\n $mainmenu.find('.content').before($clipboard);\n }\n\n // Mainmenu = section #0, sitetopic = section #1\n if ($mainmenu) {\n $mainmenu.find('.footer').before(create_target(id, 0));\n }\n if ($sitetopic) {\n $sitetopic.find('ul.section').append(create_target(id, 1));\n }\n } else {\n var $container = $('.course-content');\n $container.prepend($clipboard);\n $container.find(M.course.format.get_section_wrapper(null)).each(function(index, sectionDOM) {\n var $section = $(sectionDOM);\n var section = $section.attr('id').match(/(\\d+)$/)[1];\n $section.find('ul.section').first().append(create_target(id, section));\n }, this);\n }\n };\n }();\n\n // /////// INITIALIZATION /////////\n\n /**\n *\n * @returns {string|*}\n */\n $.get_plugin_name = function() {\n var $blockheader = $block.find(\"h2\");\n\n if (!$blockheader.length) {\n $blockheader = $block.find(\"h3\");\n\n if ($blockheader.length) {\n return $blockheader.html();\n }\n } else {\n return $blockheader.html();\n }\n\n return \"\";\n };\n\n /**\n *\n * @param e\n * @param activityName\n */\n $.on_backup = function(e, activityName) {\n var cmid = (function($backup) {\n var $activity = $backup.closest('li.activity');\n if ($activity.length) {\n return $activity.attr('id').match(/(\\d+)$/)[1];\n }\n var $commands = $backup.closest('.commands');\n var dataowner = $commands.attr('data-owner');\n if (dataowner.length) {\n return dataowner.match(/(\\d+)$/)[1];\n }\n return $commands.find('a.editing_delete').attr('href').match(/delete=(\\d+)/)[1];\n })($(e.target));\n\n var data =\n {\n \"action\": \"is_userdata_copyable\",\n \"cmid\": cmid\n };\n\n on_backup_modal(data, activityName, str('confirm_backup'), false);\n };\n\n /**\n * On movedir command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_movedir = function(e) {\n var $commands = $(e.target).closest('.commands');\n\n var $current_dir = $commands.closest('li.directory');\n var current_path = $current_dir.length ? $current_dir.attr('directory-path') : '/';\n\n var item_id = $(e.target).closest('li.activity').attr('id').match(/(\\d+)$/)[1];\n\n var dirs = [];\n $block.find('li.directory').each(function() {\n dirs.push($(this).attr('directory-path'));\n });\n\n var $form = $('');\n // eslint-disable-next-line no-script-url\n $form.attr('action', 'javascript:void(0)');\n\n function submit() {\n var folder_to = $form.find('[name=\"to\"]').val();\n var $spinner = add_spinner();\n $.post(get_action_url('rest'),\n {\n \"action\": \"movedir\",\n \"item_id\": item_id,\n \"folder_to\": folder_to,\n \"sesskey\": M.cfg.sesskey\n },\n function() {\n reload_tree();\n directories.reset();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n });\n }\n\n $form.submit(submit);\n\n if (dirs.length === 0) {\n var $input = $('').val(current_path);\n setTimeout(function() {\n $input.focus();\n }, 1);\n $form.append($input);\n } else {\n dirs.unshift('/');\n\n var $select = $('').val(current_path);\n $select.remove();\n $edit.replaceWith($input);\n $input.focus();\n });\n\n $form.append($edit);\n }\n\n var $cancel = create_command('cancel');\n $cancel.on('click', function() {\n $form.remove();\n $commands.find('a').show();\n });\n $form.append($cancel);\n\n $commands.find('a').each(function() {\n $(this).hide();\n });\n $commands.append($form);\n };\n\n /**\n * On move command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_move = function(e) {\n var $item = $(e.target).closest('li.activity');\n var id = $item.attr('id').match(/(\\d+)$/)[1];\n\n move_targets.show(id);\n };\n\n /**\n * On delete command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_delete = function(e) {\n var $item = $(e.target).closest('li');\n var liText = $item[0].innerText;\n\n var isDirectory = false;\n var modalBody;\n var item;\n var description_text = '';\n\n if ($item.hasClass(\"directory\")) {\n isDirectory = true;\n item = str('folder_string');\n description_text = str('delete_folder');\n } else {\n item = str('activity_string');\n }\n\n modalBody = '

    ' + item + ' ' + liText + description_text + '

    ';\n\n confirm_modal({\n 'title': str('confirm_delete'),\n 'body': modalBody,\n 'save_button': str('modal_confirm_delete'),\n 'checkbox': false,\n 'next': function() {\n\n var data = {};\n\n if (isDirectory === true) {\n data = {\n \"action\": \"delete_directory\",\n \"path\": $item.attr(\"directory-path\"),\n \"sesskey\": M.cfg.sesskey\n };\n } else if ($item.hasClass(\"activity\")) {\n data = {\n \"action\": \"delete\",\n \"id\": $item.attr('id').match(/(\\d+)$/)[1],\n \"sesskey\": M.cfg.sesskey\n };\n }\n\n var $spinner = add_spinner();\n\n $.post(get_action_url(\"rest\"), data,\n function() {\n reload_tree();\n })\n .fail(function(response) {\n show_error(response);\n })\n .always(function() {\n $spinner.hide();\n });\n\n e.stopPropagation();\n }\n });\n };\n\n /**\n * On restore command clicked\n *\n * @param {DOMEventFacade} e\n */\n $.on_restore = function(e) {\n var $item = $(e.target).closest('li');\n var id = null;\n\n if ($item.hasClass(\"directory\")) {\n id = $item.attr(\"directory-path\");\n restore_targets.is_directory = true;\n } else if ($item.hasClass(\"activity\")) {\n id = $item.attr('id').match(/(\\d+)$/)[1];\n restore_targets.is_directory = false;\n }\n\n restore_targets.show(id);\n };\n\n /**\n * On backup the whole section as a folder\n *\n * @param {int} sectionId\n * @param {int} sectionNumber\n * @param {int} courseId\n * @param {string} sectionName\n */\n $.on_section_backup = function(sectionId, sectionNumber, courseId, sectionName) {\n var data =\n {\n \"action\": \"is_userdata_copyable_section\",\n \"sectionid\": sectionId,\n \"sectionnumber\": sectionNumber,\n \"courseid\": courseId,\n };\n\n var body_html = '

    ' + str('backup_heavy_load_warning_message') +\n '

    ' + str('confirm_backup_section');\n\n on_backup_modal(data, sectionName, body_html, true);\n };\n\n /**\n * Initialize the delete bulk\n */\n $.init_bulk_delete = function(isspeciallayout) {\n var bulkdelete = $block.find('.editing_bulkdelete');\n if (bulkdelete.length) {\n if (isspeciallayout) {\n bulkdelete.attr('role', 'menuitem').addClass('dropdown-item menu-action');\n bulkdelete.append($(\"\").append(bulkdelete.attr('title')));\n\n $block.find('.menubar .dropdown .dropdown-menu').append(bulkdelete);\n } else {\n $block.find('.header .commands').append(bulkdelete);\n }\n }\n };\n\n /**\n * Initialize the help icon\n */\n $.init_help_icon = function(isspeciallayout) {\n var helpicon = $block.find('.header-commands > .help-icon');\n\n if (isspeciallayout) {\n $block.find('.header-commands').parent().css('display', 'block');\n } else {\n $block.find('.header .commands').append(helpicon);\n }\n };\n\n /**\n * Initialize the Sharing Cart block header\n */\n $.init_block_header = function() {\n var isspeciallayout = verify_layout();\n $.init_bulk_delete(isspeciallayout);\n $.init_help_icon(isspeciallayout);\n };\n\n /**\n * Initialize the Sharing Cart item tree\n */\n $.init_item_tree = function() {\n function add_actions(item, actions) {\n var $item = $(item);\n var $commands = $item.find('.commands').first();\n\n $.each(actions, function(index, action) {\n var $command = create_command(action);\n $command.on('click', function(e) {\n $['on_' + action](e);\n });\n $commands.append($command);\n }, this);\n }\n\n var activity_actions = ['movedir', 'move', 'delete'];\n if (course) {\n activity_actions.push('restore');\n }\n\n var directory_actions = ['delete', 'restore'];\n\n // Initialize items\n $block.find('li.activity').each(function(index, item) {\n if($(item).attr('data-disable-copy') == 1) {\n add_actions(item, ['movedir', 'move', 'delete']);\n return;\n }\n add_actions(item, activity_actions);\n });\n\n // Initialize directory items\n $block.find('li.directory').each(function(index, item) {\n add_actions(item, directory_actions);\n });\n\n // Initialize directories\n directories.init();\n };\n\n /**\n * Extract html object from area where moodle ajax was called.\n *\n * Call add_activity_backup_control to re append sharing cart icon.\n */\n $.init_activity_commands = function() {\n $(document).ajaxComplete(function(event, xhr, settings) {\n\n var url = settings.url;\n var lastslashindex = url.lastIndexOf('=');\n var result = url.substring(lastslashindex + 1);\n\n if (result === 'core_course_edit_module' || result === 'core_course_get_module') {\n\n var data = JSON.parse(settings.data);\n var action = data[0].args.action;\n\n // Don't try to add icon if activity has been deleted.\n if (action === 'delete') {\n return;\n }\n\n setTimeout(function() {\n var activity_id = data[0].args.id;\n var activity = $('#module-' + activity_id);\n add_activity_backup_control(activity);\n\n if (action === 'duplicate') {\n var duplicated = activity.next();\n add_activity_backup_control(duplicated);\n }\n }, 1);\n }\n });\n\n /**\n * Create the backup icon\n *\n * @returns $backupIcon\n */\n function create_backup_icon() {\n\n var $backupIcon = $('
    ')\n .append($(''))\n .attr('title', str('backup'));\n\n if (addMethod !== 'click_to_add') {\n $backupIcon.addClass('d-none');\n }\n\n return $backupIcon;\n }\n\n /**\n * Add backup control with a click event to an activity\n * Added fix for copying an activity without backup routine\n *\n * @param $activity\n */\n function add_activity_backup_control($activity) {\n\n var activityClass = $activity[0].className;\n\n // Selecting modtype without prefix.\n var modtype = activityClass.substr(activityClass.indexOf('modtype_') + 8);\n\n // Default activity name.\n var activityName = str('activity_string');\n\n // Label is using a different html / css layout, so it's needed to get the name by using another $find.\n if (modtype !== 'label') {\n activityName = $('.activity#' + $activity[0].id)\n .find('.mod-indent-outer .activityinstance span.instancename')\n .html();\n }\n\n var $backupIcon = create_backup_icon();\n\n $backupIcon.on('click', function(e) {\n $.on_backup(e, activityName);\n });\n\n var $actionMenuItem = $activity.find('.action-menu.section-cm-edit-actions').parent('.actions');\n\n if (!$actionMenuItem.find('.add-to-sharing-cart').length) {\n $actionMenuItem.append($backupIcon);\n }\n }\n\n /**\n * Add backup control with a click event to a section\n *\n * @param $section\n */\n function add_section_backup_control($section) {\n\n var sectionId = $section.find('.section_action_menu').data('sectionid');\n var sectionNumber = parseInt(String($section.attr('id')).match(/\\d+/)[0]);\n var sectionName = $section.attr('aria-label') || $section.find('.sectionname').text().trim();\n\n var isFlexibleCourseFormat = $('body[id$=flexsections]').length;\n\n // Extract the section ID from the section if this is a Flexible\n // course format (since this format doesn't have an action menu)\n if (isFlexibleCourseFormat && (typeof sectionId === 'undefined' || sectionId === null)) {\n sectionId = $section.data('section-id');\n }\n\n // A bit unsafe to extract the course ID from the body but it's the best option we got at the moment\n var courseId = parseInt(String($('body').attr('class')).match(/course-([0-9]*)( |$)/)[1]);\n\n var $backupIcon = create_backup_icon();\n\n $backupIcon.on('click', function() {\n var inPlaceEditSectionName = in_place_edit_section_name($section);\n sectionName = (inPlaceEditSectionName !== '') ? inPlaceEditSectionName : sectionName;\n $.on_section_backup(sectionId, sectionNumber, courseId, sectionName);\n });\n\n var $sectionTitle = $section.find('h3.sectionname').first().find('a').last();\n\n var $inPlaceEditable = $section.find('h3.sectionname .inplaceeditable').first();\n if ($inPlaceEditable.length) {\n $sectionTitle = $inPlaceEditable;\n }\n\n // Add the backup icon after the cog wheel if this is a Flexible course format\n if (isFlexibleCourseFormat && sectionNumber === 0) {\n $sectionTitle = $section.find('> .controls');\n $sectionTitle.prepend($backupIcon);\n } else {\n $backupIcon.insertAfter($sectionTitle);\n }\n\n var activitySelector = 'li.activity';\n\n var $activities = $section.find(activitySelector);\n\n $($activities).each(function() {\n add_activity_backup_control($(this));\n });\n }\n\n $(\"body.editing .course-content li.section\").each(function() {\n add_section_backup_control($(this));\n });\n };\n\n /**\n * Initialize the Sharing Cart footer basket for 4.0+.\n */\n function init_footer_basket() {\n let currentDragging;\n const activities = document.querySelectorAll(\".activity.activity-wrapper\");\n const sections = document.querySelectorAll(\".course-section-header\");\n const sharingCartBlock = document.querySelector('section[data-block=\"sharing_cart\"]');\n\n add_draggable_to_first_section();\n\n const footer = document.getElementById('page-footer');\n const footerIconContainer = footer.querySelector('div[data-region=\"footer-container-popover\"]');\n\n var basket = document.createElement('i');\n basket.setAttribute('class', 'fa fa-shopping-basket');\n\n var basketButton = document.createElement('button');\n basketButton.setAttribute('class', 'btn btn-icon bg-secondary icon-no-margin btn-footer-popover sharing_cart_basket');\n basketButton.setAttribute('style', 'z-index: 1001;');\n basketButton.append(basket);\n\n var dropAreaText = document.createElement('p');\n dropAreaText.setAttribute('class', 'font-weight-bold text-white');\n dropAreaText.innerText = str('drop_here');\n\n var dropArea = document.createElement('div');\n dropArea.setAttribute('class',\n 'h-100 w-100 position-absolute d-flex justify-content-center align-items-center');\n dropArea.append(dropAreaText);\n\n sections.forEach(section => {\n drag_event_listeners(section);\n });\n\n activities.forEach(activity => {\n drag_event_listeners(activity);\n });\n\n /**\n * Initialize events for dragging\n * @param {object} draggable\n */\n function drag_event_listeners(draggable) {\n draggable.addEventListener('dragstart', (e) => {\n basketButton.classList.remove('shake_basket');\n\n footerIconContainer?.prepend(basketButton);\n sharingCartBlock.children[0].classList.add('dragging_item');\n sharingCartBlock.append(dropArea);\n currentDragging = e.target;\n isDragging = true;\n });\n\n draggable.addEventListener('dragend', () => {\n if (currentDragging instanceof HTMLElement) {\n footerIconContainer?.removeChild(basketButton);\n }\n\n sharingCartBlock.children[0].classList.remove('dragging_item');\n sharingCartBlock.removeChild(dropArea);\n isDragging = false;\n });\n }\n\n [basketButton, sharingCartBlock].forEach((dropzone) => {\n dropzone.addEventListener(\"dragover\", (e) => {\n e.preventDefault();\n dropzone.classList.add('drag_over');\n });\n\n dropzone.addEventListener(\"dragenter\", (e) => {\n e.preventDefault();\n dropzone.classList.add('drag_over');\n });\n\n dropzone.addEventListener(\"dragleave\", () => {\n dropzone.classList.remove('drag_over');\n });\n\n dropzone.addEventListener(\"drop\", () => {\n if (currentDragging instanceof HTMLElement) {\n currentDragging.querySelector('.add-to-sharing-cart').click();\n }\n\n dropzone.classList.remove('drag_over');\n currentDragging = undefined;\n isDragging = false;\n });\n });\n }\n\n /**\n * Make the first section (General) draggable\n */\n function add_draggable_to_first_section() {\n const courseSectionHeader = document.getElementsByClassName(\"course-section-header\")[0] ?? null;\n\n if (courseSectionHeader instanceof HTMLElement) {\n courseSectionHeader.classList.add('draggable');\n courseSectionHeader.setAttribute('draggable', true);\n }\n }\n\n /**\n * Initialize the Sharing Cart block\n */\n $.init = function() {\n M.str.block_sharing_cart.pluginname = this.get_plugin_name();\n\n // Arrange header icons (bulkdelete, help)\n $.init_block_header();\n $.init_item_tree();\n $.init_activity_commands();\n\n if (addMethod === 'drag_and_drop') {\n init_footer_basket();\n }\n };\n var $spinner = $('').addClass('spinner fa fa-3x fa-circle-o-notch fa-spin');\n $('div#sharing-cart-spinner-modal div.spinner-container').prepend($spinner);\n\n $.init();\n });\n\n $('.copy_section').on('click', function() {\n\n var $section_selected = ($('.section-dropdown option:selected'));\n var sectionId = $section_selected.data('section-id');\n var sectionNumber = $section_selected.data('section-number');\n var courseId = $section_selected.data('course-id');\n var sectionName = $section_selected.data('section-name');\n\n $.on_section_backup(sectionId, sectionNumber, courseId, sectionName);\n });\n }\n };\n});\n"],"names":["define","$","ModalFactory","ModalEvents","init","addMethod","document","ready","isDragging","str","identifier","M","block_sharing_cart","moodle","get_action_url","name","args","url","cfg","wwwroot","q","k","push","encodeURIComponent","join","remove_basket","footerIconContainer","getElementById","querySelector","sharingCartBasket","removeChild","classList","remove","confirm_modal","obj","checkbox","body","create","type","types","SAVE_CANCEL","title","done","modal","is_submitted","setSaveButtonText","save_button","getRoot","on","save","e","response","target","find","is","next","cancel","hidden","removeClass","show","in_place_edit_section_name","$section","sectionName","$inPlaceEditable","length","data","on_backup_modal","post_data","title_str","body_str","isSection","post","sectionId","sectionNumber","courseId","userdata","$commands","closest","attr","text","trim","String","parent","inPlaceEditSectionName","$spinner","add_spinner","$node_spinner","add_node_spinner","sesskey","reload_tree","fail","show_error","always","hide","backup_section","sectionid","sectionnumber","courseid","cmid","course","id","backup","add","shake_basket","on_success","icon","css","iconClass","$block","match","is_frontpage","hasClass","ex","JSON","parse","responseText","core","exception","message","create_command","iconElement","addClass","append","$node","replaceWith","init_item_tree","directories","param","readCookie","KEY","opens","cookie","pop","split","map","v","parseInt","expires","Date","setDate","getDate","value","expireTimeInMillisecond","d","setTime","getTime","toUTCString","setCookie","open","$dir","visible","i","each","index","dir","toggle","reset","move_targets","$cancel","targets","this","$target","item_id","$current","$next","$list","next_id","create_target","area_to","$anchor","m","move","item","$item","to","before","restore_targets","is_directory","$clipboard","section","href","URL","util","image_url","$view","html","prepend","cloneNode","replace","$sitetopic","$mainmenu","$container","format","get_section_wrapper","sectionDOM","first","init_footer_basket","currentDragging","activities","querySelectorAll","sections","sharingCartBlock","courseSectionHeader","getElementsByClassName","HTMLElement","setAttribute","add_draggable_to_first_section","basket","createElement","basketButton","dropAreaText","innerText","dropArea","drag_event_listeners","draggable","addEventListener","children","forEach","activity","dropzone","preventDefault","click","undefined","get_plugin_name","$blockheader","on_backup","activityName","$backup","$activity","dataowner","on_movedir","$current_dir","current_path","dirs","$form","submit","folder_to","val","$input","setTimeout","focus","unshift","$select","change","$edit","on_move","on_delete","modalBody","liText","isDirectory","description_text","stopPropagation","on_restore","on_section_backup","init_bulk_delete","isspeciallayout","bulkdelete","init_help_icon","helpicon","init_block_header","add_actions","actions","action","$command","activity_actions","directory_actions","init_activity_commands","create_backup_icon","$backupIcon","add_activity_backup_control","activityClass","className","modtype","substr","indexOf","$actionMenuItem","ajaxComplete","event","xhr","settings","lastslashindex","lastIndexOf","result","substring","activity_id","isFlexibleCourseFormat","$sectionTitle","last","insertAfter","$activities","add_section_backup_control","pluginname","$section_selected"],"mappings":";;;;;;;AAuBAA,mCAAO,CAAC,SAAU,qBAAsB,sBAAsB,SAASC,EAAGC,aAAcC,mBAC7E,CACHC,KAAM,SAASC,WAEXJ,EAAEK,UAAUC,OAAM,eACVC,YAAa,WAQRC,IAAIC,mBACFC,EAAEF,IAAIG,mBAAmBF,aAAeC,EAAEF,IAAII,OAAOH,qBAUvDI,eAAeC,KAAMC,UACtBC,IAAMN,EAAEO,IAAIC,QAAU,wBAA0BJ,KAAO,UACvDC,KAA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,KAAK,kBAAkB8I,QAAQ9I,KAAK,KAAK0O,OAElEhO,iBAAmBF,SAASR,KAAK,mCAAmC8I,QACpEpI,iBAAiBC,SACjB8N,cAAgB/N,kBAIhB8N,wBAA4C,IAAlBpN,eAC1BqN,cAAgBjO,SAASR,KAAK,gBAChBqI,QAAQkF,aAEtBA,YAAYoB,YAAYF,mBAKxBG,YAAcpO,SAASR,KAFJ,eAIvBpD,EAAEgS,aAAazI,MAAK,WAChBqH,4BAA4B5Q,EAAE+J,UAKlCkI,CAA2BjS,EAAE+J,WA+GrC/J,EAAEG,KAAO,WACLO,EAAEF,IAAIG,mBAAmBuR,WAAanI,KAAK+D,kBAG3C9N,EAAEkQ,oBACFlQ,EAAE4H,iBACF5H,EAAEyQ,yBAEgB,kBAAdrQ,WACA+L,0BAGJhH,SAAWnF,EAAE,QAAQwH,SAAS,8CAClCxH,EAAE,wDAAwDyL,QAAQtG,UAElEnF,EAAEG,UAGNH,EAAE,iBAAiB+C,GAAG,SAAS,eAEvBoP,kBAAqBnS,EAAE,qCACvBuE,UAAY4N,kBAAkBnO,KAAK,cACnCQ,cAAgB2N,kBAAkBnO,KAAK,kBACvCS,SAAW0N,kBAAkBnO,KAAK,aAClCH,YAAcsO,kBAAkBnO,KAAK,gBAEzChE,EAAE4P,kBAAkBrL,UAAWC,cAAeC,SAAUZ"} \ No newline at end of file diff --git a/amd/src/script.js b/amd/src/script.js index b6c316c..340d442 100644 --- a/amd/src/script.js +++ b/amd/src/script.js @@ -647,42 +647,23 @@ define(['jquery', 'core/modal_factory', 'core/modal_events'], function($, ModalF * @returns {jQuery} */ - function create_target(id, section) { - var href = ''; - - var inSection = $('#copy-section-form').data('in-section'); - if (restore_targets.is_directory) { - href = get_action_url('restore', { - 'directory': true, - 'path': id, - 'course': course.id, - 'section': section, - 'in_section': inSection, - 'sesskey': M.cfg.sesskey - }); - } else { - href = get_action_url('restore', { - 'directory': false, - 'id': id, - 'course': course.id, - 'section': section, - 'in_section': inSection, - 'sesskey': M.cfg.sesskey - }); - } + const href = get_action_url('restore', { + 'directory': (restore_targets.is_directory === true), + 'target': id, + 'course': course.id, + 'section': section, + 'in_section': $('#copy-section-form').data('in-section'), + 'sesskey': M.cfg.sesskey, + 'returnurl': document.URL, + }); - var $target = $('') - .attr('class', 'restore') - .attr('href', href) - .attr('title', str('copyhere')) - .append( - $('') - .attr('alt', str('copyhere')) - .attr('src', M.util.image_url('dropzone_arrow', 'block_sharing_cart')) - ); + let $target = $('').attr('href', href).attr('title', str('copyhere')).append( + $('').attr('alt', str('copyhere')).attr('src', M.util.image_url('dropzone_arrow', 'block_sharing_cart')) + ); targets.push($target); + return $target; } diff --git a/block_sharing_cart.php b/block_sharing_cart.php index 1f7af34..8180d21 100644 --- a/block_sharing_cart.php +++ b/block_sharing_cart.php @@ -18,7 +18,7 @@ * Sharing Cart block * * @package block_sharing_cart - * @copyright 2021 (C) Don Hinkelman and others + * @copyright 2023 (c) Don Hinkelman, moxis and others * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/classes/section_title_form.php b/classes/section_title_form.php index fe762a6..7019ee3 100644 --- a/classes/section_title_form.php +++ b/classes/section_title_form.php @@ -14,7 +14,10 @@ class section_title_form extends \moodleform { private $directory; /** @var string */ - private $path; + private $target; + + /** @var string */ + private $returnurl; /** @var int */ private $courseid; @@ -29,18 +32,19 @@ class section_title_form extends \moodleform { * section_title_form constructor. * * @param bool $directory - * @param string $path + * @param string $target * @param int $courseid * @param int $sectionnumber * @param array $eligible_sections * @param int $items_count */ - public function __construct(bool $directory, string $path, int $courseid, int $sectionnumber, array $eligible_sections, int $items_count = 0) { + public function __construct(bool $directory, string $target, int $courseid, int $sectionnumber, array $eligible_sections, string $returnurl, int $items_count = 0) { $this->directory = $directory; - $this->path = $path; + $this->target = $target; $this->courseid = $courseid; $this->sectionnumber = $sectionnumber; $this->sections = $eligible_sections; + $this->returnurl = $returnurl; $this->items_count = $items_count; parent::__construct(); } @@ -51,39 +55,42 @@ public function definition(): void { $mform =& $this->_form; if ($this->items_count > 9) { - $mform->addElement('static', 'restore_heavy_load_warning_message', '', - ''); + $mform->addElement( + 'static', + 'restore_heavy_load_warning_message', + '', + '' + ); } $mform->addElement('static', 'description', '', get_string('conflict_description', 'block_sharing_cart')); - $mform->addElement('radio', 'sharing_cart_section', - get_string('conflict_no_overwrite', 'block_sharing_cart', $current_section_name), null, 0); + $mform->addElement('radio', 'overwrite', get_string('conflict_no_overwrite', 'block_sharing_cart', $current_section_name), null, 0); + foreach ($this->sections as $section) { $option_title = get_string('conflict_overwrite_title', 'block_sharing_cart', $section->name); - if ($section->summary != null) { - $option_title .= '
    ' . get_string('summary') . ': ' . - strip_tags($section->summary) . '
    '; - } - - $mform->addElement('radio', 'sharing_cart_section', $option_title, null, $section->id); + $option_title .= ($section->summary != null) ? '
    '.get_string('summary').': '.strip_tags($section->summary).'
    ' : ''; + $mform->addElement('radio', 'overwrite', $option_title, null, $section->id); } - $mform->setDefault('section_title', 0); + + $mform->setDefault('overwrite', 0); + $mform->addElement('hidden', 'directory', $this->directory); $mform->setType('directory', PARAM_BOOL); - $mform->addElement('hidden', 'path', $this->path); - $mform->setType('path', PARAM_TEXT); + + $mform->addElement('hidden', 'target', $this->target); + $mform->setType('target', PARAM_TEXT); + $mform->addElement('hidden', 'course', $this->courseid); $mform->setType('course', PARAM_INT); + $mform->addElement('hidden', 'section', $this->sectionnumber); $mform->setType('section', PARAM_INT); + + $mform->addElement('hidden', 'returnurl', $this->returnurl); + $mform->setType('returnurl', PARAM_TEXT); - $mform->addElement('static', 'description_note', '', - '
    ' . get_string('conflict_description_note', 'block_sharing_cart') . '
    '); + $mform->addElement('static', 'description_note', '', '
    '.get_string('conflict_description_note', 'block_sharing_cart').'
    '); $this->add_action_buttons(true, get_string('conflict_submit', 'block_sharing_cart')); } diff --git a/restore.php b/restore.php index 8b9fa55..f64ef5a 100644 --- a/restore.php +++ b/restore.php @@ -27,105 +27,82 @@ require_once '../../config.php'; -global $OUTPUT, $PAGE; +global $CFG, $OUTPUT, $PAGE, $DB, $USER; $directory = required_param('directory', PARAM_BOOL); -$id = null; -$path = null; - -if ($directory) { - $path = required_param('path', PARAM_TEXT); -} else { - $id = required_param('id', PARAM_INT); -} +$target = required_param('target', PARAM_RAW); $courseid = required_param('course', PARAM_INT); $sectionnumber = required_param('section', PARAM_INT); -$in_section = optional_param('in_section', 0, PARAM_INT); +$overwrite = optional_param('overwrite', 0, PARAM_INT); +$returnurl = optional_param('returnurl', '', PARAM_TEXT); -if ($courseid == SITEID) { - $returnurl = new moodle_url('/'); -} else { - $returnurl = new moodle_url('/course/view.php', array('id' => $courseid)); -} - -if ($in_section) { - $returnurl .= '§ion=' . $sectionnumber; -} else { - $returnurl .= '#section-' . $sectionnumber; +if (!$returnurl) { + $returnurl = ($courseid == SITEID) ? new moodle_url('/') : new moodle_url('/course/view.php', ['id' => $courseid]); } require_login($courseid); try { + $controller = new controller(); + // Trying to restore a directory of items if ($directory) { - $form = new section_title_form($directory, $path, $courseid, $sectionnumber, array()); - if ($form->is_cancelled()) { - redirect($returnurl); - exit; - } - $use_sc_section = optional_param('sharing_cart_section', -1, PARAM_INT); + $form = new section_title_form($directory, $target, $courseid, $sectionnumber, [], $returnurl, 0); - if ($path[0] == '/') { - $path = substr($path, 1); + if ($form->is_cancelled()) { + redirect($returnurl); exit; } - GLOBAL $DB, $USER; - $items = $DB->get_records('block_sharing_cart', array('tree' => $path, 'userid' => $USER->id)); - $items_count = count($items); - - if ($use_sc_section < 0) { - $sections = $controller->get_path_sections($path); - if (count($sections) > 0) { - $dest_section = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $sectionnumber)); + $target = ltrim($target, '/'); - $PAGE->set_pagelayout('standard'); - $PAGE->set_url('/blocks/sharing_cart/restore.php'); - $PAGE->set_title(get_string('pluginname', 'block_sharing_cart') . ' - ' . - get_string('restore', 'block_sharing_cart')); - $PAGE->set_heading(get_string('restore', 'block_sharing_cart')); + $sections = $controller->get_path_sections($target); - $urlchunk = '#section-'; - if ($in_section) { - $urlchunk = '§ion='; - } + // Directory contains an entire section of items. Display form to let user resolve conflicts + if (count($sections) > 0 && !$form->is_submitted()) { - $PAGE->navbar - ->add(get_section_name($courseid, $sectionnumber), - new moodle_url("/course/view.php?id={$courseid}{$urlchunk}{$sectionnumber}")) - ->add(get_string('pluginname', 'block_sharing_cart')) - ->add(get_string('restore', 'block_sharing_cart')); + $items = $DB->get_records('block_sharing_cart', array('tree' => $target, 'userid' => $USER->id)); + $items_count = count($items); - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('section_name_conflict', 'block_sharing_cart')); + $dest_section = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $sectionnumber)); - $form = new section_title_form($directory, $path, $courseid, $sectionnumber, $sections, $items_count); - $form->display(); + $PAGE->set_pagelayout('standard'); + $PAGE->set_url($returnurl); + $PAGE->set_title(get_string('pluginname', 'block_sharing_cart').' - '.get_string('restore', 'block_sharing_cart')); + $PAGE->set_heading(get_string('restore', 'block_sharing_cart')); - echo $OUTPUT->footer(); - exit; - } + $form = new section_title_form($directory, $target, $courseid, $sectionnumber, $sections, $returnurl, $items_count); - $use_sc_section = 0; + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('section_name_conflict', 'block_sharing_cart')); + $form->display(); + echo $OUTPUT->footer(); + exit; } - if ($use_sc_section > -1) { - $controller->restore_directory($path, $courseid, $sectionnumber, $use_sc_section); - } + // Perform directory restore + $controller->restore_directory($target, $courseid, $sectionnumber, $overwrite); + } else { - $controller->restore($id, $courseid, $sectionnumber); + + // Restore single item + $controller->restore($target, $courseid, $sectionnumber); + } redirect($returnurl); -} catch (sharing_cart\exception $ex) { +} catch (\block_sharing_cart\exception $ex) { + print_error($ex->errorcode, $ex->module, $returnurl, $ex->a); + } catch (Exception $ex) { + if (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER) { print_error('notlocalisederrormessage', 'error', '', $ex->__toString()); } else { print_error('unexpectederror', 'block_sharing_cart', $returnurl); } + } diff --git a/script.js b/script.js deleted file mode 100644 index 025218b..0000000 --- a/script.js +++ /dev/null @@ -1,1236 +0,0 @@ -// This file is part of Moodle - http://moodle.org/ -// -// Moodle is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Moodle. If not, see . - -/** - * Sharing Cart - * - * @package block_sharing_cart - * @copyright 2017 (C) VERSION2, INC. - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -require(['jquery', 'core/modal_factory', 'core/modal_events'], function($, ModalFactory, ModalEvents) { - $(document).ready(function() { - - /** - * Returns a localized string - * - * @param {String} identifier - * @return {String} - */ - function str(identifier) { - return M.str.block_sharing_cart[identifier] || M.str.moodle[identifier]; - } - - /** - * Get an action URL - * - * @param {String} name The action name - * @param {Object} [args] The action parameters - * @return {String} - */ - function get_action_url(name, args) { - var url = M.cfg.wwwroot + '/blocks/sharing_cart/' + name + '.php'; - if (args) { - var q = []; - for (var k in args) { - q.push(k + '=' + encodeURIComponent(args[k])); - } - url += '?' + q.join('&'); - } - return url; - } - - /** - * Modal called when confirming an action. - * - * @param obj - */ - function confirm_modal(obj) { - - // Checkbox for copying userdata confirmation. - if (obj.checkbox) { - obj.body += - ''; - } - - ModalFactory.create({ - type: ModalFactory.types.SAVE_CANCEL, - title: obj.title, - body: obj.body, - }).done(function(modal) { - modal.setSaveButtonText(obj.save_button); - - // On save save check - if checkbox is checked. - modal.getRoot().on(ModalEvents.save, function(e) { - - var response = { - 'checkbox': $(e.target).find('.modal-checkbox').is(':checked'), - }; - - obj.next(response); - }); - - // Remove modal from html. - modal.getRoot().on(ModalEvents.hidden, function() { - $('body').removeClass('modal-open'); - }); - - modal.show(); - }); - } - - /** - * Get the section name from the section when - * it's changed with the in place editor - * - * @param $section - * @returns {*} - */ - function in_place_edit_section_name($section) { - var sectionName = ''; - var $inPlaceEditable = $section.find('h3.sectionname .inplaceeditable'); - if ($inPlaceEditable.length) { - sectionName = $inPlaceEditable.data('value'); - } - return sectionName; - } - - /** - * @param post_data - * @param title_str - * @param body_str - * @param isSection - */ - function on_backup_modal(post_data, title_str, body_str, isSection) { - (function(on_success) { - $.post(get_action_url('rest'), post_data, - function(response) { - on_success(response); - }, "text") - .fail(function(response) { - show_error(response); - }); - })(function(response) { - var copyable = response === '1'; - var checkbox = false; - - if (copyable) { - checkbox = true; - } - - confirm_modal({ - 'title': title_str, - 'body': body_str, - 'save_button': str('modal_confirm_backup'), - 'checkbox': checkbox, - 'next': function(data) { - if (isSection === true) { - backup_section(post_data.sectionid, post_data.sectionnumber, post_data.courseid, data.checkbox); - } else { - backup(post_data.cmid, data.checkbox); - } - } - }); - }); - } - - /** @var {Object} The icon configurations */ - var icon = { - // Actions - 'backup': { - css: 'editing_backup', - iconClass: 'fa fa-frown-o', - }, - 'movedir': { - css: 'editing_right', - iconClass: 'fa fa-arrow-right', - }, - 'move': { - css: 'editing_move_', - iconClass: 'fa fa-arrows-v', - }, - 'edit': { - css: 'editing_update', - iconClass: 'fa fa-pencil', - }, - 'cancel': { - css: 'editing_cancel', - iconClass: 'fa fa-ban', - }, - 'delete': { - css: 'editing_update', - iconClass: 'fa fa-trash', - }, - 'restore': { - css: 'editing_restore', - iconClass: 'fa fa-clone', - }, - // Directories - 'dir-open': { - iconClass: 'fa fa-folder-open-o' - }, - 'dir-closed': { - iconClass: 'fa fa-folder-o' - }, - }; - - /** @var {Node} The Sharing Cart block container node */ - var $block = $('.block_sharing_cart'); - - /** @var {Object} The current course */ - var course = new function() { - var body = $('body'); - this.id = body.attr('class').match(/course-(\d+)/)[1]; - this.is_frontpage = body.hasClass('pagelayout-frontpage'); - }(); - - /** - * Shows an error message with given Ajax error - * - * @param {Object} response The Ajax response - */ - function show_error(response) { - try { - var ex = JSON.parse(response.responseText); - new M.core.exception({ - name: str('pluginname') + ' - ' + str('error'), - message: ex.message - }); - } catch (e) { - new M.core.exception({ - name: str('pluginname') + ' - ' + str('error'), - message: response.responseText - }); - } - } - - /** - * Check special layout (theme boost) - * - * @return {Boolean} - */ - function verify_layout() { - var menuelement = $block.find('.menubar .dropdown .dropdown-menu'); - return (menuelement.length); - } - - /** - * Set Cookie - * @param name - * @param value - * @param expireTimeInMillisecond - */ - function setCookie(name, value, expireTimeInMillisecond) { - var d = new Date(); - d.setTime(d.getTime() + expireTimeInMillisecond); - var expires = 'expires=' + d.toUTCString(); - document.cookie = name + '=' + value + ';' + expires + ''; - } - - /** - * Get Cookie Value - * @param param - * @returns {*} - */ - function getCookieValue(param) { - var readCookie = document.cookie.match('(^|;)\\s*' + param + '\\s*=\\s*([^;]+)'); - return readCookie ? readCookie.pop() : ''; - } - - /** - * Create a command icon - * - * @param {String} name The command name, predefined in icon - * @param {String} [pix] The icon pix name to override - */ - function create_command(name) { - var iconElement = $('') - .attr('alt', str(name)) - .attr('class', icon[name].iconClass); - // If (verify_layout()) { - // iconElement.addClass('iconcustom'); - // } - - return $('
    ') - .addClass(icon[name].css) - .attr('title', str(name)) - .append(iconElement); - } - - /** - * Create a spinner - * @param $node - * @returns {*|jQuery} - */ - function add_spinner() { - var $spinner = ($('
    ')); - $('section.block_sharing_cart').append($spinner); - return $spinner; - } - - /** - * - * @param $node - * @returns {jQuery.fn.init} - */ - function add_node_spinner($node) { - var $node_spinner = $(''); - $node.append($node_spinner); - return $node_spinner; - } - - /** - * - * Reload the Sharing Cart item tree - */ - function reload_tree() { - $.post(get_action_url("rest"), - { - "action": "render_tree" - }, - function(response) { - $block.find(".tree").replaceWith($(response)); - $.init_item_tree(); - }, "html") - .fail(function(response) { - show_error(response); - }); - } - - /** - * Backup an activity - * - * @param {int} cmid - * @param {Boolean} userdata - */ - function backup(cmid, userdata) { - var $commands = $('#module-' + cmid + ' .actions'); - if (!$commands.length) { - $commands = $('[data-owner="#module-' + cmid + '"]'); - } - - var $spinner = add_spinner(); - var $node_spinner = add_node_spinner($commands); - - $.post(get_action_url("rest"), - { - "action": "backup", - "cmid": cmid, - "userdata": userdata, - "sesskey": M.cfg.sesskey, - "course": course.id - }, - function() { - reload_tree(); - }) - .fail(function(response) { - show_error(response); - }) - .always(function() { - $node_spinner.hide(); - $spinner.hide(); - }); - } - - /** - * Backup an activities in a section - * - * @param {int} sectionId - * @param {int} sectionNumber - * @param {int} courseId - * @param {Boolean} userdata - */ - function backup_section(sectionId, sectionNumber, courseId, userdata) { - var $commands = $('span.inplaceeditable[data-itemtype=sectionname][data-itemid=' + sectionId + ']'); - var $section = $commands.closest("li.section.main"); - var sectionName = $section.attr('aria-label'); - - if (sectionName === null) { - sectionName = String($('#region-main .section_action_menu[data-sectionid=\'' + sectionId + '\']') - .parent().parent().find('h3.sectionname').text()); - } - - var inPlaceEditSectionName = in_place_edit_section_name($section); - sectionName = (inPlaceEditSectionName !== '') ? inPlaceEditSectionName : sectionName; - - var $spinner = add_spinner(); - var $node_spinner = add_node_spinner($commands); - - $.post(get_action_url("rest"), - { - "action": "backup_section", - "sectionid": sectionId, - "sectionnumber": sectionNumber, - "courseid": courseId, - "sectionname": sectionName, - "userdata": userdata, - "sesskey": M.cfg.sesskey, - "course": course.id - }, - function() { - reload_tree(); - }) - .fail(function(response) { - show_error(response); - }) - .always(function() { - $spinner.hide(); - $node_spinner.hide(); - }); - } - - - // /////// CLASSES ///////// - - /** - * @class Directory states manager - */ - var directories = new function() { - var KEY = 'block_sharing_cart-dirs'; - - var opens = getCookieValue(KEY).split(',').map(function(v) { - return parseInt(v); - }); - - function save() { - var expires = new Date(); - expires.setDate(expires.getDate() + 30); - setCookie(KEY, opens.join(','), expires); - } - - function open($dir, visible) { - var iconIndex = visible ? 'dir-open' : 'dir-closed'; - var iconElement = icon[iconIndex].iconClass; - $dir.find('> div i.icon').attr('class', 'icon ' + iconElement); - $dir.find('> ul.list')[visible ? 'show' : 'hide'](); - } - - function toggle(e) { - var $dir = $(e.target).closest('li.directory'); - var i = $dir.attr('id').match(/(\d+)$/)[1]; - var v = $dir.find('> ul.list').css('display') === 'none'; - - open($dir, v); - opens[i] = v ? 1 : 0; - save(); - } - - /** - * Initialize directory states - */ - this.init = function() { - var i = 0; - $block.find('li.directory').each(function(index, dir) { - var $dir = $(dir); - $dir.attr('id', 'block_sharing_cart-dir-' + i); - if (i >= opens.length) { - opens.push(0); - } else if (opens[i]) { - open($dir, true); - } - $dir.find('> div div.toggle-wrapper').css('cursor', 'pointer').on('click', function(e) { - toggle(e); - }); - i++; - }); - }; - - /** - * Reset directory states - */ - this.reset = function() { - opens = []; - this.init(); - save(); - }; - }(); - - /** - * @class Targets for moving an item directory - */ - var move_targets = new function() { - var $cancel = null, - targets = []; - - /** - * Hide move targets - */ - this.hide = function() { - if ($cancel !== null) { - var $commands = $cancel.closest('.commands'); - $cancel.remove(); - $cancel = null; - $commands.closest('li.activity').css('opacity', 1.0); - $commands.find('a').each(function() { - $(this).show(); - }); - $.each(targets, function(index, $target) { - $target.remove(); - }); - targets = []; - } - }; - - /** - * Show move targets for a given item - * - * @param {int} id The item ID - */ - this.show = function(item_id) { - this.hide(); - - function move(e) { - - var m = $(e.target).closest('a').attr('class').match(/move-(\d+)-to-(\d+)/); - var item_id = m[1], - area_to = m[2]; - - var $spinner = add_spinner(); - $.post(get_action_url("rest"), - { - "action": "move", - "item_id": item_id, - "area_to": area_to, - "sesskey": M.cfg.sesskey - }, - function() { - reload_tree(); - }) - .fail(function(response) { - show_error(response); - }) - .always(function() { - $spinner.hide(); - }); - } - - var $current = $block.find('#block_sharing_cart-item-' + item_id); - var $next = $current.next(); - var $list = $current.closest('ul'); - - var next_id = 0; - if ($next.length) { - next_id = $next.attr('id').match(/item-(\d+)$/)[1]; - } - - /** - * - * @param item_id - * @param area_to - * @returns {jQuery} - */ - function create_target(item_id, area_to) { - var $anchor = $('
    ') - .addClass('move-' + item_id + '-to-' + area_to) - .attr('title', str('movehere')) - .append( - $('

    ' + str('clicktomove') + '

    ') - .attr('alt', str('movehere')) - ); - - var $target = $('
  • ') - .append($anchor); - $anchor.on('click', function(e) { - move(e); - }); - - return $target; - } - - $list.find('> li.activity').each(function(index, item) { - var $item = $(item); - var to = $item.attr('id').match(/item-(\d+)$/)[1]; - if (to === item_id) { - $cancel = create_command('cancel', 't/left'); - $cancel.on('click', function() { - move_targets.hide(); - }); - var $commands = $item.find('.commands'); - $commands.find('a').each(function() { - $(this).hide(); - }); - $commands.append($cancel); - $item.css('opacity', 0.5); - } else if (to !== next_id) { - var $target = create_target(item_id, to); - $item.before($target); - targets.push($target); - } - }, this); - - if ($next) { - var $target = create_target(item_id, 0); - $list.append($target); - targets.push($target); - } - }; - }(); - - /** - * @class Targets for restoring an item - */ - var restore_targets = new function() { - this.is_directory = null; - var $clipboard = null, - targets = []; - - /** - * - * @param id - * @param section - * @returns {jQuery} - */ - function create_target(id, section) { - var href = ''; - - var inSection = $('#copy-section-form').data('in-section'); - if (restore_targets.is_directory) { - href = get_action_url('restore', { - 'directory': true, - 'path': id, - 'course': course.id, - 'section': section, - 'in_section': inSection, - 'sesskey': M.cfg.sesskey - }); - } else { - href = get_action_url('restore', { - 'directory': false, - 'id': id, - 'course': course.id, - 'section': section, - 'in_section': inSection, - 'sesskey': M.cfg.sesskey - }); - } - - var $target = $('') - .attr('href', href) - .attr('title', str('copyhere')) - .append( - $('') - .attr('alt', str('copyhere')) - .attr('src', M.util.image_url('dropzone_arrow', 'block_sharing_cart')) - ); - - targets.push($target); - return $target; - } - - /** - * Hide restore targets - */ - this.hide = function() { - if ($clipboard !== null) { - $clipboard.remove(); - $clipboard = null; - $.each(targets, function(index, $target) { - $target.remove(); - }); - targets = []; - } - }; - - /** - * - * - * @param {int} id The item ID - */ - this.show = function(id) { - this.hide(); - - var $view = $(""); - - if (this.is_directory) { - $view.html(id).css('display', 'inline'); - $view.prepend( - $("").addClass("icon") - .attr("alt", id) - // .attr("src", M.util.image_url(icon['dir-closed'].pix, null)) - ); - } else { - var $item = $block.find('#block_sharing_cart-item-' + id); - $view = $($item.find('div')[0].cloneNode(true)).css('display', 'inline'); - $view.attr('class', $view.attr('class').replace(/mod-indent-\d+/, '')); - $view.find('.commands').remove(); - } - - var $cancel = create_command('cancel'); - - $cancel.on('click', this.hide); - - $clipboard = $('
    '); - $clipboard.append(str('clipboard') + ": ").append($view).append($cancel); - - if (course.is_frontpage) { - var $sitetopic = $('.sitetopic'); - var $mainmenu = $('.block_site_main_menu'); - if ($sitetopic) { - $sitetopic.find('*').before($clipboard); - } else if ($mainmenu) { - $mainmenu.find('.content').before($clipboard); - } - - // Mainmenu = section #0, sitetopic = section #1 - if ($mainmenu) { - $mainmenu.find('.footer').before(create_target(id, 0)); - } - if ($sitetopic) { - $sitetopic.find('ul.section').append(create_target(id, 1)); - } - } else { - var $container = $('.course-content'); - $container.prepend($clipboard); - $container.find(M.course.format.get_section_wrapper(null)).each(function(index, sectionDOM) { - var $section = $(sectionDOM); - var section = $section.attr('id').match(/(\d+)$/)[1]; - $section.find('ul.section').first().append(create_target(id, section)); - }, this); - } - }; - }(); - - // /////// INITIALIZATION ///////// - - /** - * - * @returns {string|*} - */ - $.get_plugin_name = function() { - var $blockheader = $block.find("h2"); - - if (!$blockheader.length) { - $blockheader = $block.find("h3"); - - if ($blockheader.length) { - return $blockheader.html(); - } - } else { - return $blockheader.html(); - } - - return ""; - }; - - /** - * - * @param e - * @param activityName - */ - $.on_backup = function(e, activityName) { - var cmid = (function($backup) { - var $activity = $backup.closest('li.activity'); - if ($activity.length) { - return $activity.attr('id').match(/(\d+)$/)[1]; - } - var $commands = $backup.closest('.commands'); - var dataowner = $commands.attr('data-owner'); - if (dataowner.length) { - return dataowner.match(/(\d+)$/)[1]; - } - return $commands.find('a.editing_delete').attr('href').match(/delete=(\d+)/)[1]; - })($(e.target)); - - var data = - { - "action": "is_userdata_copyable", - "cmid": cmid - }; - - on_backup_modal(data, activityName, str('confirm_backup'), false); - }; - - /** - * On movedir command clicked - * - * @param {DOMEventFacade} e - */ - $.on_movedir = function(e) { - var $commands = $(e.target).closest('.commands'); - - var $current_dir = $commands.closest('li.directory'); - var current_path = $current_dir.length ? $current_dir.attr('directory-path') : '/'; - - var item_id = $(e.target).closest('li.activity').attr('id').match(/(\d+)$/)[1]; - - var dirs = []; - $block.find('li.directory').each(function() { - dirs.push($(this).attr('directory-path')); - }); - - var $form = $(''); - $form.attr('action', 'javascript:void(0)'); - - function submit() { - var folder_to = $form.find('[name="to"]').val(); - var $spinner = add_spinner(); - $.post(get_action_url('rest'), - { - "action": "movedir", - "item_id": item_id, - "folder_to": folder_to, - "sesskey": M.cfg.sesskey - }, - function() { - reload_tree(); - directories.reset(); - }) - .fail(function(response) { - show_error(response); - }) - .always(function() { - $spinner.hide(); - }); - } - - $form.submit(submit); - - if (dirs.length === 0) { - var $input = $('').val(current_path); - setTimeout(function() { - $input.focus(); - }, 1); - $form.append($input); - } else { - dirs.unshift('/'); - - var $select = $('').val(current_path); - $select.remove(); - $edit.replaceWith($input); - $input.focus(); - }); - - $form.append($edit); - } - - var $cancel = create_command('cancel'); - $cancel.on('click', function() { - $form.remove(); - $commands.find('a').show(); - }); - $form.append($cancel); - - $commands.find('a').each(function() { - $(this).hide(); - }); - $commands.append($form); - }; - - /** - * On move command clicked - * - * @param {DOMEventFacade} e - */ - $.on_move = function(e) { - var $item = $(e.target).closest('li.activity'); - var id = $item.attr('id').match(/(\d+)$/)[1]; - - move_targets.show(id); - }; - - /** - * On delete command clicked - * - * @param {DOMEventFacade} e - */ - $.on_delete = function(e) { - var $item = $(e.target).closest('li'); - var liText = $item[0].innerText; - - var isDirectory = false; - var modalBody; - var item; - var description_text = ''; - - if ($item.hasClass("directory")) { - isDirectory = true; - item = str('folder_string'); - description_text = str('delete_folder'); - } else { - item = str('activity_string'); - } - - modalBody = '

    ' + item + ' ' + liText + description_text + '

    '; - - confirm_modal({ - 'title': str('confirm_delete'), - 'body': modalBody, - 'save_button': str('modal_confirm_delete'), - 'checkbox': false, - 'next': function() { - - var data = {}; - - if (isDirectory === true) { - data = { - "action": "delete_directory", - "path": $item.attr("directory-path"), - "sesskey": M.cfg.sesskey - }; - } else if ($item.hasClass("activity")) { - data = { - "action": "delete", - "id": $item.attr('id').match(/(\d+)$/)[1], - "sesskey": M.cfg.sesskey - }; - } - - var $spinner = add_spinner(); - - $.post(get_action_url("rest"), data, - function() { - reload_tree(); - }) - .fail(function(response) { - show_error(response); - }) - .always(function() { - $spinner.hide(); - }); - - e.stopPropagation(); - } - }); - }; - - /** - * On restore command clicked - * - * @param {DOMEventFacade} e - */ - $.on_restore = function(e) { - var $item = $(e.target).closest('li'); - var id = null; - - if ($item.hasClass("directory")) { - id = $item.attr("directory-path"); - restore_targets.is_directory = true; - } else if ($item.hasClass("activity")) { - id = $item.attr('id').match(/(\d+)$/)[1]; - restore_targets.is_directory = false; - } - - restore_targets.show(id); - }; - - /** - * On backup the whole section as a folder - * - * @param {int} sectionId - * @param {int} sectionNumber - * @param {int} courseId - * @param {string} sectionName - */ - $.on_section_backup = function(sectionId, sectionNumber, courseId, sectionName) { - var data = - { - "action": "is_userdata_copyable_section", - "sectionid": sectionId, - "sectionnumber": sectionNumber, - "courseid": courseId, - }; - - on_backup_modal(data, sectionName, str('confirm_backup_section'), true); - }; - - /** - * Initialize the delete bulk - */ - $.init_bulk_delete = function(isspeciallayout) { - var bulkdelete = $block.find('.editing_bulkdelete'); - if (bulkdelete.length) { - if (isspeciallayout) { - bulkdelete.attr('role', 'menuitem').addClass('dropdown-item menu-action'); - bulkdelete.append($("").append(bulkdelete.attr('title'))); - - $block.find('.menubar .dropdown .dropdown-menu').append(bulkdelete); - } else { - $block.find('.header .commands').append(bulkdelete); - } - } - }; - - /** - * Initialize the help icon - */ - $.init_help_icon = function(isspeciallayout) { - var helpicon = $block.find('.header-commands > .help-icon'); - - if (isspeciallayout) { - $block.find('.header-commands').parent().css('display', 'block'); - } else { - $block.find('.header .commands').append(helpicon); - } - }; - - /** - * Initialize the Sharing Cart block header - */ - $.init_block_header = function() { - var isspeciallayout = verify_layout(); - $.init_bulk_delete(isspeciallayout); - $.init_help_icon(isspeciallayout); - }; - - /** - * Remove an action - * - * @param actions The actions - * @param actionKey The key of the action to remove - * - * @returns actions The actions without the item to remove - */ - $.remove_action = function(actions, actionKey) { - var indexOfAction = actions.indexOf(actionKey); - if (indexOfAction > -1) { - actions.splice(indexOfAction, 1); - } - return actions; - }; - - /** - * Initialize the Sharing Cart item tree - */ - $.init_item_tree = function() { - function add_actions(item, actions) { - var $item = $(item); - var $commands = $item.find('.commands').first(); - - var disallowedActions = $('#alert-disallow').data('disallowed-actions'); - if (disallowedActions != null) { - disallowedActions.split(',').forEach(function(actionKey) { - $.remove_action(actions, actionKey); - }); - } - - $.each(actions, function(index, action) { - var $command = create_command(action); - $command.on('click', function(e) { - $['on_' + action](e); - }); - $commands.append($command); - }, this); - } - - var activity_actions = ['movedir', 'move', 'delete']; - if (course) { - activity_actions.push('restore'); - } - - var directory_actions = ['delete', 'restore']; - - // Initialize items - $block.find('li.activity').each(function(index, item) { - add_actions(item, activity_actions); - }); - - // Initialize directory items - $block.find('li.directory').each(function(index, item) { - add_actions(item, directory_actions); - }); - - // Initialize directories - directories.init(); - }; - - /** - * Extract html object from area where moodle ajax was called. - * - * Call add_activity_backup_control to re append sharing cart icon. - */ - $.init_activity_commands = function() { - $(document).ajaxComplete(function(event, xhr, settings) { - - var url = settings.url; - var lastslashindex = url.lastIndexOf('='); - var result = url.substring(lastslashindex + 1); - - if (result === 'core_course_edit_module' || result === 'core_course_get_module') { - - var data = JSON.parse(settings.data); - var action = data[0].args.action; - - // Don't try to add icon if activity has been deleted. - if (action === 'delete') { - return; - } - - setTimeout(function() { - var activity_id = data[0].args.id; - var activity = $('#module-' + activity_id); - add_activity_backup_control(activity); - - if (action === 'duplicate') { - var duplicated = activity.next(); - add_activity_backup_control(duplicated); - } - }, 1); - } - }); - - /** - * Create the backup icon - * - * @returns $backupIcon - */ - function create_backup_icon() { - - var $backupIcon = $('
    ') - .append($('')) - .attr('title', str('backup')); - - return $backupIcon; - } - - /** - * Add backup control with a click event to an activity - * Added fix for copying an activity without backup routine - * - * @param $activity - */ - function add_activity_backup_control($activity) { - - var activityClass = $activity[0].className; - - // Selecting modtype without prefix. - var modtype = activityClass.substr(activityClass.indexOf('modtype_') + 8); - - // Default activity name. - var activityName = str('activity_string'); - - // Label is using a different html / css layout, so it's needed to get the name by using another $find. - if (modtype !== 'label') { - activityName = $('.activity#' + $activity[0].id) - .find('.mod-indent-outer .activityinstance span.instancename') - .html(); - } - - var $backupIcon = create_backup_icon(); - - $backupIcon.on('click', function(e) { - $.on_backup(e, activityName); - }); - - var $actionMenuItem = $activity.find('.action-menu.section-cm-edit-actions').parent('.actions'); - - $actionMenuItem.append($backupIcon); - } - - /** - * Add backup control with a click event to a section - * - * @param $section - */ - function add_section_backup_control($section) { - - var sectionId = $section.find('.section_action_menu').data('sectionid'); - var sectionNumber = parseInt(String($section.attr('id')).match(/\d+/)[0]); - var sectionName = $section.attr('aria-label'); - - var isFlexibleCourseFormat = $('body[id$=flexsections]').length; - - // Extract the section ID from the section if this is a Flexible - // course format (since this format doesn't have an action menu) - if (isFlexibleCourseFormat && (typeof sectionId === 'undefined' || sectionId === null)) { - sectionId = $section.data('section-id'); - } - - // A bit unsafe to extract the course ID from the body but it's the best option we got at the moment - var courseId = parseInt(String($('body').attr('class')).match(/course-([0-9]*)( |$)/)[1]); - - var $backupIcon = create_backup_icon(); - - $backupIcon.on('click', function() { - var inPlaceEditSectionName = in_place_edit_section_name($section); - sectionName = (inPlaceEditSectionName !== '') ? inPlaceEditSectionName : sectionName; - $.on_section_backup(sectionId, sectionNumber, courseId, sectionName); - }); - - var $sectionTitle = $section.find('h3.sectionname').first().find('a').last(); - - var $inPlaceEditable = $section.find('h3.sectionname .inplaceeditable').first(); - if ($inPlaceEditable.length) { - $sectionTitle = $inPlaceEditable; - } - - // Add the backup icon after the cog wheel if this is a Flexible course format - if (isFlexibleCourseFormat && sectionNumber === 0) { - $sectionTitle = $section.find('> .controls'); - $sectionTitle.prepend($backupIcon); - } else { - $backupIcon.insertAfter($sectionTitle); - } - - var activitySelector = 'li.activity'; - - if (isFlexibleCourseFormat) { - activitySelector = 'li.activity.activity-section-' + sectionId; - } - - var $activities = $section.find(activitySelector); - - $($activities).each(function() { - add_activity_backup_control($(this)); - }); - } - - $("body.editing .course-content li.section").each(function() { - add_section_backup_control($(this)); - }); - }; - - /** - * Initialize the Sharing Cart block - */ - $.init = function() { - M.str.block_sharing_cart.pluginname = this.get_plugin_name(); - - // Arrange header icons (bulkdelete, help) - $.init_block_header(); - $.init_item_tree(); - $.init_activity_commands(); - }; - var $spinner = $('').addClass('spinner fa fa-3x fa-circle-o-notch fa-spin'); - $('div#sharing-cart-spinner-modal div.spinner-container').prepend($spinner); - - $.init(); - }); - - $('.copy_section').on('click', function() { - - var $section_selected = ($('.section-dropdown option:selected')); - var sectionId = $section_selected.data('section-id'); - var sectionNumber = $section_selected.data('section-number'); - var courseId = $section_selected.data('course-id'); - var sectionName = $section_selected.data('section-name'); - - $.on_section_backup(sectionId, sectionNumber, courseId, sectionName); - }); -}); \ No newline at end of file diff --git a/settings.php b/settings.php index 1515e02..5a8d6d3 100644 --- a/settings.php +++ b/settings.php @@ -18,7 +18,7 @@ * Sharing Cart * * @package block_sharing_cart - * @copyright 2021 (C) Don Hinkelman and others + * @copyright 2023 (c) Don Hinkelman, moxis and others * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/version.php b/version.php index 2c5d150..b6bfb9a 100644 --- a/version.php +++ b/version.php @@ -18,7 +18,7 @@ * Sharing Cart * * @package block_sharing_cart - * @copyright 2022 (c) Don Hinkelman, Praxis and others + * @copyright 2023 (c) Don Hinkelman, moxis and others * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -26,7 +26,7 @@ /** @var object $plugin */ $plugin->component = 'block_sharing_cart'; -$plugin->version = 2023032300; +$plugin->version = 2023070500; $plugin->requires = 2022112800; // Moodle 4.1.0 -$plugin->release = '4.1, release 1'; +$plugin->release = '4.1, release 2'; $plugin->maturity = MATURITY_STABLE; From a012f768253ae6ffc20786720f67f8f42c396625 Mon Sep 17 00:00:00 2001 From: Sven Bachmann Date: Fri, 7 Jul 2023 12:42:56 +0200 Subject: [PATCH 3/3] Adjust CI workflows --- .github/workflows/push.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index be93924..0c8dce4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -5,7 +5,6 @@ on: branches: - master - MOODLE_41_STABLE - - MOODLE_40_STABLE env: php: 8.2 @@ -17,18 +16,6 @@ jobs: strategy: matrix: include: - ## Moodle 4.0+ with PHP 7.4 - - os: ubuntu-20.04 - php: 7.4 - db: mysqli - moodle: MOODLE_400_STABLE - experimental: false - ## Moodle 4.0+ with PHP 8.0 - - os: ubuntu-22.04 - php: 8.0 - db: mysqli - moodle: MOODLE_400_STABLE - experimental: false ## Moodle 4.1+ with PHP 8.0 - os: ubuntu-22.04 php: 8.0