From 2170453f81e331bf88705af94a5ec98a8ee53f4a Mon Sep 17 00:00:00 2001 From: Frederik Milling Pytlick Date: Mon, 19 Aug 2024 10:44:07 +0200 Subject: [PATCH] #164 - Refactored drag & drop to hook into reactivity components --- amd/build/app/block/element.min.js | 2 +- amd/build/app/block/element.min.js.map | 2 +- amd/build/local/block.min.js | 2 +- amd/build/local/block.min.js.map | 2 +- amd/src/app/block/element.js | 53 +++++++++----------------- amd/src/local/block.js | 34 +++++++++++++++++ version.php | 2 +- 7 files changed, 57 insertions(+), 40 deletions(-) diff --git a/amd/build/app/block/element.min.js b/amd/build/app/block/element.min.js index 148dc31..645335e 100644 --- a/amd/build/app/block/element.min.js +++ b/amd/build/app/block/element.min.js @@ -1,3 +1,3 @@ -define("block_sharing_cart/app/block/element",["exports","../../lib/sortablejs","core/modal_factory","core/modal_events","core/str","core/ajax","core/notification"],(function(_exports,_sortablejs,_modal_factory,_modal_events,_str,_ajax,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classPrivateFieldInitSpec(obj,privateMap,value){!function(obj,privateCollection){if(privateCollection.has(obj))throw new TypeError("Cannot initialize the same private elements twice on an object")}(obj,privateMap),privateMap.set(obj,value)}function _classPrivateFieldGet(receiver,privateMap){return function(receiver,descriptor){if(descriptor.get)return descriptor.get.call(receiver);return descriptor.value}(receiver,_classExtractFieldDescriptor(receiver,privateMap,"get"))}function _classPrivateFieldSet(receiver,privateMap,value){return function(receiver,descriptor,value){if(descriptor.set)descriptor.set.call(receiver,value);else{if(!descriptor.writable)throw new TypeError("attempted to set read only private field");descriptor.value=value}}(receiver,_classExtractFieldDescriptor(receiver,privateMap,"set"),value),value}function _classExtractFieldDescriptor(receiver,privateMap,action){if(!privateMap.has(receiver))throw new TypeError("attempted to "+action+" private field on non-instance");return privateMap.get(receiver)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_sortablejs=_interopRequireDefault(_sortablejs),_modal_factory=_interopRequireDefault(_modal_factory),_modal_events=_interopRequireDefault(_modal_events),_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification);var _baseFactory=new WeakMap,_element=new WeakMap,_course=new WeakMap,_queue=new WeakMap,_items=new WeakMap,_sortable=new WeakMap,_clipboardItem=new WeakMap,_canBackupUserdata=new WeakMap,_canAnonymizeUserdata=new WeakMap,_showSharingCartBasket=new WeakMap,_draggedCourseModuleId=new WeakMap,_draggedSectionId=new WeakMap;return _exports.default=class{constructor(baseFactory,element,canBackupUserdata,canAnonymizeUserdata,showSharingCartBasket){_classPrivateFieldInitSpec(this,_baseFactory,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_element,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_course,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_queue,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_items,{writable:!0,value:[]}),_classPrivateFieldInitSpec(this,_sortable,{writable:!0,value:null}),_classPrivateFieldInitSpec(this,_clipboardItem,{writable:!0,value:null}),_classPrivateFieldInitSpec(this,_canBackupUserdata,{writable:!0,value:!1}),_classPrivateFieldInitSpec(this,_canAnonymizeUserdata,{writable:!0,value:!1}),_classPrivateFieldInitSpec(this,_showSharingCartBasket,{writable:!0,value:!1}),_classPrivateFieldInitSpec(this,_draggedCourseModuleId,{writable:!0,value:null}),_classPrivateFieldInitSpec(this,_draggedSectionId,{writable:!0,value:null}),_classPrivateFieldSet(this,_baseFactory,baseFactory),_classPrivateFieldSet(this,_element,element),_classPrivateFieldSet(this,_canBackupUserdata,canBackupUserdata),_classPrivateFieldSet(this,_canAnonymizeUserdata,canAnonymizeUserdata),_classPrivateFieldSet(this,_showSharingCartBasket,showSharingCartBasket)}addEventListeners(){return this.setupCourse(),this.setupQueue(),this.setupItems(),this.setupDragAndDrop(),this.setupBulkDelete(),{course:_classPrivateFieldGet(this,_course),queue:_classPrivateFieldGet(this,_queue),block:this}}setupCourse(){const course=document.querySelector(".course-content");_classPrivateFieldSet(this,_course,_classPrivateFieldGet(this,_baseFactory).block().course().element(this,course))}setupQueue(){const queue=document.querySelector(".sharing_cart_queue");_classPrivateFieldSet(this,_queue,_classPrivateFieldGet(this,_baseFactory).block().queue().element(this,queue))}setupItems(){_classPrivateFieldGet(this,_element).querySelectorAll(".sharing_cart_item").forEach((element=>{this.setupItem(element)})),_classPrivateFieldSet(this,_sortable,new _sortablejs.default(_classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items"),{dataIdAttr:"data-itemid",onUpdate:()=>{_ajax.default.call([{methodname:"block_sharing_cart_reorder_sharing_cart_items",args:{item_ids:_classPrivateFieldGet(this,_sortable).toArray()},fail:data=>{_notification.default.exception(data)}}])}}))}setupDragAndDrop(){const dropZone=_classPrivateFieldGet(this,_element),draggableCourseModules=document.querySelectorAll('.course-content .activity[data-for="cmitem"][data-id]'),draggableSections=document.querySelectorAll('.course-content .section[data-for="section"][data-id]');draggableCourseModules.forEach((courseModule=>{const courseModuleId=Number.parseInt(courseModule.dataset.id);courseModuleId&&(courseModule.addEventListener("dragstart",(()=>{_classPrivateFieldSet(this,_draggedCourseModuleId,courseModuleId),dropZone.classList.add("dragging_item")})),courseModule.addEventListener("dragend",(()=>{_classPrivateFieldSet(this,_draggedCourseModuleId,null),dropZone.classList.remove("dragging_item")})))})),draggableSections.forEach((section=>{const id=Number.parseInt(section.dataset.id);if(!id)return;const draggable=section.querySelector('[data-for="section_title"]');draggable.addEventListener("dragstart",(()=>{_classPrivateFieldSet(this,_draggedSectionId,id),dropZone.classList.add("dragging_item")})),draggable.addEventListener("dragend",(()=>{_classPrivateFieldSet(this,_draggedSectionId,null),dropZone.classList.remove("dragging_item")}))})),dropZone.addEventListener("dragover",(e=>{(_classPrivateFieldGet(this,_draggedSectionId)||_classPrivateFieldGet(this,_draggedCourseModuleId))&&(e.preventDefault(),e.stopPropagation())})),dropZone.addEventListener("dragleave",(e=>{(_classPrivateFieldGet(this,_draggedSectionId)||_classPrivateFieldGet(this,_draggedCourseModuleId))&&(e.preventDefault(),e.stopPropagation())})),dropZone.addEventListener("drop",(async e=>{(_classPrivateFieldGet(this,_draggedSectionId)||_classPrivateFieldGet(this,_draggedCourseModuleId))&&(e.preventDefault(),e.stopPropagation(),_classPrivateFieldGet(this,_draggedSectionId)?await this.addSectionBackupToSharingCart(_classPrivateFieldGet(this,_draggedSectionId)):_classPrivateFieldGet(this,_draggedCourseModuleId)&&await this.addCourseModuleBackupToSharingCart(_classPrivateFieldGet(this,_draggedCourseModuleId)))}))}setupBulkDelete(){const enableBulkDeleteButton=_classPrivateFieldGet(this,_element).querySelector("#block_sharing_cart_bulk_delete"),disableBulkDeleteButton=_classPrivateFieldGet(this,_element).querySelector("#block_sharing_cart_cancel_bulk_delete"),bulkDeleteButton=_classPrivateFieldGet(this,_element).querySelector("#block_sharing_cart_bulk_delete_confirm"),checkboxSelector='.sharing_cart_item input[data-action="bulk_select"][type="checkbox"]';enableBulkDeleteButton.addEventListener("click",(()=>{enableBulkDeleteButton.classList.add("d-none"),disableBulkDeleteButton.classList.remove("d-none"),bulkDeleteButton.classList.remove("d-none"),_classPrivateFieldGet(this,_element).querySelectorAll(checkboxSelector).forEach((checkbox=>{checkbox.classList.remove("d-none"),checkbox.checked=!1}))})),disableBulkDeleteButton.addEventListener("click",(()=>{disableBulkDeleteButton.classList.add("d-none"),bulkDeleteButton.classList.add("d-none"),bulkDeleteButton.disabled=!0,enableBulkDeleteButton.classList.remove("d-none"),_classPrivateFieldGet(this,_element).querySelectorAll(checkboxSelector).forEach((checkbox=>{checkbox.classList.add("d-none"),checkbox.checked=!1}))})),bulkDeleteButton.addEventListener("click",(async()=>{if(bulkDeleteButton.disabled)return;const itemIds=[];_classPrivateFieldGet(this,_element).querySelectorAll(checkboxSelector+":checked").forEach((checkbox=>{itemIds.push(checkbox.value)})),await this.confirmDeleteItems(itemIds)}))}setupItem(element){var _classPrivateFieldGet2;const itemElement=_classPrivateFieldGet(this,_baseFactory).block().item().element(this,element);null===(_classPrivateFieldGet2=_classPrivateFieldGet(this,_element).querySelector(".no-items"))||void 0===_classPrivateFieldGet2||_classPrivateFieldGet2.remove(),_classPrivateFieldGet(this,_items).push(itemElement)}async setClipboard(item){_classPrivateFieldSet(this,_clipboardItem,item),await _classPrivateFieldGet(this,_course).setClipboard(item)}clearClipboard(){_classPrivateFieldSet(this,_clipboardItem,null)}async removeItemElement(item){var _classPrivateFieldGet4;item.getItemChildrenRecursively().forEach((childItem=>{var _classPrivateFieldGet3;const index=_classPrivateFieldGet(this,_items).findIndex((i=>i.getItemId()===Number.parseInt(childItem.dataset.itemid)));-1!==index&&(_classPrivateFieldGet(this,_items)[index].getItemId()===(null===(_classPrivateFieldGet3=_classPrivateFieldGet(this,_clipboardItem))||void 0===_classPrivateFieldGet3?void 0:_classPrivateFieldGet3.getItemId())&&_classPrivateFieldGet(this,_course).clearClipboard(),_classPrivateFieldGet(this,_items).splice(index,1),childItem.remove())}));const index=_classPrivateFieldGet(this,_items).findIndex((i=>i.getItemId()===item.getItemId()));_classPrivateFieldGet(this,_items)[index].getItemId()===(null===(_classPrivateFieldGet4=_classPrivateFieldGet(this,_clipboardItem))||void 0===_classPrivateFieldGet4?void 0:_classPrivateFieldGet4.getItemId())&&_classPrivateFieldGet(this,_course).clearClipboard(),_classPrivateFieldGet(this,_items).splice(index,1),item.remove(),0===_classPrivateFieldGet(this,_items).length&&(_classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items").innerHTML=await(0,_str.get_string)("no_items","block_sharing_cart"))}deleteItem(item){_ajax.default.call([{methodname:"block_sharing_cart_delete_item_from_sharing_cart",args:{item_id:item.getItemId()},done:async deleted=>{deleted?await this.removeItemElement(item):await _notification.default.alert("Failed to delete item")},fail:data=>{_notification.default.exception(data)}}])}deleteItems(itemIds){itemIds=itemIds.map((id=>Number.parseInt(id))),_ajax.default.call([{methodname:"block_sharing_cart_delete_items_from_sharing_cart",args:{item_ids:itemIds},done:async deletedItemIds=>{const items=_classPrivateFieldGet(this,_items).filter((i=>itemIds.includes(i.getItemId())));for(const item of items){deletedItemIds.includes(item.getItemId())?await this.removeItemElement(item):_notification.default.alert('Failed to delete item: "'+item.getItemName()+'"')}document.getElementById("block_sharing_cart_bulk_delete_confirm").disabled=!0},fail:data=>{_notification.default.exception(data)}}])}async createBackupItemToSharingCartModal(itemName,onSave){const strings=await(0,_str.get_strings)([{key:"backup_item",component:"block_sharing_cart"},{key:"into_sharing_cart",component:"block_sharing_cart"},{key:"backup",component:"block_sharing_cart"},{key:"cancel",component:"core"}]),{html:html,js:js}=await _classPrivateFieldGet(this,_baseFactory).moodle().template().renderTemplate("block_sharing_cart/modal/backup_to_sharing_cart_modal_body",{show_user_data_backup:_classPrivateFieldGet(this,_canBackupUserdata),show_anonymize_user_data:_classPrivateFieldGet(this,_canBackupUserdata)&&_classPrivateFieldGet(this,_canAnonymizeUserdata)}),modal=await _modal_factory.default.create({type:_modal_factory.default.types.SAVE_CANCEL,title:strings[0]+': "'+itemName.slice(0,50).trim()+'" '+strings[1],body:html,buttons:{save:strings[2],cancel:strings[3]},removeOnClose:!0});return modal.getRoot().on(_modal_events.default.shown,(()=>_classPrivateFieldGet(this,_baseFactory).moodle().template().runTemplateJS(js))),modal.getRoot().on(_modal_events.default.save,(()=>{var _modalUserdataCheckbo,_modalAnonymizeCheckb;const modalUserdataCheckbox=document.getElementById("modal-userdata-checkbox"),modalAnonymizeCheckbox=document.getElementById("modal-anonymize-checkbox");onSave({users:null!==(_modalUserdataCheckbo=null==modalUserdataCheckbox?void 0:modalUserdataCheckbox.checked)&&void 0!==_modalUserdataCheckbo&&_modalUserdataCheckbo,anonymize:null!==(_modalAnonymizeCheckb=null==modalAnonymizeCheckbox?void 0:modalAnonymizeCheckbox.checked)&&void 0!==_modalAnonymizeCheckb&&_modalAnonymizeCheckb})})),modal}async addSectionBackupToSharingCart(sectionId){const sectionName=_classPrivateFieldGet(this,_course).getSectionName(sectionId);if(0===_classPrivateFieldGet(this,_course).getSectionCourseModules(sectionId).length){const strings=await(0,_str.get_strings)([{key:"no_course_modules_in_section",component:"block_sharing_cart"},{key:"no_course_modules_in_section_description",component:"block_sharing_cart"}]);return void await _notification.default.alert(strings[0],strings[1])}const modal=await this.createBackupItemToSharingCartModal(sectionName,(settings=>{_ajax.default.call([{methodname:"block_sharing_cart_backup_section_into_sharing_cart",args:{section_id:sectionId,settings:settings},done:async data=>{await this.renderItem(data)},fail:data=>{_notification.default.exception(data)}}])}));await modal.show()}async addCourseModuleBackupToSharingCart(courseModuleId){const courseModuleName=_classPrivateFieldGet(this,_course).getCourseModuleName(courseModuleId),modal=await this.createBackupItemToSharingCartModal(courseModuleName,(settings=>{_ajax.default.call([{methodname:"block_sharing_cart_backup_course_module_into_sharing_cart",args:{course_module_id:courseModuleId,settings:settings},done:async data=>{await this.renderItem(data)},fail:data=>{_notification.default.exception(data)}}])}));await modal.show()}async renderItem(item){var _classPrivateFieldGet5,_item$task_id;const existingItemIndex=_classPrivateFieldGet(this,_items).findIndex((i=>i.getItemId()===item.id)),existingItem=null!==(_classPrivateFieldGet5=_classPrivateFieldGet(this,_items)[existingItemIndex])&&void 0!==_classPrivateFieldGet5&&_classPrivateFieldGet5,oldElement=_classPrivateFieldGet(this,_element).querySelector('.sharing_cart_items .sharing_cart_item[data-itemid="'+item.id+'"]');if(existingItem&&oldElement){const element=await _classPrivateFieldGet(this,_baseFactory).moodle().template().createElementFromFragment("block_sharing_cart","item",1,{item_id:item.id});return _classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items").replaceChild(element,oldElement),_classPrivateFieldGet(this,_items)[existingItemIndex]=_classPrivateFieldGet(this,_baseFactory).block().item().element(this,element),void element.querySelectorAll(".sharing_cart_item").forEach((subItem=>{this.setupItem(subItem)}))}const element=await _classPrivateFieldGet(this,_baseFactory).moodle().template().createElementFromTemplate("block_sharing_cart/block/item",{id:item.id,name:item.name,type:item.type,status:0,old_instance_id:item.old_instance_id,status_awaiting:!0,has_run_now:!0,task_id:null!==(_item$task_id=item.task_id)&&void 0!==_item$task_id?_item$task_id:null,status_finished:!1,status_failed:!1,is_module:"section"!==item.type,is_section:"section"===item.type,is_root:!0});_classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items").prepend(element),this.setupItem(element)}importItem(item,sectionId,modal){_classPrivateFieldGet(this,_course).clearClipboard();const courseModuleIds=[];if(modal.querySelectorAll('input[type="checkbox"][data-type="coursemodule"]:checked').forEach((checkbox=>{courseModuleIds.push(checkbox.dataset.id)})),item.isSection()&&0===courseModuleIds.length)return modal.querySelectorAll(".form-check-input").forEach((async item=>{item.setCustomValidity(await(0,_str.get_string)("atleast_one_course_module_must_be_included","block_sharing_cart")),item.reportValidity()})),!1;item.isModule()&&courseModuleIds.push(item.getItemOldInstanceId()),_ajax.default.call([{methodname:"block_sharing_cart_restore_item_from_sharing_cart_into_section",args:{item_id:item.getItemId(),section_id:sectionId,course_modules_to_include:courseModuleIds},done:async success=>{success&&await _classPrivateFieldGet(this,_queue).loadQueue(!0)},fail:data=>{_notification.default.exception(data)}}])}async confirmImportBackupFromSharingCart(item,sectionId,e){e.preventDefault(),e.stopPropagation();const strings=await(0,_str.get_strings)([{key:"copy_item",component:"block_sharing_cart"},{key:"into_section",component:"block_sharing_cart"},{key:"import",component:"core"},{key:"cancel",component:"core"}]),sectionName=_classPrivateFieldGet(this,_course).getSectionName(sectionId),{html:html,js:js}=await _classPrivateFieldGet(this,_baseFactory).moodle().template().renderFragment("block_sharing_cart","item_restore_form",1,{item_id:item.getItemId()}),modal=await _modal_factory.default.create({type:_modal_factory.default.types.SAVE_CANCEL,title:strings[0]+': "'+item.getItemName().slice(0,50).trim()+'" '+strings[1]+': "'+sectionName.slice(0,50).trim()+'"',body:html,buttons:{save:strings[2],cancel:strings[3]},removeOnClose:!0});modal.getRoot().on(_modal_events.default.shown,(()=>_classPrivateFieldGet(this,_baseFactory).moodle().template().runTemplateJS(js))),modal.getRoot().on(_modal_events.default.save,this.importItem.bind(this,item,sectionId,modal.getRoot()[0])),await modal.show()}async confirmDeleteItems(itemIds){const strings=await(0,_str.get_strings)([{key:"delete_items",component:"block_sharing_cart"},{key:"confirm_delete_items",component:"block_sharing_cart"},{key:"delete",component:"core"},{key:"cancel",component:"core"}]),modal=await _modal_factory.default.create({type:_modal_factory.default.types.DELETE_CANCEL,title:strings[0],body:strings[1],buttons:{delete:strings[2],cancel:strings[3]},removeOnClose:!0});modal.getRoot().on(_modal_events.default.delete,this.deleteItems.bind(this,itemIds)),await modal.show()}},_exports.default})); +define("block_sharing_cart/app/block/element",["exports","../../lib/sortablejs","core/modal_factory","core/modal_events","core/str","core/ajax","core/notification"],(function(_exports,_sortablejs,_modal_factory,_modal_events,_str,_ajax,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _classPrivateFieldInitSpec(obj,privateMap,value){!function(obj,privateCollection){if(privateCollection.has(obj))throw new TypeError("Cannot initialize the same private elements twice on an object")}(obj,privateMap),privateMap.set(obj,value)}function _classPrivateFieldGet(receiver,privateMap){return function(receiver,descriptor){if(descriptor.get)return descriptor.get.call(receiver);return descriptor.value}(receiver,_classExtractFieldDescriptor(receiver,privateMap,"get"))}function _classPrivateFieldSet(receiver,privateMap,value){return function(receiver,descriptor,value){if(descriptor.set)descriptor.set.call(receiver,value);else{if(!descriptor.writable)throw new TypeError("attempted to set read only private field");descriptor.value=value}}(receiver,_classExtractFieldDescriptor(receiver,privateMap,"set"),value),value}function _classExtractFieldDescriptor(receiver,privateMap,action){if(!privateMap.has(receiver))throw new TypeError("attempted to "+action+" private field on non-instance");return privateMap.get(receiver)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_sortablejs=_interopRequireDefault(_sortablejs),_modal_factory=_interopRequireDefault(_modal_factory),_modal_events=_interopRequireDefault(_modal_events),_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification);var _baseFactory=new WeakMap,_element=new WeakMap,_course=new WeakMap,_queue=new WeakMap,_items=new WeakMap,_sortable=new WeakMap,_clipboardItem=new WeakMap,_canBackupUserdata=new WeakMap,_canAnonymizeUserdata=new WeakMap,_showSharingCartBasket=new WeakMap,_draggedCourseModuleId=new WeakMap,_draggedSectionId=new WeakMap;return _exports.default=class{constructor(baseFactory,element,canBackupUserdata,canAnonymizeUserdata,showSharingCartBasket){_classPrivateFieldInitSpec(this,_baseFactory,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_element,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_course,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_queue,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_items,{writable:!0,value:[]}),_classPrivateFieldInitSpec(this,_sortable,{writable:!0,value:null}),_classPrivateFieldInitSpec(this,_clipboardItem,{writable:!0,value:null}),_classPrivateFieldInitSpec(this,_canBackupUserdata,{writable:!0,value:!1}),_classPrivateFieldInitSpec(this,_canAnonymizeUserdata,{writable:!0,value:!1}),_classPrivateFieldInitSpec(this,_showSharingCartBasket,{writable:!0,value:!1}),_classPrivateFieldInitSpec(this,_draggedCourseModuleId,{writable:!0,value:null}),_classPrivateFieldInitSpec(this,_draggedSectionId,{writable:!0,value:null}),_classPrivateFieldSet(this,_baseFactory,baseFactory),_classPrivateFieldSet(this,_element,element),_classPrivateFieldSet(this,_canBackupUserdata,canBackupUserdata),_classPrivateFieldSet(this,_canAnonymizeUserdata,canAnonymizeUserdata),_classPrivateFieldSet(this,_showSharingCartBasket,showSharingCartBasket)}addEventListeners(){return this.setupCourse(),this.setupQueue(),this.setupItems(),this.setupDragAndDrop(),this.setupBulkDelete(),{course:_classPrivateFieldGet(this,_course),queue:_classPrivateFieldGet(this,_queue),block:this}}setupCourse(){const course=document.querySelector(".course-content");_classPrivateFieldSet(this,_course,_classPrivateFieldGet(this,_baseFactory).block().course().element(this,course))}setupQueue(){const queue=document.querySelector(".sharing_cart_queue");_classPrivateFieldSet(this,_queue,_classPrivateFieldGet(this,_baseFactory).block().queue().element(this,queue))}setupItems(){_classPrivateFieldGet(this,_element).querySelectorAll(".sharing_cart_item").forEach((element=>{this.setupItem(element)})),_classPrivateFieldSet(this,_sortable,new _sortablejs.default(_classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items"),{dataIdAttr:"data-itemid",onUpdate:()=>{_ajax.default.call([{methodname:"block_sharing_cart_reorder_sharing_cart_items",args:{item_ids:_classPrivateFieldGet(this,_sortable).toArray()},fail:data=>{_notification.default.exception(data)}}])}}))}setupDragAndDrop(){const dropZone=_classPrivateFieldGet(this,_element);dropZone.addEventListener("dragover",(e=>{(_classPrivateFieldGet(this,_draggedSectionId)||_classPrivateFieldGet(this,_draggedCourseModuleId))&&(e.preventDefault(),e.stopPropagation())})),dropZone.addEventListener("dragleave",(e=>{(_classPrivateFieldGet(this,_draggedSectionId)||_classPrivateFieldGet(this,_draggedCourseModuleId))&&(e.preventDefault(),e.stopPropagation())})),dropZone.addEventListener("drop",(async e=>{(_classPrivateFieldGet(this,_draggedSectionId)||_classPrivateFieldGet(this,_draggedCourseModuleId))&&(e.preventDefault(),e.stopPropagation(),_classPrivateFieldGet(this,_draggedSectionId)?await this.addSectionBackupToSharingCart(_classPrivateFieldGet(this,_draggedSectionId)):_classPrivateFieldGet(this,_draggedCourseModuleId)&&await this.addCourseModuleBackupToSharingCart(_classPrivateFieldGet(this,_draggedCourseModuleId)))}))}setupBulkDelete(){const enableBulkDeleteButton=_classPrivateFieldGet(this,_element).querySelector("#block_sharing_cart_bulk_delete"),disableBulkDeleteButton=_classPrivateFieldGet(this,_element).querySelector("#block_sharing_cart_cancel_bulk_delete"),bulkDeleteButton=_classPrivateFieldGet(this,_element).querySelector("#block_sharing_cart_bulk_delete_confirm"),checkboxSelector='.sharing_cart_item input[data-action="bulk_select"][type="checkbox"]';enableBulkDeleteButton.addEventListener("click",(()=>{enableBulkDeleteButton.classList.add("d-none"),disableBulkDeleteButton.classList.remove("d-none"),bulkDeleteButton.classList.remove("d-none"),_classPrivateFieldGet(this,_element).querySelectorAll(checkboxSelector).forEach((checkbox=>{checkbox.classList.remove("d-none"),checkbox.checked=!1}))})),disableBulkDeleteButton.addEventListener("click",(()=>{disableBulkDeleteButton.classList.add("d-none"),bulkDeleteButton.classList.add("d-none"),bulkDeleteButton.disabled=!0,enableBulkDeleteButton.classList.remove("d-none"),_classPrivateFieldGet(this,_element).querySelectorAll(checkboxSelector).forEach((checkbox=>{checkbox.classList.add("d-none"),checkbox.checked=!1}))})),bulkDeleteButton.addEventListener("click",(async()=>{if(bulkDeleteButton.disabled)return;const itemIds=[];_classPrivateFieldGet(this,_element).querySelectorAll(checkboxSelector+":checked").forEach((checkbox=>{itemIds.push(checkbox.value)})),await this.confirmDeleteItems(itemIds)}))}setupItem(element){var _classPrivateFieldGet2;const itemElement=_classPrivateFieldGet(this,_baseFactory).block().item().element(this,element);null===(_classPrivateFieldGet2=_classPrivateFieldGet(this,_element).querySelector(".no-items"))||void 0===_classPrivateFieldGet2||_classPrivateFieldGet2.remove(),_classPrivateFieldGet(this,_items).push(itemElement)}async setClipboard(item){_classPrivateFieldSet(this,_clipboardItem,item),await _classPrivateFieldGet(this,_course).setClipboard(item)}clearClipboard(){_classPrivateFieldSet(this,_clipboardItem,null)}setDraggedSectionId(id){_classPrivateFieldSet(this,_draggedSectionId,id)}setDraggedCourseModuleId(id){_classPrivateFieldSet(this,_draggedCourseModuleId,id)}async removeItemElement(item){var _classPrivateFieldGet4;item.getItemChildrenRecursively().forEach((childItem=>{var _classPrivateFieldGet3;const index=_classPrivateFieldGet(this,_items).findIndex((i=>i.getItemId()===Number.parseInt(childItem.dataset.itemid)));-1!==index&&(_classPrivateFieldGet(this,_items)[index].getItemId()===(null===(_classPrivateFieldGet3=_classPrivateFieldGet(this,_clipboardItem))||void 0===_classPrivateFieldGet3?void 0:_classPrivateFieldGet3.getItemId())&&_classPrivateFieldGet(this,_course).clearClipboard(),_classPrivateFieldGet(this,_items).splice(index,1),childItem.remove())}));const index=_classPrivateFieldGet(this,_items).findIndex((i=>i.getItemId()===item.getItemId()));_classPrivateFieldGet(this,_items)[index].getItemId()===(null===(_classPrivateFieldGet4=_classPrivateFieldGet(this,_clipboardItem))||void 0===_classPrivateFieldGet4?void 0:_classPrivateFieldGet4.getItemId())&&_classPrivateFieldGet(this,_course).clearClipboard(),_classPrivateFieldGet(this,_items).splice(index,1),item.remove(),0===_classPrivateFieldGet(this,_items).length&&(_classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items").innerHTML=await(0,_str.get_string)("no_items","block_sharing_cart"))}deleteItem(item){_ajax.default.call([{methodname:"block_sharing_cart_delete_item_from_sharing_cart",args:{item_id:item.getItemId()},done:async deleted=>{deleted?await this.removeItemElement(item):await _notification.default.alert("Failed to delete item")},fail:data=>{_notification.default.exception(data)}}])}deleteItems(itemIds){itemIds=itemIds.map((id=>Number.parseInt(id))),_ajax.default.call([{methodname:"block_sharing_cart_delete_items_from_sharing_cart",args:{item_ids:itemIds},done:async deletedItemIds=>{const items=_classPrivateFieldGet(this,_items).filter((i=>itemIds.includes(i.getItemId())));for(const item of items){deletedItemIds.includes(item.getItemId())?await this.removeItemElement(item):_notification.default.alert('Failed to delete item: "'+item.getItemName()+'"')}document.getElementById("block_sharing_cart_bulk_delete_confirm").disabled=!0},fail:data=>{_notification.default.exception(data)}}])}getElement(){return _classPrivateFieldGet(this,_element)}async createBackupItemToSharingCartModal(itemName,onSave){const strings=await(0,_str.get_strings)([{key:"backup_item",component:"block_sharing_cart"},{key:"into_sharing_cart",component:"block_sharing_cart"},{key:"backup",component:"block_sharing_cart"},{key:"cancel",component:"core"}]),{html:html,js:js}=await _classPrivateFieldGet(this,_baseFactory).moodle().template().renderTemplate("block_sharing_cart/modal/backup_to_sharing_cart_modal_body",{show_user_data_backup:_classPrivateFieldGet(this,_canBackupUserdata),show_anonymize_user_data:_classPrivateFieldGet(this,_canBackupUserdata)&&_classPrivateFieldGet(this,_canAnonymizeUserdata)}),modal=await _modal_factory.default.create({type:_modal_factory.default.types.SAVE_CANCEL,title:strings[0]+': "'+itemName.slice(0,50).trim()+'" '+strings[1],body:html,buttons:{save:strings[2],cancel:strings[3]},removeOnClose:!0});return modal.getRoot().on(_modal_events.default.shown,(()=>_classPrivateFieldGet(this,_baseFactory).moodle().template().runTemplateJS(js))),modal.getRoot().on(_modal_events.default.save,(()=>{var _modalUserdataCheckbo,_modalAnonymizeCheckb;const modalUserdataCheckbox=document.getElementById("modal-userdata-checkbox"),modalAnonymizeCheckbox=document.getElementById("modal-anonymize-checkbox");onSave({users:null!==(_modalUserdataCheckbo=null==modalUserdataCheckbox?void 0:modalUserdataCheckbox.checked)&&void 0!==_modalUserdataCheckbo&&_modalUserdataCheckbo,anonymize:null!==(_modalAnonymizeCheckb=null==modalAnonymizeCheckbox?void 0:modalAnonymizeCheckbox.checked)&&void 0!==_modalAnonymizeCheckb&&_modalAnonymizeCheckb})})),modal}async addSectionBackupToSharingCart(sectionId){const sectionName=_classPrivateFieldGet(this,_course).getSectionName(sectionId);if(0===_classPrivateFieldGet(this,_course).getSectionCourseModules(sectionId).length){const strings=await(0,_str.get_strings)([{key:"no_course_modules_in_section",component:"block_sharing_cart"},{key:"no_course_modules_in_section_description",component:"block_sharing_cart"}]);return void await _notification.default.alert(strings[0],strings[1])}const modal=await this.createBackupItemToSharingCartModal(sectionName,(settings=>{_ajax.default.call([{methodname:"block_sharing_cart_backup_section_into_sharing_cart",args:{section_id:sectionId,settings:settings},done:async data=>{await this.renderItem(data)},fail:data=>{_notification.default.exception(data)}}])}));await modal.show()}async addCourseModuleBackupToSharingCart(courseModuleId){const courseModuleName=_classPrivateFieldGet(this,_course).getCourseModuleName(courseModuleId),modal=await this.createBackupItemToSharingCartModal(courseModuleName,(settings=>{_ajax.default.call([{methodname:"block_sharing_cart_backup_course_module_into_sharing_cart",args:{course_module_id:courseModuleId,settings:settings},done:async data=>{await this.renderItem(data)},fail:data=>{_notification.default.exception(data)}}])}));await modal.show()}async renderItem(item){var _classPrivateFieldGet5,_item$task_id;const existingItemIndex=_classPrivateFieldGet(this,_items).findIndex((i=>i.getItemId()===item.id)),existingItem=null!==(_classPrivateFieldGet5=_classPrivateFieldGet(this,_items)[existingItemIndex])&&void 0!==_classPrivateFieldGet5&&_classPrivateFieldGet5,oldElement=_classPrivateFieldGet(this,_element).querySelector('.sharing_cart_items .sharing_cart_item[data-itemid="'+item.id+'"]');if(existingItem&&oldElement){const element=await _classPrivateFieldGet(this,_baseFactory).moodle().template().createElementFromFragment("block_sharing_cart","item",1,{item_id:item.id});return _classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items").replaceChild(element,oldElement),_classPrivateFieldGet(this,_items)[existingItemIndex]=_classPrivateFieldGet(this,_baseFactory).block().item().element(this,element),void element.querySelectorAll(".sharing_cart_item").forEach((subItem=>{this.setupItem(subItem)}))}const element=await _classPrivateFieldGet(this,_baseFactory).moodle().template().createElementFromTemplate("block_sharing_cart/block/item",{id:item.id,name:item.name,type:item.type,status:0,old_instance_id:item.old_instance_id,status_awaiting:!0,has_run_now:!0,task_id:null!==(_item$task_id=item.task_id)&&void 0!==_item$task_id?_item$task_id:null,status_finished:!1,status_failed:!1,is_module:"section"!==item.type,is_section:"section"===item.type,is_root:!0});_classPrivateFieldGet(this,_element).querySelector(".sharing_cart_items").prepend(element),this.setupItem(element)}importItem(item,sectionId,modal){_classPrivateFieldGet(this,_course).clearClipboard();const courseModuleIds=[];if(modal.querySelectorAll('input[type="checkbox"][data-type="coursemodule"]:checked').forEach((checkbox=>{courseModuleIds.push(checkbox.dataset.id)})),item.isSection()&&0===courseModuleIds.length)return modal.querySelectorAll(".form-check-input").forEach((async item=>{item.setCustomValidity(await(0,_str.get_string)("atleast_one_course_module_must_be_included","block_sharing_cart")),item.reportValidity()})),!1;item.isModule()&&courseModuleIds.push(item.getItemOldInstanceId()),_ajax.default.call([{methodname:"block_sharing_cart_restore_item_from_sharing_cart_into_section",args:{item_id:item.getItemId(),section_id:sectionId,course_modules_to_include:courseModuleIds},done:async success=>{success&&await _classPrivateFieldGet(this,_queue).loadQueue(!0)},fail:data=>{_notification.default.exception(data)}}])}async confirmImportBackupFromSharingCart(item,sectionId,e){e.preventDefault(),e.stopPropagation();const strings=await(0,_str.get_strings)([{key:"copy_item",component:"block_sharing_cart"},{key:"into_section",component:"block_sharing_cart"},{key:"import",component:"core"},{key:"cancel",component:"core"}]),sectionName=_classPrivateFieldGet(this,_course).getSectionName(sectionId),{html:html,js:js}=await _classPrivateFieldGet(this,_baseFactory).moodle().template().renderFragment("block_sharing_cart","item_restore_form",1,{item_id:item.getItemId()}),modal=await _modal_factory.default.create({type:_modal_factory.default.types.SAVE_CANCEL,title:strings[0]+': "'+item.getItemName().slice(0,50).trim()+'" '+strings[1]+': "'+sectionName.slice(0,50).trim()+'"',body:html,buttons:{save:strings[2],cancel:strings[3]},removeOnClose:!0});modal.getRoot().on(_modal_events.default.shown,(()=>_classPrivateFieldGet(this,_baseFactory).moodle().template().runTemplateJS(js))),modal.getRoot().on(_modal_events.default.save,this.importItem.bind(this,item,sectionId,modal.getRoot()[0])),await modal.show()}async confirmDeleteItems(itemIds){const strings=await(0,_str.get_strings)([{key:"delete_items",component:"block_sharing_cart"},{key:"confirm_delete_items",component:"block_sharing_cart"},{key:"delete",component:"core"},{key:"cancel",component:"core"}]),modal=await _modal_factory.default.create({type:_modal_factory.default.types.DELETE_CANCEL,title:strings[0],body:strings[1],buttons:{delete:strings[2],cancel:strings[3]},removeOnClose:!0});modal.getRoot().on(_modal_events.default.delete,this.deleteItems.bind(this,itemIds)),await modal.show()}},_exports.default})); //# sourceMappingURL=element.min.js.map \ No newline at end of file diff --git a/amd/build/app/block/element.min.js.map b/amd/build/app/block/element.min.js.map index 24e657d..9e1bb5e 100644 --- a/amd/build/app/block/element.min.js.map +++ b/amd/build/app/block/element.min.js.map @@ -1 +1 @@ -{"version":3,"file":"element.min.js","sources":["../../../src/app/block/element.js"],"sourcesContent":["import Sortable from '../../lib/sortablejs';\nimport ModalFactory from 'core/modal_factory';\nimport ModalEvents from 'core/modal_events';\nimport {get_string, get_strings} from \"core/str\";\nimport Ajax from \"core/ajax\";\nimport Notification from \"core/notification\";\n\nexport default class BlockElement {\n /**\n * @type {BaseFactory}\n */\n #baseFactory;\n\n /**\n * @type {HTMLElement}\n */\n #element;\n\n /**\n * @type {CourseElement}\n */\n #course;\n\n /**\n * @type {QueueElement}\n */\n #queue;\n\n /**\n * @type {ItemElement[]}\n */\n #items = [];\n\n /**\n * @type {Sortable|NULL}\n */\n #sortable = null;\n\n /**\n * @type {ItemElement|NULL}\n */\n #clipboardItem = null;\n\n /**\n * @type {Boolean}\n */\n #canBackupUserdata = false;\n\n /**\n * @type {Boolean}\n */\n #canAnonymizeUserdata = false;\n\n /**\n * @type {Boolean}\n */\n #showSharingCartBasket = false;\n\n /**\n * @type {Number|null}\n */\n #draggedCourseModuleId = null;\n\n /**\n * @type {Number|null}\n */\n #draggedSectionId = null;\n\n /**\n * @param {BaseFactory} baseFactory\n * @param {HTMLElement} element\n * @param {Boolean} canBackupUserdata\n * @param {Boolean} canAnonymizeUserdata\n * @param {Boolean} showSharingCartBasket\n */\n constructor(baseFactory, element, canBackupUserdata, canAnonymizeUserdata, showSharingCartBasket) {\n this.#baseFactory = baseFactory;\n this.#element = element;\n this.#canBackupUserdata = canBackupUserdata;\n this.#canAnonymizeUserdata = canAnonymizeUserdata;\n this.#showSharingCartBasket = showSharingCartBasket;\n }\n\n /**\n * @return {{course: CourseElement, block: BlockElement, queue: QueueElement}}\n */\n addEventListeners() {\n this.setupCourse();\n this.setupQueue();\n this.setupItems();\n this.setupDragAndDrop();\n this.setupBulkDelete();\n\n return {course: this.#course, queue: this.#queue, block: this};\n }\n\n setupCourse() {\n const course = document.querySelector('.course-content');\n\n this.#course = this.#baseFactory.block().course().element(this, course);\n }\n\n setupQueue() {\n const queue = document.querySelector('.sharing_cart_queue');\n\n this.#queue = this.#baseFactory.block().queue().element(this, queue);\n }\n\n setupItems() {\n const items = this.#element.querySelectorAll('.sharing_cart_item');\n\n items.forEach((element) => {\n this.setupItem(element);\n });\n\n this.#sortable = new Sortable(this.#element.querySelector('.sharing_cart_items'), {\n dataIdAttr: 'data-itemid',\n onUpdate: () => {\n Ajax.call([{\n methodname: 'block_sharing_cart_reorder_sharing_cart_items',\n args: {\n item_ids: this.#sortable.toArray(),\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n });\n }\n\n setupDragAndDrop() {\n const dropZone = this.#element;\n const draggableCourseModules = document.querySelectorAll('.course-content .activity[data-for=\"cmitem\"][data-id]');\n const draggableSections = document.querySelectorAll('.course-content .section[data-for=\"section\"][data-id]');\n\n draggableCourseModules.forEach((courseModule) => {\n const courseModuleId = Number.parseInt(courseModule.dataset.id);\n if (!courseModuleId) {\n return;\n }\n\n courseModule.addEventListener('dragstart', () => {\n this.#draggedCourseModuleId = courseModuleId;\n dropZone.classList.add('dragging_item');\n });\n courseModule.addEventListener('dragend', () => {\n this.#draggedCourseModuleId = null;\n dropZone.classList.remove('dragging_item');\n });\n });\n draggableSections.forEach((section) => {\n const id = Number.parseInt(section.dataset.id);\n if (!id) {\n return;\n }\n\n const draggable = section.querySelector('[data-for=\"section_title\"]');\n\n draggable.addEventListener('dragstart', () => {\n this.#draggedSectionId = id;\n dropZone.classList.add('dragging_item');\n });\n draggable.addEventListener('dragend', () => {\n this.#draggedSectionId = null;\n dropZone.classList.remove('dragging_item');\n });\n });\n\n dropZone.addEventListener('dragover', (e) => {\n if (!this.#draggedSectionId && !this.#draggedCourseModuleId) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n });\n dropZone.addEventListener('dragleave', (e) => {\n if (!this.#draggedSectionId && !this.#draggedCourseModuleId) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n });\n dropZone.addEventListener('drop', async (e) => {\n if (!this.#draggedSectionId && !this.#draggedCourseModuleId) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (this.#draggedSectionId) {\n await this.addSectionBackupToSharingCart(this.#draggedSectionId);\n } else if (this.#draggedCourseModuleId) {\n await this.addCourseModuleBackupToSharingCart(this.#draggedCourseModuleId);\n }\n });\n }\n\n setupBulkDelete() {\n const enableBulkDeleteButton = this.#element.querySelector('#block_sharing_cart_bulk_delete');\n const disableBulkDeleteButton = this.#element.querySelector('#block_sharing_cart_cancel_bulk_delete');\n const bulkDeleteButton = this.#element.querySelector('#block_sharing_cart_bulk_delete_confirm');\n\n const checkboxSelector = '.sharing_cart_item input[data-action=\"bulk_select\"][type=\"checkbox\"]';\n\n enableBulkDeleteButton.addEventListener('click', () => {\n enableBulkDeleteButton.classList.add('d-none');\n disableBulkDeleteButton.classList.remove('d-none');\n bulkDeleteButton.classList.remove('d-none');\n\n this.#element.querySelectorAll(checkboxSelector).forEach((checkbox) => {\n checkbox.classList.remove('d-none');\n checkbox.checked = false;\n });\n });\n\n disableBulkDeleteButton.addEventListener('click', () => {\n disableBulkDeleteButton.classList.add('d-none');\n bulkDeleteButton.classList.add('d-none');\n bulkDeleteButton.disabled = true;\n enableBulkDeleteButton.classList.remove('d-none');\n\n this.#element.querySelectorAll(checkboxSelector).forEach((checkbox) => {\n checkbox.classList.add('d-none');\n checkbox.checked = false;\n });\n });\n\n bulkDeleteButton.addEventListener('click', async () => {\n if (bulkDeleteButton.disabled) {\n return;\n }\n\n const itemIds = [];\n this.#element.querySelectorAll(checkboxSelector + ':checked').forEach((checkbox) => {\n itemIds.push(checkbox.value);\n });\n\n await this.confirmDeleteItems(itemIds);\n });\n }\n\n /**\n * @param {HTMLElement} element\n */\n setupItem(element) {\n const itemElement = this.#baseFactory.block().item().element(this, element);\n\n this.#element.querySelector('.no-items')?.remove();\n\n this.#items.push(\n itemElement\n );\n }\n\n /**\n * @param {ItemElement} item\n */\n async setClipboard(item) {\n this.#clipboardItem = item;\n\n await this.#course.setClipboard(item);\n }\n\n clearClipboard() {\n this.#clipboardItem = null;\n }\n\n /**\n * @param {ItemElement} item\n */\n async removeItemElement(item) {\n const childItems = item.getItemChildrenRecursively();\n childItems.forEach((childItem) => {\n const index = this.#items.findIndex((i) => i.getItemId() === Number.parseInt(childItem.dataset.itemid));\n if (index === -1) {\n return;\n }\n\n if (this.#items[index].getItemId() === this.#clipboardItem?.getItemId()) {\n this.#course.clearClipboard();\n }\n\n this.#items.splice(index, 1);\n childItem.remove();\n });\n\n const index = this.#items.findIndex((i) => i.getItemId() === item.getItemId());\n if (this.#items[index].getItemId() === this.#clipboardItem?.getItemId()) {\n this.#course.clearClipboard();\n }\n\n this.#items.splice(index, 1);\n item.remove();\n\n if (this.#items.length === 0) {\n this.#element.querySelector('.sharing_cart_items')\n .innerHTML = await get_string('no_items', 'block_sharing_cart');\n }\n }\n\n /**\n * @param {ItemElement} item\n */\n deleteItem(item) {\n Ajax.call([{\n methodname: 'block_sharing_cart_delete_item_from_sharing_cart',\n args: {\n item_id: item.getItemId(),\n },\n done: async (deleted) => {\n if (deleted) {\n await this.removeItemElement(item);\n } else {\n await Notification.alert('Failed to delete item');\n }\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n\n /**\n * @param {Array} itemIds\n */\n deleteItems(itemIds) {\n itemIds = itemIds.map((id) => Number.parseInt(id));\n\n Ajax.call([{\n methodname: 'block_sharing_cart_delete_items_from_sharing_cart',\n args: {\n item_ids: itemIds,\n },\n done: async (deletedItemIds) => {\n const items = this.#items.filter((i) => itemIds.includes(i.getItemId()));\n for (const item of items) {\n const deleted = deletedItemIds.includes(item.getItemId());\n if (!deleted) {\n Notification.alert('Failed to delete item: \"' + item.getItemName() + '\"');\n continue;\n }\n\n await this.removeItemElement(item);\n }\n\n document.getElementById('block_sharing_cart_bulk_delete_confirm').disabled = true;\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n\n /**\n * @param {String} itemName\n * @param {CallableFunction} onSave\n * @return {Promise}\n */\n async createBackupItemToSharingCartModal(itemName, onSave) {\n const strings = await get_strings([\n {\n key: 'backup_item',\n component: 'block_sharing_cart',\n },\n {\n key: 'into_sharing_cart',\n component: 'block_sharing_cart',\n },\n {\n key: 'backup',\n component: 'block_sharing_cart',\n },\n {\n key: 'cancel',\n component: 'core',\n }\n ]);\n\n const {html, js} = await this.#baseFactory.moodle().template().renderTemplate(\n 'block_sharing_cart/modal/backup_to_sharing_cart_modal_body',\n {\n show_user_data_backup: this.#canBackupUserdata,\n show_anonymize_user_data: this.#canBackupUserdata && this.#canAnonymizeUserdata,\n }\n );\n\n /**\n * @type {Modal}\n */\n const modal = await ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: strings[0] + ': \"' + itemName.slice(0, 50).trim() + '\" ' + strings[1],\n body: html,\n buttons: {\n save: strings[2],\n cancel: strings[3],\n },\n removeOnClose: true,\n });\n modal.getRoot().on(ModalEvents.shown, () => this.#baseFactory.moodle().template().runTemplateJS(js));\n modal.getRoot().on(ModalEvents.save, () => {\n const modalUserdataCheckbox = document.getElementById('modal-userdata-checkbox');\n const modalAnonymizeCheckbox = document.getElementById('modal-anonymize-checkbox');\n\n onSave({\n users: modalUserdataCheckbox?.checked ?? false,\n anonymize: modalAnonymizeCheckbox?.checked ?? false\n });\n });\n\n return modal;\n }\n\n /**\n * @param {Number} sectionId\n */\n async addSectionBackupToSharingCart(sectionId) {\n const sectionName = this.#course.getSectionName(sectionId);\n\n const cms = this.#course.getSectionCourseModules(sectionId);\n\n if (cms.length === 0) {\n const strings = await get_strings([\n {\n key: 'no_course_modules_in_section',\n component: 'block_sharing_cart',\n },\n {\n key: 'no_course_modules_in_section_description',\n component: 'block_sharing_cart',\n },\n ]);\n\n await Notification.alert(strings[0], strings[1]);\n\n return;\n }\n\n const modal = await this.createBackupItemToSharingCartModal(sectionName, (settings) => {\n Ajax.call([{\n methodname: 'block_sharing_cart_backup_section_into_sharing_cart',\n args: {\n section_id: sectionId,\n settings: settings\n },\n done: async (data) => {\n await this.renderItem(data);\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n });\n\n await modal.show();\n }\n\n /**\n * @param {Number} courseModuleId\n */\n async addCourseModuleBackupToSharingCart(courseModuleId) {\n const courseModuleName = this.#course.getCourseModuleName(courseModuleId);\n\n const modal = await this.createBackupItemToSharingCartModal(courseModuleName, (settings) => {\n Ajax.call([{\n methodname: 'block_sharing_cart_backup_course_module_into_sharing_cart',\n args: {\n course_module_id: courseModuleId,\n settings: settings\n },\n done: async (data) => {\n await this.renderItem(data);\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n });\n await modal.show();\n }\n\n /**\n * @param {Object} item\n */\n async renderItem(item) {\n const existingItemIndex = this.#items.findIndex((i) => i.getItemId() === item.id);\n const existingItem = this.#items[existingItemIndex] ?? false;\n const oldElement = this.#element.querySelector('.sharing_cart_items .sharing_cart_item[data-itemid=\"' + item.id + '\"]');\n if (existingItem && oldElement) {\n const element = await this.#baseFactory.moodle().template().createElementFromFragment(\n 'block_sharing_cart',\n 'item',\n 1,\n {\n item_id: item.id,\n }\n );\n\n this.#element.querySelector('.sharing_cart_items').replaceChild(element, oldElement);\n this.#items[existingItemIndex] = this.#baseFactory.block().item().element(this, element);\n\n element.querySelectorAll('.sharing_cart_item').forEach((subItem) => {\n this.setupItem(subItem);\n });\n\n return;\n }\n\n const element = await this.#baseFactory.moodle().template().createElementFromTemplate(\n 'block_sharing_cart/block/item',\n {\n id: item.id,\n name: item.name,\n type: item.type,\n status: 0,\n old_instance_id: item.old_instance_id,\n status_awaiting: true,\n has_run_now: true,\n task_id: item.task_id ?? null,\n status_finished: false,\n status_failed: false,\n is_module: item.type !== 'section',\n is_section: item.type === 'section',\n is_root: true,\n }\n );\n this.#element.querySelector('.sharing_cart_items').prepend(element);\n\n this.setupItem(element);\n }\n\n /**\n * @param {ItemElement} item\n * @param {Number} sectionId\n * @param {HTMLElement} modal\n */\n importItem(item, sectionId, modal) {\n this.#course.clearClipboard();\n\n const courseModuleIds = [];\n modal.querySelectorAll('input[type=\"checkbox\"][data-type=\"coursemodule\"]:checked').forEach((checkbox) => {\n courseModuleIds.push(checkbox.dataset.id);\n });\n\n if (item.isSection() && courseModuleIds.length === 0) {\n modal.querySelectorAll('.form-check-input').forEach(async (item) => {\n item.setCustomValidity(\n await get_string('atleast_one_course_module_must_be_included', 'block_sharing_cart')\n );\n item.reportValidity();\n });\n return false;\n }\n\n if (item.isModule()) {\n courseModuleIds.push(item.getItemOldInstanceId());\n }\n\n Ajax.call([{\n methodname: 'block_sharing_cart_restore_item_from_sharing_cart_into_section',\n args: {\n item_id: item.getItemId(),\n section_id: sectionId,\n course_modules_to_include: courseModuleIds,\n },\n done: async (success) => {\n if (success) {\n await this.#queue.loadQueue(true);\n }\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n\n /**\n * @param {ItemElement} item\n * @param {Number} sectionId\n * @param {Event} e\n */\n async confirmImportBackupFromSharingCart(item, sectionId, e) {\n e.preventDefault();\n e.stopPropagation();\n\n const strings = await get_strings([\n {\n key: 'copy_item',\n component: 'block_sharing_cart',\n },\n {\n key: 'into_section',\n component: 'block_sharing_cart',\n },\n {\n key: 'import',\n component: 'core',\n },\n {\n key: 'cancel',\n component: 'core',\n }\n ]);\n\n const sectionName = this.#course.getSectionName(sectionId);\n\n const {html, js} = await this.#baseFactory.moodle().template().renderFragment(\n 'block_sharing_cart',\n 'item_restore_form',\n 1,\n {\n item_id: item.getItemId()\n }\n );\n\n const modal = await ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: strings[0] + ': ' +\n '\"' + item.getItemName().slice(0, 50).trim() + '\"' +\n ' ' + strings[1] + ': ' +\n '\"' + sectionName.slice(0, 50).trim() + '\"',\n body: html,\n buttons: {\n save: strings[2],\n cancel: strings[3],\n },\n removeOnClose: true,\n });\n modal.getRoot().on(ModalEvents.shown, () => this.#baseFactory.moodle().template().runTemplateJS(js));\n modal.getRoot().on(ModalEvents.save, this.importItem.bind(this, item, sectionId, modal.getRoot()[0]));\n await modal.show();\n }\n\n /**\n * @param {Array} itemIds\n */\n async confirmDeleteItems(itemIds) {\n const strings = await get_strings([\n {\n key: 'delete_items',\n component: 'block_sharing_cart',\n },\n {\n key: 'confirm_delete_items',\n component: 'block_sharing_cart',\n },\n {\n key: 'delete',\n component: 'core',\n },\n {\n key: 'cancel',\n component: 'core',\n }\n ]);\n\n const modal = await ModalFactory.create({\n type: ModalFactory.types.DELETE_CANCEL,\n title: strings[0],\n body: strings[1],\n buttons: {\n delete: strings[2],\n cancel: strings[3],\n },\n removeOnClose: true,\n });\n\n modal.getRoot().on(ModalEvents.delete, this.deleteItems.bind(this, itemIds));\n await modal.show();\n }\n}\n"],"names":["constructor","baseFactory","element","canBackupUserdata","canAnonymizeUserdata","showSharingCartBasket","addEventListeners","setupCourse","setupQueue","setupItems","setupDragAndDrop","setupBulkDelete","course","this","queue","block","document","querySelector","_classPrivateFieldGet","querySelectorAll","forEach","setupItem","Sortable","dataIdAttr","onUpdate","call","methodname","args","item_ids","toArray","fail","data","exception","dropZone","draggableCourseModules","draggableSections","courseModule","courseModuleId","Number","parseInt","dataset","id","addEventListener","classList","add","remove","section","draggable","e","preventDefault","stopPropagation","async","addSectionBackupToSharingCart","addCourseModuleBackupToSharingCart","enableBulkDeleteButton","disableBulkDeleteButton","bulkDeleteButton","checkboxSelector","checkbox","checked","disabled","itemIds","push","value","confirmDeleteItems","itemElement","item","setClipboard","clearClipboard","getItemChildrenRecursively","childItem","index","findIndex","i","getItemId","itemid","_classPrivateFieldGet3","splice","_classPrivateFieldGet4","length","innerHTML","deleteItem","item_id","done","deleted","removeItemElement","Notification","alert","deleteItems","map","items","filter","includes","deletedItemIds","getItemName","getElementById","itemName","onSave","strings","key","component","html","js","moodle","template","renderTemplate","show_user_data_backup","show_anonymize_user_data","modal","ModalFactory","create","type","types","SAVE_CANCEL","title","slice","trim","body","buttons","save","cancel","removeOnClose","getRoot","on","ModalEvents","shown","runTemplateJS","modalUserdataCheckbox","modalAnonymizeCheckbox","users","anonymize","sectionId","sectionName","getSectionName","getSectionCourseModules","createBackupItemToSharingCartModal","settings","section_id","renderItem","show","courseModuleName","getCourseModuleName","course_module_id","existingItemIndex","existingItem","oldElement","createElementFromFragment","replaceChild","subItem","createElementFromTemplate","name","status","old_instance_id","status_awaiting","has_run_now","task_id","status_finished","status_failed","is_module","is_section","is_root","prepend","importItem","courseModuleIds","isSection","setCustomValidity","reportValidity","isModule","getItemOldInstanceId","course_modules_to_include","success","loadQueue","renderFragment","bind","DELETE_CANCEL","delete"],"mappings":"+/DA2EIA,YAAYC,YAAaC,QAASC,kBAAmBC,qBAAsBC,sWA5ClE,kEAKG,yEAKK,8EAKI,8EAKG,+EAKC,8EAKA,4EAKL,+CAUIJ,iDACJC,uDACUC,oEACGC,wEACCC,uBAMlCC,gCACSC,mBACAC,kBACAC,kBACAC,wBACAC,kBAEE,CAACC,6BAAQC,cAAcC,4BAAOD,aAAaE,MAAOF,MAG7DN,oBACUK,OAASI,SAASC,cAAc,sDAEvBC,yCAAkBH,QAAQH,SAASV,QAAQW,KAAMD,SAGpEJ,mBACUM,MAAQE,SAASC,cAAc,yDAEvBC,yCAAkBH,QAAQD,QAAQZ,QAAQW,KAAMC,QAGlEL,aACkBS,qCAAcC,iBAAiB,sBAEvCC,SAASlB,eACNmB,UAAUnB,iDAGF,IAAIoB,oBAASJ,qCAAcD,cAAc,uBAAwB,CAC9EM,WAAY,cACZC,SAAU,mBACDC,KAAK,CAAC,CACPC,WAAY,gDACZC,KAAM,CACFC,SAAUV,sCAAeW,WAE7BC,KAAOC,6BACUC,UAAUD,cAO3CrB,yBACUuB,+BAAWpB,eACXqB,uBAAyBlB,SAASG,iBAAiB,yDACnDgB,kBAAoBnB,SAASG,iBAAiB,yDAEpDe,uBAAuBd,SAASgB,qBACtBC,eAAiBC,OAAOC,SAASH,aAAaI,QAAQC,IACvDJ,iBAILD,aAAaM,iBAAiB,aAAa,uDACTL,gBAC9BJ,SAASU,UAAUC,IAAI,oBAE3BR,aAAaM,iBAAiB,WAAW,uDACP,MAC9BT,SAASU,UAAUE,OAAO,wBAGlCV,kBAAkBf,SAAS0B,gB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,GAAGC,sBAAYC,OAAO,IAAM3G,yCAAkBqF,SAASC,WAAWsB,cAAcxB,MAChGM,MAAMc,UAAUC,GAAGC,sBAAYL,KAAM1G,KAAKqJ,WAAWW,KAAKhK,KAAMqD,KAAMiE,UAAWvB,MAAMc,UAAU,WAC3Fd,MAAM+B,gCAMS9E,eACfqC,cAAgB,oBAAY,CAC9B,CACIC,IAAK,eACLC,UAAW,sBAEf,CACID,IAAK,uBACLC,UAAW,sBAEf,CACID,IAAK,SACLC,UAAW,QAEf,CACID,IAAK,SACLC,UAAW,UAIbQ,YAAcC,uBAAaC,OAAO,CACpCC,KAAMF,uBAAaG,MAAM8D,cACzB5D,MAAOhB,QAAQ,GACfmB,KAAMnB,QAAQ,GACdoB,QAAS,CACLyD,OAAQ7E,QAAQ,GAChBsB,OAAQtB,QAAQ,IAEpBuB,eAAe,IAGnBb,MAAMc,UAAUC,GAAGC,sBAAYmD,OAAQlK,KAAK2E,YAAYqF,KAAKhK,KAAMgD,gBAC7D+C,MAAM+B"} \ No newline at end of file +{"version":3,"file":"element.min.js","sources":["../../../src/app/block/element.js"],"sourcesContent":["import Sortable from '../../lib/sortablejs';\nimport ModalFactory from 'core/modal_factory';\nimport ModalEvents from 'core/modal_events';\nimport {get_string, get_strings} from \"core/str\";\nimport Ajax from \"core/ajax\";\nimport Notification from \"core/notification\";\n\nexport default class BlockElement {\n /**\n * @type {BaseFactory}\n */\n #baseFactory;\n\n /**\n * @type {HTMLElement}\n */\n #element;\n\n /**\n * @type {CourseElement}\n */\n #course;\n\n /**\n * @type {QueueElement}\n */\n #queue;\n\n /**\n * @type {ItemElement[]}\n */\n #items = [];\n\n /**\n * @type {Sortable|NULL}\n */\n #sortable = null;\n\n /**\n * @type {ItemElement|NULL}\n */\n #clipboardItem = null;\n\n /**\n * @type {Boolean}\n */\n #canBackupUserdata = false;\n\n /**\n * @type {Boolean}\n */\n #canAnonymizeUserdata = false;\n\n /**\n * @type {Boolean}\n */\n #showSharingCartBasket = false;\n\n /**\n * @type {Number|null}\n */\n #draggedCourseModuleId = null;\n\n /**\n * @type {Number|null}\n */\n #draggedSectionId = null;\n\n /**\n * @param {BaseFactory} baseFactory\n * @param {HTMLElement} element\n * @param {Boolean} canBackupUserdata\n * @param {Boolean} canAnonymizeUserdata\n * @param {Boolean} showSharingCartBasket\n */\n constructor(baseFactory, element, canBackupUserdata, canAnonymizeUserdata, showSharingCartBasket) {\n this.#baseFactory = baseFactory;\n this.#element = element;\n this.#canBackupUserdata = canBackupUserdata;\n this.#canAnonymizeUserdata = canAnonymizeUserdata;\n this.#showSharingCartBasket = showSharingCartBasket;\n }\n\n /**\n * @return {{course: CourseElement, block: BlockElement, queue: QueueElement}}\n */\n addEventListeners() {\n this.setupCourse();\n this.setupQueue();\n this.setupItems();\n this.setupDragAndDrop();\n this.setupBulkDelete();\n\n return {course: this.#course, queue: this.#queue, block: this};\n }\n\n setupCourse() {\n const course = document.querySelector('.course-content');\n\n this.#course = this.#baseFactory.block().course().element(this, course);\n }\n\n setupQueue() {\n const queue = document.querySelector('.sharing_cart_queue');\n\n this.#queue = this.#baseFactory.block().queue().element(this, queue);\n }\n\n setupItems() {\n const items = this.#element.querySelectorAll('.sharing_cart_item');\n\n items.forEach((element) => {\n this.setupItem(element);\n });\n\n this.#sortable = new Sortable(this.#element.querySelector('.sharing_cart_items'), {\n dataIdAttr: 'data-itemid',\n onUpdate: () => {\n Ajax.call([{\n methodname: 'block_sharing_cart_reorder_sharing_cart_items',\n args: {\n item_ids: this.#sortable.toArray(),\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n });\n }\n\n setupDragAndDrop() {\n const dropZone = this.#element;\n\n dropZone.addEventListener('dragover', (e) => {\n if (!this.#draggedSectionId && !this.#draggedCourseModuleId) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n });\n dropZone.addEventListener('dragleave', (e) => {\n if (!this.#draggedSectionId && !this.#draggedCourseModuleId) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n });\n dropZone.addEventListener('drop', async (e) => {\n if (!this.#draggedSectionId && !this.#draggedCourseModuleId) {\n return;\n }\n\n e.preventDefault();\n e.stopPropagation();\n\n if (this.#draggedSectionId) {\n await this.addSectionBackupToSharingCart(this.#draggedSectionId);\n } else if (this.#draggedCourseModuleId) {\n await this.addCourseModuleBackupToSharingCart(this.#draggedCourseModuleId);\n }\n });\n }\n\n setupBulkDelete() {\n const enableBulkDeleteButton = this.#element.querySelector('#block_sharing_cart_bulk_delete');\n const disableBulkDeleteButton = this.#element.querySelector('#block_sharing_cart_cancel_bulk_delete');\n const bulkDeleteButton = this.#element.querySelector('#block_sharing_cart_bulk_delete_confirm');\n\n const checkboxSelector = '.sharing_cart_item input[data-action=\"bulk_select\"][type=\"checkbox\"]';\n\n enableBulkDeleteButton.addEventListener('click', () => {\n enableBulkDeleteButton.classList.add('d-none');\n disableBulkDeleteButton.classList.remove('d-none');\n bulkDeleteButton.classList.remove('d-none');\n\n this.#element.querySelectorAll(checkboxSelector).forEach((checkbox) => {\n checkbox.classList.remove('d-none');\n checkbox.checked = false;\n });\n });\n\n disableBulkDeleteButton.addEventListener('click', () => {\n disableBulkDeleteButton.classList.add('d-none');\n bulkDeleteButton.classList.add('d-none');\n bulkDeleteButton.disabled = true;\n enableBulkDeleteButton.classList.remove('d-none');\n\n this.#element.querySelectorAll(checkboxSelector).forEach((checkbox) => {\n checkbox.classList.add('d-none');\n checkbox.checked = false;\n });\n });\n\n bulkDeleteButton.addEventListener('click', async () => {\n if (bulkDeleteButton.disabled) {\n return;\n }\n\n const itemIds = [];\n this.#element.querySelectorAll(checkboxSelector + ':checked').forEach((checkbox) => {\n itemIds.push(checkbox.value);\n });\n\n await this.confirmDeleteItems(itemIds);\n });\n }\n\n /**\n * @param {HTMLElement} element\n */\n setupItem(element) {\n const itemElement = this.#baseFactory.block().item().element(this, element);\n\n this.#element.querySelector('.no-items')?.remove();\n\n this.#items.push(\n itemElement\n );\n }\n\n /**\n * @param {ItemElement} item\n */\n async setClipboard(item) {\n this.#clipboardItem = item;\n\n await this.#course.setClipboard(item);\n }\n\n clearClipboard() {\n this.#clipboardItem = null;\n }\n\n /**\n * @param {Number|null} id\n */\n setDraggedSectionId(id) {\n this.#draggedSectionId = id;\n }\n\n /**\n * @param {Number|null} id\n */\n setDraggedCourseModuleId(id) {\n this.#draggedCourseModuleId = id;\n }\n\n /**\n * @param {ItemElement} item\n */\n async removeItemElement(item) {\n const childItems = item.getItemChildrenRecursively();\n childItems.forEach((childItem) => {\n const index = this.#items.findIndex((i) => i.getItemId() === Number.parseInt(childItem.dataset.itemid));\n if (index === -1) {\n return;\n }\n\n if (this.#items[index].getItemId() === this.#clipboardItem?.getItemId()) {\n this.#course.clearClipboard();\n }\n\n this.#items.splice(index, 1);\n childItem.remove();\n });\n\n const index = this.#items.findIndex((i) => i.getItemId() === item.getItemId());\n if (this.#items[index].getItemId() === this.#clipboardItem?.getItemId()) {\n this.#course.clearClipboard();\n }\n\n this.#items.splice(index, 1);\n item.remove();\n\n if (this.#items.length === 0) {\n this.#element.querySelector('.sharing_cart_items')\n .innerHTML = await get_string('no_items', 'block_sharing_cart');\n }\n }\n\n /**\n * @param {ItemElement} item\n */\n deleteItem(item) {\n Ajax.call([{\n methodname: 'block_sharing_cart_delete_item_from_sharing_cart',\n args: {\n item_id: item.getItemId(),\n },\n done: async (deleted) => {\n if (deleted) {\n await this.removeItemElement(item);\n } else {\n await Notification.alert('Failed to delete item');\n }\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n\n /**\n * @param {Array} itemIds\n */\n deleteItems(itemIds) {\n itemIds = itemIds.map((id) => Number.parseInt(id));\n\n Ajax.call([{\n methodname: 'block_sharing_cart_delete_items_from_sharing_cart',\n args: {\n item_ids: itemIds,\n },\n done: async (deletedItemIds) => {\n const items = this.#items.filter((i) => itemIds.includes(i.getItemId()));\n for (const item of items) {\n const deleted = deletedItemIds.includes(item.getItemId());\n if (!deleted) {\n Notification.alert('Failed to delete item: \"' + item.getItemName() + '\"');\n continue;\n }\n\n await this.removeItemElement(item);\n }\n\n document.getElementById('block_sharing_cart_bulk_delete_confirm').disabled = true;\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n\n getElement() {\n return this.#element;\n }\n\n /**\n * @param {String} itemName\n * @param {CallableFunction} onSave\n * @return {Promise}\n */\n async createBackupItemToSharingCartModal(itemName, onSave) {\n const strings = await get_strings([\n {\n key: 'backup_item',\n component: 'block_sharing_cart',\n },\n {\n key: 'into_sharing_cart',\n component: 'block_sharing_cart',\n },\n {\n key: 'backup',\n component: 'block_sharing_cart',\n },\n {\n key: 'cancel',\n component: 'core',\n }\n ]);\n\n const {html, js} = await this.#baseFactory.moodle().template().renderTemplate(\n 'block_sharing_cart/modal/backup_to_sharing_cart_modal_body',\n {\n show_user_data_backup: this.#canBackupUserdata,\n show_anonymize_user_data: this.#canBackupUserdata && this.#canAnonymizeUserdata,\n }\n );\n\n /**\n * @type {Modal}\n */\n const modal = await ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: strings[0] + ': \"' + itemName.slice(0, 50).trim() + '\" ' + strings[1],\n body: html,\n buttons: {\n save: strings[2],\n cancel: strings[3],\n },\n removeOnClose: true,\n });\n modal.getRoot().on(ModalEvents.shown, () => this.#baseFactory.moodle().template().runTemplateJS(js));\n modal.getRoot().on(ModalEvents.save, () => {\n const modalUserdataCheckbox = document.getElementById('modal-userdata-checkbox');\n const modalAnonymizeCheckbox = document.getElementById('modal-anonymize-checkbox');\n\n onSave({\n users: modalUserdataCheckbox?.checked ?? false,\n anonymize: modalAnonymizeCheckbox?.checked ?? false\n });\n });\n\n return modal;\n }\n\n /**\n * @param {Number} sectionId\n */\n async addSectionBackupToSharingCart(sectionId) {\n const sectionName = this.#course.getSectionName(sectionId);\n\n const cms = this.#course.getSectionCourseModules(sectionId);\n\n if (cms.length === 0) {\n const strings = await get_strings([\n {\n key: 'no_course_modules_in_section',\n component: 'block_sharing_cart',\n },\n {\n key: 'no_course_modules_in_section_description',\n component: 'block_sharing_cart',\n },\n ]);\n\n await Notification.alert(strings[0], strings[1]);\n\n return;\n }\n\n const modal = await this.createBackupItemToSharingCartModal(sectionName, (settings) => {\n Ajax.call([{\n methodname: 'block_sharing_cart_backup_section_into_sharing_cart',\n args: {\n section_id: sectionId,\n settings: settings\n },\n done: async (data) => {\n await this.renderItem(data);\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n });\n\n await modal.show();\n }\n\n /**\n * @param {Number} courseModuleId\n */\n async addCourseModuleBackupToSharingCart(courseModuleId) {\n const courseModuleName = this.#course.getCourseModuleName(courseModuleId);\n\n const modal = await this.createBackupItemToSharingCartModal(courseModuleName, (settings) => {\n Ajax.call([{\n methodname: 'block_sharing_cart_backup_course_module_into_sharing_cart',\n args: {\n course_module_id: courseModuleId,\n settings: settings\n },\n done: async (data) => {\n await this.renderItem(data);\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n });\n await modal.show();\n }\n\n /**\n * @param {Object} item\n */\n async renderItem(item) {\n const existingItemIndex = this.#items.findIndex((i) => i.getItemId() === item.id);\n const existingItem = this.#items[existingItemIndex] ?? false;\n const oldElement = this.#element.querySelector('.sharing_cart_items .sharing_cart_item[data-itemid=\"' + item.id + '\"]');\n if (existingItem && oldElement) {\n const element = await this.#baseFactory.moodle().template().createElementFromFragment(\n 'block_sharing_cart',\n 'item',\n 1,\n {\n item_id: item.id,\n }\n );\n\n this.#element.querySelector('.sharing_cart_items').replaceChild(element, oldElement);\n this.#items[existingItemIndex] = this.#baseFactory.block().item().element(this, element);\n\n element.querySelectorAll('.sharing_cart_item').forEach((subItem) => {\n this.setupItem(subItem);\n });\n\n return;\n }\n\n const element = await this.#baseFactory.moodle().template().createElementFromTemplate(\n 'block_sharing_cart/block/item',\n {\n id: item.id,\n name: item.name,\n type: item.type,\n status: 0,\n old_instance_id: item.old_instance_id,\n status_awaiting: true,\n has_run_now: true,\n task_id: item.task_id ?? null,\n status_finished: false,\n status_failed: false,\n is_module: item.type !== 'section',\n is_section: item.type === 'section',\n is_root: true,\n }\n );\n this.#element.querySelector('.sharing_cart_items').prepend(element);\n\n this.setupItem(element);\n }\n\n /**\n * @param {ItemElement} item\n * @param {Number} sectionId\n * @param {HTMLElement} modal\n */\n importItem(item, sectionId, modal) {\n this.#course.clearClipboard();\n\n const courseModuleIds = [];\n modal.querySelectorAll('input[type=\"checkbox\"][data-type=\"coursemodule\"]:checked').forEach((checkbox) => {\n courseModuleIds.push(checkbox.dataset.id);\n });\n\n if (item.isSection() && courseModuleIds.length === 0) {\n modal.querySelectorAll('.form-check-input').forEach(async (item) => {\n item.setCustomValidity(\n await get_string('atleast_one_course_module_must_be_included', 'block_sharing_cart')\n );\n item.reportValidity();\n });\n return false;\n }\n\n if (item.isModule()) {\n courseModuleIds.push(item.getItemOldInstanceId());\n }\n\n Ajax.call([{\n methodname: 'block_sharing_cart_restore_item_from_sharing_cart_into_section',\n args: {\n item_id: item.getItemId(),\n section_id: sectionId,\n course_modules_to_include: courseModuleIds,\n },\n done: async (success) => {\n if (success) {\n await this.#queue.loadQueue(true);\n }\n },\n fail: (data) => {\n Notification.exception(data);\n }\n }]);\n }\n\n /**\n * @param {ItemElement} item\n * @param {Number} sectionId\n * @param {Event} e\n */\n async confirmImportBackupFromSharingCart(item, sectionId, e) {\n e.preventDefault();\n e.stopPropagation();\n\n const strings = await get_strings([\n {\n key: 'copy_item',\n component: 'block_sharing_cart',\n },\n {\n key: 'into_section',\n component: 'block_sharing_cart',\n },\n {\n key: 'import',\n component: 'core',\n },\n {\n key: 'cancel',\n component: 'core',\n }\n ]);\n\n const sectionName = this.#course.getSectionName(sectionId);\n\n const {html, js} = await this.#baseFactory.moodle().template().renderFragment(\n 'block_sharing_cart',\n 'item_restore_form',\n 1,\n {\n item_id: item.getItemId()\n }\n );\n\n const modal = await ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: strings[0] + ': ' +\n '\"' + item.getItemName().slice(0, 50).trim() + '\"' +\n ' ' + strings[1] + ': ' +\n '\"' + sectionName.slice(0, 50).trim() + '\"',\n body: html,\n buttons: {\n save: strings[2],\n cancel: strings[3],\n },\n removeOnClose: true,\n });\n modal.getRoot().on(ModalEvents.shown, () => this.#baseFactory.moodle().template().runTemplateJS(js));\n modal.getRoot().on(ModalEvents.save, this.importItem.bind(this, item, sectionId, modal.getRoot()[0]));\n await modal.show();\n }\n\n /**\n * @param {Array} itemIds\n */\n async confirmDeleteItems(itemIds) {\n const strings = await get_strings([\n {\n key: 'delete_items',\n component: 'block_sharing_cart',\n },\n {\n key: 'confirm_delete_items',\n component: 'block_sharing_cart',\n },\n {\n key: 'delete',\n component: 'core',\n },\n {\n key: 'cancel',\n component: 'core',\n }\n ]);\n\n const modal = await ModalFactory.create({\n type: ModalFactory.types.DELETE_CANCEL,\n title: strings[0],\n body: strings[1],\n buttons: {\n delete: strings[2],\n cancel: strings[3],\n },\n removeOnClose: true,\n });\n\n modal.getRoot().on(ModalEvents.delete, this.deleteItems.bind(this, itemIds));\n await modal.show();\n }\n}\n"],"names":["constructor","baseFactory","element","canBackupUserdata","canAnonymizeUserdata","showSharingCartBasket","addEventListeners","setupCourse","setupQueue","setupItems","setupDragAndDrop","setupBulkDelete","course","this","queue","block","document","querySelector","_classPrivateFieldGet","querySelectorAll","forEach","setupItem","Sortable","dataIdAttr","onUpdate","call","methodname","args","item_ids","toArray","fail","data","exception","dropZone","addEventListener","e","preventDefault","stopPropagation","async","addSectionBackupToSharingCart","addCourseModuleBackupToSharingCart","enableBulkDeleteButton","disableBulkDeleteButton","bulkDeleteButton","checkboxSelector","classList","add","remove","checkbox","checked","disabled","itemIds","push","value","confirmDeleteItems","itemElement","item","setClipboard","clearClipboard","setDraggedSectionId","id","setDraggedCourseModuleId","getItemChildrenRecursively","childItem","index","findIndex","i","getItemId","Number","parseInt","dataset","itemid","_classPrivateFieldGet3","splice","_classPrivateFieldGet4","length","innerHTML","deleteItem","item_id","done","deleted","removeItemElement","Notification","alert","deleteItems","map","items","filter","includes","deletedItemIds","getItemName","getElementById","getElement","itemName","onSave","strings","key","component","html","js","moodle","template","renderTemplate","show_user_data_backup","show_anonymize_user_data","modal","ModalFactory","create","type","types","SAVE_CANCEL","title","slice","trim","body","buttons","save","cancel","removeOnClose","getRoot","on","ModalEvents","shown","runTemplateJS","modalUserdataCheckbox","modalAnonymizeCheckbox","users","anonymize","sectionId","sectionName","getSectionName","getSectionCourseModules","createBackupItemToSharingCartModal","settings","section_id","renderItem","show","courseModuleId","courseModuleName","getCourseModuleName","course_module_id","existingItemIndex","existingItem","oldElement","createElementFromFragment","replaceChild","subItem","createElementFromTemplate","name","status","old_instance_id","status_awaiting","has_run_now","task_id","status_finished","status_failed","is_module","is_section","is_root","prepend","importItem","courseModuleIds","isSection","setCustomValidity","reportValidity","isModule","getItemOldInstanceId","course_modules_to_include","success","loadQueue","renderFragment","bind","DELETE_CANCEL","delete"],"mappings":"+/DA2EIA,YAAYC,YAAaC,QAASC,kBAAmBC,qBAAsBC,sWA5ClE,kEAKG,yEAKK,8EAKI,8EAKG,+EAKC,8EAKA,4EAKL,+CAUIJ,iDACJC,uDACUC,oEACGC,wEACCC,uBAMlCC,gCACSC,mBACAC,kBACAC,kBACAC,wBACAC,kBAEE,CAACC,6BAAQC,cAAcC,4BAAOD,aAAaE,MAAOF,MAG7DN,oBACUK,OAASI,SAASC,cAAc,sDAEvBC,yCAAkBH,QAAQH,SAASV,QAAQW,KAAMD,SAGpEJ,mBACUM,MAAQE,SAASC,cAAc,yDAEvBC,yCAAkBH,QAAQD,QAAQZ,QAAQW,KAAMC,QAGlEL,aACkBS,qCAAcC,iBAAiB,sBAEvCC,SAASlB,eACNmB,UAAUnB,iDAGF,IAAIoB,oBAASJ,qCAAcD,cAAc,uBAAwB,CAC9EM,WAAY,cACZC,SAAU,mBACDC,KAAK,CAAC,CACPC,WAAY,gDACZC,KAAM,CACFC,SAAUV,sCAAeW,WAE7BC,KAAOC,6BACUC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WAAWW,KAAK9J,KAAM2C,KAAMwE,UAAWvB,MAAMc,UAAU,WAC3Fd,MAAM+B,gCAMSrF,eACf4C,cAAgB,oBAAY,CAC9B,CACIC,IAAK,eACLC,UAAW,sBAEf,CACID,IAAK,uBACLC,UAAW,sBAEf,CACID,IAAK,SACLC,UAAW,QAEf,CACID,IAAK,SACLC,UAAW,UAIbQ,YAAcC,uBAAaC,OAAO,CACpCC,KAAMF,uBAAaG,MAAM+D,cACzB7D,MAAOhB,QAAQ,GACfmB,KAAMnB,QAAQ,GACdoB,QAAS,CACL0D,OAAQ9E,QAAQ,GAChBsB,OAAQtB,QAAQ,IAEpBuB,eAAe,IAGnBb,MAAMc,UAAUC,GAAGC,sBAAYoD,OAAQhK,KAAKuE,YAAYuF,KAAK9J,KAAMsC,gBAC7DsD,MAAM+B"} \ No newline at end of file diff --git a/amd/build/local/block.min.js b/amd/build/local/block.min.js index a762323..593d6f8 100644 --- a/amd/build/local/block.min.js +++ b/amd/build/local/block.min.js @@ -1,3 +1,3 @@ -define("block_sharing_cart/local/block",["exports","core/reactive","core/str","core_courseformat/courseeditor","../app/factory"],(function(_exports,_reactive,_str,_courseeditor,_factory){var obj;function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_factory=(obj=_factory)&&obj.__esModule?obj:{default:obj};class Block extends _reactive.BaseComponent{constructor(){super(...arguments),_defineProperty(this,"course",void 0),_defineProperty(this,"block",void 0),_defineProperty(this,"queue",void 0)}create(descriptor){var _descriptor$canBackup,_descriptor$canAnonym,_descriptor$showShari;this.name="sharing_cart_block",this.selectors={COPY_SECTION_CONTAINER:"#copy_section_container"},this.canBackupUserdata=null!==(_descriptor$canBackup=descriptor.canBackupUserdata)&&void 0!==_descriptor$canBackup&&_descriptor$canBackup,this.canAnonymizeUserdata=null!==(_descriptor$canAnonym=descriptor.canAnonymizeUserdata)&&void 0!==_descriptor$canAnonym&&_descriptor$canAnonym,this.showSharingCartBasket=null!==(_descriptor$showShari=descriptor.showSharingCartBasket)&&void 0!==_descriptor$showShari&&_descriptor$showShari}static init(target,canBackupUserdata,canAnonymizeUserdata,showSharingCartBasket){return new this({element:document.getElementById(target),reactive:(0,_courseeditor.getCurrentCourseEditor)(),canBackupUserdata:canBackupUserdata,canAnonymizeUserdata:canAnonymizeUserdata,showSharingCartBasket:showSharingCartBasket})}stateReady(){this.baseFactory=_factory.default.make();const{course:course,block:block,queue:queue}=this.baseFactory.block().eventHandler().onLoad(this.canBackupUserdata,this.canAnonymizeUserdata,this.showSharingCartBasket);this.course=course,this.block=block,this.queue=queue;const courseContent=document.querySelector(".course-content");if(courseContent){courseContent.querySelectorAll('[data-for="section"]').forEach((sectionElement=>{const section=this.reactive.state.section.get(sectionElement.dataset.id);this._refreshSection({element:section})}));courseContent.querySelectorAll('[data-for="cmitem"]').forEach((courseModuleElement=>{const courseModule=this.reactive.state.cm.get(courseModuleElement.dataset.id);this._refreshCourseModule({element:courseModule})}))}const showCopySectionInBlockSegment=this.getElement(this.selectors.COPY_SECTION_CONTAINER);if(showCopySectionInBlockSegment){this._refreshCopySectionOptions();const select=showCopySectionInBlockSegment.querySelector("select");showCopySectionInBlockSegment.querySelector("button").addEventListener("click",(async()=>{await this.block.addSectionBackupToSharingCart(select.value)}))}}getWatchers(){return[{watch:"section:created",handler:this._refreshSection},{watch:"section:updated",handler:this._refreshSection},{watch:"cm:created",handler:this._refreshCourseModule},{watch:"cm:updated",handler:this._refreshCourseModule}]}async getBackupToSharingCartButton(){return this._sharingCartButton||(this._sharingCartButton=await this.baseFactory.moodle().template().createElementFromTemplate("block_sharing_cart/block/course/add_to_sharing_cart_button",{})),this._sharingCartButton.cloneNode(!0)}async _refreshCopySectionOptions(){const showCopySectionInBlockSegment=this.getElement(this.selectors.COPY_SECTION_CONTAINER);if(!showCopySectionInBlockSegment)return;const select=showCopySectionInBlockSegment.querySelector("select"),selectedValue=select.value,noCourseModulesInSections=await(0,_str.get_string)("no_course_modules_in_section","block_sharing_cart"),div=document.createElement("div"),option=document.createElement("option");option.disabled=!0,option.text=await(0,_str.get_string)("choosedots","core"),div.appendChild(option),this.reactive.state.section.forEach((section=>{const option=document.createElement("option");0===section.cmlist.length&&(option.disabled=!0,option.title=noCourseModulesInSections),option.value=section.id,option.text=section.title,option.selected=Number.parseInt(section.id)===Number.parseInt(selectedValue),div.appendChild(option)})),select.innerHTML=div.innerHTML}async _refreshSection(_ref){let{element:element}=_ref;if(this._refreshCopySectionOptions(),this.showSharingCartBasket){let backupButton=await this.getBackupToSharingCartButton();const sectionTitle=document.querySelector('.course-content [data-for="section_title"] .inplaceeditable[data-itemid="'+element.id+'"]');if(sectionTitle){sectionTitle.parentElement.querySelector(".add_to_sharing_cart")||(sectionTitle.after(backupButton),backupButton.addEventListener("click",(e=>{e.currentTarget.classList.contains("disabled")||this.block.addSectionBackupToSharingCart(element.id)}))),backupButton=sectionTitle.parentElement.querySelector(".add_to_sharing_cart");const disabled=0===element.cmlist.length;backupButton.classList.toggle("disabled",disabled),backupButton.title=disabled?await(0,_str.get_string)("no_course_modules_in_section_description","block_sharing_cart"):""}}}async _refreshCourseModule(_ref2){let{element:element}=_ref2;if(this.showSharingCartBasket){const backupButton=await this.getBackupToSharingCartButton(),courseModuleActionMenu=document.querySelector('.course-content .cm_action_menu[data-cmid="'+element.id+'"]');if(!courseModuleActionMenu)return void setTimeout((()=>this._refreshCourseModule({element:element})),100);courseModuleActionMenu.querySelector(".add_to_sharing_cart")||(courseModuleActionMenu.append(backupButton),backupButton.addEventListener("click",this.block.addCourseModuleBackupToSharingCart.bind(this.block,element.id)))}}}return _exports.default=Block,_exports.default})); +define("block_sharing_cart/local/block",["exports","core/reactive","core/str","core_courseformat/courseeditor","../app/factory"],(function(_exports,_reactive,_str,_courseeditor,_factory){var obj;function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_factory=(obj=_factory)&&obj.__esModule?obj:{default:obj};class Block extends _reactive.BaseComponent{constructor(){super(...arguments),_defineProperty(this,"course",void 0),_defineProperty(this,"block",void 0),_defineProperty(this,"queue",void 0)}create(descriptor){var _descriptor$canBackup,_descriptor$canAnonym,_descriptor$showShari;this.name="sharing_cart_block",this.selectors={COPY_SECTION_CONTAINER:"#copy_section_container"},this.canBackupUserdata=null!==(_descriptor$canBackup=descriptor.canBackupUserdata)&&void 0!==_descriptor$canBackup&&_descriptor$canBackup,this.canAnonymizeUserdata=null!==(_descriptor$canAnonym=descriptor.canAnonymizeUserdata)&&void 0!==_descriptor$canAnonym&&_descriptor$canAnonym,this.showSharingCartBasket=null!==(_descriptor$showShari=descriptor.showSharingCartBasket)&&void 0!==_descriptor$showShari&&_descriptor$showShari}static init(target,canBackupUserdata,canAnonymizeUserdata,showSharingCartBasket){return new this({element:document.getElementById(target),reactive:(0,_courseeditor.getCurrentCourseEditor)(),canBackupUserdata:canBackupUserdata,canAnonymizeUserdata:canAnonymizeUserdata,showSharingCartBasket:showSharingCartBasket})}stateReady(){this.baseFactory=_factory.default.make();const{course:course,block:block,queue:queue}=this.baseFactory.block().eventHandler().onLoad(this.canBackupUserdata,this.canAnonymizeUserdata,this.showSharingCartBasket);this.course=course,this.block=block,this.queue=queue;const courseContent=document.querySelector(".course-content");if(courseContent){courseContent.querySelectorAll('[data-for="section"]').forEach((sectionElement=>{const section=this.reactive.state.section.get(sectionElement.dataset.id);this._refreshSection({element:section})}));courseContent.querySelectorAll('[data-for="cmitem"]').forEach((courseModuleElement=>{const courseModule=this.reactive.state.cm.get(courseModuleElement.dataset.id);this._refreshCourseModule({element:courseModule})}))}const showCopySectionInBlockSegment=this.getElement(this.selectors.COPY_SECTION_CONTAINER);if(showCopySectionInBlockSegment){this._refreshCopySectionOptions();const select=showCopySectionInBlockSegment.querySelector("select");showCopySectionInBlockSegment.querySelector("button").addEventListener("click",(async()=>{await this.block.addSectionBackupToSharingCart(select.value)}))}}getWatchers(){return[{watch:"section:created",handler:this._refreshSection},{watch:"section:updated",handler:this._refreshSection},{watch:"section.dragging:created",handler:this._onDraggingSection},{watch:"section.dragging:updated",handler:this._onDraggingSection},{watch:"cm.dragging:created",handler:this._onDraggingCourseModule},{watch:"cm.dragging:updated",handler:this._onDraggingCourseModule},{watch:"cm:created",handler:this._refreshCourseModule},{watch:"cm:updated",handler:this._refreshCourseModule}]}async getBackupToSharingCartButton(){return this._sharingCartButton||(this._sharingCartButton=await this.baseFactory.moodle().template().createElementFromTemplate("block_sharing_cart/block/course/add_to_sharing_cart_button",{})),this._sharingCartButton.cloneNode(!0)}async _refreshCopySectionOptions(){const showCopySectionInBlockSegment=this.getElement(this.selectors.COPY_SECTION_CONTAINER);if(!showCopySectionInBlockSegment)return;const select=showCopySectionInBlockSegment.querySelector("select"),selectedValue=select.value,noCourseModulesInSections=await(0,_str.get_string)("no_course_modules_in_section","block_sharing_cart"),div=document.createElement("div"),option=document.createElement("option");option.disabled=!0,option.text=await(0,_str.get_string)("choosedots","core"),div.appendChild(option),this.reactive.state.section.forEach((section=>{const option=document.createElement("option");0===section.cmlist.length&&(option.disabled=!0,option.title=noCourseModulesInSections),option.value=section.id,option.text=section.title,option.selected=Number.parseInt(section.id)===Number.parseInt(selectedValue),div.appendChild(option)})),select.innerHTML=div.innerHTML}async _refreshSection(_ref){let{element:element}=_ref;if(this._refreshCopySectionOptions(),this.showSharingCartBasket){let backupButton=await this.getBackupToSharingCartButton();const sectionTitle=document.querySelector('.course-content [data-for="section_title"] .inplaceeditable[data-itemid="'+element.id+'"]');if(sectionTitle){sectionTitle.parentElement.querySelector(".add_to_sharing_cart")||(sectionTitle.after(backupButton),backupButton.addEventListener("click",(e=>{e.currentTarget.classList.contains("disabled")||this.block.addSectionBackupToSharingCart(element.id)}))),backupButton=sectionTitle.parentElement.querySelector(".add_to_sharing_cart");const disabled=0===element.cmlist.length;backupButton.classList.toggle("disabled",disabled),backupButton.title=disabled?await(0,_str.get_string)("no_course_modules_in_section_description","block_sharing_cart"):""}}}async _refreshCourseModule(_ref2){let{element:element}=_ref2;if(this.showSharingCartBasket){const backupButton=await this.getBackupToSharingCartButton(),courseModuleActionMenu=document.querySelector('.course-content .cm_action_menu[data-cmid="'+element.id+'"]');if(!courseModuleActionMenu)return void setTimeout((()=>this._refreshCourseModule({element:element})),100);courseModuleActionMenu.querySelector(".add_to_sharing_cart")||(courseModuleActionMenu.append(backupButton),backupButton.addEventListener("click",this.block.addCourseModuleBackupToSharingCart.bind(this.block,element.id)))}}async _onDraggingSection(_ref3){let{element:element}=_ref3;element.dragging?(this.block.getElement().classList.add("dragging_item"),this.block.setDraggedSectionId(element.id)):(this.block.getElement().classList.remove("dragging_item"),this.block.setDraggedSectionId(null))}async _onDraggingCourseModule(_ref4){let{element:element}=_ref4;element.dragging?(this.block.getElement().classList.add("dragging_item"),this.block.setDraggedCourseModuleId(element.id)):(this.block.getElement().classList.remove("dragging_item"),this.block.setDraggedCourseModuleId(null))}}return _exports.default=Block,_exports.default})); //# sourceMappingURL=block.min.js.map \ No newline at end of file diff --git a/amd/build/local/block.min.js.map b/amd/build/local/block.min.js.map index 42af92a..691e72e 100644 --- a/amd/build/local/block.min.js.map +++ b/amd/build/local/block.min.js.map @@ -1 +1 @@ -{"version":3,"file":"block.min.js","sources":["../../src/local/block.js"],"sourcesContent":["import {BaseComponent} from 'core/reactive';\nimport {get_string as getString} from 'core/str';\nimport {getCurrentCourseEditor} from \"core_courseformat/courseeditor\";\nimport BaseFactory from \"../app/factory\";\n\nexport default class Block extends BaseComponent {\n /**\n * @type {CourseElement}\n */\n course;\n\n /**\n * @type {BlockElement}\n */\n block;\n\n /**\n * @type {QueueElement}\n */\n queue;\n\n /**\n * Constructor hook.\n * @param {Object} descriptor\n */\n create(descriptor) {\n // Optional component name for debugging.\n this.name = 'sharing_cart_block';\n // Default query selectors.\n this.selectors = {\n COPY_SECTION_CONTAINER: '#copy_section_container',\n };\n\n this.canBackupUserdata = descriptor.canBackupUserdata ?? false;\n this.canAnonymizeUserdata = descriptor.canAnonymizeUserdata ?? false;\n this.showSharingCartBasket = descriptor.showSharingCartBasket ?? false;\n }\n\n /**\n * Static method to create a component instance form the mustache template.\n *\n * @param {String} target\n * @param {Boolean} canBackupUserdata\n * @param {Boolean} canAnonymizeUserdata\n * @param {Boolean} showSharingCartBasket\n */\n static init(target, canBackupUserdata, canAnonymizeUserdata, showSharingCartBasket) {\n return new this({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n canBackupUserdata,\n canAnonymizeUserdata,\n showSharingCartBasket\n });\n }\n\n /**\n * Initial state ready method.\n */\n stateReady() {\n this.baseFactory = BaseFactory.make();\n const {course, block, queue} = this.baseFactory.block().eventHandler().onLoad(\n this.canBackupUserdata,\n this.canAnonymizeUserdata,\n this.showSharingCartBasket\n );\n\n this.course = course;\n this.block = block;\n this.queue = queue;\n\n const courseContent = document.querySelector('.course-content');\n if (courseContent) {\n const sectionElements = courseContent.querySelectorAll('[data-for=\"section\"]');\n sectionElements.forEach(sectionElement => {\n const section = this.reactive.state.section.get(sectionElement.dataset.id);\n this._refreshSection({element: section});\n });\n\n const courseModuleElements = courseContent.querySelectorAll('[data-for=\"cmitem\"]');\n courseModuleElements.forEach(courseModuleElement => {\n const courseModule = this.reactive.state.cm.get(courseModuleElement.dataset.id);\n this._refreshCourseModule({element: courseModule});\n });\n }\n\n const showCopySectionInBlockSegment = this.getElement(this.selectors.COPY_SECTION_CONTAINER);\n if (showCopySectionInBlockSegment) {\n this._refreshCopySectionOptions();\n\n const select = showCopySectionInBlockSegment.querySelector('select');\n const copySectionButton = showCopySectionInBlockSegment.querySelector('button');\n copySectionButton.addEventListener('click', async () => {\n await this.block.addSectionBackupToSharingCart(select.value);\n });\n }\n }\n\n /**\n * Component watchers.\n *\n * @returns {Array} of watchers\n */\n getWatchers() {\n return [\n {watch: `section:created`, handler: this._refreshSection},\n {watch: `section:updated`, handler: this._refreshSection},\n {watch: `cm:created`, handler: this._refreshCourseModule},\n {watch: `cm:updated`, handler: this._refreshCourseModule},\n ];\n }\n\n async getBackupToSharingCartButton() {\n if (!this._sharingCartButton) {\n this._sharingCartButton = await this.baseFactory.moodle().template().createElementFromTemplate(\n 'block_sharing_cart/block/course/add_to_sharing_cart_button',\n {}\n );\n }\n\n return this._sharingCartButton.cloneNode(true);\n }\n\n async _refreshCopySectionOptions() {\n const showCopySectionInBlockSegment = this.getElement(this.selectors.COPY_SECTION_CONTAINER);\n if (!showCopySectionInBlockSegment) {\n return;\n }\n\n const select = showCopySectionInBlockSegment.querySelector('select');\n const selectedValue = select.value;\n\n const noCourseModulesInSections = await getString('no_course_modules_in_section', 'block_sharing_cart');\n\n const div = document.createElement('div');\n\n const option = document.createElement('option');\n option.disabled = true;\n option.text = await getString('choosedots', 'core');\n div.appendChild(option);\n\n this.reactive.state.section.forEach((section) => {\n const option = document.createElement('option');\n\n const sectionIsEmpty = section.cmlist.length === 0;\n if (sectionIsEmpty) {\n option.disabled = true;\n option.title = noCourseModulesInSections;\n }\n\n option.value = section.id;\n option.text = section.title;\n option.selected = Number.parseInt(section.id) === Number.parseInt(selectedValue);\n\n div.appendChild(option);\n });\n\n select.innerHTML = div.innerHTML;\n }\n\n /**\n * Refresh the section.\n * @param {Object} param\n * @param {Object} param.element\n */\n async _refreshSection({element}) {\n this._refreshCopySectionOptions();\n\n if (this.showSharingCartBasket) {\n let backupButton = await this.getBackupToSharingCartButton();\n\n const sectionTitle = document.querySelector(\n '.course-content [data-for=\"section_title\"] .inplaceeditable[data-itemid=\"' + element.id + '\"]'\n );\n if (sectionTitle) {\n const hasBackupButton = sectionTitle.parentElement.querySelector('.add_to_sharing_cart');\n if (!hasBackupButton) {\n sectionTitle.after(backupButton);\n\n backupButton.addEventListener(\n 'click',\n (e) => {\n if (e.currentTarget.classList.contains('disabled')) {\n return;\n }\n\n this.block.addSectionBackupToSharingCart(element.id);\n }\n );\n }\n\n backupButton = sectionTitle.parentElement.querySelector('.add_to_sharing_cart');\n\n const disabled = element.cmlist.length === 0;\n backupButton.classList.toggle('disabled', disabled);\n backupButton.title = disabled ?\n await getString('no_course_modules_in_section_description', 'block_sharing_cart') :\n '';\n }\n }\n }\n\n /**\n * Refresh the course module.\n * @param {Object} param\n * @param {Object} param.element\n */\n async _refreshCourseModule({element}) {\n if (this.showSharingCartBasket) {\n const backupButton = await this.getBackupToSharingCartButton();\n\n const courseModuleActionMenu = document.querySelector(\n '.course-content .cm_action_menu[data-cmid=\"' + element.id + '\"]'\n );\n if (!courseModuleActionMenu) {\n setTimeout(() => this._refreshCourseModule({element}), 100);\n return;\n }\n\n const hasBackupButton = courseModuleActionMenu.querySelector('.add_to_sharing_cart');\n if (!hasBackupButton) {\n courseModuleActionMenu.append(backupButton);\n\n backupButton.addEventListener(\n 'click',\n this.block.addCourseModuleBackupToSharingCart.bind(this.block, element.id)\n );\n }\n }\n }\n}\n"],"names":["Block","BaseComponent","create","descriptor","name","selectors","COPY_SECTION_CONTAINER","canBackupUserdata","canAnonymizeUserdata","showSharingCartBasket","target","this","element","document","getElementById","reactive","stateReady","baseFactory","BaseFactory","make","course","block","queue","eventHandler","onLoad","courseContent","querySelector","querySelectorAll","forEach","sectionElement","section","state","get","dataset","id","_refreshSection","courseModuleElement","courseModule","cm","_refreshCourseModule","showCopySectionInBlockSegment","getElement","_refreshCopySectionOptions","select","addEventListener","async","addSectionBackupToSharingCart","value","getWatchers","watch","handler","_sharingCartButton","moodle","template","createElementFromTemplate","cloneNode","selectedValue","noCourseModulesInSections","div","createElement","option","disabled","text","appendChild","cmlist","length","title","selected","Number","parseInt","innerHTML","backupButton","getBackupToSharingCartButton","sectionTitle","parentElement","after","e","currentTarget","classList","contains","toggle","courseModuleActionMenu","setTimeout","append","addCourseModuleBackupToSharingCart","bind"],"mappings":"ufAKqBA,cAAcC,0KAoB/BC,OAAOC,uFAEEC,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AAW,IAAMvE,KAAK4B,qBAAqB,CAAC3B,QAAAA,WAAW,KAInCqE,uBAAuBvD,cAAc,0BAEzDuD,uBAAuBE,OAAOZ,cAE9BA,aAAa3B,iBACT,QACAjC,KAAKU,MAAM+D,mCAAmCC,KAAK1E,KAAKU,MAAOT,QAAQsB"} \ No newline at end of file +{"version":3,"file":"block.min.js","sources":["../../src/local/block.js"],"sourcesContent":["import {BaseComponent} from 'core/reactive';\nimport {get_string as getString} from 'core/str';\nimport {getCurrentCourseEditor} from \"core_courseformat/courseeditor\";\nimport BaseFactory from \"../app/factory\";\n\nexport default class Block extends BaseComponent {\n /**\n * @type {CourseElement}\n */\n course;\n\n /**\n * @type {BlockElement}\n */\n block;\n\n /**\n * @type {QueueElement}\n */\n queue;\n\n /**\n * Constructor hook.\n * @param {Object} descriptor\n */\n create(descriptor) {\n // Optional component name for debugging.\n this.name = 'sharing_cart_block';\n // Default query selectors.\n this.selectors = {\n COPY_SECTION_CONTAINER: '#copy_section_container',\n };\n\n this.canBackupUserdata = descriptor.canBackupUserdata ?? false;\n this.canAnonymizeUserdata = descriptor.canAnonymizeUserdata ?? false;\n this.showSharingCartBasket = descriptor.showSharingCartBasket ?? false;\n }\n\n /**\n * Static method to create a component instance form the mustache template.\n *\n * @param {String} target\n * @param {Boolean} canBackupUserdata\n * @param {Boolean} canAnonymizeUserdata\n * @param {Boolean} showSharingCartBasket\n */\n static init(target, canBackupUserdata, canAnonymizeUserdata, showSharingCartBasket) {\n return new this({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n canBackupUserdata,\n canAnonymizeUserdata,\n showSharingCartBasket\n });\n }\n\n /**\n * Initial state ready method.\n */\n stateReady() {\n this.baseFactory = BaseFactory.make();\n const {course, block, queue} = this.baseFactory.block().eventHandler().onLoad(\n this.canBackupUserdata,\n this.canAnonymizeUserdata,\n this.showSharingCartBasket\n );\n\n this.course = course;\n this.block = block;\n this.queue = queue;\n\n const courseContent = document.querySelector('.course-content');\n if (courseContent) {\n const sectionElements = courseContent.querySelectorAll('[data-for=\"section\"]');\n sectionElements.forEach(sectionElement => {\n const section = this.reactive.state.section.get(sectionElement.dataset.id);\n this._refreshSection({element: section});\n });\n\n const courseModuleElements = courseContent.querySelectorAll('[data-for=\"cmitem\"]');\n courseModuleElements.forEach(courseModuleElement => {\n const courseModule = this.reactive.state.cm.get(courseModuleElement.dataset.id);\n this._refreshCourseModule({element: courseModule});\n });\n }\n\n const showCopySectionInBlockSegment = this.getElement(this.selectors.COPY_SECTION_CONTAINER);\n if (showCopySectionInBlockSegment) {\n this._refreshCopySectionOptions();\n\n const select = showCopySectionInBlockSegment.querySelector('select');\n const copySectionButton = showCopySectionInBlockSegment.querySelector('button');\n copySectionButton.addEventListener('click', async () => {\n await this.block.addSectionBackupToSharingCart(select.value);\n });\n }\n }\n\n /**\n * Component watchers.\n *\n * @returns {Array} of watchers\n */\n getWatchers() {\n return [\n {watch: `section:created`, handler: this._refreshSection},\n {watch: `section:updated`, handler: this._refreshSection},\n {watch: `section.dragging:created`, handler: this._onDraggingSection},\n {watch: `section.dragging:updated`, handler: this._onDraggingSection},\n {watch: `cm.dragging:created`, handler: this._onDraggingCourseModule},\n {watch: `cm.dragging:updated`, handler: this._onDraggingCourseModule},\n {watch: `cm:created`, handler: this._refreshCourseModule},\n {watch: `cm:updated`, handler: this._refreshCourseModule},\n ];\n }\n\n async getBackupToSharingCartButton() {\n if (!this._sharingCartButton) {\n this._sharingCartButton = await this.baseFactory.moodle().template().createElementFromTemplate(\n 'block_sharing_cart/block/course/add_to_sharing_cart_button',\n {}\n );\n }\n\n return this._sharingCartButton.cloneNode(true);\n }\n\n async _refreshCopySectionOptions() {\n const showCopySectionInBlockSegment = this.getElement(this.selectors.COPY_SECTION_CONTAINER);\n if (!showCopySectionInBlockSegment) {\n return;\n }\n\n const select = showCopySectionInBlockSegment.querySelector('select');\n const selectedValue = select.value;\n\n const noCourseModulesInSections = await getString('no_course_modules_in_section', 'block_sharing_cart');\n\n const div = document.createElement('div');\n\n const option = document.createElement('option');\n option.disabled = true;\n option.text = await getString('choosedots', 'core');\n div.appendChild(option);\n\n this.reactive.state.section.forEach((section) => {\n const option = document.createElement('option');\n\n const sectionIsEmpty = section.cmlist.length === 0;\n if (sectionIsEmpty) {\n option.disabled = true;\n option.title = noCourseModulesInSections;\n }\n\n option.value = section.id;\n option.text = section.title;\n option.selected = Number.parseInt(section.id) === Number.parseInt(selectedValue);\n\n div.appendChild(option);\n });\n\n select.innerHTML = div.innerHTML;\n }\n\n /**\n * Refresh the section.\n * @param {Object} param\n * @param {Object} param.element\n */\n async _refreshSection({element}) {\n this._refreshCopySectionOptions();\n\n if (this.showSharingCartBasket) {\n let backupButton = await this.getBackupToSharingCartButton();\n\n const sectionTitle = document.querySelector(\n '.course-content [data-for=\"section_title\"] .inplaceeditable[data-itemid=\"' + element.id + '\"]'\n );\n if (sectionTitle) {\n const hasBackupButton = sectionTitle.parentElement.querySelector('.add_to_sharing_cart');\n if (!hasBackupButton) {\n sectionTitle.after(backupButton);\n\n backupButton.addEventListener(\n 'click',\n (e) => {\n if (e.currentTarget.classList.contains('disabled')) {\n return;\n }\n\n this.block.addSectionBackupToSharingCart(element.id);\n }\n );\n }\n\n backupButton = sectionTitle.parentElement.querySelector('.add_to_sharing_cart');\n\n const disabled = element.cmlist.length === 0;\n backupButton.classList.toggle('disabled', disabled);\n backupButton.title = disabled ?\n await getString('no_course_modules_in_section_description', 'block_sharing_cart') :\n '';\n }\n }\n }\n\n /**\n * Refresh the course module.\n * @param {Object} param\n * @param {Object} param.element\n */\n async _refreshCourseModule({element}) {\n if (this.showSharingCartBasket) {\n const backupButton = await this.getBackupToSharingCartButton();\n\n const courseModuleActionMenu = document.querySelector(\n '.course-content .cm_action_menu[data-cmid=\"' + element.id + '\"]'\n );\n if (!courseModuleActionMenu) {\n setTimeout(() => this._refreshCourseModule({element}), 100);\n return;\n }\n\n const hasBackupButton = courseModuleActionMenu.querySelector('.add_to_sharing_cart');\n if (!hasBackupButton) {\n courseModuleActionMenu.append(backupButton);\n\n backupButton.addEventListener(\n 'click',\n this.block.addCourseModuleBackupToSharingCart.bind(this.block, element.id)\n );\n }\n }\n }\n\n /**\n * On dragging section\n * @param {Object} param\n * @param {Object} param.element\n */\n async _onDraggingSection({element}) {\n if (element.dragging) {\n this.block.getElement().classList.add('dragging_item');\n this.block.setDraggedSectionId(element.id);\n } else {\n this.block.getElement().classList.remove('dragging_item');\n this.block.setDraggedSectionId(null);\n }\n }\n\n /**\n * On dragging course module\n * @param {Object} param\n * @param {Object} param.element\n */\n async _onDraggingCourseModule({element}) {\n if (element.dragging) {\n this.block.getElement().classList.add('dragging_item');\n this.block.setDraggedCourseModuleId(element.id);\n } else {\n this.block.getElement().classList.remove('dragging_item');\n this.block.setDraggedCourseModuleId(null);\n }\n }\n}\n"],"names":["Block","BaseComponent","create","descriptor","name","selectors","COPY_SECTION_CONTAINER","canBackupUserdata","canAnonymizeUserdata","showSharingCartBasket","target","this","element","document","getElementById","reactive","stateReady","baseFactory","BaseFactory","make","course","block","queue","eventHandler","onLoad","courseContent","querySelector","querySelectorAll","forEach","sectionElement","section","state","get","dataset","id","_refreshSection","courseModuleElement","courseModule","cm","_refreshCourseModule","showCopySectionInBlockSegment","getElement","_refreshCopySectionOptions","select","addEventListener","async","addSectionBackupToSharingCart","value","getWatchers","watch","handler","_onDraggingSection","_onDraggingCourseModule","_sharingCartButton","moodle","template","createElementFromTemplate","cloneNode","selectedValue","noCourseModulesInSections","div","createElement","option","disabled","text","appendChild","cmlist","length","title","selected","Number","parseInt","innerHTML","backupButton","getBackupToSharingCartButton","sectionTitle","parentElement","after","e","currentTarget","classList","contains","toggle","courseModuleActionMenu","setTimeout","append","addCourseModuleBackupToSharingCart","bind","dragging","add","setDraggedSectionId","remove","setDraggedCourseModuleId"],"mappings":"ufAKqBA,cAAcC,0KAoB/BC,OAAOC,uFAEEC,KAAO,0BAEPC,UAAY,CACbC,uBAAwB,gCAGvBC,gDAAoBJ,W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,mBAAqB9D,KAAK+D,+BAE1BS,uBAAyBtE,SAASa,cACpC,8CAAgDd,QAAQsB,GAAK,UAE5DiD,mCACDC,YAAW,IAAMzE,KAAK4B,qBAAqB,CAAC3B,QAAAA,WAAW,KAInCuE,uBAAuBzD,cAAc,0BAEzDyD,uBAAuBE,OAAOZ,cAE9BA,aAAa7B,iBACT,QACAjC,KAAKU,MAAMiE,mCAAmCC,KAAK5E,KAAKU,MAAOT,QAAQsB,2CAW9DtB,QAACA,eAClBA,QAAQ4E,eACHnE,MAAMoB,aAAauC,UAAUS,IAAI,sBACjCpE,MAAMqE,oBAAoB9E,QAAQsB,WAElCb,MAAMoB,aAAauC,UAAUW,OAAO,sBACpCtE,MAAMqE,oBAAoB,gDAST9E,QAACA,eACvBA,QAAQ4E,eACHnE,MAAMoB,aAAauC,UAAUS,IAAI,sBACjCpE,MAAMuE,yBAAyBhF,QAAQsB,WAEvCb,MAAMoB,aAAauC,UAAUW,OAAO,sBACpCtE,MAAMuE,yBAAyB"} \ No newline at end of file diff --git a/amd/src/app/block/element.js b/amd/src/app/block/element.js index df1c9f1..3025f4f 100644 --- a/amd/src/app/block/element.js +++ b/amd/src/app/block/element.js @@ -131,41 +131,6 @@ export default class BlockElement { setupDragAndDrop() { const dropZone = this.#element; - const draggableCourseModules = document.querySelectorAll('.course-content .activity[data-for="cmitem"][data-id]'); - const draggableSections = document.querySelectorAll('.course-content .section[data-for="section"][data-id]'); - - draggableCourseModules.forEach((courseModule) => { - const courseModuleId = Number.parseInt(courseModule.dataset.id); - if (!courseModuleId) { - return; - } - - courseModule.addEventListener('dragstart', () => { - this.#draggedCourseModuleId = courseModuleId; - dropZone.classList.add('dragging_item'); - }); - courseModule.addEventListener('dragend', () => { - this.#draggedCourseModuleId = null; - dropZone.classList.remove('dragging_item'); - }); - }); - draggableSections.forEach((section) => { - const id = Number.parseInt(section.dataset.id); - if (!id) { - return; - } - - const draggable = section.querySelector('[data-for="section_title"]'); - - draggable.addEventListener('dragstart', () => { - this.#draggedSectionId = id; - dropZone.classList.add('dragging_item'); - }); - draggable.addEventListener('dragend', () => { - this.#draggedSectionId = null; - dropZone.classList.remove('dragging_item'); - }); - }); dropZone.addEventListener('dragover', (e) => { if (!this.#draggedSectionId && !this.#draggedCourseModuleId) { @@ -269,6 +234,20 @@ export default class BlockElement { this.#clipboardItem = null; } + /** + * @param {Number|null} id + */ + setDraggedSectionId(id) { + this.#draggedSectionId = id; + } + + /** + * @param {Number|null} id + */ + setDraggedCourseModuleId(id) { + this.#draggedCourseModuleId = id; + } + /** * @param {ItemElement} item */ @@ -355,6 +334,10 @@ export default class BlockElement { }]); } + getElement() { + return this.#element; + } + /** * @param {String} itemName * @param {CallableFunction} onSave diff --git a/amd/src/local/block.js b/amd/src/local/block.js index 9ce3581..600b48e 100644 --- a/amd/src/local/block.js +++ b/amd/src/local/block.js @@ -105,6 +105,10 @@ export default class Block extends BaseComponent { return [ {watch: `section:created`, handler: this._refreshSection}, {watch: `section:updated`, handler: this._refreshSection}, + {watch: `section.dragging:created`, handler: this._onDraggingSection}, + {watch: `section.dragging:updated`, handler: this._onDraggingSection}, + {watch: `cm.dragging:created`, handler: this._onDraggingCourseModule}, + {watch: `cm.dragging:updated`, handler: this._onDraggingCourseModule}, {watch: `cm:created`, handler: this._refreshCourseModule}, {watch: `cm:updated`, handler: this._refreshCourseModule}, ]; @@ -228,4 +232,34 @@ export default class Block extends BaseComponent { } } } + + /** + * On dragging section + * @param {Object} param + * @param {Object} param.element + */ + async _onDraggingSection({element}) { + if (element.dragging) { + this.block.getElement().classList.add('dragging_item'); + this.block.setDraggedSectionId(element.id); + } else { + this.block.getElement().classList.remove('dragging_item'); + this.block.setDraggedSectionId(null); + } + } + + /** + * On dragging course module + * @param {Object} param + * @param {Object} param.element + */ + async _onDraggingCourseModule({element}) { + if (element.dragging) { + this.block.getElement().classList.add('dragging_item'); + this.block.setDraggedCourseModuleId(element.id); + } else { + this.block.getElement().classList.remove('dragging_item'); + this.block.setDraggedCourseModuleId(null); + } + } } diff --git a/version.php b/version.php index 146e00d..aced28b 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ /** @var object $plugin */ $plugin->component = 'block_sharing_cart'; -$plugin->version = 2024080801; +$plugin->version = 2024081900; $plugin->requires = 2023042400; // Moodle 4.2.0 $plugin->release = '5.0, release 1'; $plugin->maturity = MATURITY_STABLE;