Skip to content

Commit

Permalink
Making Websites With October CMS - Part 47 - Better Links and URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandoric committed Sep 22, 2018
1 parent ecc71b3 commit 3d3bc57
Show file tree
Hide file tree
Showing 676 changed files with 29,759 additions and 7,833 deletions.
16 changes: 16 additions & 0 deletions modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ protected function registerAssetBundles()
$combiner->registerBundle('~/modules/backend/assets/less/october.less');
$combiner->registerBundle('~/modules/backend/assets/js/october.js');
$combiner->registerBundle('~/modules/backend/widgets/table/assets/js/build.js');
$combiner->registerBundle('~/modules/backend/widgets/mediamanager/assets/js/mediamanager-browser.js');
$combiner->registerBundle('~/modules/backend/widgets/mediamanager/assets/less/mediamanager.less');
$combiner->registerBundle('~/modules/backend/formwidgets/codeeditor/assets/less/codeeditor.less');
$combiner->registerBundle('~/modules/backend/formwidgets/repeater/assets/less/repeater.less');
$combiner->registerBundle('~/modules/backend/formwidgets/codeeditor/assets/js/build.js');
$combiner->registerBundle('~/modules/backend/formwidgets/fileupload/assets/less/fileupload.less');

Expand Down Expand Up @@ -96,6 +99,14 @@ protected function registerBackendNavigation()
'url' => Backend::url('backend'),
'permissions' => ['backend.access_dashboard'],
'order' => 10
],
'media' => [
'label' => 'backend::lang.media.menu_label',
'icon' => 'icon-folder',
'iconSvg' => 'modules/backend/assets/images/media-icon.svg',
'url' => Backend::url('backend/media'),
'permissions' => ['media.*'],
'order' => 200
]
]);
});
Expand Down Expand Up @@ -140,6 +151,10 @@ protected function registerBackendPermissions()
'backend.manage_branding' => [
'label' => 'system::lang.permissions.manage_branding',
'tab' => 'system::lang.permissions.name'
],
'media.manage_media' => [
'label' => 'backend::lang.permissions.manage_media',
'tab' => 'system::lang.permissions.name',
]
]);
});
Expand All @@ -163,6 +178,7 @@ protected function registerBackendWidgets()
$manager->registerFormWidget('Backend\FormWidgets\RecordFinder', 'recordfinder');
$manager->registerFormWidget('Backend\FormWidgets\Repeater', 'repeater');
$manager->registerFormWidget('Backend\FormWidgets\TagList', 'taglist');
$manager->registerFormWidget('Backend\FormWidgets\MediaFinder', 'mediafinder');
});
}

Expand Down
22 changes: 22 additions & 0 deletions modules/backend/assets/images/media-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion modules/backend/assets/js/october-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion modules/backend/assets/js/october.datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
DateTimeConverter.prototype.constructor = DateTimeConverter

DateTimeConverter.prototype.init = function() {

this.initDefaults()

this.$el.text(this.getDateTimeValue())
Expand Down Expand Up @@ -77,6 +76,11 @@
DateTimeConverter.prototype.getDateTimeValue = function() {
this.datetime = this.$el.attr('datetime')

if (this.$el.get(0).hasAttribute('data-ignore-timezone')) {
this.appTimezone = 'UTC'
this.options.timezone = 'UTC'
}

var momentObj = moment.tz(this.datetime, this.appTimezone),
result

Expand Down
2 changes: 1 addition & 1 deletion modules/backend/assets/js/october.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
=require ../vendor/sweet-alert/sweet-alert.js
=require ../vendor/jcrop/js/jquery.Jcrop.js
=require ../../../system/assets/vendor/prettify/prettify.js
=require ../../../cms/widgets/mediamanager/assets/js/mediamanager-global.js
=require ../../widgets/mediamanager/assets/js/mediamanager-global.js
=require october.lang.js
=require october.alert.js
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/assets/js/october.sidenav-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
return false
})

this.$searchInput.on('keyup', function(){
this.$searchInput.on('input', function(){
self.handleSearchChange()
})

Expand Down
57 changes: 29 additions & 28 deletions modules/backend/behaviors/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Redirect;
use Backend;
use Backend\Classes\ControllerBehavior;
use October\Rain\Html\Helper as HtmlHelper;
use October\Rain\Router\Helper as RouterHelper;
use ApplicationException;
use Exception;
Expand Down Expand Up @@ -127,17 +128,7 @@ public function initForm($model, $context = null)
/*
* Each page can supply a unique form definition, if desired
*/
$formFields = $this->config->form;

if ($context == self::CONTEXT_CREATE) {
$formFields = $this->getConfig('create[form]', $formFields);
}
elseif ($context == self::CONTEXT_UPDATE) {
$formFields = $this->getConfig('update[form]', $formFields);
}
elseif ($context == self::CONTEXT_PREVIEW) {
$formFields = $this->getConfig('preview[form]', $formFields);
}
$formFields = $this->getConfig("{$context}[form]", $this->config->form);

$config = $this->makeConfig($formFields);
$config->model = $model;
Expand Down Expand Up @@ -209,7 +200,7 @@ public function create($context = null)
try {
$this->context = strlen($context) ? $context : $this->getConfig('create[context]', self::CONTEXT_CREATE);
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang(
'create[title]',
"{$this->context}[title]",
'backend::lang.form.create_title'
);

Expand Down Expand Up @@ -255,7 +246,7 @@ public function create_onSave($context = null)
$this->controller->formAfterSave($model);
$this->controller->formAfterCreate($model);

Flash::success($this->getLang('create[flashSave]', 'backend::lang.form.create_success'));
Flash::success($this->getLang("{$this->context}[flashSave]", 'backend::lang.form.create_success'));

if ($redirect = $this->makeRedirect('create', $model)) {
return $redirect;
Expand All @@ -280,7 +271,7 @@ public function update($recordId = null, $context = null)
try {
$this->context = strlen($context) ? $context : $this->getConfig('update[context]', self::CONTEXT_UPDATE);
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang(
'update[title]',
"{$this->context}[title]",
'backend::lang.form.update_title'
);

Expand Down Expand Up @@ -322,7 +313,7 @@ public function update_onSave($recordId = null, $context = null)
$this->controller->formAfterSave($model);
$this->controller->formAfterUpdate($model);

Flash::success($this->getLang('update[flashSave]', 'backend::lang.form.update_success'));
Flash::success($this->getLang("{$this->context}[flashSave]", 'backend::lang.form.update_success'));

if ($redirect = $this->makeRedirect('update', $model)) {
return $redirect;
Expand All @@ -349,7 +340,7 @@ public function update_onDelete($recordId = null)

$this->controller->formAfterDelete($model);

Flash::success($this->getLang('update[flashDelete]', 'backend::lang.form.delete_success'));
Flash::success($this->getLang("{$this->context}[flashDelete]", 'backend::lang.form.delete_success'));

if ($redirect = $this->makeRedirect('delete', $model)) {
return $redirect;
Expand All @@ -374,7 +365,7 @@ public function preview($recordId = null, $context = null)
try {
$this->context = strlen($context) ? $context : $this->getConfig('preview[context]', self::CONTEXT_PREVIEW);
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang(
'preview[title]',
"{$this->context}[title]",
'backend::lang.form.preview_title'
);

Expand Down Expand Up @@ -464,7 +455,7 @@ public function makeRedirect($context = null, $model = null)
if (post('close') && !ends_with($context, '-close')) {
$context .= '-close';
}

if (post('refresh', false)) {
return Redirect::refresh();
}
Expand All @@ -477,7 +468,15 @@ public function makeRedirect($context = null, $model = null)
$redirectUrl = RouterHelper::parseValues($model, array_keys($model->getAttributes()), $redirectUrl);
}

return ($redirectUrl) ? Backend::redirect($redirectUrl) : null;
if (starts_with($redirectUrl, 'http://') || starts_with($redirectUrl, 'https://')) {
// Process absolute redirects
$redirect = Redirect::to($redirectUrl);
} else {
// Process relative redirects
$redirect = ($redirectUrl) ? Backend::redirect($redirectUrl) : null;
}

return $redirect;
}

/**
Expand All @@ -489,16 +488,17 @@ public function makeRedirect($context = null, $model = null)
*/
protected function getRedirectUrl($context = null)
{
$redirects = [
'default' => $this->getConfig('defaultRedirect', ''),
'create' => $this->getConfig('create[redirect]', ''),
'create-close' => $this->getConfig('create[redirectClose]', ''),
'update' => $this->getConfig('update[redirect]', ''),
'update-close' => $this->getConfig('update[redirectClose]', ''),
'preview' => $this->getConfig('preview[redirect]', ''),
];
$redirectContext = explode('-', $context, 2)[0];
$redirectSource = ends_with($context, '-close') ? 'redirectClose' : 'redirect';

// Get the redirect for the provided context
$redirects = [$context => $this->getConfig("{$redirectContext}[{$redirectSource}]", '')];

// Assign the default redirect afterwards to prevent the
// source for the default redirect being default[redirect]
$redirects['default'] = $this->getConfig('defaultRedirect', '');

if (!isset($redirects[$context])) {
if (empty($redirects[$context])) {
return $redirects['default'];
}

Expand Down Expand Up @@ -789,6 +789,7 @@ public function formExtendFieldsBefore($host)
/**
* Called after the form fields are defined.
* @param Backend\Widgets\Form $host The hosting form widget
* @param array $fields Array of all defined form field objects (\Backend\Classes\FormField)
* @return void
*/
public function formExtendFields($host, $fields)
Expand Down
13 changes: 13 additions & 0 deletions modules/backend/behaviors/ImportExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public function onImport()
catch (Exception $ex) {
$this->controller->handleError($ex);
}

$this->vars['sourceIndexOffset'] = $this->getImportSourceIndexOffset($importOptions['firstRowTitles']);

return $this->importExportMakePartial('import_result_form');
}
Expand Down Expand Up @@ -332,6 +334,17 @@ protected function getImportFileColumns()

return $firstRow;
}

/**
* Get the index offset to add to the reported row number in status messages
*
* @param bool $firstRowTitles Whether or not the first row contains column titles
* @return int $offset
*/
protected function getImportSourceIndexOffset($firstRowTitles)
{
return $firstRowTitles ? 2 : 1;
}

protected function makeImportUploadFormWidget()
{
Expand Down
9 changes: 5 additions & 4 deletions modules/backend/behaviors/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function makeList($definition = null)
'recordUrl',
'recordOnClick',
'recordsPerPage',
'showPageNumbers',
'noRecordsMessage',
'defaultSort',
'showSorting',
Expand Down Expand Up @@ -175,7 +176,7 @@ public function makeList($definition = null)
});

$widget->bindEvent('list.extendRecords', function ($records) use ($definition) {
$this->controller->listExtendRecords($records, $definition);
return $this->controller->listExtendRecords($records, $definition);
});

$widget->bindEvent('list.injectRowClass', function ($record) use ($definition) {
Expand Down Expand Up @@ -238,7 +239,7 @@ public function makeList($definition = null)
* Filter the list when the scopes are changed
*/
$filterWidget->bindEvent('filter.update', function () use ($widget, $filterWidget) {
return $widget->onRefresh();
return $widget->onFilter();
});

/*
Expand Down Expand Up @@ -456,7 +457,7 @@ public function listGetConfig($definition = null)
public function listExtendColumns($host)
{
}

/**
* Called after the filter scopes are defined.
* @param \Backend\Widgets\Filter $host The hosting filter widget
Expand Down Expand Up @@ -559,7 +560,7 @@ public static function extendListColumns($callback)
call_user_func_array($callback, [$widget, $widget->model]);
});
}

/**
* Static helper for extending filter scopes.
* @param callable $callback
Expand Down
Loading

0 comments on commit 3d3bc57

Please sign in to comment.