From f2a4cbe0189ad7ab180b5609f5c1f5c07c971d44 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 18 Sep 2024 17:35:43 +0200 Subject: [PATCH 1/5] Fix module ID --- .github/workflows/marketplace-upload.yml | 2 +- .github/workflows/php-test-develop.yml | 4 +- .github/workflows/php-test-master.yml | 2 +- .github/workflows/php-test-next.yml | 26 +++++------ Events.php | 44 +++++++++---------- assets/Assets.php | 2 +- assets/InlineStyleAssets.php | 2 +- assets/TinyMcePluginsAssets.php | 4 +- components/PageUrlRule.php | 2 +- composer.json | 2 +- config.php | 4 +- .../AbstractCustomContainerController.php | 2 +- controllers/PageController.php | 6 +-- controllers/SnippetController.php | 4 +- controllers/ViewController.php | 20 ++++----- docs/CHANGELOG.md | 1 + helpers/Url.php | 26 +++++------ lib/templates/twig/TwigEngine.php | 2 +- .../m240918_142252_update_module_id.php | 32 ++++++++++++++ models/Target.php | 4 +- models/forms/SettingsForm.php | 2 +- module.json | 2 +- modules/template/assets/InlineEditorAsset.php | 2 +- modules/template/assets/SourceEditorAsset.php | 2 +- modules/template/assets/SwitchAssetBundle.php | 2 +- modules/template/assets/TemplateCoreAsset.php | 2 +- .../assets/TemplatePageStyleAsset.php | 2 +- .../template/controllers/AdminController.php | 14 +++--- modules/template/models/AssetVariable.php | 2 +- .../template/models/AssetVariablePhp74.php | 2 +- modules/template/models/ContainerContent.php | 4 +- .../template/models/ContainerContentItem.php | 2 +- ...custom_pages.template.TemplateContainer.js | 6 +-- ...om_pages.template.TemplateContainerItem.js | 12 ++--- ...b.custom_pages.template.TemplateElement.js | 4 +- .../js/humhub.custom_pages.template.editor.js | 18 ++++---- .../js/humhub.custom_pages.template.js | 8 ++-- .../js/humhub.custom_pages.template.source.js | 10 ++--- ...humhub.custom_pages.template.source.min.js | 2 +- modules/template/views/admin/editSource.php | 4 +- modules/template/views/admin/preview.php | 4 +- .../template/widgets/DeleteContentButton.php | 2 +- .../template/widgets/TemplateAdminMenu.php | 6 +-- .../widgets/TemplateEditorElement.php | 2 +- modules/template/widgets/TemplatePage.php | 14 +++--- .../widgets/views/deleteContentButton.php | 2 +- .../widgets/views/imageContentFormFields.php | 2 +- .../widgets/views/templateElementAdminRow.php | 4 +- .../widgets/views/templatePageEditButton.php | 4 +- permissions/ManagePages.php | 2 +- .../acceptance/CreateContainerPageCest.php | 6 +-- .../acceptance/CreateGlobalPageCest.php | 8 ++-- .../acceptance/CreateGlobalSnippetCest.php | 4 +- .../acceptance/CreatePhpPageCest.php | 6 +-- .../acceptance/CreatePhpSnippetCest.php | 6 +-- .../template/CreateTemplatePageCest.php | 4 +- .../ContainerContentDefinitionFixture.php | 2 +- .../fixtures/ContainerContentFixture.php | 2 +- .../fixtures/ContainerContentItemFixture.php | 2 +- .../ContainerContentTemplateFixture.php | 2 +- .../fixtures/ContainerSnippetFixture.php | 2 +- tests/codeception/fixtures/ContentFixture.php | 2 +- .../fixtures/OwnerContentFixture.php | 2 +- tests/codeception/fixtures/PageFixture.php | 2 +- .../fixtures/RichtextContentFixture.php | 2 +- tests/codeception/fixtures/SnippetFixture.php | 2 +- .../fixtures/TemplateElementFixture.php | 2 +- .../codeception/fixtures/TemplateFixture.php | 2 +- .../fixtures/TemplateInstanceFixture.php | 2 +- .../codeception/functional/InterfaceCest.php | 6 +-- tests/config/test.php | 5 +-- views/container/iframe.php | 2 +- views/global/iframe.php | 2 +- widgets/AdminMenu.php | 4 +- widgets/ContainerPageMenu.php | 4 +- widgets/OverviewSubMenu.php | 6 +-- widgets/views/snippet_iframe.php | 2 +- 77 files changed, 227 insertions(+), 199 deletions(-) create mode 100644 migrations/m240918_142252_update_module_id.php diff --git a/.github/workflows/marketplace-upload.yml b/.github/workflows/marketplace-upload.yml index 6dc05c40..e8bcc3ed 100644 --- a/.github/workflows/marketplace-upload.yml +++ b/.github/workflows/marketplace-upload.yml @@ -10,5 +10,5 @@ jobs: uses: humhub/actions/.github/workflows/module-marketplace-upload.yml@main with: install-composer: true - module-id: custom_pages + module-id: custom-pages secrets: inherit diff --git a/.github/workflows/php-test-develop.yml b/.github/workflows/php-test-develop.yml index e61a73a2..b0c79ccd 100644 --- a/.github/workflows/php-test-develop.yml +++ b/.github/workflows/php-test-develop.yml @@ -9,5 +9,5 @@ jobs: tests: uses: humhub/actions/.github/workflows/module-tests-develop.yml@main with: - module-id: custom_pages - install-composer: true \ No newline at end of file + module-id: custom-pages + install-composer: true diff --git a/.github/workflows/php-test-master.yml b/.github/workflows/php-test-master.yml index 847759d7..3bf9f7d9 100644 --- a/.github/workflows/php-test-master.yml +++ b/.github/workflows/php-test-master.yml @@ -7,5 +7,5 @@ jobs: tests: uses: humhub/actions/.github/workflows/module-tests-master.yml@main with: - module-id: custom_pages + module-id: custom-pages install-composer: true diff --git a/.github/workflows/php-test-next.yml b/.github/workflows/php-test-next.yml index 4df4f140..58071be9 100644 --- a/.github/workflows/php-test-next.yml +++ b/.github/workflows/php-test-next.yml @@ -1,13 +1,13 @@ -name: PHP Codeception Tests - next - -on: - push: - schedule: - - cron: "0 0 * * 0" - -jobs: - tests: - uses: humhub/actions/.github/workflows/module-tests-next.yml@main - with: - module-id: custom_pages - install-composer: true +name: PHP Codeception Tests - next + +on: + push: + schedule: + - cron: "0 0 * * 0" + +jobs: + tests: + uses: humhub/actions/.github/workflows/module-tests-next.yml@main + with: + module-id: custom-pages + install-composer: true diff --git a/Events.php b/Events.php index 27f3b494..7394c3e9 100644 --- a/Events.php +++ b/Events.php @@ -43,16 +43,16 @@ public static function onBeforeRequest() */ public static function registerAutoloader() { - Yii::setAlias('@vendor/tinymce/tinymce', '@custom_pages/vendor/tinymce/tinymce'); - Yii::setAlias('@vendor/2amigos/yii2-tinymce-widget/src/assets', '@custom_pages/vendor/2amigos/yii2-tinymce-widget/src/assets'); + Yii::setAlias('@vendor/tinymce/tinymce', '@custom-pages/vendor/tinymce/tinymce'); + Yii::setAlias('@vendor/2amigos/yii2-tinymce-widget/src/assets', '@custom-pages/vendor/2amigos/yii2-tinymce-widget/src/assets'); - require Yii::getAlias('@custom_pages/vendor/autoload.php'); + require Yii::getAlias('@custom-pages/vendor/autoload.php'); } public static function onAdminMenuInit($event) { try { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); if (!Yii::$app->user->can([ManageModules::class, ManagePages::class])) { return; @@ -64,7 +64,7 @@ public static function onAdminMenuInit($event) 'group' => 'manage', 'icon' => '', 'isActive' => (Yii::$app->controller->module - && (Yii::$app->controller->module->id === 'custom_pages' + && (Yii::$app->controller->module->id === 'custom-pages' && (Yii::$app->controller->id === 'page' || Yii::$app->controller->id === 'config')) || Yii::$app->controller->module->id == 'template'), 'sortOrder' => 300, @@ -78,11 +78,11 @@ public static function onAdminMenuInit($event) public static function onSpaceMenuInit($event) { try { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); /* @var $space \humhub\modules\space\models\Space */ $space = $event->sender->space; - if ($space->moduleManager->isEnabled('custom_pages')) { + if ($space->moduleManager->isEnabled('custom-pages')) { /* @var Page[] $pages */ $pages = ContainerPage::find() ->contentContainer($space) @@ -104,7 +104,7 @@ public static function onSpaceMenuInit($event) 'url' => $page->getUrl(), 'icon' => '', 'isActive' => (Yii::$app->controller->module - && Yii::$app->controller->module->id === 'custom_pages' + && Yii::$app->controller->module->id === 'custom-pages' && Yii::$app->controller->id === 'view' && Yii::$app->controller->action->id === 'index' && Yii::$app->request->get('id') == $page->id), 'sortOrder' => ($page->sort_order != '') ? $page->sort_order : 1000, @@ -119,18 +119,18 @@ public static function onSpaceMenuInit($event) public static function onSpaceAdminMenuInit($event) { try { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); /* @var $space \humhub\modules\space\models\Space */ $space = $event->sender->space; - if ($space->moduleManager->isEnabled('custom_pages') && $space->isAdmin() && $space->isMember()) { + if ($space->moduleManager->isEnabled('custom-pages') && $space->isAdmin() && $space->isMember()) { $event->sender->addItem([ 'label' => Yii::t('CustomPagesModule.base', 'Custom Pages'), 'group' => 'admin', 'url' => Url::toPageOverview($space), 'icon' => '', 'isActive' => (Yii::$app->controller->module - && Yii::$app->controller->module->id === 'custom_pages' + && Yii::$app->controller->module->id === 'custom-pages' && Yii::$app->controller->id === 'container' && Yii::$app->controller->action->id !== 'view'), ]); @@ -146,7 +146,7 @@ public static function onTopMenuInit($event) $menu = $event->sender; try { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); foreach (self::findPagesByTarget(Page::NAV_CLASS_TOPNAV) as $page) { if (!$page->canView()) { @@ -156,12 +156,12 @@ public static function onTopMenuInit($event) $menu->addEntry(new MenuLink([ 'id' => 'custom-page-' . $page->id, 'label' => Html::encode(Yii::t('CustomPagesModule.base', $page->title)), - 'url' => ['/custom_pages/view', 'id' => $page->id], + 'url' => ['/custom-pages/view', 'id' => $page->id], 'htmlOptions' => ['target' => ($page->in_new_window) ? '_blank' : ''], 'icon' => $page->icon, 'isActive' => ( ( - MenuLink::isActiveState('custom_pages', 'view') + MenuLink::isActiveState('custom-pages', 'view') && !Yii::$app->controller->contentContainer && (int)Yii::$app->request->get('id') === $page->id ) @@ -203,7 +203,7 @@ private static function isCurrentTargetUrl(Page $page): bool public static function onAccountMenuInit($event) { try { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); foreach (self::findPagesByTarget(Page::NAV_CLASS_ACCOUNTNAV) as $page) { if (!$page->canView()) { @@ -212,11 +212,11 @@ public static function onAccountMenuInit($event) $event->sender->addItem([ 'label' => Html::encode(Yii::t('CustomPagesModule.base', $page->title)), - 'url' => Url::to(['/custom_pages/view', 'id' => $page->id]), + 'url' => Url::to(['/custom-pages/view', 'id' => $page->id]), 'htmlOptions' => ['target' => ($page->in_new_window) ? '_blank' : ''], 'icon' => '', 'isActive' => (Yii::$app->controller->module - && Yii::$app->controller->module->id === 'custom_pages' + && Yii::$app->controller->module->id === 'custom-pages' && Yii::$app->controller->id === 'view' && Yii::$app->request->get('id') == $page->id), 'sortOrder' => ($page->sort_order != '') ? $page->sort_order : 1000, ]); @@ -239,7 +239,7 @@ public static function onAccountTopMenuInit($event) public static function onDashboardSidebarInit($event) { try { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); /* @var Snippet[] $snippets */ $snippets = Snippet::find()->where(['target' => Snippet::SIDEBAR_DASHBOARD])->readable()->all(); @@ -258,11 +258,11 @@ public static function onDashboardSidebarInit($event) public static function onSpaceSidebarInit($event) { try { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); $space = $event->sender->space; $canEdit = PagePermission::canEdit(); - if ($space->moduleManager->isEnabled('custom_pages')) { + if ($space->moduleManager->isEnabled('custom-pages')) { /* @var Snippet[] $snippets */ $snippets = ContainerSnippet::find()->contentContainer($space)->readable()->all(); foreach ($snippets as $snippet) { @@ -288,7 +288,7 @@ public static function onFooterMenuInit($event) $event->sender->addItem([ 'label' => Html::encode(Yii::t('CustomPagesModule.base', $page->title)), - 'url' => Url::to(['/custom_pages/view', 'id' => $page->id], true), + 'url' => Url::to(['/custom-pages/view', 'id' => $page->id], true), 'htmlOptions' => ['target' => ($page->in_new_window) ? '_blank' : ''], 'sortOrder' => ($page->sort_order != '') ? $page->sort_order : 1000, ]); @@ -310,7 +310,7 @@ public static function onPeopleHeadingButtonsInit($event) $peopleHeadingButtons->addEntry(new MenuLink([ 'label' => Html::encode(Yii::t('CustomPagesModule.base', $page->title)), - 'url' => Url::to(['/custom_pages/view', 'id' => $page->id]), + 'url' => Url::to(['/custom-pages/view', 'id' => $page->id]), 'htmlOptions' => ['target' => ($page->in_new_window) ? '_blank' : ''], 'sortOrder' => ($page->sort_order != '') ? $page->sort_order : 1000, 'icon' => $page->icon, diff --git a/assets/Assets.php b/assets/Assets.php index a47557a7..546335eb 100644 --- a/assets/Assets.php +++ b/assets/Assets.php @@ -20,7 +20,7 @@ class Assets extends AssetBundle */ public $defer = true; - public $sourcePath = '@custom_pages/resources'; + public $sourcePath = '@custom-pages/resources'; public $publishOptions = [ 'forceCopy' => false, diff --git a/assets/InlineStyleAssets.php b/assets/InlineStyleAssets.php index aa0fa157..6a743c79 100644 --- a/assets/InlineStyleAssets.php +++ b/assets/InlineStyleAssets.php @@ -14,7 +14,7 @@ class InlineStyleAssets extends AssetBundle /** * @inheritdoc */ - public $sourcePath = '@custom_pages/resources'; + public $sourcePath = '@custom-pages/resources'; /** * @inheritdoc diff --git a/assets/TinyMcePluginsAssets.php b/assets/TinyMcePluginsAssets.php index cc4c565d..cf4f87e1 100644 --- a/assets/TinyMcePluginsAssets.php +++ b/assets/TinyMcePluginsAssets.php @@ -14,5 +14,5 @@ class TinyMcePluginsAssets extends AssetBundle /** * @inheritdoc */ - public $sourcePath = '@custom_pages/resources/tinymce/plugins'; -} \ No newline at end of file + public $sourcePath = '@custom-pages/resources/tinymce/plugins'; +} diff --git a/components/PageUrlRule.php b/components/PageUrlRule.php index 1adb0d3d..794a489a 100644 --- a/components/PageUrlRule.php +++ b/components/PageUrlRule.php @@ -23,7 +23,7 @@ class PageUrlRule extends Component implements UrlRuleInterface /** * @var string default route to page home */ - public $defaultRoutes = ['custom_pages/view', 'custom_pages/view/view']; + public $defaultRoutes = ['custom-pages/view', 'custom-pages/view/view']; /** * @var array map with space guid/url pairs diff --git a/composer.json b/composer.json index 29732c11..53e0fb60 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "humhub/custom_pages", + "name": "humhub/custom-pages", "description": "Custom Pages", "type": "library", "require": { diff --git a/config.php b/config.php index efe505ff..118e6211 100644 --- a/config.php +++ b/config.php @@ -14,7 +14,7 @@ use humhub\widgets\TopMenu; return [ - 'id' => 'custom_pages', + 'id' => 'custom-pages', 'class' => 'humhub\modules\custom_pages\Module', 'modules' => [ 'template' => [ @@ -40,4 +40,4 @@ ['class' => DashboardSidebar::class, 'event' => BaseMenu::EVENT_INIT, 'callback' => [Events::class, 'onDashboardSidebarInit']], ['class' => SpaceSidebar::class, 'event' => BaseMenu::EVENT_INIT, 'callback' => [Events::class, 'onSpaceSidebarInit']], ], -]; \ No newline at end of file +]; diff --git a/controllers/AbstractCustomContainerController.php b/controllers/AbstractCustomContainerController.php index 6de5cb17..4e5a876c 100644 --- a/controllers/AbstractCustomContainerController.php +++ b/controllers/AbstractCustomContainerController.php @@ -42,7 +42,7 @@ abstract class AbstractCustomContainerController extends ContentContainerControl public function init() { - Yii::$app->moduleManager->getModule('custom_pages')->checkOldGlobalContent(); + Yii::$app->moduleManager->getModule('custom-pages')->checkOldGlobalContent(); parent::init(); } diff --git a/controllers/PageController.php b/controllers/PageController.php index 24ebe602..5207e004 100644 --- a/controllers/PageController.php +++ b/controllers/PageController.php @@ -104,7 +104,7 @@ public function actionIndex() */ public function actionOverview() { - return $this->render('@custom_pages/views/common/list', [ + return $this->render('@custom-pages/views/common/list', [ 'targets' => $this->customPagesService->getTargets($this->getPageType(), $this->contentContainer), 'pageType' => $this->getPageType(), 'subNav' => $this->getSubNav() @@ -144,7 +144,7 @@ public function actionAdd($targetId, $type = null) return $this->redirect(Url::toCreatePage($targetId, $this->getPageType(), $type, $this->contentContainer)); } - return $this->render('@custom_pages/views/common/add', [ + return $this->render('@custom-pages/views/common/add', [ 'model' => $model, 'target' => $target, 'pageType' => $this->getPageType(), @@ -196,7 +196,7 @@ public function actionEdit($targetId = null, $type = null, $id = null) // if its visibility is not allowed for its page type: $page->fixVisibility(); - return $this->render('@custom_pages/views/common/edit', [ + return $this->render('@custom-pages/views/common/edit', [ 'page' => $page, 'pageType' => $this->getPageType(), 'subNav' => $this->getSubNav() diff --git a/controllers/SnippetController.php b/controllers/SnippetController.php index da5c8bf7..6ccfaaa4 100644 --- a/controllers/SnippetController.php +++ b/controllers/SnippetController.php @@ -30,8 +30,8 @@ public function actionEditSnippet($id) } $view = $this->contentContainer - ? '@custom_pages/views/container/edit_snippet' - : '@custom_pages/views/global/edit_snippet'; + ? '@custom-pages/views/container/edit_snippet' + : '@custom-pages/views/global/edit_snippet'; return $this->render($view, [ 'snippet' => $snippet, diff --git a/controllers/ViewController.php b/controllers/ViewController.php index 6c699b9b..d7a8d78d 100644 --- a/controllers/ViewController.php +++ b/controllers/ViewController.php @@ -58,7 +58,7 @@ public function actionIndex() ? $page->getTargetModel()->getSubLayout() : $this->subLayout; - $this->view->pageTitle = Html::encode($page->title); + $this->view->setPageTitle(Html::encode($page->title)); if(!$page->getTargetModel()->isAllowedContentType($page->type)) { throw new HttpException(404); @@ -88,15 +88,15 @@ public function renderContainerView($page) { switch ($page->type) { case IframeType::ID: - return $this->render('@custom_pages/views/container/iframe', ['page' => $page, 'url' => $page->page_content]); + return $this->render('@custom-pages/views/container/iframe', ['page' => $page, 'url' => $page->page_content]); case TemplateType::ID: - return $this->viewTemplatePage($page, '@custom_pages/views/container/template'); + return $this->viewTemplatePage($page, '@custom-pages/views/container/template'); case LinkType::ID: return $this->redirect($page->page_content); case MarkdownType::ID: - return $this->render('@custom_pages/views/container/markdown', ['page' => $page, 'md' => $page->page_content]); + return $this->render('@custom-pages/views/container/markdown', ['page' => $page, 'md' => $page->page_content]); case PhpType::ID: - return $this->render('@custom_pages/views/container/php', ['page' => $page, 'contentContainer' => $this->contentContainer]); + return $this->render('@custom-pages/views/container/php', ['page' => $page, 'contentContainer' => $this->contentContainer]); default: throw new HttpException('500', 'Invalid page type!'); } @@ -111,22 +111,22 @@ public function renderGlobalView($page) { switch ($page->type) { case HtmlType::ID: - return $this->render('@custom_pages/views/global/html', ['page' => $page, 'html' => $page->getPageContent(), 'title' => $page->title]); + return $this->render('@custom-pages/views/global/html', ['page' => $page, 'html' => $page->getPageContent(), 'title' => $page->title]); case IframeType::ID: - return $this->render('@custom_pages/views/global/iframe', ['page' => $page, 'url' => $page->page_content, 'navigationClass' => $page->getTargetId()]); + return $this->render('@custom-pages/views/global/iframe', ['page' => $page, 'url' => $page->page_content, 'navigationClass' => $page->getTargetId()]); case TemplateType::ID: - return $this->viewTemplatePage($page, '@custom_pages/views/global/template'); + return $this->viewTemplatePage($page, '@custom-pages/views/global/template'); case LinkType::ID: return $this->redirect($page->page_content); case MarkdownType::ID: - return $this->render('@custom_pages/views/global/markdown', [ + return $this->render('@custom-pages/views/global/markdown', [ 'page' => $page, 'md' => $page->page_content, 'navigationClass' => $page->getTargetId(), 'title' => $page->title ]); case PhpType::ID: - return $this->render('@custom_pages/views/global/php', ['page' => $page]); + return $this->render('@custom-pages/views/global/php', ['page' => $page]); default: throw new HttpException('500', 'Invalid page type!'); } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 5823fea1..697e1613 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,7 @@ Changelog ----------------------- - Enh #342: JS Dependency Updates - Enh #344: Replace theme variables with CSS variables +- Fix #345: Fix module ID 1.10.6 (August 6, 2024) ----------------------- diff --git a/helpers/Url.php b/helpers/Url.php index b6ce3f13..94e521f8 100644 --- a/helpers/Url.php +++ b/helpers/Url.php @@ -12,25 +12,25 @@ class Url extends BaseUrl { - const ROUTE_CONFIG = '/custom_pages/config'; - const ROUTE_EDIT_PAGE = '/custom_pages/page/edit'; + const ROUTE_CONFIG = '/custom-pages/config'; + const ROUTE_EDIT_PAGE = '/custom-pages/page/edit'; - const ROUTE_PAGE_DELETE = '/custom_pages/page/delete'; - const ROUTE_SNIPPET_DELETE = '/custom_pages/snippet/delete'; + const ROUTE_PAGE_DELETE = '/custom-pages/page/delete'; + const ROUTE_SNIPPET_DELETE = '/custom-pages/snippet/delete'; - const ROUTE_EDIT_SNIPPET = '/custom_pages/snippet/edit'; - const ROUTE_PAGE_OVERVIEW = '/custom_pages/page'; + const ROUTE_EDIT_SNIPPET = '/custom-pages/snippet/edit'; + const ROUTE_PAGE_OVERVIEW = '/custom-pages/page'; - const ROUTE_PAGE_ADD = '/custom_pages/page/add'; - const ROUTE_SNIPPET_ADD = '/custom_pages/snippet/add'; + const ROUTE_PAGE_ADD = '/custom-pages/page/add'; + const ROUTE_SNIPPET_ADD = '/custom-pages/snippet/add'; - const ROUTE_SNIPPET_OVERVIEW = '/custom_pages/snippet'; + const ROUTE_SNIPPET_OVERVIEW = '/custom-pages/snippet'; - const ROUTE_TEMPLATE_LAYOUT_ADMIN = '/custom_pages/template/layout-admin'; + const ROUTE_TEMPLATE_LAYOUT_ADMIN = '/custom-pages/template/layout-admin'; - const ROUTE_PAGE_INLINE_EDIT = '/custom_pages/view'; + const ROUTE_PAGE_INLINE_EDIT = '/custom-pages/view'; - const ROUTE_SNIPPET_INLINE_EDIT = '/custom_pages/snippet/edit-snippet'; + const ROUTE_SNIPPET_INLINE_EDIT = '/custom-pages/snippet/edit-snippet'; public static function toInlineEdit(CustomContentContainer $content, ContentContainerActiveRecord $container = null) { @@ -145,4 +145,4 @@ public static function toDeletePage(CustomContentContainer $page, ContentContain return static::create($route, ['id' => $page->id], $container); } -} \ No newline at end of file +} diff --git a/lib/templates/twig/TwigEngine.php b/lib/templates/twig/TwigEngine.php index 552aa764..65ace5e0 100644 --- a/lib/templates/twig/TwigEngine.php +++ b/lib/templates/twig/TwigEngine.php @@ -44,7 +44,7 @@ public function render($template, $content) private function getSecurityPolicy(): ?SecurityPolicy { /** @var Module $module */ - $module = Yii::$app->getModule('custom_pages'); + $module = Yii::$app->getModule('custom-pages'); if (!$module->enableTwiqSandboxExtension) { return null; diff --git a/migrations/m240918_142252_update_module_id.php b/migrations/m240918_142252_update_module_id.php new file mode 100644 index 00000000..df4de0c6 --- /dev/null +++ b/migrations/m240918_142252_update_module_id.php @@ -0,0 +1,32 @@ + 'custom_pages']); + if ($moduleEnabled) { + $moduleEnabled->module_id = 'custom-pages'; + $moduleEnabled->save(); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m240918_142252_update_module_id cannot be reverted.\n"; + + return false; + } +} diff --git a/models/Target.php b/models/Target.php index 9e529c90..b2ef6d7c 100644 --- a/models/Target.php +++ b/models/Target.php @@ -53,7 +53,7 @@ class Target extends Model /** * @var string used to create the access url */ - public $accessRoute = '/custom_pages/view'; + public $accessRoute = '/custom-pages/view'; /** * @var string defines a sublayout used when rendering an entry @@ -139,4 +139,4 @@ public function getSubLayout() return $this->subLayout; } -} \ No newline at end of file +} diff --git a/models/forms/SettingsForm.php b/models/forms/SettingsForm.php index 7538b6d8..07dc1844 100644 --- a/models/forms/SettingsForm.php +++ b/models/forms/SettingsForm.php @@ -54,7 +54,7 @@ class SettingsForm extends Model */ public function init() { - $this->settings = Yii::$app->getModule('custom_pages')->settings; + $this->settings = Yii::$app->getModule('custom-pages')->settings; $this->phpPagesActive = intval($this->settings->get('phpPagesActive', 0)); $this->phpGlobalPagePath = $this->settings->get('phpGlobalPagePath', static::DEFAULT_VIEW_PATH_PAGES); $this->phpGlobalSnippetPath = $this->settings->get('phpGlobalSnippetPath', static::DEFAULT_VIEW_PATH_SNIPPETS); diff --git a/module.json b/module.json index 765b2d73..630ddfc4 100644 --- a/module.json +++ b/module.json @@ -1,5 +1,5 @@ { - "id": "custom_pages", + "id": "custom-pages", "name": "Custom Pages", "description": "Create custom pages and widgets and share them with your users. Take advantage of a wide range of editing options, including HTML and Markdown.", "keywords": ["pages", "custom", "iframe", "markdown", "link", "navigation", "spaces"], diff --git a/modules/template/assets/InlineEditorAsset.php b/modules/template/assets/InlineEditorAsset.php index 75ad4300..8c5ecdbd 100644 --- a/modules/template/assets/InlineEditorAsset.php +++ b/modules/template/assets/InlineEditorAsset.php @@ -6,7 +6,7 @@ class InlineEditorAsset extends AssetBundle { - public $sourcePath = '@custom_pages/modules/template/resources'; + public $sourcePath = '@custom-pages/modules/template/resources'; public $publishOptions = [ 'forceCopy' => false diff --git a/modules/template/assets/SourceEditorAsset.php b/modules/template/assets/SourceEditorAsset.php index 86fea91c..b0068ea0 100644 --- a/modules/template/assets/SourceEditorAsset.php +++ b/modules/template/assets/SourceEditorAsset.php @@ -7,7 +7,7 @@ class SourceEditorAsset extends AssetBundle { - public $sourcePath = '@custom_pages/modules/template/resources'; + public $sourcePath = '@custom-pages/modules/template/resources'; public $jsOptions = ['position' => \yii\web\View::POS_END]; diff --git a/modules/template/assets/SwitchAssetBundle.php b/modules/template/assets/SwitchAssetBundle.php index a81b6096..1fb893f4 100644 --- a/modules/template/assets/SwitchAssetBundle.php +++ b/modules/template/assets/SwitchAssetBundle.php @@ -6,7 +6,7 @@ class SwitchAssetBundle extends AssetBundle { - public $sourcePath = '@custom_pages/modules/template/resources/js/switch'; + public $sourcePath = '@custom-pages/modules/template/resources/js/switch'; public $jsOptions = ['position' => \yii\web\View::POS_BEGIN]; diff --git a/modules/template/assets/TemplateCoreAsset.php b/modules/template/assets/TemplateCoreAsset.php index 39530fbc..41c903bf 100644 --- a/modules/template/assets/TemplateCoreAsset.php +++ b/modules/template/assets/TemplateCoreAsset.php @@ -10,7 +10,7 @@ class TemplateCoreAsset extends AssetBundle 'forceCopy' => false ]; - public $sourcePath = '@custom_pages/modules/template/resources'; + public $sourcePath = '@custom-pages/modules/template/resources'; public $jsOptions = ['position' => \yii\web\View::POS_END]; diff --git a/modules/template/assets/TemplatePageStyleAsset.php b/modules/template/assets/TemplatePageStyleAsset.php index ebffa530..3cfc9243 100644 --- a/modules/template/assets/TemplatePageStyleAsset.php +++ b/modules/template/assets/TemplatePageStyleAsset.php @@ -7,7 +7,7 @@ class TemplatePageStyleAsset extends AssetBundle { - public $sourcePath = '@custom_pages/modules/template/resources'; + public $sourcePath = '@custom-pages/modules/template/resources'; public $css = [ 'css/template-pages.css' diff --git a/modules/template/controllers/AdminController.php b/modules/template/controllers/AdminController.php index 5d01632e..04205b81 100644 --- a/modules/template/controllers/AdminController.php +++ b/modules/template/controllers/AdminController.php @@ -64,7 +64,7 @@ public function actionIndex() $searchModel = new TemplateSearch(['type' => $this->type]); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - return $this->render('@custom_pages/modules/template/views/admin/index', [ + return $this->render('@custom-pages/modules/template/views/admin/index', [ 'helpText' => $this->indexHelp, 'type' => $this->type, 'dataProvider' => $dataProvider, @@ -94,7 +94,7 @@ public function actionEdit($id = null) return $this->redirect(['edit-source', 'id' => $model->id]); } - return $this->render('@custom_pages/modules/template/views/admin/edit', ['model' => $model]); + return $this->render('@custom-pages/modules/template/views/admin/edit', ['model' => $model]); } /** @@ -120,7 +120,7 @@ public function actionEditSource() return $this->redirect(['edit-source', 'id' => $model->id]); } - return $this->render('@custom_pages/modules/template/views/admin/editSource', [ + return $this->render('@custom-pages/modules/template/views/admin/editSource', [ 'model' => $model, 'contentTypes' => $this->getContentTypes() ]); @@ -144,7 +144,7 @@ public function actionEditUsage() ] ]); - return $this->render('@custom_pages/modules/template/views/admin/editUsage', [ + return $this->render('@custom-pages/modules/template/views/admin/editUsage', [ 'model' => $model, 'dataProvider' => $dataProvider ]); @@ -262,12 +262,12 @@ public function actionPreview($id, $editView = null, $reload = null) $editView = ($editView != null) ? $editView : false; if ($reload != null) { - return $this->renderPartial('@custom_pages/modules/template/views/admin/preview', [ + return $this->renderPartial('@custom-pages/modules/template/views/admin/preview', [ 'template' => $template, 'editView' => $editView ]); } else { - return $this->render('@custom_pages/modules/template/views/admin/preview', [ + return $this->render('@custom-pages/modules/template/views/admin/preview', [ 'template' => $template, 'editView' => $editView ]); @@ -366,7 +366,7 @@ public function actionEditMultiple($id) */ public function actionInfo() { - return $this->renderPartial('@custom_pages/modules/template/views/admin/info'); + return $this->renderPartial('@custom-pages/modules/template/views/admin/info'); } } diff --git a/modules/template/models/AssetVariable.php b/modules/template/models/AssetVariable.php index 31e2bee3..b7ad1c3f 100644 --- a/modules/template/models/AssetVariable.php +++ b/modules/template/models/AssetVariable.php @@ -31,7 +31,7 @@ public function get($name) private function getModule() { if($this->module == null) { - $this->module = Yii::$app->getModule('custom_pages'); + $this->module = Yii::$app->getModule('custom-pages'); } return $this->module; } diff --git a/modules/template/models/AssetVariablePhp74.php b/modules/template/models/AssetVariablePhp74.php index 2628a538..8698cf22 100644 --- a/modules/template/models/AssetVariablePhp74.php +++ b/modules/template/models/AssetVariablePhp74.php @@ -31,7 +31,7 @@ public function get($name) private function getModule() { if($this->module == null) { - $this->module = Yii::$app->getModule('custom_pages'); + $this->module = Yii::$app->getModule('custom-pages'); } return $this->module; } diff --git a/modules/template/models/ContainerContent.php b/modules/template/models/ContainerContent.php index 08d36b45..de32b149 100644 --- a/modules/template/models/ContainerContent.php +++ b/modules/template/models/ContainerContent.php @@ -100,7 +100,7 @@ public function render($options = []) } if ($this->isEditMode($options)) { - $options['jsWidget'] = 'custom_pages.template.TemplateContainer'; + $options['jsWidget'] = 'custom-pages.template.TemplateContainer'; return $this->wrap('div', $result, $options, ['data-template-multiple' => $this->definition->allow_multiple]); } else { return $result; @@ -109,7 +109,7 @@ public function render($options = []) public function renderEmpty($options = []) { - $options['jsWidget'] = 'custom_pages.template.TemplateContainer'; + $options['jsWidget'] = 'custom-pages.template.TemplateContainer'; return $this->renderEmptyDiv(Yii::t('CustomPagesModule.models_Container', 'Empty
Container'), $options, [ 'class' => 'emptyContainerBlock', 'data-template-multiple' => $this->definition->allow_multiple diff --git a/modules/template/models/ContainerContentItem.php b/modules/template/models/ContainerContentItem.php index 5e9a7c54..f9895d5f 100644 --- a/modules/template/models/ContainerContentItem.php +++ b/modules/template/models/ContainerContentItem.php @@ -91,7 +91,7 @@ public function wrap($content, $inline) 'class' => ($inline) ? 'inline' : '', 'data-allow-inline-activation' => $this->template->allow_inline_activation, 'data-template-item' => $this->id, - 'data-template-edit-url' => Url::to(['/custom_pages/template/container-admin/edit-source', 'id' => $this->template_id]), + 'data-template-edit-url' => Url::to(['/custom-pages/template/container-admin/edit-source', 'id' => $this->template_id]), 'data-template-item-title' => $this->title, 'data-template-owner' => ContainerContent::class, 'data-template-owner-id' => $this->container_content_id diff --git a/modules/template/resources/js/humhub.custom_pages.template.TemplateContainer.js b/modules/template/resources/js/humhub.custom_pages.template.TemplateContainer.js index d42aa8b5..a8082ec5 100644 --- a/modules/template/resources/js/humhub.custom_pages.template.TemplateContainer.js +++ b/modules/template/resources/js/humhub.custom_pages.template.TemplateContainer.js @@ -1,8 +1,8 @@ -humhub.module('custom_pages.template.TemplateContainer', function (module, require, $) { +humhub.module('custom-pages.template.TemplateContainer', function (module, require, $) { var string = require('util').string; var object = require('util').object; var modal = require('ui.modal'); - var TemplateElement = require('custom_pages.template.TemplateElement'); + var TemplateElement = require('custom-pages.template.TemplateElement'); /** * TemplateContainer @@ -64,4 +64,4 @@ humhub.module('custom_pages.template.TemplateContainer', function (module, requi TemplateContainer.template['addButton'] = ''; module.export = TemplateContainer; -}); \ No newline at end of file +}); diff --git a/modules/template/resources/js/humhub.custom_pages.template.TemplateContainerItem.js b/modules/template/resources/js/humhub.custom_pages.template.TemplateContainerItem.js index e31d5c54..9e950f20 100644 --- a/modules/template/resources/js/humhub.custom_pages.template.TemplateContainerItem.js +++ b/modules/template/resources/js/humhub.custom_pages.template.TemplateContainerItem.js @@ -1,9 +1,9 @@ -humhub.module('custom_pages.template.TemplateContainerItem', function (module, require, $) { - var customPage = require('custom_pages.template.editor'); +humhub.module('custom-pages.template.TemplateContainerItem', function (module, require, $) { + var customPage = require('custom-pages.template.editor'); var client = require('client'); var object = require('util').object; var string = require('util').string; - var TemplateElement = require('custom_pages.template.TemplateElement'); + var TemplateElement = require('custom-pages.template.TemplateElement'); /** * TemplateContainerItem @@ -161,7 +161,7 @@ humhub.module('custom_pages.template.TemplateContainerItem', function (module, r this.data('isActiveItem', true); this.data('active', true); - this.$root.trigger('custom_pages.afterActivateContainer', [this]); + this.$root.trigger('custom-pages.afterActivateContainer', [this]); }; TemplateContainerItem.prototype.stopInlineEdit = function () { @@ -172,7 +172,7 @@ humhub.module('custom_pages.template.TemplateContainerItem', function (module, r if ($overlay.length) { $overlay.fadeOut('fast', function () { $overlay.remove(); - that.$root.trigger('custom_pages.afterDeactivateContainer', [that]); + that.$root.trigger('custom-pages.afterDeactivateContainer', [that]); }); } this.$.css('background-color', ''); @@ -210,4 +210,4 @@ humhub.module('custom_pages.template.TemplateContainerItem', function (module, r TemplateContainerItem.template.moveButton = ''; module.export = TemplateContainerItem; -}); \ No newline at end of file +}); diff --git a/modules/template/resources/js/humhub.custom_pages.template.TemplateElement.js b/modules/template/resources/js/humhub.custom_pages.template.TemplateElement.js index 6fdacde7..fd14a24a 100644 --- a/modules/template/resources/js/humhub.custom_pages.template.TemplateElement.js +++ b/modules/template/resources/js/humhub.custom_pages.template.TemplateElement.js @@ -1,5 +1,5 @@ -humhub.module('custom_pages.template.TemplateElement', function (module, require, $) { - var customPage = require('custom_pages.template.editor'); +humhub.module('custom-pages.template.TemplateElement', function (module, require, $) { + var customPage = require('custom-pages.template.editor'); var Widget = require('ui.widget').Widget; var object = require('util').object; var string = require('util').string; diff --git a/modules/template/resources/js/humhub.custom_pages.template.editor.js b/modules/template/resources/js/humhub.custom_pages.template.editor.js index 21ee525a..23b82661 100644 --- a/modules/template/resources/js/humhub.custom_pages.template.editor.js +++ b/modules/template/resources/js/humhub.custom_pages.template.editor.js @@ -1,4 +1,4 @@ -humhub.module('custom_pages.template.editor', function (module, require, $) { +humhub.module('custom-pages.template.editor', function (module, require, $) { var Widget = require('ui.widget').Widget; var object = require('util').object; var client = require('client'); @@ -30,13 +30,13 @@ humhub.module('custom_pages.template.editor', function (module, require, $) { evt.stopPropagation(); }); - this.$.on('custom_pages.afterActivateContainer', function (event, item) { + this.$.on('custom-pages.afterActivateContainer', function (event, item) { that.activeItem = item; that.setActivateElement(item.$); that.clearExcept(item); }); - this.$.on('custom_pages.afterDeactivateContainer', function (event, item) { + this.$.on('custom-pages.afterDeactivateContainer', function (event, item) { that.activeItem = undefined; if (item.getParent()) { that.setActivateElement(item.getParent().$); @@ -44,7 +44,7 @@ humhub.module('custom_pages.template.editor', function (module, require, $) { }); // Set the currentElement when menu buttons are used. - $(document).off('click.custom_pages').on('click.custom_pages', '.template-menu-button', function () { + $(document).off('click.custom-pages').on('click.custom-pages', '.template-menu-button', function () { var $this = $(this); if ($this.data('action-target')) { that.currentElement = Widget.instance($this.data('action-target')); @@ -172,7 +172,7 @@ humhub.module('custom_pages.template.editor', function (module, require, $) { return false; } - var hasRootOwner = element.owner === "humhub\\modules\\custom_pages\\modules\\template\\models\\TemplateInstance"; + var hasRootOwner = element.owner === "humhub\\modules\\custom-pages\\modules\\template\\models\\TemplateInstance"; var isActiveCotnainerItemContent = this.activeItem && this.activeItem.isParentOf(element); var isEmptyContainer = element.$.is('.emptyContainerBlock'); @@ -234,7 +234,7 @@ humhub.module('custom_pages.template.editor', function (module, require, $) { var _initEvents = function () { // Tab logic in edit item modal - $(document).on('keyup.custom_pages', '.template-edit-multiple-tab', function (e) { + $(document).on('keyup.custom-pages', '.template-edit-multiple-tab', function (e) { switch (e.which) { case 13: e.preventDefault(); @@ -255,7 +255,7 @@ humhub.module('custom_pages.template.editor', function (module, require, $) { } break; } - }).on('click.custom_pages', '.template-edit-multiple-tab', function () { + }).on('click.custom-pages', '.template-edit-multiple-tab', function () { $(this).next('.panel-body').slideToggle('fast'); var $switchIcon = $(this).find('.switchIcon'); if ($switchIcon.hasClass('fa-caret-down')) { @@ -270,7 +270,7 @@ humhub.module('custom_pages.template.editor', function (module, require, $) { var unload = function () { $('.editMenu, .elementMenu').remove(); - $(document).off('.custom_pages'); + $(document).off('.custom-pages'); }; module.export({ @@ -278,4 +278,4 @@ humhub.module('custom_pages.template.editor', function (module, require, $) { unload: unload, TemplateInlineEditor: TemplateInlineEditor }); -}); \ No newline at end of file +}); diff --git a/modules/template/resources/js/humhub.custom_pages.template.js b/modules/template/resources/js/humhub.custom_pages.template.js index a4f0010f..ff3c2f3b 100644 --- a/modules/template/resources/js/humhub.custom_pages.template.js +++ b/modules/template/resources/js/humhub.custom_pages.template.js @@ -1,4 +1,4 @@ -humhub.module('custom_pages.template', function (module, require, $) { +humhub.module('custom-pages.template', function (module, require, $) { var object = require('util').object; var string = require('util').string; var Preview = require('file').Preview; @@ -46,7 +46,7 @@ humhub.module('custom_pages.template', function (module, require, $) { var _initEvents = function () { // Tab logic in edit item modal - $(document).on('keyup.custom_pages', '.template-edit-multiple-tab', function (e) { + $(document).on('keyup.custom-pages', '.template-edit-multiple-tab', function (e) { switch (e.which) { case 13: e.preventDefault(); @@ -67,7 +67,7 @@ humhub.module('custom_pages.template', function (module, require, $) { } break; } - }).on('click.custom_pages', '.template-edit-multiple-tab', function () { + }).on('click.custom-pages', '.template-edit-multiple-tab', function () { $(this).next('.panel-body').slideToggle('fast'); var $switchIcon = $(this).find('.switchIcon'); if ($switchIcon.hasClass('fa-caret-down')) { @@ -81,7 +81,7 @@ humhub.module('custom_pages.template', function (module, require, $) { }; var unload = function () { - $(document).off('.custom_pages'); + $(document).off('.custom-pages'); }; const deleteElementContent = function (evt) { diff --git a/modules/template/resources/js/humhub.custom_pages.template.source.js b/modules/template/resources/js/humhub.custom_pages.template.source.js index 837a21ee..0af38aa5 100644 --- a/modules/template/resources/js/humhub.custom_pages.template.source.js +++ b/modules/template/resources/js/humhub.custom_pages.template.source.js @@ -1,4 +1,4 @@ -humhub.module('custom_pages.template.source', function (module, require, $) { +humhub.module('custom-pages.template.source', function (module, require, $) { var client = require('client'); var modal = require('ui.modal'); var Widget = require('ui.widget').Widget; @@ -41,7 +41,7 @@ humhub.module('custom_pages.template.source', function (module, require, $) { }); // Note some browser do not support custom messages for this event. - $(window).on('beforeunload.custom_pages', function () { + $(window).on('beforeunload.custom-pages', function () { if (that.$sourceInput.data('changed')) { return module.text('warning.beforeunload'); } @@ -227,8 +227,8 @@ humhub.module('custom_pages.template.source', function (module, require, $) { }; var unload = function () { - $(document).off('.custom_pages'); - $(window).off('.custom_pages'); + $(document).off('.custom-pages'); + $(window).off('.custom-pages'); $(document).on('pjax:beforeSend'); }; @@ -238,4 +238,4 @@ humhub.module('custom_pages.template.source', function (module, require, $) { TemplateSourceEditor: TemplateSourceEditor, TemplateSourcePreview: TemplateSourcePreview }); -}); \ No newline at end of file +}); diff --git a/modules/template/resources/js/humhub.custom_pages.template.source.min.js b/modules/template/resources/js/humhub.custom_pages.template.source.min.js index a1452786..717390b5 100644 --- a/modules/template/resources/js/humhub.custom_pages.template.source.min.js +++ b/modules/template/resources/js/humhub.custom_pages.template.source.min.js @@ -1 +1 @@ -humhub.module("custom_pages.template.source",function(module,require,$){var client=require("client");var modal=require("ui.modal");var Widget=require("ui.widget").Widget;var object=require("util").object;var TemplateSourceEditor=function(node,options){Widget.call(this,node,options)};object.inherits(TemplateSourceEditor,Widget);TemplateSourceEditor.prototype.init=function(){this.$sourceInput=$("#template-form-source");this.$form=$("#sourceForm");this.$elements=$("#templateElementTable");this.initEvents()};TemplateSourceEditor.prototype.initEvents=function(){var that=this;this.codeMirror=CodeMirror.fromTextArea($("#template-form-source")[0],{lineNumbers:true,mode:"text/html",extraKeys:{"Ctrl-Space":"autocomplete"}});this.codeMirror.on("change",function(){console.log("changed");that.$sourceInput.data("changed",true)});this.$form.on("submit",function(){that.$sourceInput.data("changed",false)});$(window).on("beforeunload.custom_pages",function(){if(that.$sourceInput.data("changed")){return module.text("warning.beforeunload")}});$(document).on("pjax:beforeSend",function(evt){if(that.$sourceInput.data("changed")&&!window.confirm(module.text("warning.beforeunload"))){evt.preventDefault();return}that.$sourceInput.data("changed",false)})};TemplateSourceEditor.prototype.editElementSubmit=function(evt){var that=this;client.submit(evt,{dataType:"json"}).then(function(response){if(response.success){that.updateElement(response);modal.global.close()}else{modal.global.setDialog(response)}}).catch(function(e){module.log.error(e,true)})};TemplateSourceEditor.prototype.editMultipleElementsSubmit=function(evt){var that=this;client.submit(evt).then(function(response){if(response.success){that.$elements.replaceWith(response.output);modal.global.close()}else{modal.global.setDialog(response)}}).catch(function(e){module.log.error(e)})};TemplateSourceEditor.prototype.deleteElementSubmit=function(evt){var that=this;client.post(evt).then(function(response){if(response.success){that.removeElement(response.id)}}).catch(function(e){module.log.error(e,true)})};TemplateSourceEditor.prototype.removeElement=function(id){$('[data-template-element-definition="'+id+'"]').fadeOut("fast",function(){$(this).remove()})};TemplateSourceEditor.prototype.updateElement=function(response){var $currentRow=$('[data-template-element-definition="'+response.id+'"]');if(!$currentRow.length){var $content=$(response.output).hide();$("#templateElements").append($content);$content.fadeIn("fast");if(response.name){this.insertPlaceholder("{{ "+response.name+" }}")}}else{$currentRow.replaceWith(response.output)}};TemplateSourceEditor.prototype.insertPlaceholder=function(txt){codeMirror=this.getCodeMirror();codeMirror.getDoc().replaceSelection(txt);codeMirror.save()};TemplateSourceEditor.prototype.getCodeMirror=function(){return $(".CodeMirror:visible")[0].CodeMirror};TemplateSourceEditor.prototype.reset=function(evt){var that=this;client.post(evt).then(function(response){if(response.success){that.updateElement(response);modal.global.close()}}).catch(function(e){module.log.error(e,true)})};var _getCaret=function(el){if(el.selectionStart){return el.selectionStart}else if(document.selection){el.focus();var r=document.selection.createRange();if(r==null){return 0}var re=el.createTextRange();var rc=re.duplicate();re.moveToBookmark(r.getBookmark());rc.setEndPoint("EndToStart",re);return rc.text.length}return 0};var TemplateSourcePreview=function(node,options){Widget.call(this,node,options)};object.inherits(TemplateSourcePreview,Widget);TemplateSourcePreview.prototype.update=function(evt){var options={data:{reload:1,editView:$("#editModePreview").is(":visible")?"1":"0"}};var that=this;client.html(evt,options).then(function(response){var $result=$(response.html);$result.find("#stage").hide();that.$.replaceWith($result);$result.find("#stage").fadeIn("fast")}).catch(function(e){module.log.error(e,true)})};TemplateSourcePreview.prototype.switchMode=function(evt){evt.$trigger.toggleClass("active");$("#nonEditModePreview, #editModePreview").toggle()};module.initOnPjaxLoad=true;var init=function(){if($("#templatePageRoot").length&&require("ui.view").getState().action==="edit-source"){module.editor=Widget.instance("#templatePageRoot");_initEvents()}};var _initEvents=function(){};var unload=function(){$(document).off(".custom_pages");$(window).off(".custom_pages");$(document).on("pjax:beforeSend")};module.export({init:init,unload:unload,TemplateSourceEditor:TemplateSourceEditor,TemplateSourcePreview:TemplateSourcePreview})}); \ No newline at end of file +humhub.module("custom-pages.template.source",function(module,require,$){var client=require("client");var modal=require("ui.modal");var Widget=require("ui.widget").Widget;var object=require("util").object;var TemplateSourceEditor=function(node,options){Widget.call(this,node,options)};object.inherits(TemplateSourceEditor,Widget);TemplateSourceEditor.prototype.init=function(){this.$sourceInput=$("#template-form-source");this.$form=$("#sourceForm");this.$elements=$("#templateElementTable");this.initEvents()};TemplateSourceEditor.prototype.initEvents=function(){var that=this;this.codeMirror=CodeMirror.fromTextArea($("#template-form-source")[0],{lineNumbers:true,mode:"text/html",extraKeys:{"Ctrl-Space":"autocomplete"}});this.codeMirror.on("change",function(){console.log("changed");that.$sourceInput.data("changed",true)});this.$form.on("submit",function(){that.$sourceInput.data("changed",false)});$(window).on("beforeunload.custom-pages",function(){if(that.$sourceInput.data("changed")){return module.text("warning.beforeunload")}});$(document).on("pjax:beforeSend",function(evt){if(that.$sourceInput.data("changed")&&!window.confirm(module.text("warning.beforeunload"))){evt.preventDefault();return}that.$sourceInput.data("changed",false)})};TemplateSourceEditor.prototype.editElementSubmit=function(evt){var that=this;client.submit(evt,{dataType:"json"}).then(function(response){if(response.success){that.updateElement(response);modal.global.close()}else{modal.global.setDialog(response)}}).catch(function(e){module.log.error(e,true)})};TemplateSourceEditor.prototype.editMultipleElementsSubmit=function(evt){var that=this;client.submit(evt).then(function(response){if(response.success){that.$elements.replaceWith(response.output);modal.global.close()}else{modal.global.setDialog(response)}}).catch(function(e){module.log.error(e)})};TemplateSourceEditor.prototype.deleteElementSubmit=function(evt){var that=this;client.post(evt).then(function(response){if(response.success){that.removeElement(response.id)}}).catch(function(e){module.log.error(e,true)})};TemplateSourceEditor.prototype.removeElement=function(id){$('[data-template-element-definition="'+id+'"]').fadeOut("fast",function(){$(this).remove()})};TemplateSourceEditor.prototype.updateElement=function(response){var $currentRow=$('[data-template-element-definition="'+response.id+'"]');if(!$currentRow.length){var $content=$(response.output).hide();$("#templateElements").append($content);$content.fadeIn("fast");if(response.name){this.insertPlaceholder("{{ "+response.name+" }}")}}else{$currentRow.replaceWith(response.output)}};TemplateSourceEditor.prototype.insertPlaceholder=function(txt){codeMirror=this.getCodeMirror();codeMirror.getDoc().replaceSelection(txt);codeMirror.save()};TemplateSourceEditor.prototype.getCodeMirror=function(){return $(".CodeMirror:visible")[0].CodeMirror};TemplateSourceEditor.prototype.reset=function(evt){var that=this;client.post(evt).then(function(response){if(response.success){that.updateElement(response);modal.global.close()}}).catch(function(e){module.log.error(e,true)})};var _getCaret=function(el){if(el.selectionStart){return el.selectionStart}else if(document.selection){el.focus();var r=document.selection.createRange();if(r==null){return 0}var re=el.createTextRange();var rc=re.duplicate();re.moveToBookmark(r.getBookmark());rc.setEndPoint("EndToStart",re);return rc.text.length}return 0};var TemplateSourcePreview=function(node,options){Widget.call(this,node,options)};object.inherits(TemplateSourcePreview,Widget);TemplateSourcePreview.prototype.update=function(evt){var options={data:{reload:1,editView:$("#editModePreview").is(":visible")?"1":"0"}};var that=this;client.html(evt,options).then(function(response){var $result=$(response.html);$result.find("#stage").hide();that.$.replaceWith($result);$result.find("#stage").fadeIn("fast")}).catch(function(e){module.log.error(e,true)})};TemplateSourcePreview.prototype.switchMode=function(evt){evt.$trigger.toggleClass("active");$("#nonEditModePreview, #editModePreview").toggle()};module.initOnPjaxLoad=true;var init=function(){if($("#templatePageRoot").length&&require("ui.view").getState().action==="edit-source"){module.editor=Widget.instance("#templatePageRoot");_initEvents()}};var _initEvents=function(){};var unload=function(){$(document).off(".custom-pages");$(window).off(".custom-pages");$(document).on("pjax:beforeSend")};module.export({init:init,unload:unload,TemplateSourceEditor:TemplateSourceEditor,TemplateSourcePreview:TemplateSourcePreview})}); diff --git a/modules/template/views/admin/editSource.php b/modules/template/views/admin/editSource.php index 45683cf9..5eb772fd 100644 --- a/modules/template/views/admin/editSource.php +++ b/modules/template/views/admin/editSource.php @@ -62,7 +62,7 @@
'btn btn-primary', 'data-ui-loader' => ""]); ?>