@kohanajs/mod-cms
Advanced tools
Comparing version 9.4.4 to 9.5.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [9.5.0](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v9.4.4...v9.5.0) (2022-08-26) | ||
### Features | ||
* page edit save value when item add / delete ([fcde017](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/fcde0175b4a1d657d40397b89fd9dd9b9df0d8e1)) | ||
* save other fields when add / delete blocks, block item ([3e9ef24](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/3e9ef2481609148391d25fc78ceea12cd07f3ebc)) | ||
### [9.4.4](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v9.4.3...v9.4.4) (2022-08-25) | ||
@@ -7,0 +15,0 @@ |
@@ -64,3 +64,2 @@ const { ControllerAdmin } = require('@kohanajs/mod-admin'); | ||
const slug = $_POST[':name'].toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, ''); | ||
console.log(slug); | ||
const slugExist = await ORM.readBy(Page, 'slug', [slug], {database, asArray:false}); | ||
@@ -94,4 +93,30 @@ instance.slug = slugExist ? (slug + instance.id) : slug; | ||
if($_POST['action'] === "publish"){ | ||
await this.publish(instance); | ||
const action = $_POST['action']; | ||
const actions = action.split(':'); | ||
const actionType = actions[0]; | ||
const actionParam = actions[1] ?? ""; | ||
const actionParams = actionParam.split('|'); | ||
switch (actionType){ | ||
case "publish": | ||
await this.publish(instance); | ||
break; | ||
case "block-add": | ||
await this.block_add(instance, $_POST['block-select']); | ||
break; | ||
case "block-delete": | ||
await this.block_delete(instance, actionParam); | ||
break; | ||
case "block-item-add": | ||
await this.block_item_add(instance, actionParams[0], actionParams[1]); | ||
break; | ||
case "block-item-delete": | ||
await this.block_item_delete(instance, actionParams[0], actionParams[1], actionParams[2]); | ||
break; | ||
case "item-add": | ||
await this.item_add(instance, actionParam); | ||
break; | ||
case "item-delete": | ||
await this.item_add(instance, actionParams[0], actionParams[1]); | ||
break; | ||
} | ||
@@ -265,2 +290,63 @@ | ||
if(!page) throw new Error(`Page ${pageId} not found`); | ||
await this.item_add(page, itemName); | ||
await this.redirect(`/admin/pages/${page.id}`, true); | ||
} | ||
async action_delete_item(){ | ||
const pageId = this.request.params['page_id']; | ||
const itemName= this.request.params['item_name']; | ||
const itemIndex= this.request.params['index']; | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const page = await ORM.factory(Page, pageId, {database}); | ||
await this.item_delete(page, itemName, itemIndex); | ||
await this.redirect(`/admin/pages/${page.id}`, true); | ||
} | ||
async block_add(page, blockName){ | ||
if(!blockName)return; | ||
const blueprint = KohanaJS.config.cms.blocks[blockName]; | ||
if(!blueprint) throw new Error(`Block ${blockName} not defined in config`); | ||
const defaultBlock = HelperPageText.blueprint(blockName, KohanaJS.config.cms.blocks, KohanaJS.config.cms.defaultLanguage); | ||
delete defaultBlock.blocks; | ||
const original = HelperPageText.getOriginal(page); | ||
original.blocks ||=[]; | ||
original.blocks.push(defaultBlock); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
} | ||
async block_delete(page, blockIndex){ | ||
const original = JSON.parse(page.original); | ||
original.blocks.splice(parseInt(blockIndex), 1); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
} | ||
async block_item_add(page, blockIndex, itemName){ | ||
const original = HelperPageText.getOriginal(page); | ||
const blockItems = original.blocks[blockIndex].items[itemName]; | ||
blockItems.push({attributes:{_weight: blockItems.length}, values:{}}); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
} | ||
async block_item_delete(page, blockIndex, itemName, itemIndex){ | ||
const original = JSON.parse(page.original); | ||
const blockItems = original.blocks[blockIndex].items[itemName]; | ||
blockItems.splice(parseInt(itemIndex), 1); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
} | ||
async item_add(page, itemName){ | ||
const defaultOriginal = HelperPageText.blueprint(page.page_type, KohanaJS.config.cms.blueprint, KohanaJS.config.cms.defaultLanguage || 'en'); | ||
@@ -280,20 +366,9 @@ const defaultItem = defaultOriginal.items[itemName][0]; | ||
await page.write(); | ||
await this.redirect(`/admin/pages/${page.id}`, true); | ||
} | ||
async action_delete_item(){ | ||
const pageId = this.request.params['page_id']; | ||
const itemName= this.request.params['item_name']; | ||
const itemIndex= this.request.params['index']; | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const page = await ORM.factory(Page, pageId, {database}); | ||
async item_delete(page, itemName, itemIndex){ | ||
const original = JSON.parse(page.original); | ||
original.items[itemName].splice(itemIndex, 1); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
await this.redirect(`/admin/pages/${page.id}`, true); | ||
} | ||
@@ -304,5 +379,2 @@ | ||
const blockName= this.request.params['block_name']; | ||
const blueprint = KohanaJS.config.cms.blocks[blockName]; | ||
if(!blueprint) throw new Error(`Block ${blockName} not defined in config`); | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
@@ -312,12 +384,4 @@ const page = await ORM.factory(Page, pageId, {database}); | ||
const defaultBlock = HelperPageText.blueprint(blockName, KohanaJS.config.cms.blocks, KohanaJS.config.cms.defaultLanguage); | ||
delete defaultBlock.blocks; | ||
await this.block_add(page, blockName); | ||
const original = HelperPageText.getOriginal(page); | ||
original.blocks ||=[]; | ||
original.blocks.push(defaultBlock); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
await this.redirect(`/admin/pages/${pageId}`, true); | ||
@@ -334,8 +398,3 @@ } | ||
const original = JSON.parse(page.original); | ||
original.blocks.splice(parseInt(blockIndex), 1); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
await this.block_delete(page, blockIndex); | ||
await this.redirect(`/admin/pages/${pageId}`,true); | ||
@@ -349,10 +408,3 @@ } | ||
const page = await ORM.factory(Page, pageId, {database}); | ||
const original = HelperPageText.getOriginal(page); | ||
const blockItems = original.blocks[blockIndex].items[itemName]; | ||
blockItems.push({attributes:{_weight: blockItems.length}, values:{}}); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
await this.block_item_add(page, blockIndex, itemName); | ||
await this.redirect(`/admin/pages/${pageId}`, true); | ||
@@ -365,8 +417,4 @@ } | ||
const page = await ORM.factory(Page, pageId, {database}); | ||
const original = JSON.parse(page.original); | ||
const blockItems = original.blocks[blockIndex].items[itemName]; | ||
blockItems.splice(parseInt(itemIndex), 1); | ||
await this.block_item_delete(page, blockIndex, itemName, itemIndex); | ||
page.original = JSON.stringify(original); | ||
await page.write(); | ||
await this.redirect(`/admin/pages/${pageId}`, true); | ||
@@ -373,0 +421,0 @@ } |
@@ -6,3 +6,3 @@ import HelperPage from "../../../classes/helper/Page.mjs"; | ||
//HelperPage.enablePointers(); | ||
HelperPage.enableBlock(); | ||
//HelperPage.enableBlock(); | ||
HelperPage.enablePageTag(); | ||
@@ -9,0 +9,0 @@ |
@@ -1,2 +0,2 @@ | ||
(()=>{"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function n(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),Object.defineProperty(e,"prototype",{writable:!1}),e}var a=function(){function t(){e(this,t)}return n(t,null,[{key:"saveScroll",value:function(){sessionStorage.setItem("adminPageScroll",window.scrollY.toString()),sessionStorage.setItem("adminPageExit",window.location.href.split("?")[0])}},{key:"restoreScroll",value:function(){var e=sessionStorage.getItem("adminPageScroll");if(e){if(sessionStorage.getItem("adminPageExit")!==window.location.href.split("?")[0])return;window.scrollTo({top:parseInt(e)})}}},{key:"saveOnSubmit",value:function(e){var t=this;e.addEventListener("submit",(function(){t.saveScroll()}))}}]),t}(),o=function(){function t(){e(this,t)}return n(t,null,[{key:"enableAutoSave",value:function(){var e=document.getElementById("autosave");e&&e.addEventListener("change",(function(e){e.currentTarget.form.submit()}))}},{key:"enablePointers",value:function(){var e=document.querySelector("html").getAttribute("lang");document.querySelectorAll("select.ref-pages").forEach((function(t){var n=t.getAttribute("data-pagetype");fetch("/admin/api/pages/".concat(n,"?language=").concat(e)).then((function(e){e.json().then((function(e){console.log(e)}))})),console.log(t)})),document.querySelectorAll("select.ref-page-items").forEach((function(t){var n=t.innerHTML,a=t.getAttribute("data-value"),o=t.getAttribute("data-pagetype"),r=t.getAttribute("data-item"),c="/admin/api/page-items/".concat(o,"/").concat(r,"?language=").concat(e);t.innerHTML='<option value="">Loading...</option>',fetch(c).then((function(e){e.json().then((function(e){var o=[n];e.forEach((function(e){o.push('<optgroup label="'.concat(e.name,'">')),e.items.forEach((function(e){o.push('<option value="'.concat(e.id,'" ').concat(e.id.toString()===a?"selected":"",">").concat(e.name,"</option>"))})),o.push("</optgroup>")})),t.innerHTML=o.join("/n")}))}))}))}},{key:"enableBlock",value:function(){var e=document.getElementById("add-block");if(e){var t=e.querySelector("select"),n=e.querySelector("a");t.addEventListener("change",(function(){n.setAttribute("href",n.getAttribute("data-link").replace("[block_name]",t.value))}))}}},{key:"addPageTag",value:function(e,t,n){fetch("/admin/api/page/".concat(e,"/tag/").concat(t),{credentials:"include",method:"POST"}).then((function(e){return e.json().then((function(e){console.log(e),!0===e.payload.success&&n(e.payload)}))}))}},{key:"enablePageTag",value:function(){var e=this;document.querySelectorAll(".page-tag-form").forEach((function(t){var n=t.getAttribute("data-page"),a=t.querySelector(".tag-add-input"),o=t.querySelector(".page-tag-list"),r=function(e){var t=e.currentTarget;fetch("/admin/api/page_tag/".concat(t.getAttribute("data-id")),{credentials:"include",method:"DELETE"}).then((function(e){return e.json().then((function(e){console.log(e),t.remove()}))}))};t.querySelector(".toggle-input-tag").addEventListener("click",(function(e){a.classList.contains("visually-hidden")?a.classList.remove("visually-hidden"):a.classList.add("visually-hidden")})),t.querySelectorAll(".page-tag.badge").forEach((function(e){e.addEventListener("click",r)})),a.addEventListener("change",(function(){var c=t.querySelector('option[value="'.concat(a.value,'"]'));if(c){var i=c.getAttribute("data-id"),l=c.getAttribute("data-value"),u=c.getAttribute("data-name");e.addPageTag(n,i,(function(e){var t=document.createElement("span");t.value="".concat(l," ( ").concat(u," )"),t.setAttribute("data-id",e.id),t.setAttribute("role","button"),t.classList.add("badge","bg-primary","rounded-pill"),t.innerHTML="".concat(l,' <i class="fas fa-times"></i>'),o.appendChild(t),o.appendChild(document.createTextNode(" ")),a.value="",t.addEventListener("click",r)}))}}))}))}}]),t}();function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var l=function(){function t(){e(this,t)}return n(t,null,[{key:"enableUpload",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i({apiKey:"api",dir:"cms",selector:".page-field-upload",selectorFile:'input[type="file"]',callback:function(e,n,a){if(e)throw e;var o=a.files[0],r=n.querySelector(".page-field-upload-text"),c=n.querySelector(".preview img");r.value="/".concat(o),c&&(c.src="".concat(t.previewUrl||"https://www.example.com").concat(o))}},t),a=document.querySelectorAll(n.selector);a.forEach((function(t){var a=t.querySelector(n.selectorFile);a.addEventListener("change",(function(){var o=new FormData;o.append("file",a.files[0]),o.append("dir",n.dir),o.append("api-key",n.apiKey),fetch(e,{method:"POST",body:o,mode:"cors"}).then((function(e){e.json().then((function(e){var a=e.files[0];if(!a)return n.callback(new Error("upload error"),t,a);n.callback(null,t,e)}))})).catch((function(e){return n.callback(e,t,null)}))}),!1)}))}}]),t}();a.restoreScroll(),a.saveOnSubmit(document.getElementById("main-form")),o.enableAutoSave(),o.enablePointers(),o.enableBlock(),o.enablePageTag(),l.enableUpload("https://mediaport.dappod.com/upload",{apiKey:"occadmin",dir:"cms",previewUrl:"https://www-admin.occasionspr.com/"}),tinymce.init({selector:"textarea",menubar:"",branding:!1,width:"100%",plugins:"code",toolbar:"undo redo bold italic code"}).then()})(); | ||
(()=>{"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function n(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),Object.defineProperty(e,"prototype",{writable:!1}),e}var a=function(){function t(){e(this,t)}return n(t,null,[{key:"saveScroll",value:function(){sessionStorage.setItem("adminPageScroll",window.scrollY.toString()),sessionStorage.setItem("adminPageExit",window.location.href.split("?")[0])}},{key:"restoreScroll",value:function(){var e=sessionStorage.getItem("adminPageScroll");if(e){if(sessionStorage.getItem("adminPageExit")!==window.location.href.split("?")[0])return;window.scrollTo({top:parseInt(e)})}}},{key:"saveOnSubmit",value:function(e){var t=this;e.addEventListener("submit",(function(){t.saveScroll()}))}}]),t}(),o=function(){function t(){e(this,t)}return n(t,null,[{key:"enableAutoSave",value:function(){var e=document.getElementById("autosave");e&&e.addEventListener("change",(function(e){e.currentTarget.form.submit()}))}},{key:"enablePointers",value:function(){var e=document.querySelector("html").getAttribute("lang");document.querySelectorAll("select.ref-pages").forEach((function(t){var n=t.getAttribute("data-pagetype");fetch("/admin/api/pages/".concat(n,"?language=").concat(e)).then((function(e){e.json().then((function(e){console.log(e)}))})),console.log(t)})),document.querySelectorAll("select.ref-page-items").forEach((function(t){var n=t.innerHTML,a=t.getAttribute("data-value"),o=t.getAttribute("data-pagetype"),r=t.getAttribute("data-item"),c="/admin/api/page-items/".concat(o,"/").concat(r,"?language=").concat(e);t.innerHTML='<option value="">Loading...</option>',fetch(c).then((function(e){e.json().then((function(e){var o=[n];e.forEach((function(e){o.push('<optgroup label="'.concat(e.name,'">')),e.items.forEach((function(e){o.push('<option value="'.concat(e.id,'" ').concat(e.id.toString()===a?"selected":"",">").concat(e.name,"</option>"))})),o.push("</optgroup>")})),t.innerHTML=o.join("/n")}))}))}))}},{key:"enableBlock",value:function(){var e=document.getElementById("add-block");if(e){var t=e.querySelector("select"),n=e.querySelector("a");t.addEventListener("change",(function(){n.setAttribute("href",n.getAttribute("data-link").replace("[block_name]",t.value))}))}}},{key:"addPageTag",value:function(e,t,n){fetch("/admin/api/page/".concat(e,"/tag/").concat(t),{credentials:"include",method:"POST"}).then((function(e){return e.json().then((function(e){console.log(e),!0===e.payload.success&&n(e.payload)}))}))}},{key:"enablePageTag",value:function(){var e=this;document.querySelectorAll(".page-tag-form").forEach((function(t){var n=t.getAttribute("data-page"),a=t.querySelector(".tag-add-input"),o=t.querySelector(".page-tag-list"),r=function(e){var t=e.currentTarget;fetch("/admin/api/page_tag/".concat(t.getAttribute("data-id")),{credentials:"include",method:"DELETE"}).then((function(e){return e.json().then((function(e){console.log(e),t.remove()}))}))};t.querySelector(".toggle-input-tag").addEventListener("click",(function(e){a.classList.contains("visually-hidden")?a.classList.remove("visually-hidden"):a.classList.add("visually-hidden")})),t.querySelectorAll(".page-tag.badge").forEach((function(e){e.addEventListener("click",r)})),a.addEventListener("change",(function(){var c=t.querySelector('option[value="'.concat(a.value,'"]'));if(c){var i=c.getAttribute("data-id"),l=c.getAttribute("data-value"),u=c.getAttribute("data-name");e.addPageTag(n,i,(function(e){var t=document.createElement("span");t.value="".concat(l," ( ").concat(u," )"),t.setAttribute("data-id",e.id),t.setAttribute("role","button"),t.classList.add("badge","bg-primary","rounded-pill"),t.innerHTML="".concat(l,' <i class="fas fa-times"></i>'),o.appendChild(t),o.appendChild(document.createTextNode(" ")),a.value="",t.addEventListener("click",r)}))}}))}))}}]),t}();function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var l=function(){function t(){e(this,t)}return n(t,null,[{key:"enableUpload",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i({apiKey:"api",dir:"cms",selector:".page-field-upload",selectorFile:'input[type="file"]',callback:function(e,n,a){if(e)throw e;var o=a.files[0],r=n.querySelector(".page-field-upload-text"),c=n.querySelector(".preview img");r.value="/".concat(o),c&&(c.src="".concat(t.previewUrl||"https://www.example.com").concat(o))}},t),a=document.querySelectorAll(n.selector);a.forEach((function(t){var a=t.querySelector(n.selectorFile);a.addEventListener("change",(function(){var o=new FormData;o.append("file",a.files[0]),o.append("dir",n.dir),o.append("api-key",n.apiKey),fetch(e,{method:"POST",body:o,mode:"cors"}).then((function(e){e.json().then((function(e){var a=e.files[0];if(!a)return n.callback(new Error("upload error"),t,a);n.callback(null,t,e)}))})).catch((function(e){return n.callback(e,t,null)}))}),!1)}))}}]),t}();a.restoreScroll(),a.saveOnSubmit(document.getElementById("main-form")),o.enableAutoSave(),o.enablePageTag(),l.enableUpload({"www2-admin.occasionspr.com":"https://mediaport.dappod.com/upload","www-admin.occasionspr.com":"https://mediaport.dappod.com/upload"}[window.location.hostname]||"/admin/upload",{apiKey:{"www2-admin.occasionspr.com":"occadmintest","www-admin.occasionspr.com":"occadmin"}[window.location.hostname]||"occadmin",dir:"cms",previewUrl:window.location.origin+"/"}),tinymce.init({selector:"textarea",menubar:"",branding:!1,width:"100%",plugins:"code",toolbar:"undo redo bold italic removeformat code",paste_as_text:!0}).then()})(); | ||
//# sourceMappingURL=controller_admin_page_read.bundle.js.map |
{ | ||
"name": "@kohanajs/mod-cms", | ||
"version": "9.4.4", | ||
"version": "9.5.0", | ||
"description": "The CMS module for KohanaJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
154347
1458