diff --git a/modules/cms/assets/js/october.cmspage.js b/modules/cms/assets/js/october.cmspage.js
index 6692e2715..9361581b7 100644
--- a/modules/cms/assets/js/october.cmspage.js
+++ b/modules/cms/assets/js/october.cmspage.js
@@ -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()
diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php
index 7751ede8f..cdef7f6d7 100644
--- a/modules/cms/controllers/Index.php
+++ b/modules/cms/controllers/Index.php
@@ -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
diff --git a/modules/cms/controllers/index/_common_toolbar_actions.htm b/modules/cms/controllers/index/_common_toolbar_actions.htm
new file mode 100644
index 000000000..42b247e8e
--- /dev/null
+++ b/modules/cms/controllers/index/_common_toolbar_actions.htm
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/cms/controllers/index/_content_toolbar.htm b/modules/cms/controllers/index/_content_toolbar.htm
index fb01abe95..02476a792 100644
--- a/modules/cms/controllers/index/_content_toolbar.htm
+++ b/modules/cms/controllers/index/_content_toolbar.htm
@@ -8,20 +8,5 @@
= e(trans('backend::lang.form.save')) ?>
-
-
-
-
-
-
+ = $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'content']); ?>
diff --git a/modules/cms/controllers/index/_layout_toolbar.htm b/modules/cms/controllers/index/_layout_toolbar.htm
index 1510ea3ca..fe336a1b1 100644
--- a/modules/cms/controllers/index/_layout_toolbar.htm
+++ b/modules/cms/controllers/index/_layout_toolbar.htm
@@ -8,20 +8,5 @@
= e(trans('backend::lang.form.save')) ?>
-
-
-
-
-
-
+ = $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'layout']); ?>
diff --git a/modules/cms/controllers/index/_page_toolbar.htm b/modules/cms/controllers/index/_page_toolbar.htm
index 790da0689..e72f76d0b 100644
--- a/modules/cms/controllers/index/_page_toolbar.htm
+++ b/modules/cms/controllers/index/_page_toolbar.htm
@@ -19,20 +19,5 @@
= e(trans('cms::lang.editor.preview')) ?>
-
-
-
-
-
-
+ = $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'page']); ?>
diff --git a/modules/cms/controllers/index/_partial_toolbar.htm b/modules/cms/controllers/index/_partial_toolbar.htm
index 6cfc6dd49..4f4df2cbd 100644
--- a/modules/cms/controllers/index/_partial_toolbar.htm
+++ b/modules/cms/controllers/index/_partial_toolbar.htm
@@ -8,20 +8,5 @@
= e(trans('backend::lang.form.save')) ?>
-
-
-
-
-
-
+ = $this->makePartial('common_toolbar_actions', ['toolbarSource' => 'partial']); ?>
diff --git a/modules/cms/lang/en/lang.php b/modules/cms/lang/en/lang.php
index d96915e4c..7bf82ba7c 100644
--- a/modules/cms/lang/en/lang.php
+++ b/modules/cms/lang/en/lang.php
@@ -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',