Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to duplicate pages #7

Merged
merged 7 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions assets/js/pages-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
this.proxy(this.onCreateObject)
)

// Duplicate object button click
$(document).on(
'click',
'#pages-master-tabs form[data-object-type=page] [data-control=duplicate-object]',
this.proxy(this.onDuplicateObject)
)

// Submenu item is clicked in the sidebar
$(document).on('submenu.oc.treeview', 'form.layout[data-content-id=pages]', this.proxy(this.onSidebarSubmenuItemClick))

Expand Down Expand Up @@ -367,6 +374,36 @@
return false
}

/*
* Triggered when the Duplicate button is clicked on the page form
*/
PagesPage.prototype.onDuplicateObject = function(e) {
var self = this,
$button = $(e.target),
$form = $button.closest('form'),
parent = $button.data('parent') !== undefined ? $button.data('parent') : null,
der-On marked this conversation as resolved.
Show resolved Hide resolved
type = $form.data('object-type') ? $form.data('object-type') : $form.data('template-type'),
tabId = type + Math.random()

$.wn.stripeLoadIndicator.show()
$form.request('onDuplicateObject', {
data: {
type: type,
parent: parent
}
}).done(function(data){
self.$masterTabs.ocTab('addTab', data.tabTitle, data.tab, tabId, $form.data('type-icon') + ' new-template')
$('#layout-side-panel').trigger('close.oc.sidePanel')
self.setPageTitle(data.tabTitle)
}).always(function(){
$.wn.stripeLoadIndicator.hide()
})

e.stopPropagation()

return false
}

/*
* Triggered when an item is clicked in the sidebar submenu
*/
Expand Down
46 changes: 46 additions & 0 deletions controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,52 @@ public function onCreateObject()
return $result;
}

public function onDuplicateObject()
{
$this->validateRequestTheme();

$type = Request::input('objectType');

$object = $this->loadObject($type, trim(Request::input('objectPath')));
$parentPage = null;
$parent = null;

if ($type === 'page') {
$parentPage = $object->getParent() ?? null;

if ($parentPage) {
$fileName = $parentPage->fileName;
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
$parent = substr(
$fileName, 0, -strlen('.' . $ext)
);
}
}

$className = get_class($object);
$data = $object->toArray();
$duplicatedObject = new $className($data);

$widget = $this->makeObjectFormWidget($type, $duplicatedObject);
$this->vars['objectPath'] = '';
$this->vars['canCommit'] = $this->canCommitObject($duplicatedObject);
$this->vars['canReset'] = $this->canResetObject($duplicatedObject);

$result = [
'tabTitle' => $this->getTabTitle($type, $duplicatedObject),
'tab' => $this->makePartial('form_page', [
'form' => $widget,
'objectType' => $type,
'objectTheme' => $this->theme->getDirName(),
'objectMtime' => null,
'objectParent' => $parent,
'parentPage' => $parentPage
der-On marked this conversation as resolved.
Show resolved Hide resolved
])
];

return $result;
}

public function onDelete()
{
$this->validateRequestTheme();
Expand Down
10 changes: 9 additions & 1 deletion controllers/index/_page_toolbar.htm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@

<?= $this->makePartial('~/modules/cms/controllers/index/_button_reset.htm'); ?>

<button
type="button"
class="btn btn-default empty oc-icon-clone <?php if (!$objectPath): ?>hide<?php endif ?>"
title="<?= e(trans('winter.pages::lang.editor.duplicate')) ?>"
data-control="duplicate-object"
>
</button>

<button
type="button"
class="btn btn-default empty oc-icon-trash-o <?php if (!$objectPath): ?>hide<?php endif ?>"
Expand All @@ -33,4 +41,4 @@
</button>

<?= $this->makePartial('~/modules/cms/controllers/index/_button_lastmodified.htm'); ?>
</div>
</div>
1 change: 1 addition & 0 deletions lang/de/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
'layout' => 'Layout',
'description' => 'Beschreibung',
'preview' => 'Vorschau',
'duplicate' => 'Duplizieren',
'enter_fullscreen' => 'Vollbildmodus einschalten',
'exit_fullscreen' => 'Vollbildmodus verlassen',
'hidden' => 'Verstecken',
Expand Down
1 change: 1 addition & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
'layout' => 'Layout',
'description' => 'Description',
'preview' => 'Preview',
'duplicate' => 'Duplicate',
'enter_fullscreen' => 'Enter fullscreen mode',
'exit_fullscreen' => 'Exit fullscreen mode',
'hidden' => 'Hidden',
Expand Down
1 change: 1 addition & 0 deletions lang/fr/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
'layout' => 'Maquette',
'description' => 'Description',
'preview' => 'Aperçu',
'duplicate' => 'Dupliquer',
'enter_fullscreen' => 'Activer le mode plein écran',
'exit_fullscreen' => 'Annuler le mode plein écran',
'hidden' => 'Caché',
Expand Down
1 change: 1 addition & 0 deletions lang/nl/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'layout' => 'Layout',
'description' => 'Beschrijving',
'preview' => 'Voorbeeld',
'duplicate' => 'Dupliceren',
'enter_fullscreen' => 'Volledig scherm openen',
'exit_fullscreen' => 'Volledig scherm afsluiten',
'hidden' => 'Verborgen',
Expand Down
2 changes: 1 addition & 1 deletion lang/pl/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@
'child_pages_description' => 'Wyświetla listę stron podrzędnych dla aktualnej strony',
'static_menu_menu_code' => 'Podaj kod systemowy menu',
],
];
];
1 change: 1 addition & 0 deletions lang/sk/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
'layout' => 'Layout',
'description' => 'Popis',
'preview' => 'Náhľad',
'duplicate' => 'Duplikovať',
'enter_fullscreen' => 'Zapnúť režim celej obrazovky',
'exit_fullscreen' => 'Vypnúť režim celej obrazovky',
'hidden' => 'Skrytá',
Expand Down