Added base structure of the Commit & Reset buttons, NOTE: Have not actually implemented the logic for them yet, just added the initial shells / UI for them.

This commit is contained in:
Luke Towers 2018-11-22 13:34:19 -06:00
parent 1920d5b4b6
commit 0a8450b21c
8 changed files with 149 additions and 84 deletions

View File

@ -173,7 +173,7 @@
var dataId = $target.closest('li').attr('data-tab-id'),
title = $target.attr('title'),
$sidePanel = $('#cms-side-panel')
if (title)
this.setPageTitle(title)
@ -250,6 +250,8 @@
$form.on('changed.oc.changeMonitor', function() {
$panel.trigger('modified.oc.tab')
$panel.find('[data-control=commit-button]').addClass('hide');
$panel.find('[data-control=reset-button]').addClass('hide');
self.updateModifiedCounter()
})
@ -279,6 +281,10 @@
CmsPage.prototype.onAjaxSuccess = function(ev, context, data) {
var element = ev.target
// Update the visibilities of the commit & reset buttons
$('[data-control=commit-button]', element).toggleClass('hide', !data.canCommit)
$('[data-control=reset-button]', element).toggleClass('hide', !data.canReset)
if (data.templatePath !== undefined) {
$('input[name=templatePath]', element).val(data.templatePath)
$('input[name=templateMtime]', element).val(data.templateMtime)
@ -359,7 +365,7 @@
}).done(function(data) {
var tabs = $('#cms-master-tabs').data('oc.tab');
$.each(data.deleted, function(index, path){
var
var
tabId = templateType + '-' + data.theme + '-' + path,
tab = tabs.findByIdentifier(tabId)
@ -640,7 +646,7 @@
}
CmsPage.prototype.reloadForm = function(form) {
var
var
$form = $(form),
data = {
type: $('[name=templateType]', $form).val(),
@ -682,7 +688,7 @@
$(form).request('onGetTemplateList', {
success: function(data) {
$('#cms-master-tabs > .tab-content select[name="settings[layout]"]').each(function(){
var
var
$select = $(this),
value = $select.val()

View File

@ -134,6 +134,8 @@ class Index extends Controller
$this->vars['templatePath'] = Request::input('path');
$this->vars['lastModified'] = DateTime::makeCarbon($template->mtime);
$this->vars['canCommit'] = $this->canCommitTemplate($template);
$this->vars['canReset'] = $this->canResetTemplate($template);
if ($type === 'page') {
$router = new RainRouter;
@ -225,20 +227,7 @@ class Index extends Controller
Flash::success(Lang::get('cms::lang.template.saved'));
$result = [
'templatePath' => $template->fileName,
'templateMtime' => $template->mtime,
'tabTitle' => $this->getTabTitle($type, $template)
];
if ($type === 'page') {
$result['pageUrl'] = Url::to($template->url);
$router = new Router($this->theme);
$router->clearCache();
CmsCompoundObject::clearCache($this->theme);
}
return $result;
return $this->getUpdateResponse($template, $type);
}
/**
@ -266,6 +255,8 @@ class Index extends Controller
$widget = $this->makeTemplateFormWidget($type, $template);
$this->vars['templatePath'] = '';
$this->vars['canCommit'] = $this->canCommitTemplate($template);
$this->vars['canReset'] = $this->canResetTemplate($template);
return [
'tabTitle' => $this->getTabTitle($type, $template),
@ -397,10 +388,100 @@ class Index extends Controller
return $content;
}
/**
* Commits the DB changes of a template to the filesystem
*
* @return void
*/
public function onCommit()
{
$this->validateRequestTheme();
$type = Request::input('templateType');
$template = $this->loadTemplate($type, trim(Request::input('templatePath')));
if ($this->canCommitTemplate($template)) {
}
return $this->getUpdateResponse($template, $type);
}
/**
* Resets a template to the version on the filesystem
*
* @return void
*/
public function onReset()
{
$this->validateRequestTheme();
$type = Request::input('templateType');
$template = $this->loadTemplate($type, trim(Request::input('templatePath')));
if ($this->canResetTemplate($template)) {
}
return $this->getUpdateResponse($template, $type);
}
//
// Methods for the internal use
// Methods for internal use
//
/**
* Get the response to return in an AJAX request that updates a template
*
* @param CmsObject $template The template that has been affected
* @param string $type The type of template being affected
* @return array $result;
*/
protected function getUpdateResponse($template, $type)
{
$result = [
'templatePath' => $template->fileName,
'templateMtime' => $template->mtime,
'tabTitle' => $this->getTabTitle($type, $template)
];
if ($type === 'page') {
$result['pageUrl'] = Url::to($template->url);
$router = new Router($this->theme);
$router->clearCache();
CmsCompoundObject::clearCache($this->theme);
}
$result['canCommit'] = $this->canCommitTemplate($template);
$result['canReset'] = $this->canResetTemplate($template);
return $result;
}
/**
* Check to see if the provided template can be committed
*
* @param CmsObject $template
* @return boolean
*/
protected function canCommitTemplate($template)
{
$result = true;
return $result;
}
/**
* Check to see if the provided template can be reset
*
* @param CmsObject $template
* @return boolean
*/
protected function canResetTemplate($template)
{
$result = true;
return $result;
}
/**
* Validate that the current request is within the active theme
* @return void

View File

@ -0,0 +1,34 @@
<button
type="button"
class="btn btn-danger oc-icon-download <?php if (!$canCommit): ?>hide<?php endif ?>"
data-request="onCommit"
data-request-confirm="<?= e(trans('cms::lang.editor.commit_confirm')) ?>"
data-control="commit-button">
<?= e(trans('cms::lang.editor.commit')) ?>
</button>
<button
type="button"
class="btn btn-danger oc-icon-bomb <?php if (!$canReset): ?>hide<?php endif ?>"
data-request="onReset"
data-request-confirm="<?= e(trans('cms::lang.editor.reset_confirm')) ?>"
data-control="reset-button">
<?= e(trans('cms::lang.editor.reset')) ?>
</button>
<button
type="button"
class="btn btn-danger empty oc-icon-trash-o <?php if (!$templatePath): ?>hide<?php endif ?>"
data-request="onDelete"
data-request-confirm="<?= e(trans('cms::lang.' . $toolbarSource . '.delete_confirm_single')) ?>"
data-request-success="$.oc.cmsPage.updateTemplateList('<?= $toolbarSource ?>'); $(this).trigger('close.oc.tab', [{force: true}])"
data-control="delete-button"></button>
<?php if (isset($lastModified)): ?>
<span
class="btn empty oc-icon-calendar"
title="<?= e(trans('backend::lang.media.last_modified')) ?>: <?= $lastModified ?>"
data-toggle="tooltip"
data-placement="right">
</span>
<?php endif; ?>

View File

@ -8,20 +8,5 @@
<?= e(trans('backend::lang.form.save')) ?>
</a>
<button
type="button"
class="btn btn-danger empty oc-icon-trash-o <?php if (!$templatePath): ?>hide<?php endif ?>"
data-request="onDelete"
data-request-confirm="<?= e(trans('cms::lang.content.delete_confirm_single')) ?>"
data-request-success="$.oc.cmsPage.updateTemplateList('content'); $(this).trigger('close.oc.tab', [{force: true}])"
data-control="delete-button"></button>
<?php if (isset($lastModified)): ?>
<span
class="btn empty oc-icon-calendar"
title="<?= e(trans('backend::lang.media.last_modified')) ?>: <?= $lastModified ?>"
data-toggle="tooltip"
data-placement="right">
</span>
<?php endif; ?>
<?= $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'content']); ?>
</div>

View File

@ -8,20 +8,5 @@
<?= e(trans('backend::lang.form.save')) ?>
</a>
<button
type="button"
class="btn btn-danger empty oc-icon-trash-o <?php if (!$templatePath): ?>hide<?php endif ?>"
data-request="onDelete"
data-request-confirm="<?= e(trans('cms::lang.layout.delete_confirm_single')) ?>"
data-request-success="$.oc.cmsPage.updateTemplateList('layout'); $(this).trigger('close.oc.tab', [{force: true}])"
data-control="delete-button"></button>
<?php if (isset($lastModified)): ?>
<span
class="btn empty oc-icon-calendar"
title="<?= e(trans('backend::lang.media.last_modified')) ?>: <?= $lastModified ?>"
data-toggle="tooltip"
data-placement="right">
</span>
<?php endif; ?>
<?= $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'layout']); ?>
</div>

View File

@ -19,20 +19,5 @@
<?= e(trans('cms::lang.editor.preview')) ?>
</a>
<button
type="button"
class="btn btn-danger empty oc-icon-trash-o <?php if (!$templatePath): ?>hide<?php endif ?>"
data-request="onDelete"
data-request-confirm="<?= e(trans('cms::lang.page.delete_confirm_single')) ?>"
data-request-success="$.oc.cmsPage.updateTemplateList('page'); $(this).trigger('close.oc.tab', [{force: true}])"
data-control="delete-button"></button>
<?php if (isset($lastModified)): ?>
<span
class="btn empty oc-icon-calendar"
title="<?= e(trans('backend::lang.media.last_modified')) ?>: <?= $lastModified ?>"
data-toggle="tooltip"
data-placement="right">
</span>
<?php endif; ?>
<?= $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'page']); ?>
</div>

View File

@ -8,20 +8,5 @@
<?= e(trans('backend::lang.form.save')) ?>
</a>
<button
type="button"
class="btn btn-danger empty oc-icon-trash-o <?php if (!$templatePath): ?>hide<?php endif ?>"
data-request="onDelete"
data-request-confirm="<?= e(trans('cms::lang.partial.delete_confirm_single')) ?>"
data-request-success="$.oc.cmsPage.updateTemplateList('partial'); $(this).trigger('close.oc.tab', [{force: true}])"
data-control="delete-button"></button>
<?php if (isset($lastModified)): ?>
<span
class="btn empty oc-icon-calendar"
title="<?= e(trans('backend::lang.media.last_modified')) ?>: <?= $lastModified ?>"
data-toggle="tooltip"
data-placement="right">
</span>
<?php endif; ?>
<?= $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'partial']); ?>
</div>

View File

@ -185,7 +185,11 @@ return [
'open_searchbox' => 'Open Search box',
'close_searchbox' => 'Close Search box',
'open_replacebox' => 'Open Replace box',
'close_replacebox' => 'Close Replace box'
'close_replacebox' => 'Close Replace box',
'reset' => 'Reset',
'commit' => 'Commit',
'reset_confirm' => 'Are you sure you want to reset this file to the copy that is on the filesystem? This will completely replace it with the file that is on the filesystem',
'commit_confirm' => 'Are you sure you want to commit your changes to this file to the filesystem? This will overwrite the existing file on the filesystem',
],
'asset' => [
'menu_label' => 'Assets',