From e70977c1dac711be25444d78db28a950beaeea8a Mon Sep 17 00:00:00 2001 From: Grein-Air Date: Tue, 20 Aug 2024 20:28:10 +0200 Subject: [PATCH] Color for the columns --- amd/build/column.min.js | 2 +- amd/build/column.min.js.map | 2 +- amd/build/exporter.min.js | 2 +- amd/build/exporter.min.js.map | 2 +- amd/src/column.js | 15 +++++++++++++-- amd/src/exporter.js | 1 + classes/boardmanager.php | 10 +++++++++- classes/form/edit_column_form.php | 5 +++++ styles.css | 2 +- templates/column.mustache | 5 +++-- 10 files changed, 36 insertions(+), 10 deletions(-) diff --git a/amd/build/column.min.js b/amd/build/column.min.js index 2bf0bb79..e712697e 100644 --- a/amd/build/column.min.js +++ b/amd/build/column.min.js @@ -1,3 +1,3 @@ -define("mod_kanban/column",["exports","core/reactive","mod_kanban/selectors","mod_kanban/capabilities","mod_kanban/exporter","core/notification","core/str","core_form/modalform","mod_kanban/kanbancomponent","core/log"],(function(_exports,_reactive,_selectors,_capabilities,_exporter,_notification,Str,_modalform,_kanbancomponent,_log){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_selectors=_interopRequireDefault(_selectors),_capabilities=_interopRequireDefault(_capabilities),_exporter=_interopRequireDefault(_exporter),Str=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str),_modalform=_interopRequireDefault(_modalform),_kanbancomponent=_interopRequireDefault(_kanbancomponent),_log=_interopRequireDefault(_log);class _default extends _kanbancomponent.default{static init(target){return new this({element:document.getElementById(target)})}create(){this.id=this.element.dataset.id}getWatchers(){return[{watch:"columns[".concat(this.id,"]:updated"),handler:this._columnUpdated},{watch:"columns[".concat(this.id,"]:deleted"),handler:this._columnDeleted},{watch:"cards:created",handler:this._cardCreated}]}stateReady(state){this.addEventListener(this.getElement(_selectors.default.DELETECOLUMN,this.id),"click",this._removeConfirm),this.addEventListener(this.getElement(_selectors.default.ADDCARDFIRST),"click",this._addCard),this.addEventListener(this.getElement(_selectors.default.ADDCOLUMN,this.id),"click",this._addColumn),this.addEventListener(this.getElement(_selectors.default.LOCKCOLUMN,this.id),"click",this._lockColumn),this.addEventListener(this.getElement(_selectors.default.UNLOCKCOLUMN,this.id),"click",this._unlockColumn),this.addEventListener(this.getElement(_selectors.default.EDITDETAILS,this.id),"click",this._editDetails),this.addEventListener(this.getElement(_selectors.default.SHOWHIDDEN),"click",this._showHidden),this.addEventListener(this.getElement(_selectors.default.HIDEHIDDEN),"click",this._hideHidden),this.draggable=!1,this.dragdrop=new _reactive.DragDrop(this),this.checkDragging(state),this.boardid=state.board.id,this.cmid=state.common.id}_removeConfirm(event){Str.get_strings([{key:"deletecolumn",component:"mod_kanban"},{key:"deletecolumnconfirm",component:"mod_kanban"},{key:"delete",component:"core"}]).then((strings=>(0,_notification.saveCancel)(strings[0],strings[1],strings[2],(()=>{this._removeColumn(event)})))).catch((error=>_log.default.debug(error)))}destroy(){void 0!==this.dragdrop&&this.dragdrop.unregister()}getDraggableData(){return{id:this.id,type:"column"}}checkDragging(state){void 0===state&&(state=this.reactive.stateManager.state),state.capabilities.get(_capabilities.default.MANAGECOLUMNS).value&&0==state.columns.get(this.id).locked?this.dragdrop.setDraggable(!0):this.dragdrop.setDraggable(!1)}validateDropData(dropdata){let type=null==dropdata?void 0:dropdata.type;return"card"==type||"column"==type}drop(dropdata,event){if("card"==dropdata.type){let cards=this.getElements(_selectors.default.CARD),aftercard=0;for(let i=0;i{e.classList.remove("mod_kanban_insert")}))}_addColumn(event){document.activeElement.blur();let target=event.target.closest(_selectors.default.ADDCOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("addColumn",data.id)}async _cardCreated(_ref){let{element:element}=_ref;if(element.kanban_column==this.id){let data=JSON.parse(JSON.stringify(element));Object.assign(data,_exporter.default.exportCapabilities(this.reactive.state));let placeholder=document.createElement("li");placeholder.setAttribute("data-id",data.id);let node=this.getElement(_selectors.default.COLUMNINNER,this.id);node.appendChild(placeholder);const newelement=(await this.renderComponent(placeholder,"mod_kanban/card",data)).getElement();node.replaceChild(newelement,placeholder)}}_addCard(event){document.activeElement.blur();let target=event.target.closest(_selectors.default.ADDCARD),data=Object.assign({},target.dataset);this.reactive.dispatch("addCard",data.columnid,0)}_columnUpdated(_ref2){let{element:element}=_ref2;const el=this.getElement(_selectors.default.COLUMNINNER,this.id);if(void 0!==element.sequence){let sequence=element.sequence.split(",");[...el.children].forEach((node=>{node.classList.contains("mod_kanban_card")&&!sequence.includes(node.dataset.id)&&el.removeChild(node)})),[...el.children].sort(((a,b)=>sequence.indexOf(a.dataset.id)>sequence.indexOf(b.dataset.id)?1:-1)).forEach((node=>el.appendChild(node)))}if(void 0!==element.locked&&(this.toggleClass(0!=element.locked,"mod_kanban_locked_column"),0!=element.locked?this.getElement(_selectors.default.INPLACEEDITABLE).removeAttribute("data-inplaceeditable"):this.getElement(_selectors.default.INPLACEEDITABLE).setAttribute("data-inplaceeditable","1")),void 0!==element.title){let doc=(new DOMParser).parseFromString(element.title,"text/html");this.getElement(_selectors.default.INPLACEEDITABLE).setAttribute("data-value",doc.documentElement.textContent),this.getElement(_selectors.default.INPLACEEDITABLE).querySelector("a").innerHTML=element.title}if(void 0!==element.options){let options=JSON.parse(element.options);this.toggleClass(options.autohide,"mod_kanban_autohide")}this.checkDragging()}_columnDeleted(){this.destroy()}_removeColumn(event){let target=event.target.closest(_selectors.default.DELETECOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("deleteColumn",data.id)}_lockColumn(event){let target=event.target.closest(_selectors.default.LOCKCOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("lockColumn",data.id)}_unlockColumn(event){let target=event.target.closest(_selectors.default.UNLOCKCOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("unlockColumn",data.id)}_editDetails(event){event.preventDefault();const modalForm=new _modalform.default({formClass:"mod_kanban\\form\\edit_column_form",args:{id:this.id,boardid:this.boardid,cmid:this.cmid},modalConfig:{title:(0,Str.get_string)("editcolumn","mod_kanban")},returnFocus:this.getElement()});this.addEventListener(modalForm,modalForm.events.FORM_SUBMITTED,this._updateColumn),modalForm.show()}_updateColumn(event){this.reactive.dispatch("processUpdates",event.detail)}_showHidden(){this.getElement().classList.add("mod_kanban_show_hidden")}_hideHidden(){this.getElement().classList.remove("mod_kanban_show_hidden")}}return _exports.default=_default,_exports.default})); +define("mod_kanban/column",["exports","core/reactive","mod_kanban/selectors","mod_kanban/capabilities","mod_kanban/exporter","core/notification","core/str","core_form/modalform","mod_kanban/kanbancomponent","core/log"],(function(_exports,_reactive,_selectors,_capabilities,_exporter,_notification,Str,_modalform,_kanbancomponent,_log){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_selectors=_interopRequireDefault(_selectors),_capabilities=_interopRequireDefault(_capabilities),_exporter=_interopRequireDefault(_exporter),Str=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Str),_modalform=_interopRequireDefault(_modalform),_kanbancomponent=_interopRequireDefault(_kanbancomponent),_log=_interopRequireDefault(_log);class _default extends _kanbancomponent.default{static init(target){return new this({element:document.getElementById(target)})}create(){this.id=this.element.dataset.id}getWatchers(){return[{watch:`columns[${this.id}]:updated`,handler:this._columnUpdated},{watch:`columns[${this.id}]:deleted`,handler:this._columnDeleted},{watch:"cards:created",handler:this._cardCreated}]}stateReady(state){this.addEventListener(this.getElement(_selectors.default.DELETECOLUMN,this.id),"click",this._removeConfirm),this.addEventListener(this.getElement(_selectors.default.ADDCARDFIRST),"click",this._addCard),this.addEventListener(this.getElement(_selectors.default.ADDCOLUMN,this.id),"click",this._addColumn),this.addEventListener(this.getElement(_selectors.default.LOCKCOLUMN,this.id),"click",this._lockColumn),this.addEventListener(this.getElement(_selectors.default.UNLOCKCOLUMN,this.id),"click",this._unlockColumn),this.addEventListener(this.getElement(_selectors.default.EDITDETAILS,this.id),"click",this._editDetails),this.addEventListener(this.getElement(_selectors.default.SHOWHIDDEN),"click",this._showHidden),this.addEventListener(this.getElement(_selectors.default.HIDEHIDDEN),"click",this._hideHidden),this.draggable=!1,this.dragdrop=new _reactive.DragDrop(this),this.checkDragging(state),this.boardid=state.board.id,this.cmid=state.common.id}_removeConfirm(event){Str.get_strings([{key:"deletecolumn",component:"mod_kanban"},{key:"deletecolumnconfirm",component:"mod_kanban"},{key:"delete",component:"core"}]).then((strings=>(0,_notification.saveCancel)(strings[0],strings[1],strings[2],(()=>{this._removeColumn(event)})))).catch((error=>_log.default.debug(error)))}destroy(){void 0!==this.dragdrop&&this.dragdrop.unregister()}getDraggableData(){return{id:this.id,type:"column"}}checkDragging(state){void 0===state&&(state=this.reactive.stateManager.state),state.capabilities.get(_capabilities.default.MANAGECOLUMNS).value&&0==state.columns.get(this.id).locked?this.dragdrop.setDraggable(!0):this.dragdrop.setDraggable(!1)}validateDropData(dropdata){let type=null==dropdata?void 0:dropdata.type;return"card"==type||"column"==type}drop(dropdata,event){if("card"==dropdata.type){let cards=this.getElements(_selectors.default.CARD),aftercard=0;for(let i=0;i{e.classList.remove("mod_kanban_insert")}))}_addColumn(event){document.activeElement.blur();let target=event.target.closest(_selectors.default.ADDCOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("addColumn",data.id)}async _cardCreated(_ref){let{element:element}=_ref;if(element.kanban_column==this.id){let data=JSON.parse(JSON.stringify(element));Object.assign(data,_exporter.default.exportCapabilities(this.reactive.state));let placeholder=document.createElement("li");placeholder.setAttribute("data-id",data.id);let node=this.getElement(_selectors.default.COLUMNINNER,this.id);node.appendChild(placeholder);const newelement=(await this.renderComponent(placeholder,"mod_kanban/card",data)).getElement();node.replaceChild(newelement,placeholder)}}_addCard(event){document.activeElement.blur();let target=event.target.closest(_selectors.default.ADDCARD),data=Object.assign({},target.dataset);this.reactive.dispatch("addCard",data.columnid,0)}_columnUpdated(_ref2){let{element:element}=_ref2;const el=this.getElement(_selectors.default.COLUMNINNER,this.id);if(void 0!==element.sequence){let sequence=element.sequence.split(",");[...el.children].forEach((node=>{node.classList.contains("mod_kanban_card")&&!sequence.includes(node.dataset.id)&&el.removeChild(node)})),[...el.children].sort(((a,b)=>sequence.indexOf(a.dataset.id)>sequence.indexOf(b.dataset.id)?1:-1)).forEach((node=>el.appendChild(node)))}if(void 0!==element.locked&&(this.toggleClass(0!=element.locked,"mod_kanban_locked_column"),0!=element.locked?this.getElement(_selectors.default.INPLACEEDITABLE).removeAttribute("data-inplaceeditable"):this.getElement(_selectors.default.INPLACEEDITABLE).setAttribute("data-inplaceeditable","1")),void 0!==element.title){let doc=(new DOMParser).parseFromString(element.title,"text/html");this.getElement(_selectors.default.INPLACEEDITABLE).setAttribute("data-value",doc.documentElement.textContent),this.getElement(_selectors.default.INPLACEEDITABLE).querySelector("a").innerHTML=element.title}if(void 0!==element.options){let options=JSON.parse(element.options);void 0===options.autohide?this.toggleClass(!1,"mod_kanban_autohide"):this.toggleClass(!0,"mod_kanban_autohide"),void 0===options.colbackground?this.getElement().removeAttribute("style"):this.getElement().setAttribute("style","background-color: "+options.colbackground)}this.checkDragging()}_columnDeleted(){this.destroy()}_removeColumn(event){let target=event.target.closest(_selectors.default.DELETECOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("deleteColumn",data.id)}_lockColumn(event){let target=event.target.closest(_selectors.default.LOCKCOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("lockColumn",data.id)}_unlockColumn(event){let target=event.target.closest(_selectors.default.UNLOCKCOLUMN),data=Object.assign({},target.dataset);this.reactive.dispatch("unlockColumn",data.id)}_editDetails(event){event.preventDefault();const modalForm=new _modalform.default({formClass:"mod_kanban\\form\\edit_column_form",args:{id:this.id,boardid:this.boardid,cmid:this.cmid},modalConfig:{title:(0,Str.get_string)("editcolumn","mod_kanban")},returnFocus:this.getElement()});this.addEventListener(modalForm,modalForm.events.FORM_SUBMITTED,this._updateColumn),modalForm.show()}_updateColumn(event){this.reactive.dispatch("processUpdates",event.detail)}_showHidden(){this.getElement().classList.add("mod_kanban_show_hidden")}_hideHidden(){this.getElement().classList.remove("mod_kanban_show_hidden")}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=column.min.js.map \ No newline at end of file diff --git a/amd/build/column.min.js.map b/amd/build/column.min.js.map index b0846614..d09fe01f 100644 --- a/amd/build/column.min.js.map +++ b/amd/build/column.min.js.map @@ -1 +1 @@ -{"version":3,"file":"column.min.js","sources":["../src/column.js"],"sourcesContent":["import {DragDrop} from 'core/reactive';\nimport selectors from 'mod_kanban/selectors';\nimport capabilities from 'mod_kanban/capabilities';\nimport exporter from 'mod_kanban/exporter';\nimport {saveCancel} from 'core/notification';\nimport * as Str from 'core/str';\nimport {get_string as getString} from 'core/str';\nimport ModalForm from 'core_form/modalform';\nimport KanbanComponent from 'mod_kanban/kanbancomponent';\nimport Log from \"core/log\";\n\n/**\n * Component representing a column in a kanban board.\n */\nexport default class extends KanbanComponent {\n /**\n * Function to initialize component, called by mustache template.\n * @param {*} target The id of the HTMLElement to attach to\n * @returns {BaseComponent} New component attached to the HTMLElement represented by target\n */\n static init(target) {\n let element = document.getElementById(target);\n return new this({\n element: element,\n });\n }\n\n /**\n * Called after the component was created.\n */\n create() {\n this.id = this.element.dataset.id;\n }\n\n /**\n * Watchers for this component.\n * @returns {array}\n */\n getWatchers() {\n return [\n {watch: `columns[${this.id}]:updated`, handler: this._columnUpdated},\n {watch: `columns[${this.id}]:deleted`, handler: this._columnDeleted},\n {watch: `cards:created`, handler: this._cardCreated}\n ];\n }\n\n /**\n * Called once when state is ready, attaching event listeners and initializing drag and drop.\n * @param {object} state\n */\n stateReady(state) {\n this.addEventListener(\n this.getElement(selectors.DELETECOLUMN, this.id),\n 'click',\n this._removeConfirm\n );\n this.addEventListener(\n this.getElement(selectors.ADDCARDFIRST),\n 'click',\n this._addCard\n );\n this.addEventListener(\n this.getElement(selectors.ADDCOLUMN, this.id),\n 'click',\n this._addColumn\n );\n this.addEventListener(\n this.getElement(selectors.LOCKCOLUMN, this.id),\n 'click',\n this._lockColumn\n );\n this.addEventListener(\n this.getElement(selectors.UNLOCKCOLUMN, this.id),\n 'click',\n this._unlockColumn\n );\n this.addEventListener(\n this.getElement(selectors.EDITDETAILS, this.id),\n 'click',\n this._editDetails\n );\n this.addEventListener(\n this.getElement(selectors.SHOWHIDDEN),\n 'click',\n this._showHidden\n );\n this.addEventListener(\n this.getElement(selectors.HIDEHIDDEN),\n 'click',\n this._hideHidden\n );\n this.draggable = false;\n this.dragdrop = new DragDrop(this);\n this.checkDragging(state);\n this.boardid = state.board.id;\n this.cmid = state.common.id;\n }\n\n /**\n * Display confirmation modal for deleting a card.\n * @param {*} event\n */\n _removeConfirm(event) {\n Str.get_strings([\n {key: 'deletecolumn', component: 'mod_kanban'},\n {key: 'deletecolumnconfirm', component: 'mod_kanban'},\n {key: 'delete', component: 'core'},\n ]).then((strings) => {\n return saveCancel(\n strings[0],\n strings[1],\n strings[2],\n () => {\n this._removeColumn(event);\n }\n );\n }).catch((error) => Log.debug(error));\n }\n\n /**\n * Remove all subcomponents dependencies.\n */\n destroy() {\n if (this.dragdrop !== undefined) {\n this.dragdrop.unregister();\n }\n }\n\n /**\n * Get the draggable data of this component.\n *\n * @returns {Object} the draggable data.\n */\n getDraggableData() {\n return {id: this.id, type: 'column'};\n }\n\n /**\n * Conditionally enable / disable dragging.\n * @param {*} state\n */\n checkDragging(state) {\n if (state === undefined) {\n state = this.reactive.stateManager.state;\n }\n\n if (state.capabilities.get(capabilities.MANAGECOLUMNS).value && state.columns.get(this.id).locked == 0) {\n this.dragdrop.setDraggable(true);\n } else {\n this.dragdrop.setDraggable(false);\n }\n }\n\n /**\n * Validate draggable data. This component accepts cards and columns.\n * @param {object} dropdata\n * @returns {boolean} if the data is valid for this drop-zone.\n */\n validateDropData(dropdata) {\n let type = dropdata?.type;\n return type == 'card' || type == 'column';\n }\n\n /**\n * Executed when a valid dropdata is dropped over the drop-zone.\n * @param {object} dropdata\n * @param {object} event\n */\n drop(dropdata, event) {\n if (dropdata.type == 'card') {\n let cards = this.getElements(selectors.CARD);\n let aftercard = 0;\n for (let i = 0; i < cards.length; i++) {\n if (cards[i].offsetTop + cards[i].clientHeight / 2 <= event.layerY) {\n aftercard = cards[i].dataset.id;\n }\n }\n this.reactive.dispatch('moveCard', dropdata.id, this.id, aftercard);\n }\n if (dropdata.type == 'column') {\n if (dropdata.id != this.id) {\n this.reactive.dispatch('moveColumn', dropdata.id, this.id);\n }\n }\n }\n\n /**\n * Show some visual hints to the user.\n * @param {object} dropdata\n * @param {object} event\n */\n showDropZone(dropdata, event) {\n if (dropdata.type == 'card') {\n let cards = this.getElements(selectors.CARD);\n let aftercard = 0;\n for (let i = 0; i < cards.length; i++) {\n if (cards[i].offsetTop + cards[i].clientHeight / 2 <= event.layerY) {\n aftercard = cards[i].dataset.id;\n }\n }\n if (aftercard == 0) {\n this.getElement(selectors.ADDCARDCONTAINER).classList.add('mod_kanban_insert');\n } else {\n this.getElement(selectors.ADDCARDCONTAINER, aftercard).classList.add('mod_kanban_insert');\n }\n }\n if (dropdata.type == 'column') {\n this.getElement(selectors.ADDCOLUMNCONTAINER).classList.add('mod_kanban_insert');\n }\n }\n\n /**\n * Remove visual hints to the user.\n */\n hideDropZone() {\n this.getElement(selectors.ADDCOLUMNCONTAINER).classList.remove('mod_kanban_insert');\n this.getElements(selectors.ADDCARDCONTAINER).forEach((e) => {\n e.classList.remove('mod_kanban_insert');\n });\n }\n\n /**\n * Dispatch event to add a column after this column.\n * @param {*} event\n */\n _addColumn(event) {\n document.activeElement.blur();\n let target = event.target.closest(selectors.ADDCOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('addColumn', data.id);\n }\n\n /**\n * Called when a card was created in this column.\n * @param {*} param0\n */\n async _cardCreated({element}) {\n if (element.kanban_column == this.id) {\n let data = JSON.parse(JSON.stringify(element));\n Object.assign(data, exporter.exportCapabilities(this.reactive.state));\n let placeholder = document.createElement('li');\n placeholder.setAttribute('data-id', data.id);\n let node = this.getElement(selectors.COLUMNINNER, this.id);\n node.appendChild(placeholder);\n const newcomponent = await this.renderComponent(placeholder, 'mod_kanban/card', data);\n const newelement = newcomponent.getElement();\n node.replaceChild(newelement, placeholder);\n }\n }\n\n /**\n * Dispatch event to add a card in this column.\n * @param {*} event\n */\n _addCard(event) {\n document.activeElement.blur();\n let target = event.target.closest(selectors.ADDCARD);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('addCard', data.columnid, 0);\n }\n\n /**\n * Called when column is updated.\n * @param {*} param0\n */\n _columnUpdated({element}) {\n const el = this.getElement(selectors.COLUMNINNER, this.id);\n if (element.sequence !== undefined) {\n let sequence = element.sequence.split(',');\n // Remove all cards from frontend that are no longer present in the database.\n [...el.children]\n .forEach((node) => {\n if (node.classList.contains('mod_kanban_card') && !sequence.includes(node.dataset.id)) {\n el.removeChild(node);\n }\n });\n // Reorder cards according to sequence from the database.\n [...el.children]\n .sort((a, b) => sequence.indexOf(a.dataset.id) > sequence.indexOf(b.dataset.id) ? 1 : -1)\n .forEach(node => el.appendChild(node));\n }\n if (element.locked !== undefined) {\n this.toggleClass(element.locked != 0, 'mod_kanban_locked_column');\n // Inplace editing of the column title is disabled if the column is locked.\n if (element.locked != 0) {\n this.getElement(selectors.INPLACEEDITABLE).removeAttribute('data-inplaceeditable');\n } else {\n this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-inplaceeditable', '1');\n }\n }\n // Update data for inplace editing if title was updated (this is important if title was modified by another user).\n if (element.title !== undefined) {\n // For Moodle inplace editing title is once needed plain and once with html entities encoded.\n // This avoids double encoding of html entities as the value of \"data-value\" is exactly what is shown\n // in the input field when clicking on the inplace editable.\n let doc = new DOMParser().parseFromString(element.title, 'text/html');\n this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-value', doc.documentElement.textContent);\n this.getElement(selectors.INPLACEEDITABLE).querySelector('a').innerHTML = element.title;\n }\n // Only autohide option is relevant for the frontend for now. autoclose option is handled by the backend.\n if (element.options !== undefined) {\n let options = JSON.parse(element.options);\n this.toggleClass(options.autohide, 'mod_kanban_autohide');\n }\n // Enable/disable dragging (e.g. if column is locked).\n this.checkDragging();\n }\n\n /**\n * Called when this column is deleted.\n */\n _columnDeleted() {\n this.destroy();\n }\n\n /**\n * Dispatch event to remove this column.\n * @param {*} event\n */\n _removeColumn(event) {\n let target = event.target.closest(selectors.DELETECOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('deleteColumn', data.id);\n }\n\n /**\n * Dispatch event to lock this column.\n * @param {*} event\n */\n _lockColumn(event) {\n let target = event.target.closest(selectors.LOCKCOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('lockColumn', data.id);\n }\n\n /**\n * Dispatch event to unlock this column.\n * @param {*} event\n */\n _unlockColumn(event) {\n let target = event.target.closest(selectors.UNLOCKCOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('unlockColumn', data.id);\n }\n\n /**\n * Show modal form to edit column details.\n * @param {*} event\n */\n _editDetails(event) {\n event.preventDefault();\n\n const modalForm = new ModalForm({\n formClass: \"mod_kanban\\\\form\\\\edit_column_form\",\n args: {\n id: this.id,\n boardid: this.boardid,\n cmid: this.cmid\n },\n modalConfig: {title: getString('editcolumn', 'mod_kanban')},\n returnFocus: this.getElement(),\n });\n this.addEventListener(modalForm, modalForm.events.FORM_SUBMITTED, this._updateColumn);\n modalForm.show();\n }\n\n /**\n * Dispatch an event to update column data from the detail modal.\n * @param {*} event\n */\n _updateColumn(event) {\n this.reactive.dispatch('processUpdates', event.detail);\n }\n\n /**\n * Show hidden cards.\n */\n _showHidden() {\n this.getElement().classList.add('mod_kanban_show_hidden');\n }\n\n /**\n * Hide hidden cards.\n */\n _hideHidden() {\n this.getElement().classList.remove('mod_kanban_show_hidden');\n }\n}\n"],"names":["KanbanComponent","target","this","element","document","getElementById","create","id","dataset","getWatchers","watch","handler","_columnUpdated","_columnDeleted","_cardCreated","stateReady","state","addEventListener","getElement","selectors","DELETECOLUMN","_removeConfirm","ADDCARDFIRST","_addCard","ADDCOLUMN","_addColumn","LOCKCOLUMN","_lockColumn","UNLOCKCOLUMN","_unlockColumn","EDITDETAILS","_editDetails","SHOWHIDDEN","_showHidden","HIDEHIDDEN","_hideHidden","draggable","dragdrop","DragDrop","checkDragging","boardid","board","cmid","common","event","Str","get_strings","key","component","then","strings","_removeColumn","catch","error","Log","debug","destroy","undefined","unregister","getDraggableData","type","reactive","stateManager","capabilities","get","MANAGECOLUMNS","value","columns","locked","setDraggable","validateDropData","dropdata","drop","cards","getElements","CARD","aftercard","i","length","offsetTop","clientHeight","layerY","dispatch","showDropZone","ADDCARDCONTAINER","classList","add","ADDCOLUMNCONTAINER","hideDropZone","remove","forEach","e","activeElement","blur","closest","data","Object","assign","kanban_column","JSON","parse","stringify","exporter","exportCapabilities","placeholder","createElement","setAttribute","node","COLUMNINNER","appendChild","newelement","renderComponent","replaceChild","ADDCARD","columnid","el","sequence","split","children","contains","includes","removeChild","sort","a","b","indexOf","toggleClass","INPLACEEDITABLE","removeAttribute","title","doc","DOMParser","parseFromString","documentElement","textContent","querySelector","innerHTML","options","autohide","preventDefault","modalForm","ModalForm","formClass","args","modalConfig","returnFocus","events","FORM_SUBMITTED","_updateColumn","show","detail"],"mappings":"ysDAc6BA,qCAMbC,eAED,IAAIC,KAAK,CACZC,QAFUC,SAASC,eAAeJ,UAS1CK,cACSC,GAAKL,KAAKC,QAAQK,QAAQD,GAOnCE,oBACW,CACH,CAACC,wBAAkBR,KAAKK,gBAAeI,QAAST,KAAKU,gBACrD,CAACF,wBAAkBR,KAAKK,gBAAeI,QAAST,KAAKW,gBACrD,CAACH,sBAAwBC,QAAST,KAAKY,eAQ/CC,WAAWC,YACFC,iBACDf,KAAKgB,WAAWC,mBAAUC,aAAclB,KAAKK,IAC7C,QACAL,KAAKmB,qBAEJJ,iBACDf,KAAKgB,WAAWC,mBAAUG,cAC1B,QACApB,KAAKqB,eAEJN,iBACDf,KAAKgB,WAAWC,mBAAUK,UAAWtB,KAAKK,IAC1C,QACAL,KAAKuB,iBAEJR,iBACDf,KAAKgB,WAAWC,mBAAUO,WAAYxB,KAAKK,IAC3C,QACAL,KAAKyB,kBAEJV,iBACDf,KAAKgB,WAAWC,mBAAUS,aAAc1B,KAAKK,IAC7C,QACAL,KAAK2B,oBAEJZ,iBACDf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B,sBACS2C,UAOTL,cAAcP,WACN3C,OAAS2C,MAAM3C,OAAO6F,QAAQ3E,mBAAUC,cACxC2E,KAAOC,OAAOC,OAAO,GAAIhG,OAAOO,cAC/BqD,SAASqB,SAAS,eAAgBa,KAAKxF,IAOhDoB,YAAYiB,WACJ3C,OAAS2C,MAAM3C,OAAO6F,QAAQ3E,mBAAUO,YACxCqE,KAAOC,OAAOC,OAAO,GAAIhG,OAAOO,cAC/BqD,SAASqB,SAAS,aAAca,KAAKxF,IAO9CsB,cAAce,WACN3C,OAAS2C,MAAM3C,OAAO6F,QAAQ3E,mBAAUS,cACxCmE,KAAOC,OAAOC,OAAO,GAAIhG,OAAOO,cAC/BqD,SAASqB,SAAS,eAAgBa,KAAKxF,IAOhDwB,aAAaa,OACTA,MAAM+F,uBAEAC,UAAY,IAAIC,mBAAU,CAC5BC,UAAW,qCACXC,KAAM,CACFxI,GAAIL,KAAKK,GACTiC,QAAStC,KAAKsC,QACdE,KAAMxC,KAAKwC,MAEfsG,YAAa,CAACf,OAAO,kBAAU,aAAc,eAC7CgB,YAAa/I,KAAKgB,oBAEjBD,iBAAiB2H,UAAWA,UAAUM,OAAOC,eAAgBjJ,KAAKkJ,eACvER,UAAUS,OAOdD,cAAcxG,YACLiB,SAASqB,SAAS,iBAAkBtC,MAAM0G,QAMnDrH,mBACSf,aAAamE,UAAUC,IAAI,0BAMpCnD,mBACSjB,aAAamE,UAAUI,OAAO"} \ No newline at end of file +{"version":3,"file":"column.min.js","sources":["../src/column.js"],"sourcesContent":["import {DragDrop} from 'core/reactive';\nimport selectors from 'mod_kanban/selectors';\nimport capabilities from 'mod_kanban/capabilities';\nimport exporter from 'mod_kanban/exporter';\nimport {saveCancel} from 'core/notification';\nimport * as Str from 'core/str';\nimport {get_string as getString} from 'core/str';\nimport ModalForm from 'core_form/modalform';\nimport KanbanComponent from 'mod_kanban/kanbancomponent';\nimport Log from \"core/log\";\n\n/**\n * Component representing a column in a kanban board.\n */\nexport default class extends KanbanComponent {\n /**\n * Function to initialize component, called by mustache template.\n * @param {*} target The id of the HTMLElement to attach to\n * @returns {BaseComponent} New component attached to the HTMLElement represented by target\n */\n static init(target) {\n let element = document.getElementById(target);\n return new this({\n element: element,\n });\n }\n\n /**\n * Called after the component was created.\n */\n create() {\n this.id = this.element.dataset.id;\n }\n\n /**\n * Watchers for this component.\n * @returns {array}\n */\n getWatchers() {\n return [\n {watch: `columns[${this.id}]:updated`, handler: this._columnUpdated},\n {watch: `columns[${this.id}]:deleted`, handler: this._columnDeleted},\n {watch: `cards:created`, handler: this._cardCreated}\n ];\n }\n\n /**\n * Called once when state is ready, attaching event listeners and initializing drag and drop.\n * @param {object} state\n */\n stateReady(state) {\n this.addEventListener(\n this.getElement(selectors.DELETECOLUMN, this.id),\n 'click',\n this._removeConfirm\n );\n this.addEventListener(\n this.getElement(selectors.ADDCARDFIRST),\n 'click',\n this._addCard\n );\n this.addEventListener(\n this.getElement(selectors.ADDCOLUMN, this.id),\n 'click',\n this._addColumn\n );\n this.addEventListener(\n this.getElement(selectors.LOCKCOLUMN, this.id),\n 'click',\n this._lockColumn\n );\n this.addEventListener(\n this.getElement(selectors.UNLOCKCOLUMN, this.id),\n 'click',\n this._unlockColumn\n );\n this.addEventListener(\n this.getElement(selectors.EDITDETAILS, this.id),\n 'click',\n this._editDetails\n );\n this.addEventListener(\n this.getElement(selectors.SHOWHIDDEN),\n 'click',\n this._showHidden\n );\n this.addEventListener(\n this.getElement(selectors.HIDEHIDDEN),\n 'click',\n this._hideHidden\n );\n this.draggable = false;\n this.dragdrop = new DragDrop(this);\n this.checkDragging(state);\n this.boardid = state.board.id;\n this.cmid = state.common.id;\n }\n\n /**\n * Display confirmation modal for deleting a card.\n * @param {*} event\n */\n _removeConfirm(event) {\n Str.get_strings([\n {key: 'deletecolumn', component: 'mod_kanban'},\n {key: 'deletecolumnconfirm', component: 'mod_kanban'},\n {key: 'delete', component: 'core'},\n ]).then((strings) => {\n return saveCancel(\n strings[0],\n strings[1],\n strings[2],\n () => {\n this._removeColumn(event);\n }\n );\n }).catch((error) => Log.debug(error));\n }\n\n /**\n * Remove all subcomponents dependencies.\n */\n destroy() {\n if (this.dragdrop !== undefined) {\n this.dragdrop.unregister();\n }\n }\n\n /**\n * Get the draggable data of this component.\n *\n * @returns {Object} the draggable data.\n */\n getDraggableData() {\n return {id: this.id, type: 'column'};\n }\n\n /**\n * Conditionally enable / disable dragging.\n * @param {*} state\n */\n checkDragging(state) {\n if (state === undefined) {\n state = this.reactive.stateManager.state;\n }\n\n if (state.capabilities.get(capabilities.MANAGECOLUMNS).value && state.columns.get(this.id).locked == 0) {\n this.dragdrop.setDraggable(true);\n } else {\n this.dragdrop.setDraggable(false);\n }\n }\n\n /**\n * Validate draggable data. This component accepts cards and columns.\n * @param {object} dropdata\n * @returns {boolean} if the data is valid for this drop-zone.\n */\n validateDropData(dropdata) {\n let type = dropdata?.type;\n return type == 'card' || type == 'column';\n }\n\n /**\n * Executed when a valid dropdata is dropped over the drop-zone.\n * @param {object} dropdata\n * @param {object} event\n */\n drop(dropdata, event) {\n if (dropdata.type == 'card') {\n let cards = this.getElements(selectors.CARD);\n let aftercard = 0;\n for (let i = 0; i < cards.length; i++) {\n if (cards[i].offsetTop + cards[i].clientHeight / 2 <= event.layerY) {\n aftercard = cards[i].dataset.id;\n }\n }\n this.reactive.dispatch('moveCard', dropdata.id, this.id, aftercard);\n }\n if (dropdata.type == 'column') {\n if (dropdata.id != this.id) {\n this.reactive.dispatch('moveColumn', dropdata.id, this.id);\n }\n }\n }\n\n /**\n * Show some visual hints to the user.\n * @param {object} dropdata\n * @param {object} event\n */\n showDropZone(dropdata, event) {\n if (dropdata.type == 'card') {\n let cards = this.getElements(selectors.CARD);\n let aftercard = 0;\n for (let i = 0; i < cards.length; i++) {\n if (cards[i].offsetTop + cards[i].clientHeight / 2 <= event.layerY) {\n aftercard = cards[i].dataset.id;\n }\n }\n if (aftercard == 0) {\n this.getElement(selectors.ADDCARDCONTAINER).classList.add('mod_kanban_insert');\n } else {\n this.getElement(selectors.ADDCARDCONTAINER, aftercard).classList.add('mod_kanban_insert');\n }\n }\n if (dropdata.type == 'column') {\n this.getElement(selectors.ADDCOLUMNCONTAINER).classList.add('mod_kanban_insert');\n }\n }\n\n /**\n * Remove visual hints to the user.\n */\n hideDropZone() {\n this.getElement(selectors.ADDCOLUMNCONTAINER).classList.remove('mod_kanban_insert');\n this.getElements(selectors.ADDCARDCONTAINER).forEach((e) => {\n e.classList.remove('mod_kanban_insert');\n });\n }\n\n /**\n * Dispatch event to add a column after this column.\n * @param {*} event\n */\n _addColumn(event) {\n document.activeElement.blur();\n let target = event.target.closest(selectors.ADDCOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('addColumn', data.id);\n }\n\n /**\n * Called when a card was created in this column.\n * @param {*} param0\n */\n async _cardCreated({element}) {\n if (element.kanban_column == this.id) {\n let data = JSON.parse(JSON.stringify(element));\n Object.assign(data, exporter.exportCapabilities(this.reactive.state));\n let placeholder = document.createElement('li');\n placeholder.setAttribute('data-id', data.id);\n let node = this.getElement(selectors.COLUMNINNER, this.id);\n node.appendChild(placeholder);\n const newcomponent = await this.renderComponent(placeholder, 'mod_kanban/card', data);\n const newelement = newcomponent.getElement();\n node.replaceChild(newelement, placeholder);\n }\n }\n\n /**\n * Dispatch event to add a card in this column.\n * @param {*} event\n */\n _addCard(event) {\n document.activeElement.blur();\n let target = event.target.closest(selectors.ADDCARD);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('addCard', data.columnid, 0);\n }\n\n /**\n * Called when column is updated.\n * @param {*} param0\n */\n _columnUpdated({element}) {\n const el = this.getElement(selectors.COLUMNINNER, this.id);\n if (element.sequence !== undefined) {\n let sequence = element.sequence.split(',');\n // Remove all cards from frontend that are no longer present in the database.\n [...el.children]\n .forEach((node) => {\n if (node.classList.contains('mod_kanban_card') && !sequence.includes(node.dataset.id)) {\n el.removeChild(node);\n }\n });\n // Reorder cards according to sequence from the database.\n [...el.children]\n .sort((a, b) => sequence.indexOf(a.dataset.id) > sequence.indexOf(b.dataset.id) ? 1 : -1)\n .forEach(node => el.appendChild(node));\n }\n if (element.locked !== undefined) {\n this.toggleClass(element.locked != 0, 'mod_kanban_locked_column');\n // Inplace editing of the column title is disabled if the column is locked.\n if (element.locked != 0) {\n this.getElement(selectors.INPLACEEDITABLE).removeAttribute('data-inplaceeditable');\n } else {\n this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-inplaceeditable', '1');\n }\n }\n // Update data for inplace editing if title was updated (this is important if title was modified by another user).\n if (element.title !== undefined) {\n // For Moodle inplace editing title is once needed plain and once with html entities encoded.\n // This avoids double encoding of html entities as the value of \"data-value\" is exactly what is shown\n // in the input field when clicking on the inplace editable.\n let doc = new DOMParser().parseFromString(element.title, 'text/html');\n this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-value', doc.documentElement.textContent);\n this.getElement(selectors.INPLACEEDITABLE).querySelector('a').innerHTML = element.title;\n }\n // Only autohide and backgroundcolor option is relevant for the frontend for now.\n // Autoclose option is handled by the backend.\n if (element.options !== undefined) {\n let options = JSON.parse(element.options);\n if (options.autohide === undefined) {\n this.toggleClass(false, 'mod_kanban_autohide');\n } else {\n this.toggleClass(true, 'mod_kanban_autohide');\n }\n\n if (options.colbackground === undefined) {\n this.getElement().removeAttribute('style');\n } else {\n this.getElement().setAttribute('style', 'background-color: ' + options.colbackground);\n }\n }\n // Enable/disable dragging (e.g. if column is locked).\n this.checkDragging();\n }\n\n /**\n * Called when this column is deleted.\n */\n _columnDeleted() {\n this.destroy();\n }\n\n /**\n * Dispatch event to remove this column.\n * @param {*} event\n */\n _removeColumn(event) {\n let target = event.target.closest(selectors.DELETECOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('deleteColumn', data.id);\n }\n\n /**\n * Dispatch event to lock this column.\n * @param {*} event\n */\n _lockColumn(event) {\n let target = event.target.closest(selectors.LOCKCOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('lockColumn', data.id);\n }\n\n /**\n * Dispatch event to unlock this column.\n * @param {*} event\n */\n _unlockColumn(event) {\n let target = event.target.closest(selectors.UNLOCKCOLUMN);\n let data = Object.assign({}, target.dataset);\n this.reactive.dispatch('unlockColumn', data.id);\n }\n\n /**\n * Show modal form to edit column details.\n * @param {*} event\n */\n _editDetails(event) {\n event.preventDefault();\n\n const modalForm = new ModalForm({\n formClass: \"mod_kanban\\\\form\\\\edit_column_form\",\n args: {\n id: this.id,\n boardid: this.boardid,\n cmid: this.cmid\n },\n modalConfig: {title: getString('editcolumn', 'mod_kanban')},\n returnFocus: this.getElement(),\n });\n this.addEventListener(modalForm, modalForm.events.FORM_SUBMITTED, this._updateColumn);\n modalForm.show();\n }\n\n /**\n * Dispatch an event to update column data from the detail modal.\n * @param {*} event\n */\n _updateColumn(event) {\n this.reactive.dispatch('processUpdates', event.detail);\n }\n\n /**\n * Show hidden cards.\n */\n _showHidden() {\n this.getElement().classList.add('mod_kanban_show_hidden');\n }\n\n /**\n * Hide hidden cards.\n */\n _hideHidden() {\n this.getElement().classList.remove('mod_kanban_show_hidden');\n }\n}\n"],"names":["KanbanComponent","target","this","element","document","getElementById","create","id","dataset","getWatchers","watch","handler","_columnUpdated","_columnDeleted","_cardCreated","stateReady","state","addEventListener","getElement","selectors","DELETECOLUMN","_removeConfirm","ADDCARDFIRST","_addCard","ADDCOLUMN","_addColumn","LOCKCOLUMN","_lockColumn","UNLOCKCOLUMN","_unlockColumn","EDITDETAILS","_editDetails","SHOWHIDDEN","_showHidden","HIDEHIDDEN","_hideHidden","draggable","dragdrop","DragDrop","checkDragging","boardid","board","cmid","common","event","Str","get_strings","key","component","then","strings","_removeColumn","catch","error","Log","debug","destroy","undefined","unregister","getDraggableData","type","reactive","stateManager","capabilities","get","MANAGECOLUMNS","value","columns","locked","setDraggable","validateDropData","dropdata","drop","cards","getElements","CARD","aftercard","i","length","offsetTop","clientHeight","layerY","dispatch","showDropZone","ADDCARDCONTAINER","classList","add","ADDCOLUMNCONTAINER","hideDropZone","remove","forEach","e","activeElement","blur","closest","data","Object","assign","kanban_column","JSON","parse","stringify","exporter","exportCapabilities","placeholder","createElement","setAttribute","node","COLUMNINNER","appendChild","newelement","renderComponent","replaceChild","ADDCARD","columnid","el","sequence","split","children","contains","includes","removeChild","sort","a","b","indexOf","toggleClass","INPLACEEDITABLE","removeAttribute","title","doc","DOMParser","parseFromString","documentElement","textContent","querySelector","innerHTML","options","autohide","colbackground","preventDefault","modalForm","ModalForm","formClass","args","modalConfig","returnFocus","events","FORM_SUBMITTED","_updateColumn","show","detail"],"mappings":"ysDAc6BA,qCAMbC,eAED,IAAIC,KAAK,CACZC,QAFUC,SAASC,eAAeJ,UAS1CK,cACSC,GAAKL,KAAKC,QAAQK,QAAQD,GAOnCE,oBACW,CACH,CAACC,MAAQ,WAAUR,KAAKK,cAAeI,QAAST,KAAKU,gBACrD,CAACF,MAAQ,WAAUR,KAAKK,cAAeI,QAAST,KAAKW,gBACrD,CAACH,MAAQ,gBAAgBC,QAAST,KAAKY,eAQ/CC,WAAWC,YACFC,iBACDf,KAAKgB,WAAWC,mBAAUC,aAAclB,KAAKK,IAC7C,QACAL,KAAKmB,qBAEJJ,iBACDf,KAAKgB,WAAWC,mBAAUG,cAC1B,QACApB,KAAKqB,eAEJN,iBACDf,KAAKgB,WAAWC,mBAAUK,UAAWtB,KAAKK,IAC1C,QACAL,KAAKuB,iBAEJR,iBACDf,KAAKgB,WAAWC,mBAAUO,WAAYxB,KAAKK,IAC3C,QACAL,KAAKyB,kBAEJV,iBACDf,KAAKgB,WAAWC,mBAAUS,aAAc1B,KAAKK,IAC7C,QACAL,KAAK2B,oBAEJZ,iBACDf,KAAKgB,WAAWC,mBAAUW,YAAa5B,KAAKK,IAC5C,QACAL,KAAK6B,mBAEJd,iBACDf,KAAKgB,WAAWC,mBAAUa,YAC1B,QACA9B,KAAK+B,kBAEJhB,iBACDf,KAAKgB,WAAWC,mBAAUe,YAC1B,QACA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AM3C,OAAO6F,QAAQ3E,mBAAUC,cACxC2E,KAAOC,OAAOC,OAAO,GAAIhG,OAAOO,cAC/BqD,SAASqB,SAAS,eAAgBa,KAAKxF,IAOhDoB,YAAYiB,WACJ3C,OAAS2C,MAAM3C,OAAO6F,QAAQ3E,mBAAUO,YACxCqE,KAAOC,OAAOC,OAAO,GAAIhG,OAAOO,cAC/BqD,SAASqB,SAAS,aAAca,KAAKxF,IAO9CsB,cAAce,WACN3C,OAAS2C,MAAM3C,OAAO6F,QAAQ3E,mBAAUS,cACxCmE,KAAOC,OAAOC,OAAO,GAAIhG,OAAOO,cAC/BqD,SAASqB,SAAS,eAAgBa,KAAKxF,IAOhDwB,aAAaa,OACTA,MAAMgG,uBAEAC,UAAY,IAAIC,mBAAU,CAC5BC,UAAW,qCACXC,KAAM,CACFzI,GAAIL,KAAKK,GACTiC,QAAStC,KAAKsC,QACdE,KAAMxC,KAAKwC,MAEfuG,YAAa,CAAChB,OAAO,kBAAU,aAAc,eAC7CiB,YAAahJ,KAAKgB,oBAEjBD,iBAAiB4H,UAAWA,UAAUM,OAAOC,eAAgBlJ,KAAKmJ,eACvER,UAAUS,OAOdD,cAAczG,YACLiB,SAASqB,SAAS,iBAAkBtC,MAAM2G,QAMnDtH,mBACSf,aAAamE,UAAUC,IAAI,0BAMpCnD,mBACSjB,aAAamE,UAAUI,OAAO"} \ No newline at end of file diff --git a/amd/build/exporter.min.js b/amd/build/exporter.min.js index adb89760..72631fcf 100644 --- a/amd/build/exporter.min.js +++ b/amd/build/exporter.min.js @@ -1,3 +1,3 @@ -define("mod_kanban/exporter",["exports","mod_kanban/capabilities"],(function(_exports,_capabilities){var obj;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_capabilities=(obj=_capabilities)&&obj.__esModule?obj:{default:obj};return _exports.default=class{static exportStateForTemplate(state){let columnOrder=state.board.sequence.split(","),columns=[],hascolumns=""!=state.board.sequence;hascolumns&&(columns=columnOrder.map((value=>this.exportCardsForColumn(state,value))));let showactionmenu=1==state.common.userboards||""!=state.common.groupselector||state.capabilities.get(_capabilities.default.MANAGEBOARD).value||2==state.common.userboards&&state.capabilities.get(_capabilities.default.VIEWALLBOARDS).value;return Object.assign({cmid:state.common.id,id:state.board.id,sequence:state.board.sequence,hascolumns:hascolumns,columns:columns,locked:state.board.locked,hastemplate:0!=state.common.template,istemplate:0!=state.board.template,heading:state.board.heading,groupselector:state.common.groupselector,userboards:state.common.userboards,history:state.common.history&&state.capabilities.get(_capabilities.default.VIEWHISTORY).value,groupmode:state.common.groupmode,ismyuserboard:state.common.userid==state.board.userid,myuserid:state.common.userid,showactionmenu:showactionmenu,userboardsonly:2==state.common.userboards,iscourseboard:0==state.board.userid&&0==state.board.groupid&&0==state.board.template,users:JSON.parse(JSON.stringify(state.users))},this.exportCapabilities(state))}static exportCardsForColumn(state,columnid){let col=JSON.parse(JSON.stringify(state.columns.get(columnid))),options=JSON.parse(col.options);if(col.hascards=""!=col.sequence,col.autoclose=options.autoclose,col.autohide=options.autohide,col.hascards){let cardOrder=col.sequence.split(",");col.cards=cardOrder.map((value=>this.exportCard(state,value)))}return col}static exportCard(state,cardid){let card={id:cardid,title:"-",assignees:[],options:"{}",canedit:!1};void 0!==state.cards.get(cardid)&&(card=JSON.parse(JSON.stringify(state.cards.get(cardid)))),card.cardid=card.id,card.hasassignees=card.assignees.length>0;let options=JSON.parse(card.options);return card.hasassignees&&"number"==typeof card.assignees[0]&&(card.assignees=card.assignees.map((userid=>state.users.get(userid))),card.assignees=[...new Set(card.assignees)]),Object.assign(card,options)}static exportCapabilities(state){let capabilities=[];return state.capabilities.forEach((c=>{capabilities[c.id]=c.value})),Object.assign({},capabilities)}static exportDiscussion(state,cardId){let d=[];return state.discussions.forEach((c=>{c.kanban_card==cardId&&d.push(c)})),d=d.sort(((a,b)=>parseInt(a.timecreated)>parseInt(b.timecreated))),d}static exportHistory(state,cardId){let d=[];return state.history.forEach((c=>{c.kanban_card==cardId&&d.push(c)})),d=d.sort(((a,b)=>parseInt(a.timestamp)>parseInt(b.timestamp))),d}},_exports.default})); +define("mod_kanban/exporter",["exports","mod_kanban/capabilities"],(function(_exports,_capabilities){var obj;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_capabilities=(obj=_capabilities)&&obj.__esModule?obj:{default:obj};return _exports.default=class{static exportStateForTemplate(state){let columnOrder=state.board.sequence.split(","),columns=[],hascolumns=""!=state.board.sequence;hascolumns&&(columns=columnOrder.map((value=>this.exportCardsForColumn(state,value))));let showactionmenu=1==state.common.userboards||""!=state.common.groupselector||state.capabilities.get(_capabilities.default.MANAGEBOARD).value||2==state.common.userboards&&state.capabilities.get(_capabilities.default.VIEWALLBOARDS).value;return Object.assign({cmid:state.common.id,id:state.board.id,sequence:state.board.sequence,hascolumns:hascolumns,columns:columns,locked:state.board.locked,hastemplate:0!=state.common.template,istemplate:0!=state.board.template,heading:state.board.heading,groupselector:state.common.groupselector,userboards:state.common.userboards,history:state.common.history&&state.capabilities.get(_capabilities.default.VIEWHISTORY).value,groupmode:state.common.groupmode,ismyuserboard:state.common.userid==state.board.userid,myuserid:state.common.userid,showactionmenu:showactionmenu,userboardsonly:2==state.common.userboards,iscourseboard:0==state.board.userid&&0==state.board.groupid&&0==state.board.template,users:JSON.parse(JSON.stringify(state.users))},this.exportCapabilities(state))}static exportCardsForColumn(state,columnid){let col=JSON.parse(JSON.stringify(state.columns.get(columnid))),options=JSON.parse(col.options);if(col.hascards=""!=col.sequence,col.autoclose=options.autoclose,col.autohide=options.autohide,col.colbackground=options.colbackground,col.hascards){let cardOrder=col.sequence.split(",");col.cards=cardOrder.map((value=>this.exportCard(state,value)))}return col}static exportCard(state,cardid){let card={id:cardid,title:"-",assignees:[],options:"{}",canedit:!1};void 0!==state.cards.get(cardid)&&(card=JSON.parse(JSON.stringify(state.cards.get(cardid)))),card.cardid=card.id,card.hasassignees=card.assignees.length>0;let options=JSON.parse(card.options);return card.hasassignees&&"number"==typeof card.assignees[0]&&(card.assignees=card.assignees.map((userid=>state.users.get(userid))),card.assignees=[...new Set(card.assignees)]),Object.assign(card,options)}static exportCapabilities(state){let capabilities=[];return state.capabilities.forEach((c=>{capabilities[c.id]=c.value})),Object.assign({},capabilities)}static exportDiscussion(state,cardId){let d=[];return state.discussions.forEach((c=>{c.kanban_card==cardId&&d.push(c)})),d=d.sort(((a,b)=>parseInt(a.timecreated)>parseInt(b.timecreated))),d}static exportHistory(state,cardId){let d=[];return state.history.forEach((c=>{c.kanban_card==cardId&&d.push(c)})),d=d.sort(((a,b)=>parseInt(a.timestamp)>parseInt(b.timestamp))),d}},_exports.default})); //# sourceMappingURL=exporter.min.js.map \ No newline at end of file diff --git a/amd/build/exporter.min.js.map b/amd/build/exporter.min.js.map index 9db53237..d6f8a64c 100644 --- a/amd/build/exporter.min.js.map +++ b/amd/build/exporter.min.js.map @@ -1 +1 @@ -{"version":3,"file":"exporter.min.js","sources":["../src/exporter.js"],"sourcesContent":["import capabilities from 'mod_kanban/capabilities';\n\n/**\n * Exporter for use in mustache template.\n */\nexport default class {\n /**\n * Exports the complete state (for initial rendering).\n * @param {*} state\n * @returns {object}\n */\n static exportStateForTemplate(state) {\n let columnOrder = state.board.sequence.split(',');\n let columns = [];\n let hascolumns = state.board.sequence != '';\n if (hascolumns) {\n columns = columnOrder.map((value) => {\n return this.exportCardsForColumn(state, value);\n });\n }\n\n let showactionmenu = state.common.userboards == 1 || state.common.groupselector != '' ||\n state.capabilities.get(capabilities.MANAGEBOARD).value ||\n (state.common.userboards == 2 && state.capabilities.get(capabilities.VIEWALLBOARDS).value);\n\n return Object.assign({\n cmid: state.common.id,\n id: state.board.id,\n sequence: state.board.sequence,\n hascolumns: hascolumns,\n columns: columns,\n locked: state.board.locked,\n hastemplate: state.common.template != 0,\n istemplate: state.board.template != 0,\n heading: state.board.heading,\n groupselector: state.common.groupselector,\n userboards: state.common.userboards,\n history: state.common.history && state.capabilities.get(capabilities.VIEWHISTORY).value,\n groupmode: state.common.groupmode,\n ismyuserboard: state.common.userid == state.board.userid,\n myuserid: state.common.userid,\n showactionmenu: showactionmenu,\n userboardsonly: state.common.userboards == 2,\n iscourseboard: state.board.userid == 0 && state.board.groupid == 0 && state.board.template == 0,\n users: JSON.parse(JSON.stringify(state.users)),\n }, this.exportCapabilities(state));\n }\n\n /**\n * Exports the card for one column.\n * @param {*} state\n * @param {*} columnid\n * @returns {object}\n */\n static exportCardsForColumn(state, columnid) {\n let col = JSON.parse(JSON.stringify(state.columns.get(columnid)));\n let options = JSON.parse(col.options);\n col.hascards = col.sequence != '';\n col.autoclose = options.autoclose;\n col.autohide = options.autohide;\n if (col.hascards) {\n let cardOrder = col.sequence.split(',');\n col.cards = cardOrder.map((value) => {\n return this.exportCard(state, value);\n });\n }\n return col;\n }\n\n /**\n * Exports a card.\n * @param {*} state\n * @param {*} cardid\n * @returns {object}\n */\n static exportCard(state, cardid) {\n let card = {\n id: cardid,\n title: '-',\n assignees: [],\n options: '{}',\n canedit: false\n };\n if (state.cards.get(cardid) !== undefined) {\n card = JSON.parse(JSON.stringify(state.cards.get(cardid)));\n }\n card.cardid = card.id;\n card.hasassignees = card.assignees.length > 0;\n let options = JSON.parse(card.options);\n if (card.hasassignees && typeof card.assignees[0] == 'number') {\n card.assignees = card.assignees.map((userid) => {\n return state.users.get(userid);\n });\n card.assignees = [...new Set(card.assignees)];\n }\n return Object.assign(card, options);\n }\n\n /**\n * Exports the capabilities.\n * @param {*} state\n * @returns {object}\n */\n static exportCapabilities(state) {\n let capabilities = [];\n state.capabilities.forEach((c) => {\n capabilities[c.id] = c.value;\n });\n return Object.assign({}, capabilities);\n }\n\n /**\n * Exports the discussion for a card.\n * @param {*} state\n * @param {number} cardId\n * @returns {array}\n */\n static exportDiscussion(state, cardId) {\n let d = [];\n state.discussions.forEach((c) => {\n if (c.kanban_card == cardId) {\n d.push(c);\n }\n });\n d = d.sort((a, b) => parseInt(a.timecreated) > parseInt(b.timecreated));\n return d;\n }\n\n /**\n * Exports history for a card.\n * @param {*} state\n * @param {number} cardId\n * @returns {array}\n */\n static exportHistory(state, cardId) {\n let d = [];\n // Only get history of this card.\n state.history.forEach((c) => {\n if (c.kanban_card == cardId) {\n d.push(c);\n }\n });\n // Sort by timestamp.\n d = d.sort((a, b) => parseInt(a.timestamp) > parseInt(b.timestamp));\n return d;\n }\n}"],"names":["state","columnOrder","board","sequence","split","columns","hascolumns","map","value","this","exportCardsForColumn","showactionmenu","common","userboards","groupselector","capabilities","get","MANAGEBOARD","VIEWALLBOARDS","Object","assign","cmid","id","locked","hastemplate","template","istemplate","heading","history","VIEWHISTORY","groupmode","ismyuserboard","userid","myuserid","userboardsonly","iscourseboard","groupid","users","JSON","parse","stringify","exportCapabilities","columnid","col","options","hascards","autoclose","autohide","cardOrder","cards","exportCard","cardid","card","title","assignees","canedit","undefined","hasassignees","length","Set","forEach","c","cardId","d","discussions","kanban_card","push","sort","a","b","parseInt","timecreated","timestamp"],"mappings":"6TAWkCA,WACtBC,YAAcD,MAAME,MAAMC,SAASC,MAAM,KACzCC,QAAU,GACVC,WAAqC,IAAxBN,MAAME,MAAMC,SACzBG,aACAD,QAAUJ,YAAYM,KAAKC,OAChBC,KAAKC,qBAAqBV,MAAOQ,cAI5CG,eAA4C,GAA3BX,MAAMY,OAAOC,YAAiD,IAA9Bb,MAAMY,OAAOE,eAC9Dd,MAAMe,aAAaC,IAAID,sBAAaE,aAAaT,OACrB,GAA3BR,MAAMY,OAAOC,YAAmBb,MAAMe,aAAaC,IAAID,sBAAaG,eAAeV,aAEjFW,OAAOC,OAAO,CACjBC,KAAMrB,MAAMY,OAAOU,GACnBA,GAAItB,MAAME,MAAMoB,GAChBnB,SAAUH,MAAME,MAAMC,SACtBG,WAAYA,WACZD,QAASA,QACTkB,OAAQvB,MAAME,MAAMqB,OACpBC,YAAsC,GAAzBxB,MAAMY,OAAOa,SAC1BC,WAAoC,GAAxB1B,MAAME,MAAMuB,SACxBE,QAAS3B,MAAME,MAAMyB,QACrBb,cAAed,MA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yB,QAC1BhC,MAAMqC,MAAMrB,IAAIgB,UAE3BoB,KAAKE,UAAY,IAAI,IAAIK,IAAIP,KAAKE,aAE/BnC,OAAOC,OAAOgC,KAAMR,mCAQL5C,WAClBe,aAAe,UACnBf,MAAMe,aAAa6C,SAASC,IACxB9C,aAAa8C,EAAEvC,IAAMuC,EAAErD,SAEpBW,OAAOC,OAAO,GAAIL,sCASLf,MAAO8D,YACvBC,EAAI,UACR/D,MAAMgE,YAAYJ,SAASC,IACnBA,EAAEI,aAAeH,QACjBC,EAAEG,KAAKL,MAGfE,EAAIA,EAAEI,MAAK,CAACC,EAAGC,IAAMC,SAASF,EAAEG,aAAeD,SAASD,EAAEE,eACnDR,uBASU/D,MAAO8D,YACpBC,EAAI,UAER/D,MAAM4B,QAAQgC,SAASC,IACfA,EAAEI,aAAeH,QACjBC,EAAEG,KAAKL,MAIfE,EAAIA,EAAEI,MAAK,CAACC,EAAGC,IAAMC,SAASF,EAAEI,WAAaF,SAASD,EAAEG,aACjDT"} \ No newline at end of file +{"version":3,"file":"exporter.min.js","sources":["../src/exporter.js"],"sourcesContent":["import capabilities from 'mod_kanban/capabilities';\n\n/**\n * Exporter for use in mustache template.\n */\nexport default class {\n /**\n * Exports the complete state (for initial rendering).\n * @param {*} state\n * @returns {object}\n */\n static exportStateForTemplate(state) {\n let columnOrder = state.board.sequence.split(',');\n let columns = [];\n let hascolumns = state.board.sequence != '';\n if (hascolumns) {\n columns = columnOrder.map((value) => {\n return this.exportCardsForColumn(state, value);\n });\n }\n\n let showactionmenu = state.common.userboards == 1 || state.common.groupselector != '' ||\n state.capabilities.get(capabilities.MANAGEBOARD).value ||\n (state.common.userboards == 2 && state.capabilities.get(capabilities.VIEWALLBOARDS).value);\n\n return Object.assign({\n cmid: state.common.id,\n id: state.board.id,\n sequence: state.board.sequence,\n hascolumns: hascolumns,\n columns: columns,\n locked: state.board.locked,\n hastemplate: state.common.template != 0,\n istemplate: state.board.template != 0,\n heading: state.board.heading,\n groupselector: state.common.groupselector,\n userboards: state.common.userboards,\n history: state.common.history && state.capabilities.get(capabilities.VIEWHISTORY).value,\n groupmode: state.common.groupmode,\n ismyuserboard: state.common.userid == state.board.userid,\n myuserid: state.common.userid,\n showactionmenu: showactionmenu,\n userboardsonly: state.common.userboards == 2,\n iscourseboard: state.board.userid == 0 && state.board.groupid == 0 && state.board.template == 0,\n users: JSON.parse(JSON.stringify(state.users)),\n }, this.exportCapabilities(state));\n }\n\n /**\n * Exports the card for one column.\n * @param {*} state\n * @param {*} columnid\n * @returns {object}\n */\n static exportCardsForColumn(state, columnid) {\n let col = JSON.parse(JSON.stringify(state.columns.get(columnid)));\n let options = JSON.parse(col.options);\n col.hascards = col.sequence != '';\n col.autoclose = options.autoclose;\n col.autohide = options.autohide;\n col.colbackground = options.colbackground;\n if (col.hascards) {\n let cardOrder = col.sequence.split(',');\n col.cards = cardOrder.map((value) => {\n return this.exportCard(state, value);\n });\n }\n return col;\n }\n\n /**\n * Exports a card.\n * @param {*} state\n * @param {*} cardid\n * @returns {object}\n */\n static exportCard(state, cardid) {\n let card = {\n id: cardid,\n title: '-',\n assignees: [],\n options: '{}',\n canedit: false\n };\n if (state.cards.get(cardid) !== undefined) {\n card = JSON.parse(JSON.stringify(state.cards.get(cardid)));\n }\n card.cardid = card.id;\n card.hasassignees = card.assignees.length > 0;\n let options = JSON.parse(card.options);\n if (card.hasassignees && typeof card.assignees[0] == 'number') {\n card.assignees = card.assignees.map((userid) => {\n return state.users.get(userid);\n });\n card.assignees = [...new Set(card.assignees)];\n }\n return Object.assign(card, options);\n }\n\n /**\n * Exports the capabilities.\n * @param {*} state\n * @returns {object}\n */\n static exportCapabilities(state) {\n let capabilities = [];\n state.capabilities.forEach((c) => {\n capabilities[c.id] = c.value;\n });\n return Object.assign({}, capabilities);\n }\n\n /**\n * Exports the discussion for a card.\n * @param {*} state\n * @param {number} cardId\n * @returns {array}\n */\n static exportDiscussion(state, cardId) {\n let d = [];\n state.discussions.forEach((c) => {\n if (c.kanban_card == cardId) {\n d.push(c);\n }\n });\n d = d.sort((a, b) => parseInt(a.timecreated) > parseInt(b.timecreated));\n return d;\n }\n\n /**\n * Exports history for a card.\n * @param {*} state\n * @param {number} cardId\n * @returns {array}\n */\n static exportHistory(state, cardId) {\n let d = [];\n // Only get history of this card.\n state.history.forEach((c) => {\n if (c.kanban_card == cardId) {\n d.push(c);\n }\n });\n // Sort by timestamp.\n d = d.sort((a, b) => parseInt(a.timestamp) > parseInt(b.timestamp));\n return d;\n }\n}\n"],"names":["state","columnOrder","board","sequence","split","columns","hascolumns","map","value","this","exportCardsForColumn","showactionmenu","common","userboards","groupselector","capabilities","get","MANAGEBOARD","VIEWALLBOARDS","Object","assign","cmid","id","locked","hastemplate","template","istemplate","heading","history","VIEWHISTORY","groupmode","ismyuserboard","userid","myuserid","userboardsonly","iscourseboard","groupid","users","JSON","parse","stringify","exportCapabilities","columnid","col","options","hascards","autoclose","autohide","colbackground","cardOrder","cards","exportCard","cardid","card","title","assignees","canedit","undefined","hasassignees","length","Set","forEach","c","cardId","d","discussions","kanban_card","push","sort","a","b","parseInt","timecreated","timestamp"],"mappings":"6TAWkCA,WACtBC,YAAcD,MAAME,MAAMC,SAASC,MAAM,KACzCC,QAAU,GACVC,WAAqC,IAAxBN,MAAME,MAAMC,SACzBG,aACAD,QAAUJ,YAAYM,KAAKC,OAChBC,KAAKC,qBAAqBV,MAAOQ,cAI5CG,eAA4C,GAA3BX,MAAMY,OAAOC,YAAiD,IAA9Bb,MAAMY,OAAOE,eAC9Dd,MAAMe,aAAaC,IAAID,sBAAaE,aAAaT,OACrB,GAA3BR,MAAMY,OAAOC,YAAmBb,MAAMe,aAAaC,IAAID,sBAAaG,eAAeV,aAEjFW,OAAOC,OAAO,CACjBC,KAAMrB,MAAMY,OAAOU,GACnBA,GAAItB,MAAME,MAAMoB,GAChBnB,SAAUH,MAAME,MAAMC,SACtBG,WAAYA,WACZD,QAASA,QACTkB,OAAQvB,MAAME,MAAMqB,OACp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aAAeL,KAAKE,UAAUI,OAAS,MACxCf,QAAUN,KAAKC,MAAMc,KAAKT,gBAC1BS,KAAKK,cAA4C,iBAArBL,KAAKE,UAAU,KAC3CF,KAAKE,UAAYF,KAAKE,UAAUhD,KAAKyB,QAC1BhC,MAAMqC,MAAMrB,IAAIgB,UAE3BqB,KAAKE,UAAY,IAAI,IAAIK,IAAIP,KAAKE,aAE/BpC,OAAOC,OAAOiC,KAAMT,mCAQL5C,WAClBe,aAAe,UACnBf,MAAMe,aAAa8C,SAASC,IACxB/C,aAAa+C,EAAExC,IAAMwC,EAAEtD,SAEpBW,OAAOC,OAAO,GAAIL,sCASLf,MAAO+D,YACvBC,EAAI,UACRhE,MAAMiE,YAAYJ,SAASC,IACnBA,EAAEI,aAAeH,QACjBC,EAAEG,KAAKL,MAGfE,EAAIA,EAAEI,MAAK,CAACC,EAAGC,IAAMC,SAASF,EAAEG,aAAeD,SAASD,EAAEE,eACnDR,uBASUhE,MAAO+D,YACpBC,EAAI,UAERhE,MAAM4B,QAAQiC,SAASC,IACfA,EAAEI,aAAeH,QACjBC,EAAEG,KAAKL,MAIfE,EAAIA,EAAEI,MAAK,CAACC,EAAGC,IAAMC,SAASF,EAAEI,WAAaF,SAASD,EAAEG,aACjDT"} \ No newline at end of file diff --git a/amd/src/column.js b/amd/src/column.js index 1b558526..41c5cbdb 100644 --- a/amd/src/column.js +++ b/amd/src/column.js @@ -297,10 +297,21 @@ export default class extends KanbanComponent { this.getElement(selectors.INPLACEEDITABLE).setAttribute('data-value', doc.documentElement.textContent); this.getElement(selectors.INPLACEEDITABLE).querySelector('a').innerHTML = element.title; } - // Only autohide option is relevant for the frontend for now. autoclose option is handled by the backend. + // Only autohide and backgroundcolor option is relevant for the frontend for now. + // Autoclose option is handled by the backend. if (element.options !== undefined) { let options = JSON.parse(element.options); - this.toggleClass(options.autohide, 'mod_kanban_autohide'); + if (options.autohide === undefined) { + this.toggleClass(false, 'mod_kanban_autohide'); + } else { + this.toggleClass(true, 'mod_kanban_autohide'); + } + + if (options.colbackground === undefined) { + this.getElement().removeAttribute('style'); + } else { + this.getElement().setAttribute('style', 'background-color: ' + options.colbackground); + } } // Enable/disable dragging (e.g. if column is locked). this.checkDragging(); diff --git a/amd/src/exporter.js b/amd/src/exporter.js index 4f0f7c19..8f29db65 100644 --- a/amd/src/exporter.js +++ b/amd/src/exporter.js @@ -58,6 +58,7 @@ export default class { col.hascards = col.sequence != ''; col.autoclose = options.autoclose; col.autohide = options.autohide; + col.colbackground = options.colbackground; if (col.hascards) { let cardOrder = col.sequence.split(','); col.cards = cardOrder.map((value) => { diff --git a/classes/boardmanager.php b/classes/boardmanager.php index 20635f51..4e143ee0 100644 --- a/classes/boardmanager.php +++ b/classes/boardmanager.php @@ -943,8 +943,16 @@ public function update_column(int $columnid, array $data): void { $column = $this->get_column($columnid); $options = [ 'autoclose' => $data['autoclose'], - 'autohide' => $data['autohide'], ]; + + if (!empty($data['autohide'])) { + $options['autohide'] = $data['autohide']; + } + + if (!empty($data['color'])) { + $options['colbackground'] = $data['color']; + } + if (isset($data['title'])) { $data['title'] = s($data['title']); } diff --git a/classes/form/edit_column_form.php b/classes/form/edit_column_form.php index cfcab379..3f86ddd9 100644 --- a/classes/form/edit_column_form.php +++ b/classes/form/edit_column_form.php @@ -58,6 +58,10 @@ public function definition() { $mform->addElement('advcheckbox', 'autohide', get_string('autohide', 'kanban')); $mform->setType('autohide', PARAM_BOOL); + + $mform->addElement('color', 'color', get_string('color', 'mod_kanban'), ['size' => 5]); + $mform->setType('color', PARAM_TEXT); + $mform->setDefault('color', '#ffffff'); } /** @@ -124,6 +128,7 @@ public function set_data_for_dynamic_submission(): void { $options = json_decode($column->options); $column->autoclose = $options->autoclose; $column->autohide = $options->autohide; + $column->color = $options->colbackground; $this->set_data($column); } diff --git a/styles.css b/styles.css index feece6dc..cfaca257 100644 --- a/styles.css +++ b/styles.css @@ -389,7 +389,7 @@ a.mod_kanban_attachment_item { } .mod_kanban_board .btn { - background-color: white; + background-color: transparent; } .mod_kanban_column_container.row { diff --git a/templates/column.mustache b/templates/column.mustache index ee5a5011..92903a08 100644 --- a/templates/column.mustache +++ b/templates/column.mustache @@ -26,10 +26,11 @@ "managecolumns": true, "hascards": false, "autohide": true, - "locked": false + "locked": false, + "colbackground": "#AAAAFF" } }} -
  • +