diff --git a/core/lexicon/en/resource.inc.php b/core/lexicon/en/resource.inc.php
index ce096018023..23744a613ab 100644
--- a/core/lexicon/en/resource.inc.php
+++ b/core/lexicon/en/resource.inc.php
@@ -69,6 +69,11 @@
$_lang['resource_err_nfs'] = 'Resource with ID [[+id]] not found';
$_lang['resource_err_ns'] = 'Resource not specified.';
$_lang['resource_err_own_parent'] = 'The resource cannot be its own parent.';
+$_lang['resource_err_preview_no_zero_id'] = 'This Resource (id = [[+source_id]]) is a link to another Resource, but its preview URL can not be created because the target Resource id ([[+target_id]]) is 0 or begins with 0.';
+$_lang['resource_err_preview_self_deleted'] = 'Can not create a preview URL for this Resource (id = [[+target_id]]) because it has been marked as deleted.';
+$_lang['resource_err_preview_self_not_found'] = 'Can not create a preview URL for this Resource (id = [[+target_id]]) because it does not exist.';
+$_lang['resource_err_preview_target_deleted'] = 'This Resource (id = [[+source_id]]) is a link to another Resource, but its preview URL can not be created because the target Resource (id = [[+target_id]]) has been marked as deleted.';
+$_lang['resource_err_preview_target_not_found'] = 'This Resource (id = [[+source_id]]) is a link to another Resource, but its preview URL can not be created because the target Resource (id = [[+target_id]]) does not exist.';
$_lang['resource_err_publish'] = 'An error occurred while trying to publish the resource.';
$_lang['resource_err_new_parent_nf'] = 'New parent resource with id [[+id]] not found.';
$_lang['resource_err_remove'] = 'An error occurred while trying to delete the resource.';
@@ -86,6 +91,7 @@
$_lang['resource_err_unpublish_errorpage_dates'] = 'The resource is linked to the error_page variable and cannot have publish or unpublish dates set!';
$_lang['resource_err_unpublish_siteunavailable'] = 'The resource is linked to the site_unavailable_page variable and cannot be unpublished!';
$_lang['resource_err_unpublish_siteunavailable_dates'] = 'The resource is linked to the site_unavailable_page variable and cannot have publish or unpublish dates set!';
+$_lang['resource_err_weblink_invalid'] = 'The weblink content “[[+content]]” provided in Resource id [[+id]] is invalid.';
$_lang['resource_err_weblink_target_nf'] = 'You cannot set a weblink to a resource that does not exist.';
$_lang['resource_err_weblink_target_self'] = 'You cannot set a weblink to itself.';
$_lang['resource_folder'] = 'Container';
diff --git a/core/src/Revolution/Processors/Resource/Delete.php b/core/src/Revolution/Processors/Resource/Delete.php
index 657fec1bf96..e7da82679a2 100644
--- a/core/src/Revolution/Processors/Resource/Delete.php
+++ b/core/src/Revolution/Processors/Resource/Delete.php
@@ -1,4 +1,5 @@
getProperty('id', false);
- if (empty($id)) return $this->modx->lexicon('resource_err_ns');
+ if (empty($id)) {
+ return $this->modx->lexicon('resource_err_ns');
+ }
$this->resource = $this->modx->getObject(modResource::class, $id);
- if (empty($this->resource)) return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
+ if (empty($this->resource)) {
+ return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
+ }
/* validate resource can be deleted */
- if (!$this->checkActionPermission($this->resource->get('class_key'), 'delete')
- || !$this->resource->checkPolicy(['save' => true, 'delete' => true])) {
+ if (
+ !$this->checkActionPermission($this->resource->get('class_key'), 'delete')
+ || !$this->resource->checkPolicy(['save' => true, 'delete' => true])
+ ) {
return $this->modx->lexicon('permission_denied');
}
$this->deletedTime = time();
@@ -121,6 +128,7 @@ public function process()
]);
$outputArray['deletedCount'] = $deletedCount;
+ $outputArray['preview_url'] = $this->resource->getPreviewUrl();
return $this->success('', $outputArray);
}
diff --git a/core/src/Revolution/Processors/Resource/GetNodes.php b/core/src/Revolution/Processors/Resource/GetNodes.php
index df463964942..ce23ba8ae0f 100644
--- a/core/src/Revolution/Processors/Resource/GetNodes.php
+++ b/core/src/Revolution/Processors/Resource/GetNodes.php
@@ -1,4 +1,5 @@
getProperty('stringLiterals', false)) {
return $this->modx->toJSON($this->items);
}
-
return $this->toJSON($this->items);
} catch (xPDOException $e) {
$this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to encode JSON. ' . $e->getMessage());
@@ -129,7 +129,6 @@ public function prepare()
'new_weblink' => $this->modx->hasPermission('new_weblink') ? 'pnew pnew_modWebLink' : '',
'new_document' => $this->modx->hasPermission('new_document') ? 'pnew pnew_modDocument' : '',
];
-
}
/**
@@ -414,26 +413,52 @@ public function prepareResourceNode(modResource $resource)
$class = array_merge($class, $resource->getStatusClasses());
- if (!empty($this->permissions['save_document'])) $class[] = $this->permissions['save_document'];
- if (!empty($this->permissions['view_document'])) $class[] = $this->permissions['view_document'];
- if (!empty($this->permissions['edit_document'])) $class[] = $this->permissions['edit_document'];
+ if (!empty($this->permissions['save_document'])) {
+ $class[] = $this->permissions['save_document'];
+ }
+ if (!empty($this->permissions['view_document'])) {
+ $class[] = $this->permissions['view_document'];
+ }
+ if (!empty($this->permissions['edit_document'])) {
+ $class[] = $this->permissions['edit_document'];
+ }
if (!empty($this->permissions['resource_duplicate'])) {
if ($resource->parent != $this->defaultRootId || $this->modx->hasPermission('new_document_in_root')) {
$class[] = $this->permissions['resource_duplicate'];
}
}
if ($resource->allowChildrenResources && !$resource->deleted) {
- if (!empty($this->permissions['new_document'])) $class[] = $this->permissions['new_document'];
- if (!empty($this->permissions['new_symlink'])) $class[] = $this->permissions['new_symlink'];
- if (!empty($this->permissions['new_weblink'])) $class[] = $this->permissions['new_weblink'];
- if (!empty($this->permissions['new_static_resource'])) $class[] = $this->permissions['new_static_resource'];
- if (!empty($this->permissions['resource_quick_create'])) $class[] = $this->permissions['resource_quick_create'];
+ if (!empty($this->permissions['new_document'])) {
+ $class[] = $this->permissions['new_document'];
+ }
+ if (!empty($this->permissions['new_symlink'])) {
+ $class[] = $this->permissions['new_symlink'];
+ }
+ if (!empty($this->permissions['new_weblink'])) {
+ $class[] = $this->permissions['new_weblink'];
+ }
+ if (!empty($this->permissions['new_static_resource'])) {
+ $class[] = $this->permissions['new_static_resource'];
+ }
+ if (!empty($this->permissions['resource_quick_create'])) {
+ $class[] = $this->permissions['resource_quick_create'];
+ }
+ }
+ if (!empty($this->permissions['resource_quick_update'])) {
+ $class[] = $this->permissions['resource_quick_update'];
+ }
+ if (!empty($this->permissions['delete_document'])) {
+ $class[] = $this->permissions['delete_document'];
+ }
+ if (!empty($this->permissions['undelete_document'])) {
+ $class[] = $this->permissions['undelete_document'];
+ }
+ if (!empty($this->permissions['publish_document'])) {
+ $class[] = $this->permissions['publish_document'];
+ }
+ if (!empty($this->permissions['unpublish_document'])) {
+ $class[] = $this->permissions['unpublish_document'];
}
- if (!empty($this->permissions['resource_quick_update'])) $class[] = $this->permissions['resource_quick_update'];
- if (!empty($this->permissions['delete_document'])) $class[] = $this->permissions['delete_document'];
- if (!empty($this->permissions['undelete_document'])) $class[] = $this->permissions['undelete_document'];
- if (!empty($this->permissions['publish_document'])) $class[] = $this->permissions['publish_document'];
- if (!empty($this->permissions['unpublish_document'])) $class[] = $this->permissions['unpublish_document'];
$active = false;
if ($this->getProperty('currentResource') == $resource->id && $this->getProperty('currentAction') === 'resource/update') {
@@ -469,12 +494,6 @@ public function prepareResourceNode(modResource $resource)
// Add the ID to the item text if the user has the permission
$idNote = $this->modx->hasPermission('tree_show_resource_ids') ? ' (' . $resource->id . ')' : '';
- // Used in the preview_url, if sessions are disabled on the resource context we add an extra url param
- $sessionEnabled = '';
- if ($ctxSetting = $this->modx->getObject(modContextSetting::class, ['context_key' => $resource->get('context_key'), 'key' => 'session_enabled'])) {
- $sessionEnabled = $ctxSetting->get('value') == 0 ? ['preview' => 'true'] : '';
- }
-
$text = $resource->get($nodeField);
if (empty($text)) {
$text = $resource->get($nodeFieldFallback);
@@ -495,7 +514,7 @@ public function prepareResourceNode(modResource $resource)
'hasChildren' => $hasChildren,
'hide_children_in_tree' => $resource->hide_children_in_tree,
'qtip' => $qtip,
- 'preview_url' => (!$resource->get('deleted')) ? $this->modx->makeUrl($resource->get('id'), $resource->get('context_key'), $sessionEnabled, 'full', ['xhtml_urls' => false]) : '',
+ 'preview_url' => $resource->getPreviewUrl(),
'page' => empty($noHref) ? '?a=' . (!empty($this->permissions['edit_document']) ? 'resource/update' : 'resource/data') . '&id=' . $resource->id : '',
'allowDrop' => true,
];
diff --git a/core/src/Revolution/Processors/Resource/Undelete.php b/core/src/Revolution/Processors/Resource/Undelete.php
index d236364916a..2f25720ab74 100644
--- a/core/src/Revolution/Processors/Resource/Undelete.php
+++ b/core/src/Revolution/Processors/Resource/Undelete.php
@@ -1,4 +1,5 @@
getProperty('id', false);
- if (empty($id)) return $this->modx->lexicon('resource_err_ns');
+ if (empty($id)) {
+ return $this->modx->lexicon('resource_err_ns');
+ }
$this->resource = $this->modx->getObject(modResource::class, $id);
- if (empty($this->resource)) return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
+ if (empty($this->resource)) {
+ return $this->modx->lexicon('resource_err_nfs', ['id' => $id]);
+ }
/* check permissions on the resource */
if (!$this->resource->checkPolicy(['save' => 1, 'undelete' => 1])) {
@@ -83,6 +88,7 @@ public function process()
$outputArray = $this->resource->get(['id']);
$outputArray['deletedCount'] = $deletedCount;
+ $outputArray['preview_url'] = $this->resource->getPreviewUrl();
return $this->modx->error->success('', $outputArray);
}
diff --git a/core/src/Revolution/Processors/Resource/Update.php b/core/src/Revolution/Processors/Resource/Update.php
index 6baed8f837b..04a7c489ca3 100644
--- a/core/src/Revolution/Processors/Resource/Update.php
+++ b/core/src/Revolution/Processors/Resource/Update.php
@@ -935,10 +935,7 @@ public function cleanup()
$this->modx->reloadContext($this->workingContext->key);
}
- $returnArray['preview_url'] = '';
- if (!$this->object->get('deleted')) {
- $returnArray['preview_url'] = $this->modx->makeUrl($this->object->get('id'), $this->object->get('context_key'), '', 'full');
- }
+ $returnArray['preview_url'] = $this->object->getPreviewUrl();
return $this->success('', $returnArray);
}
diff --git a/core/src/Revolution/modResource.php b/core/src/Revolution/modResource.php
index 45cbe93c9ed..8dea54a046c 100644
--- a/core/src/Revolution/modResource.php
+++ b/core/src/Revolution/modResource.php
@@ -4,6 +4,7 @@
use MODX\Revolution\Registry\modDbRegister;
use MODX\Revolution\Registry\modRegistry;
+use MODX\Revolution\modX;
use PDO;
use ReflectionClass;
use ReflectionException;
@@ -178,17 +179,20 @@ public static function filterPathSegment(&$xpdo, $segment, array $options = [])
{
/* setup the various options */
$iconv = function_exists('iconv');
- $mbext = function_exists('mb_strlen') && (boolean)$xpdo->getOption('use_multibyte', $options, false);
+ $mbext = function_exists('mb_strlen') && (bool)$xpdo->getOption('use_multibyte', $options, false);
$charset = strtoupper((string)$xpdo->getOption('modx_charset', $options, 'UTF-8'));
$delimiter = $xpdo->getOption('friendly_alias_word_delimiter', $options, '-');
$delimiters = $xpdo->getOption('friendly_alias_word_delimiters', $options, '-_');
- $maxlength = (integer)$xpdo->getOption('friendly_alias_max_length', $options, 0);
- $stripElementTags = (boolean)$xpdo->getOption('friendly_alias_strip_element_tags', $options, true);
+ $maxlength = (int)$xpdo->getOption('friendly_alias_max_length', $options, 0);
+ $stripElementTags = (bool)$xpdo->getOption('friendly_alias_strip_element_tags', $options, true);
$trimchars = $xpdo->getOption('friendly_alias_trim_chars', $options, '/.' . $delimiters);
$restrictchars = $xpdo->getOption('friendly_alias_restrict_chars', $options, 'pattern');
- $restrictcharspattern = $xpdo->getOption('friendly_alias_restrict_chars_pattern', $options,
- '/[\0\x0B\t\n\r\f\a&=+%#<>"~`@\?\[\]\{\}\|\^\'\\\\]/');
- $lowercase = (boolean)$xpdo->getOption('friendly_alias_lowercase_only', $options, true);
+ $restrictcharspattern = $xpdo->getOption(
+ 'friendly_alias_restrict_chars_pattern',
+ $options,
+ '/[\0\x0B\t\n\r\f\a&=+%#<>"~`@\?\[\]\{\}\|\^\'\\\\]/'
+ );
+ $lowercase = (bool)$xpdo->getOption('friendly_alias_lowercase_only', $options, true);
$translit = $xpdo->getOption('friendly_alias_translit', $options, $iconv ? 'iconv' : 'none');
$translitClass = $xpdo->getOption('friendly_alias_translit_class', $options, 'translit.modTransliterate');
@@ -218,21 +222,21 @@ public static function filterPathSegment(&$xpdo, $segment, array $options = [])
break;
case 'iconv':
/* if iconv is available, use the built-in transliteration it provides */
- $segment = iconv($mbext ? mb_detect_encoding($segment) : $charset, $charset . '//TRANSLIT//IGNORE',
- $segment);
- $ampersand = iconv($mbext ? mb_detect_encoding($segment) : $charset, $charset . '//TRANSLIT//IGNORE',
- $ampersand);
+ $segment = iconv($mbext ? mb_detect_encoding($segment) : $charset, $charset . '//TRANSLIT//IGNORE', $segment);
+ $ampersand = iconv($mbext ? mb_detect_encoding($segment) : $charset, $charset . '//TRANSLIT//IGNORE', $ampersand);
break;
case 'iconv_ascii':
/* if iconv is available, use the built-in transliteration to ASCII it provides */
- $segment = iconv(($mbext) ? mb_detect_encoding($segment) : $charset, 'ASCII//TRANSLIT//IGNORE',
- $segment);
+ $segment = iconv(($mbext) ? mb_detect_encoding($segment) : $charset, 'ASCII//TRANSLIT//IGNORE', $segment);
break;
default:
/* otherwise look for a transliteration service class that will accept named transliteration tables */
if ($xpdo instanceof modX) {
- $translitClassPath = $xpdo->getOption('friendly_alias_translit_class_path', $options,
- $xpdo->getOption('core_path', $options, MODX_CORE_PATH) . 'components/');
+ $translitClassPath = $xpdo->getOption(
+ 'friendly_alias_translit_class_path',
+ $options,
+ $xpdo->getOption('core_path', $options, MODX_CORE_PATH) . 'components/'
+ );
if ($xpdo->getService('translit', $translitClass, $translitClassPath, $options)) {
$segment = $xpdo->translit->translate($segment, $translit);
$ampersand = $xpdo->translit->translate($ampersand, $translit);
@@ -394,7 +398,7 @@ public static function getTemplateVarCollection(modResource &$resource)
*/
public static function refreshURIs(modX &$modx, $parent = 0, array $options = [])
{
- $resetOverrides = array_key_exists('resetOverrides', $options) ? (boolean)$options['resetOverrides'] : false;
+ $resetOverrides = array_key_exists('resetOverrides', $options) ? (bool)$options['resetOverrides'] : false;
$contexts = array_key_exists('contexts', $options) ? explode(',', $options['contexts']) : null;
$criteria = $modx->newQuery(modResource::class, ['parent' => $parent]);
if (!$resetOverrides) {
@@ -437,21 +441,26 @@ public static function updateContextOfChildren(modX &$modx, $parent, array $opti
if ($child->save()) {
$count++;
} else {
- $modx->log(modX::LOG_LEVEL_ERROR, "Could not change Context of child resource {$child->get('id')}", '',
- __METHOD__, __FILE__, __LINE__);
+ $modx->log(
+ modX::LOG_LEVEL_ERROR,
+ "Could not change Context of child resource {$child->get('id')}",
+ '',
+ __METHOD__,
+ __FILE__,
+ __LINE__
+ );
}
}
-
return $count;
}
/**
* @param xPDO $xpdo A reference to the xPDO|modX instance
*/
- function __construct(xPDO & $xpdo)
+ public function __construct(xPDO &$xpdo)
{
parent:: __construct($xpdo);
- $this->_contextKey = isset ($this->xpdo->context) ? $this->xpdo->context->get('key') : 'web';
+ $this->_contextKey = isset($this->xpdo->context) ? $this->xpdo->context->get('key') : 'web';
$this->_cacheKey = "[contextKey]/resources/[id]";
}
@@ -481,6 +490,7 @@ public function process()
$this->xpdo->getParser();
/** @var modTemplate $baseElement */
if ($baseElement = $this->getOne('Template')) {
+ /** @disregard P1013 */
if ($baseElement->process()) {
$this->_content = $baseElement->_output;
$this->_processed = true;
@@ -488,12 +498,10 @@ public function process()
} else {
$this->_content = $this->getContent();
$maxIterations = intval($this->xpdo->getOption('parser_max_iterations', null, 10));
- $this->xpdo->parser->processElementTags('', $this->_content, false, false, '[[', ']]', [],
- $maxIterations);
+ $this->xpdo->parser->processElementTags('', $this->_content, false, false, '[[', ']]', [], $maxIterations);
$this->_processed = true;
}
}
-
return $this->_content;
}
@@ -613,6 +621,7 @@ public function getCacheKey($context = '')
*/
public function & getMany($alias, $criteria = null, $cacheFlag = false)
{
+ /** @disregard P1006 */
if ($alias === 'TemplateVars' || $alias === 'modTemplateVar' && ($criteria === null || strtolower($criteria) === 'all')) {
$collection = $this->getTemplateVars();
} else {
@@ -643,7 +652,7 @@ public function getTemplateVars()
public function set($k, $v = null, $vType = '')
{
switch ($k) {
- case 'alias' :
+ case 'alias':
$v = $this->cleanAlias($v);
break;
}
@@ -735,7 +744,7 @@ public function getProcessed()
*/
public function setProcessed($processed)
{
- $this->_processed = (boolean)$processed;
+ $this->_processed = (bool)$processed;
}
/**
@@ -758,8 +767,11 @@ public function addLock($user = 0, array $options = [])
$lockedBy = $this->getLock();
if (empty($lockedBy) || ($lockedBy == $user)) {
$this->xpdo->registry->locks->subscribe('/resource/');
- $this->xpdo->registry->locks->send('/resource/', [md5($this->get('id')) => $user],
- ['ttl' => $this->xpdo->getOption('lock_ttl', $options, 360)]);
+ $this->xpdo->registry->locks->send(
+ '/resource/',
+ [md5($this->get('id')) => $user],
+ ['ttl' => $this->xpdo->getOption('lock_ttl', $options, 360)]
+ );
$locked = true;
} elseif ($lockedBy != $user) {
$locked = $lockedBy;
@@ -835,9 +847,9 @@ public function findPolicy($context = '')
$enabled = true;
$context = !empty($context) ? $context : $this->xpdo->context->get('key');
if ($context === $this->xpdo->context->get('key')) {
- $enabled = (boolean)$this->xpdo->getOption('access_resource_group_enabled', null, true);
+ $enabled = (bool)$this->xpdo->getOption('access_resource_group_enabled', null, true);
} elseif ($this->xpdo->getContext($context)) {
- $enabled = (boolean)$this->xpdo->contexts[$context]->getOption('access_resource_group_enabled', true);
+ $enabled = (bool)$this->xpdo->contexts[$context]->getOption('access_resource_group_enabled', true);
}
if ($enabled) {
if (empty($this->_policies) || !isset($this->_policies[$context])) {
@@ -911,7 +923,7 @@ public function getTVValue($pk)
} else {
$tv = $this->xpdo->getObject(modTemplateVar::class, $byName ? ['name' => $pk] : $pk);
}
-
+ /** @disregard P1013 */
return $tv == null ? null : $tv->renderOutput($this->get('id'));
}
@@ -977,7 +989,7 @@ public function getAliasPath($alias = '', array $fields = [])
$isHtml = (strpos($contentType->get('mime_type'), 'html') !== false);
}
/* set extension to container suffix if Resource is a folder, HTML content type, and the container suffix is set */
- if (!empty($fields['isfolder']) && $isHtml && !empty ($containerSuffix)) {
+ if (!empty($fields['isfolder']) && $isHtml && !empty($containerSuffix)) {
$extension = $containerSuffix;
}
$aliasPath = '';
@@ -987,8 +999,14 @@ public function getAliasPath($alias = '', array $fields = [])
$pathParentId = $fields['parent'];
$parentResources = [];
$query = $this->xpdo->newQuery(modResource::class);
- $query->select($this->xpdo->getSelectColumns(modResource::class, '', '',
- ['parent', 'alias', 'alias_visible', 'uri', 'uri_override']));
+ $query->select(
+ $this->xpdo->getSelectColumns(
+ modResource::class,
+ '',
+ '',
+ ['parent', 'alias', 'alias_visible', 'uri', 'uri_override']
+ )
+ );
$query->where("{$this->xpdo->escape('id')} = ?");
$query->prepare();
$query->stmt->execute([$pathParentId]);
@@ -1004,7 +1022,7 @@ public function getAliasPath($alias = '', array $fields = [])
}
$parentAlias = $currResource['alias'];
- if (empty ($parentAlias)) {
+ if (empty($parentAlias)) {
$parentAlias = "{$pathParentId}";
}
@@ -1018,7 +1036,7 @@ public function getAliasPath($alias = '', array $fields = [])
$query->stmt->execute([$pathParentId]);
$currResource = $query->stmt->fetch(PDO::FETCH_ASSOC);
}
- $aliasPath = !empty ($parentResources) ? implode('/', array_reverse($parentResources)) : '';
+ $aliasPath = !empty($parentResources) ? implode('/', array_reverse($parentResources)) : '';
if (strlen($aliasPath) > 0 && $aliasPath[strlen($aliasPath) - 1] !== '/') {
$aliasPath .= '/';
}
@@ -1059,7 +1077,7 @@ public function isDuplicateAlias($aliasPath = '', $contextKey = '')
$criteria->prepare();
$duplicate = $this->xpdo->getValue($criteria->stmt);
- return $duplicate > 0 ? (integer)$duplicate : false;
+ return $duplicate > 0 ? (int)$duplicate : false;
}
/**
@@ -1077,10 +1095,12 @@ public function duplicate(array $options = [])
/* duplicate resource */
$prefixDuplicate = !empty($options['prefixDuplicate']) ? true : false;
- $newName = !empty($options['newName']) ? $options['newName'] : ($prefixDuplicate ? $this->xpdo->lexicon('duplicate_of',
- [
- 'name' => $this->get('pagetitle'),
- ]) : $this->get('pagetitle'));
+ $newName = !empty($options['newName'])
+ ? $options['newName']
+ : ($prefixDuplicate
+ ? $this->xpdo->lexicon('duplicate_of', ['name' => $this->get('pagetitle')])
+ : $this->get('pagetitle'))
+ ;
/** @var modResource $newResource */
$newResource = $this->xpdo->newObject($this->get('class_key'));
$newResource->fromArray($this->toArray('', true), '', false, true);
@@ -1127,8 +1147,10 @@ public function duplicate(array $options = [])
if (!($preserve_alias)) {
/* auto assign alias */
$aliasPath = $newResource->getAliasPath($newName);
- $dupeContext = $this->xpdo->getOption('global_duplicate_uri_check', $options,
- false) ? '' : $newResource->get('context_key');
+ $dupeContext = $this->xpdo->getOption('global_duplicate_uri_check', $options, false)
+ ? ''
+ : $newResource->get('context_key')
+ ;
if ($newResource->isDuplicateAlias($aliasPath, $dupeContext)) {
$alias = '';
if ($newResource->get('uri_override')) {
@@ -1203,9 +1225,7 @@ public function duplicate(array $options = [])
}
}
}
-
return $newResource;
-
}
/**
@@ -1242,9 +1262,10 @@ public function joinGroup($resourceGroupPk, $byName = false)
}
if ($this->isMember($resourceGroup->get('name'))) {
- $this->xpdo->log(modX::LOG_LEVEL_ERROR,
- __METHOD__ . ' - Resource ' . $this->get('id') . ' already in resource group: ' . $resourceGroupPk);
-
+ $this->xpdo->log(
+ modX::LOG_LEVEL_ERROR,
+ __METHOD__ . ' - Resource ' . $this->get('id') . ' already in resource group: ' . $resourceGroupPk
+ );
return false;
}
/** @var modResourceGroupResource $resourceGroupResource */
@@ -1273,9 +1294,10 @@ public function leaveGroup($resourceGroupPk)
/** @var modResourceGroup $resourceGroup */
$resourceGroup = $this->xpdo->getObject(modResourceGroup::class, $c);
if (empty($resourceGroup) || !is_object($resourceGroup) || !($resourceGroup instanceof modResourceGroup)) {
- $this->xpdo->log(modX::LOG_LEVEL_ERROR,
- __METHOD__ . ' - No resource group: ' . (is_object($resourceGroupPk) ? $resourceGroupPk->get('name') : $resourceGroupPk));
-
+ $this->xpdo->log(
+ modX::LOG_LEVEL_ERROR,
+ __METHOD__ . ' - No resource group: ' . (is_object($resourceGroupPk) ? $resourceGroupPk->get('name') : $resourceGroupPk)
+ );
return false;
}
} else {
@@ -1283,9 +1305,10 @@ public function leaveGroup($resourceGroupPk)
}
if (!$this->isMember($resourceGroup->get('name'))) {
- $this->xpdo->log(modX::LOG_LEVEL_ERROR,
- __METHOD__ . ' - Resource ' . $this->get('id') . ' is not in resource group: ' . (is_object($resourceGroupPk) ? $resourceGroupPk->get('name') : $resourceGroupPk));
-
+ $this->xpdo->log(
+ modX::LOG_LEVEL_ERROR,
+ __METHOD__ . ' - Resource ' . $this->get('id') . ' is not in resource group: ' . (is_object($resourceGroupPk) ? $resourceGroupPk->get('name') : $resourceGroupPk)
+ );
return false;
}
/** @var modResourceGroupResource $resourceGroupResource */
@@ -1321,8 +1344,11 @@ public function getResourceGroupNames()
{
$resourceGroupNames = [];
- $resourceGroups = $this->xpdo->getCollectionGraph(modResourceGroup::class, '{"ResourceGroupResources":{}}',
- ['ResourceGroupResources.document' => $this->get('id')]);
+ $resourceGroups = $this->xpdo->getCollectionGraph(
+ modResourceGroup::class,
+ '{"ResourceGroupResources":{}}',
+ ['ResourceGroupResources.document' => $this->get('id')]
+ );
if ($resourceGroups) {
/** @var modResourceGroup $resourceGroup */
@@ -1443,8 +1469,10 @@ public function getProperty($key, $namespace = 'core', $default = null)
$properties = $this->get('properties');
$properties = !empty($properties) ? $properties : [];
- return array_key_exists($namespace, $properties) && array_key_exists($key,
- $properties[$namespace]) ? $properties[$namespace][$key] : $default;
+ return array_key_exists($namespace, $properties) && array_key_exists($key, $properties[$namespace])
+ ? $properties[$namespace][$key]
+ : $default
+ ;
}
/**
@@ -1517,16 +1545,31 @@ public function clearCache($context = '')
$cache = $this->xpdo->cacheManager->getCacheProvider(
$this->xpdo->getOption('cache_resource_key', null, 'resource'),
[
- xPDO::OPT_CACHE_HANDLER => $this->xpdo->getOption('cache_resource_handler', null,
- $this->xpdo->getOption(xPDO::OPT_CACHE_HANDLER, null, 'xPDO\Cache\xPDOFileCache')),
- xPDO::OPT_CACHE_EXPIRES => (integer)$this->xpdo->getOption('cache_resource_expires', null,
- $this->xpdo->getOption(xPDO::OPT_CACHE_EXPIRES, null, 0)),
- xPDO::OPT_CACHE_FORMAT => (integer)$this->xpdo->getOption('cache_resource_format', null,
- $this->xpdo->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)),
- xPDO::OPT_CACHE_ATTEMPTS => (integer)$this->xpdo->getOption('cache_resource_attempts', null,
- $this->xpdo->getOption(xPDO::OPT_CACHE_ATTEMPTS, null, 10)),
- xPDO::OPT_CACHE_ATTEMPT_DELAY => (integer)$this->xpdo->getOption('cache_resource_attempt_delay', null,
- $this->xpdo->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, null, 1000)),
+ xPDO::OPT_CACHE_HANDLER => $this->xpdo->getOption(
+ 'cache_resource_handler',
+ null,
+ $this->xpdo->getOption(xPDO::OPT_CACHE_HANDLER, null, 'xPDO\Cache\xPDOFileCache')
+ ),
+ xPDO::OPT_CACHE_EXPIRES => (int)$this->xpdo->getOption(
+ 'cache_resource_expires',
+ null,
+ $this->xpdo->getOption(xPDO::OPT_CACHE_EXPIRES, null, 0)
+ ),
+ xPDO::OPT_CACHE_FORMAT => (int)$this->xpdo->getOption(
+ 'cache_resource_format',
+ null,
+ $this->xpdo->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)
+ ),
+ xPDO::OPT_CACHE_ATTEMPTS => (int)$this->xpdo->getOption(
+ 'cache_resource_attempts',
+ null,
+ $this->xpdo->getOption(xPDO::OPT_CACHE_ATTEMPTS, null, 10)
+ ),
+ xPDO::OPT_CACHE_ATTEMPT_DELAY => (int)$this->xpdo->getOption(
+ 'cache_resource_attempt_delay',
+ null,
+ $this->xpdo->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, null, 1000)
+ )
]
);
$key = $this->getCacheKey($context);
@@ -1621,4 +1664,141 @@ public function getStatusClasses()
return $classes;
}
+
+ /**
+ * Whether the target document exists and is available for preview
+ *
+ * @param int|string $targetId The id of the Resource to be previewed
+ * @param int|string|null $sourceId The id of the Resource from which the preview was requested
+ */
+ public function canPreviewResource($targetId, $sourceId = null): bool
+ {
+ if (strpos($targetId, 0) === 0) {
+ $msg = $this->xpdo->lexicon(
+ 'resource_err_preview_no_zero_id',
+ ['source_id' => $sourceId, 'target_id' => $targetId]
+ );
+ $this->xpdo->log(modX::LOG_LEVEL_ERROR, $msg);
+ return false;
+ }
+ $targetIsSelf = $sourceId === null || (int)$targetId === (int)$sourceId;
+ if ($doc = $this->xpdo->getObject('modResource', $targetId)) {
+ if (!$doc->deleted) {
+ return true;
+ }
+ $msg = $targetIsSelf
+ ? $this->xpdo->lexicon(
+ 'resource_err_preview_self_deleted',
+ ['target_id' => $targetId]
+ )
+ : $this->xpdo->lexicon(
+ 'resource_err_preview_target_deleted',
+ ['source_id' => $sourceId, 'target_id' => $targetId]
+ )
+ ;
+ $this->xpdo->log(modX::LOG_LEVEL_ERROR, $msg);
+ return false;
+ }
+ $msg = $targetIsSelf
+ ? $this->xpdo->lexicon(
+ 'resource_err_preview_self_not_found',
+ ['target_id' => $targetId]
+ )
+ : $this->xpdo->lexicon(
+ 'resource_err_preview_target_not_found',
+ ['source_id' => $sourceId, 'target_id' => $targetId]
+ )
+ ;
+ $this->xpdo->log(modX::LOG_LEVEL_ERROR, $msg);
+ return false;
+ }
+
+ /**
+ * Creates a full preview URL for the current or target (in the case of Weblinks) Resource
+ */
+ public function getPreviewUrl(): string
+ {
+ if ($this->get('deleted')) {
+ return '';
+ }
+ $contextKey = $this->get('context_key');
+ $id = $this->get('id');
+ $this->xpdo->setOption('cache_alias_map', false);
+
+ /** @var modContextSetting|null $ctxSetting */
+ $ctxSetting = $this->xpdo->getObject(
+ 'modContextSetting',
+ [
+ 'context_key' => $contextKey,
+ 'key' => 'session_enabled'
+ ]
+ );
+ $queryString = $ctxSetting && (int)$ctxSetting->get('value') === 0
+ ? ['preview' => true]
+ : ''
+ ;
+ $urlArgs = [
+ $id,
+ $contextKey,
+ $queryString,
+ 'full',
+ ['xhtml_urls' => false]
+ ];
+ $isWebLink = strpos($this->class_key, 'modWebLink') !== false;
+ $isSymLink = strpos($this->class_key, 'modSymLink') !== false;
+
+ $linkContent = '';
+ if ($isSymLink || $isWebLink) {
+ $linkContent = trim($this->getContent());
+ if (empty($linkContent)) {
+ return '';
+ }
+ }
+
+ // Symlinks can only contain integers
+ if ($isSymLink && preg_match('/^0|[^\d]/', $linkContent, $match)) {
+ return '';
+ }
+
+ if ($isWebLink) {
+ if (preg_match('/^(\[{2}~)?(\d+)(\]{2})?$/', $linkContent, $match)) {
+ // Found either a number or basic link tag, e.g. 45 or [[~45]]
+ $targetId = $match[2];
+ if (!$this->canPreviewResource($targetId, $id)) {
+ return '';
+ }
+ $urlArgs[0] = $targetId;
+ } elseif (strpos($linkContent, 'http') === 0) {
+ // Found URL, e.g., http[s]://www.mysite.com
+ return $linkContent;
+ } elseif (preg_match('/^\[{2}~(\d+)\s?\?([^[]*)\]{2}$/', $linkContent, $match)) {
+ // Link tag with options, e.g., [[~45? &scheme=`abs`]]
+ $targetId = $match[1];
+ if (!$this->canPreviewResource($targetId, $id)) {
+ return '';
+ }
+ $url = $this->parseContent();
+ if (!empty($url)) {
+ if (!empty($queryString)) {
+ $queryString = trim(modX::toQueryString($queryString), '?');
+ $url .= strpos($url, '?') === false ? '?' : '&' ;
+ $url .= $queryString;
+ }
+ // Back out any xhtml-encoded ampersands created in parseContent()
+ $url = str_replace('&', '&', $url);
+ $url = rtrim($url, '&');
+ }
+ return $url;
+ } else {
+ // Invalid link data
+ $msg = $this->xpdo->lexicon(
+ 'resource_err_weblink_invalid',
+ ['id' => $id, 'content' => $linkContent]
+ );
+ $this->xpdo->log(modX::LOG_LEVEL_ERROR, $msg);
+ return '';
+ }
+ }
+ return $this->xpdo->makeUrl(...$urlArgs);
+ }
}
diff --git a/manager/assets/modext/sections/resource/symlink/update.js b/manager/assets/modext/sections/resource/symlink/update.js
index 38254f65df0..e708e8a1417 100644
--- a/manager/assets/modext/sections/resource/symlink/update.js
+++ b/manager/assets/modext/sections/resource/symlink/update.js
@@ -6,20 +6,21 @@
* @param {Object} config An object of config properties
* @xtype modx-page-symlink-update
*/
-MODx.page.UpdateSymLink = function(config) {
- config = config || {};
- Ext.applyIf(config,{
+MODx.page.UpdateSymLink = function(config = {}) {
+ Ext.applyIf(config, {
components: [{
- xtype: 'modx-panel-symlink'
- ,renderTo: 'modx-panel-symlink-div'
- ,resource: config.resource
- ,record: config.record || {}
- ,publish_document: config.publish_document
- ,show_tvs: config.show_tvs
- ,url: config.url
+ xtype: 'modx-panel-symlink',
+ renderTo: 'modx-panel-symlink-div',
+ resource: config.resource,
+ record: config.record || {},
+ publish_document: config.publish_document,
+ show_tvs: config.show_tvs,
+ url: config.url,
+ canDelete: config.canDelete,
+ locked: config.locked
}]
});
- MODx.page.UpdateSymLink.superclass.constructor.call(this,config);
+ MODx.page.UpdateSymLink.superclass.constructor.call(this, config);
};
-Ext.extend(MODx.page.UpdateSymLink,MODx.page.UpdateResource);
-Ext.reg('modx-page-symlink-update',MODx.page.UpdateSymLink);
+Ext.extend(MODx.page.UpdateSymLink, MODx.page.UpdateResource);
+Ext.reg('modx-page-symlink-update', MODx.page.UpdateSymLink);
diff --git a/manager/assets/modext/sections/resource/update.js b/manager/assets/modext/sections/resource/update.js
index 9a54b772e2a..87d634bc18e 100644
--- a/manager/assets/modext/sections/resource/update.js
+++ b/manager/assets/modext/sections/resource/update.js
@@ -7,132 +7,137 @@
* @xtype modx-page-resource-update
*/
MODx.page.UpdateResource = function(config) {
- config = config || {record:{}};
+ config = config || { record: {} };
config.record = config.record || {};
- Ext.apply(config.record,{
- 'parent-cmb': config.record['parent']
+ Ext.apply(config.record, {
+ 'parent-cmb': config.record.parent
});
- Ext.applyIf(config,{
- url: MODx.config.connector_url
- ,which_editor: 'none'
- ,formpanel: 'modx-panel-resource'
- ,id: 'modx-page-update-resource'
- ,action: 'Resource/Update'
- ,components: [{
- xtype: config.panelXType || 'modx-panel-resource'
- ,renderTo: config.panelRenderTo || 'modx-panel-resource-div'
- ,resource: config.resource
- ,record: config.record || {}
- ,publish_document: config.publish_document
- ,show_tvs: config.show_tvs
- ,mode: config.mode
- ,url: config.url
- ,canDelete: config.canDelete
- ,locked: config.locked
- }]
- ,buttons: this.getButtons(config)
+ Ext.applyIf(config, {
+ url: MODx.config.connector_url,
+ which_editor: 'none',
+ formpanel: 'modx-panel-resource',
+ id: 'modx-page-update-resource',
+ action: 'Resource/Update',
+ components: [{
+ xtype: config.panelXType || 'modx-panel-resource',
+ renderTo: config.panelRenderTo || 'modx-panel-resource-div',
+ resource: config.resource,
+ record: config.record || {},
+ publish_document: config.publish_document,
+ show_tvs: config.show_tvs,
+ mode: config.mode,
+ url: config.url,
+ canDelete: config.canDelete,
+ locked: config.locked
+ }],
+ buttons: this.getButtons(config)
});
- MODx.page.UpdateResource.superclass.constructor.call(this,config);
+ MODx.page.UpdateResource.superclass.constructor.call(this, config);
if (!Ext.isIE) {
- Ext.EventManager.on(window, 'beforeunload',function(e) {
+ Ext.EventManager.on(window, 'beforeunload', function(e) {
MODx.releaseLock(this.config.resource);
MODx.sleep(400);
return false;
}, this);
}
new Ext.KeyMap(Ext.getBody(), {
- key: 'p'
- ,alt: true
- ,ctrl: true
- ,fn: this.preview
- ,scope: this
+ key: 'p',
+ alt: true,
+ ctrl: true,
+ fn: this.preview,
+ scope: this
});
};
-Ext.extend(MODx.page.UpdateResource,MODx.Component,{
+Ext.extend(MODx.page.UpdateResource, MODx.Component, {
preview: function() {
window.open(this.config.preview_url);
return false;
- }
-
- ,duplicateResource: function(btn,e) {
- var t = Ext.getCmp('modx-resource-tree');
- var id = this.config.resource;
- var node = t.getNodeById(this.config.record.context_key + '_' + id);
-
- var r = {
- resource: id
- ,pagetitle: this.config.record.pagetitle
- ,hasChildren: false
- ,is_folder: this.config.record.isfolder
- };
+ },
+ duplicateResource: function(btn, e) {
+ const
+ tree = Ext.getCmp('modx-resource-tree'),
+ id = this.config.resource,
+ node = tree.getNodeById(`${this.config.record.context_key}_${id}`),
+ data = {
+ resource: id,
+ pagetitle: this.config.record.pagetitle,
+ hasChildren: false,
+ is_folder: this.config.record.isfolder
+ }
+ ;
if (node) {
- r.pagetitle = node.ui.textNode.innerText;
- r.hasChildren = node.attributes.hasChildren;
- r.childCount = node.attributes.childCount;
- r.is_folder = node.getUI().hasClass('folder');
+ data.pagetitle = node.ui.textNode.innerText;
+ data.hasChildren = node.attributes.hasChildren;
+ data.childCount = node.attributes.childCount;
+ data.is_folder = node.getUI().hasClass('folder');
}
- var w = MODx.load({
- xtype: 'modx-window-resource-duplicate'
- ,resource: id
- ,pagetitle: r.pagetitle
- ,hasChildren: r.hasChildren
- ,childCount: r.childCount
- ,redirect: true
- ,listeners: {
- success: {fn:function(r) {
- var response = Ext.decode(r.a.response.responseText);
- if (response.object.redirect) {
- MODx.loadPage('resource/update', 'id='+response.object.id);
- } else if (node) {
- node.parentNode.attributes.childCount = parseInt(node.parentNode.attributes.childCount) + 1;
- t.refreshNode(node.id);
- }
- },scope:this}
+ const window = MODx.load({
+ xtype: 'modx-window-resource-duplicate',
+ resource: id,
+ pagetitle: data.pagetitle,
+ hasChildren: data.hasChildren,
+ childCount: data.childCount,
+ redirect: true,
+ listeners: {
+ success: {
+ fn: function(response) {
+ const responseData = Ext.decode(response.a.response.responseText);
+ if (responseData.object.redirect) {
+ MODx.loadPage('resource/update', `id=${responseData.object.id}`);
+ } else if (node) {
+ node.parentNode.attributes.childCount = parseInt(node.parentNode.attributes.childCount, 10) + 1;
+ tree.refreshNode(node.id);
+ }
+ },
+ scope: this
+ }
}
});
- w.setValues(r);
- w.show(e.target);
- }
+ window.setValues(data);
+ window.show(e.target);
+ },
- ,deleteResource: function(btn,e) {
+ deleteResource: function(btn, e) {
MODx.msg.confirm({
- text: _('resource_delete_confirm',{
- resource: Ext.util.Format.htmlEncode(this.config.record.pagetitle) + ' ('+ this.config.resource + ')'
- })
- ,url: MODx.config.connector_url
- ,params: {
- action: 'Resource/Delete'
- ,id: this.config.resource
- }
- ,listeners: {
- success: {fn:function(r) {
- const panel = Ext.getCmp('modx-panel-resource');
- if (panel) {
- panel.handlePreview(true);
- panel.handleDeleted(true);
- }
-
- Ext.getCmp('modx-resource-tree')?.refresh();
- Ext.getCmp('modx-trash-link')?.updateState(+r.object.deletedCount);
- },scope:this}
+ text: _('resource_delete_confirm', {
+ resource: `${Ext.util.Format.htmlEncode(this.config.record.pagetitle)} (${this.config.resource})`
+ }),
+ url: MODx.config.connector_url,
+ params: {
+ action: 'Resource/Delete',
+ id: this.config.resource
+ },
+ listeners: {
+ success: {
+ fn: function(response) {
+ const panel = Ext.getCmp('modx-panel-resource');
+ if (panel) {
+ panel.updatePreviewButton(response.object);
+ panel.handleDeleted(true);
+ }
+ Ext.getCmp('modx-resource-tree')?.refresh();
+ Ext.getCmp('modx-trash-link')?.updateState(+response.object.deletedCount);
+ },
+ scope: this
+ }
}
});
- }
+ },
- ,unDeleteResource: function() {
+ unDeleteResource: function() {
MODx.Ajax.request({
url: MODx.config.connector_url,
params: {
action: 'Resource/Undelete',
- id: this.config.resource,
+ id: this.config.resource
},
listeners: {
success: {
- fn: function(r) {
+ fn: function(response) {
const panel = Ext.getCmp('modx-panel-resource');
if (panel) {
- panel.handlePreview(false);
+ panel.updatePreviewButton(response.object);
panel.handleDeleted(false);
}
@@ -140,24 +145,23 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{
if (tree?.rendered) {
tree.refresh();
}
-
- Ext.getCmp('modx-trash-link')?.updateState(+r.object.deletedCount);
+ Ext.getCmp('modx-trash-link')?.updateState(+response.object.deletedCount);
},
- scope: this,
+ scope: this
}
}
});
- }
+ },
- ,purgeResource: function() {
+ purgeResource: function() {
MODx.msg.confirm({
text: _('resource_purge_confirm', {
- resource: Ext.util.Format.htmlEncode(this.config.record.pagetitle) + ' ('+ this.config.resource + ')'
+ resource: `${Ext.util.Format.htmlEncode(this.config.record.pagetitle)} (${this.config.resource})`
}),
url: MODx.config.connector_url,
params: {
action: 'Resource/Trash/Purge',
- ids: this.config.resource,
+ ids: this.config.resource
},
listeners: {
success: {
@@ -166,106 +170,107 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{
fp.warnUnsavedChanges = false;
MODx.loadPage('?');
},
- scope: this,
- },
- },
+ scope: this
+ }
+ }
});
- }
+ },
- ,cancel: function(btn,e) {
- var fp = Ext.getCmp(this.config.formpanel);
+ cancel: function(btn, e) {
+ const fp = Ext.getCmp(this.config.formpanel);
if (fp && fp.isDirty()) {
- Ext.Msg.confirm(_('warning'),_('resource_cancel_dirty_confirm'),function(e) {
- if (e == 'yes') {
+ Ext.Msg.confirm(_('warning'), _('resource_cancel_dirty_confirm'), function(event) {
+ if (event === 'yes') {
fp.warnUnsavedChanges = false;
MODx.releaseLock(MODx.request.id);
MODx.sleep(400);
MODx.loadPage('?');
}
- },this);
+ }, this);
} else {
MODx.releaseLock(MODx.request.id);
MODx.loadPage('?');
}
- }
+ },
- ,getButtons: function(config) {
- var buttons = [{
- process: 'Resource/Update'
- ,text: _('save')
- ,id: 'modx-abtn-save'
- ,cls: 'primary-button'
- ,method: 'remote'
- ,hidden: !(config.canSave == 1)
- ,keys: [{
- key: MODx.config.keymap_save || 's'
- ,ctrl: true
+ getButtons: function(config) {
+ const buttons = [{
+ process: 'Resource/Update',
+ text: _('save'),
+ id: 'modx-abtn-save',
+ cls: 'primary-button',
+ method: 'remote',
+ hidden: !(config.canSave === 1),
+ keys: [{
+ key: MODx.config.keymap_save || 's',
+ ctrl: true
}]
- },{
- text: (config.lockedText || '')
- ,id: 'modx-abtn-locked'
- ,handler: Ext.emptyFn
- ,hidden: (config.canSave == 1)
- ,disabled: true
+ }, {
+ text: (config.lockedText || ''),
+ id: 'modx-abtn-locked',
+ handler: Ext.emptyFn,
+ hidden: (config.canSave === 1),
+ disabled: true
}];
- if (config.canDuplicate == 1 && (config.record.parent !== parseInt(MODx.config.tree_root_id) || config.canCreateRoot == 1)) {
+ if (config.canDuplicate === 1 && (config.record.parent !== parseInt(MODx.config.tree_root_id, 10) || config.canCreateRoot === 1)) {
buttons.push({
- text: _('duplicate')
- ,id: 'modx-abtn-duplicate'
- ,handler: this.duplicateResource
- ,scope: this
+ text: _('duplicate'),
+ id: 'modx-abtn-duplicate',
+ handler: this.duplicateResource,
+ scope: this
});
}
buttons.push({
- text: _('view')
- ,id: 'modx-abtn-preview'
- ,handler: this.preview
- ,hidden: config.record.deleted
- ,scope: this
- },{
- text: _('cancel')
- ,id: 'modx-abtn-cancel'
- ,handler: this.cancel
- ,scope: this
+ text: _('view'),
+ id: 'modx-abtn-preview',
+ handler: this.preview,
+ hidden: config.record.deleted,
+ disabled: !config.preview_url.startsWith('http'),
+ scope: this
+ }, {
+ text: _('cancel'),
+ id: 'modx-abtn-cancel',
+ handler: this.cancel,
+ scope: this
});
- if (config.canDelete == 1 && !config.locked) {
+ if (config.canDelete === 1 && !config.locked) {
buttons.push({
- text: ''
- ,id: 'modx-abtn-undelete'
- ,handler: this.unDeleteResource
- ,hidden: !config.record.deleted
- ,scope: this
+ text: '',
+ id: 'modx-abtn-undelete',
+ handler: this.unDeleteResource,
+ hidden: !config.record.deleted,
+ scope: this
});
buttons.push({
- text: ''
- ,id: 'modx-abtn-delete'
- ,handler: this.deleteResource
- ,hidden: config.record.deleted
- ,scope: this
+ text: '',
+ id: 'modx-abtn-delete',
+ handler: this.deleteResource,
+ hidden: config.record.deleted,
+ scope: this
});
}
- if (config.canPurge == 1 && !config.locked) {
+ if (config.canPurge === 1 && !config.locked) {
buttons.push({
text: '',
id: 'modx-abtn-purge',
handler: this.purgeResource,
hidden: !config.record.deleted,
- scope: this,
+ scope: this
});
}
buttons.push({
- text: ''
- ,id: 'modx-abtn-help'
- ,handler: MODx.loadHelpPane
+ text: '',
+ id: 'modx-abtn-help',
+ handler: MODx.loadHelpPane
});
return buttons;
}
});
-Ext.reg('modx-page-resource-update',MODx.page.UpdateResource);
+Ext.reg('modx-page-resource-update', MODx.page.UpdateResource);
diff --git a/manager/assets/modext/sections/resource/weblink/update.js b/manager/assets/modext/sections/resource/weblink/update.js
index a3f1113668f..0927badce18 100644
--- a/manager/assets/modext/sections/resource/weblink/update.js
+++ b/manager/assets/modext/sections/resource/weblink/update.js
@@ -6,20 +6,21 @@
* @param {Object} config An object of config properties
* @xtype modx-page-weblink-update
*/
-MODx.page.UpdateWebLink = function(config) {
- config = config || {};
- Ext.applyIf(config,{
+MODx.page.UpdateWebLink = function(config = {}) {
+ Ext.applyIf(config, {
components: [{
- xtype: 'modx-panel-weblink'
- ,renderTo: 'modx-panel-weblink-div'
- ,resource: config.resource
- ,record: config.record || {}
- ,publish_document: config.publish_document
- ,show_tvs: config.show_tvs
- ,url: config.url
+ xtype: 'modx-panel-weblink',
+ renderTo: 'modx-panel-weblink-div',
+ resource: config.resource,
+ record: config.record || {},
+ publish_document: config.publish_document,
+ show_tvs: config.show_tvs,
+ url: config.url,
+ canDelete: config.canDelete,
+ locked: config.locked
}]
});
- MODx.page.UpdateWebLink.superclass.constructor.call(this,config);
+ MODx.page.UpdateWebLink.superclass.constructor.call(this, config);
};
-Ext.extend(MODx.page.UpdateWebLink,MODx.page.UpdateResource);
-Ext.reg('modx-page-weblink-update',MODx.page.UpdateWebLink);
+Ext.extend(MODx.page.UpdateWebLink, MODx.page.UpdateResource);
+Ext.reg('modx-page-weblink-update', MODx.page.UpdateWebLink);
diff --git a/manager/assets/modext/widgets/resource/modx.panel.resource.js b/manager/assets/modext/widgets/resource/modx.panel.resource.js
index f596be17d07..6d47dd3a1ee 100644
--- a/manager/assets/modext/widgets/resource/modx.panel.resource.js
+++ b/manager/assets/modext/widgets/resource/modx.panel.resource.js
@@ -1,76 +1,83 @@
MODx.panel.Resource = function(config) {
- config = config || {record:{}};
+ config = config || { record: {} };
config.record = config.record || {};
config.default_title = config.default_title || _('document_new');
- Ext.applyIf(config,{
- url: MODx.config.connector_url
- ,baseParams: {}
- ,id: 'modx-panel-resource'
- ,class_key: 'MODX\\Revolution\\modDocument'
- ,resource: ''
- ,bodyStyle: ''
- ,cls: 'container form-with-labels'
- ,defaults: {
+ Ext.applyIf(config, {
+ url: MODx.config.connector_url,
+ baseParams: {},
+ id: 'modx-panel-resource',
+ class_key: 'MODX\\Revolution\\modDocument',
+ resource: '',
+ bodyStyle: '',
+ cls: 'container form-with-labels',
+ defaults: {
collapsible: false,
autoHeight: true
- }
- ,forceLayout: true
- ,items: this.getFields(config)
- ,fileUpload: true
- ,useLoadingMask: true
- ,listeners: {
- setup: {fn:this.setup,scope:this}
- ,success: {fn:this.success,scope:this}
- ,failure: {fn:this.failure,scope:this}
- ,beforeSubmit: {fn:this.beforeSubmit,scope:this}
- ,fieldChange: {fn:this.onFieldChange,scope:this}
- ,failureSubmit: {
- fn: function () {
- this.showErroredTab(this.errorHandlingTabs, 'modx-resource-tabs')
+ },
+ forceLayout: true,
+ items: this.getFields(config),
+ fileUpload: true,
+ useLoadingMask: true,
+ listeners: {
+ setup: { fn: this.setup, scope: this },
+ success: { fn: this.success, scope: this },
+ failure: { fn: this.failure, scope: this },
+ beforeSubmit: { fn: this.beforeSubmit, scope: this },
+ fieldChange: { fn: this.onFieldChange, scope: this },
+ failureSubmit: {
+ fn: function() {
+ this.showErroredTab(this.errorHandlingTabs, 'modx-resource-tabs');
},
scope: this
- }
+ }
}
});
- MODx.panel.Resource.superclass.constructor.call(this,config);
- var ta = Ext.get(this.contentField);
- if (ta) { ta.on('keydown',this.fieldChangeEvent,this); }
- this.on('ready',this.onReady,this);
- var urio = Ext.getCmp('modx-resource-uri-override');
- if (urio) { urio.on('check',this.freezeUri); }
+ MODx.panel.Resource.superclass.constructor.call(this, config);
+ const
+ contentEl = Ext.get(this.contentField),
+ uriOverrideCmp = Ext.getCmp('modx-resource-uri-override')
+ ;
+ if (contentEl) {
+ contentEl.on('keydown', this.fieldChangeEvent, this);
+ }
+ this.on('ready', this.onReady, this);
+ if (uriOverrideCmp) {
+ uriOverrideCmp.on('check', this.freezeUri);
+ }
this.addEvents('tv-reset');
};
-Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
-
- initialized: false
- ,defaultClassKey: 'MODX\\Revolution\\modDocument'
- ,classLexiconKey: 'document'
- ,rteElements: 'ta'
- ,rteLoaded: false
- ,contentField: 'ta'
- ,warnUnsavedChanges: false
+Ext.extend(MODx.panel.Resource, MODx.FormPanel, {
- ,setup: function() {
+ initialized: false,
+ defaultClassKey: 'MODX\\Revolution\\modDocument',
+ classLexiconKey: 'document',
+ rteElements: 'ta',
+ rteLoaded: false,
+ contentField: 'ta',
+ warnUnsavedChanges: false,
+ setup: function() {
if (!this.initialized) {
/*
The itemId (not id) of each form tab to be included/excluded; these correspond to the
keys in each tab component's items property
*/
- this.errorHandlingTabs = ['modx-resource-settings','modx-page-settings','modx-panel-resource-tv'];
+ this.errorHandlingTabs = ['modx-resource-settings', 'modx-page-settings', 'modx-panel-resource-tv'];
this.errorHandlingIgnoreTabs = ['modx-resource-access-permissions'];
this.getForm().setValues(this.config.record);
- var tpl = this.getForm().findField('modx-resource-template');
- if (tpl) {
- tpl.originalValue = this.config.record.template;
+ const
+ resourceTemplate = this.getForm().findField('modx-resource-template'),
+ parentFieldCmp = this.getForm().findField('parent-cmb')
+ ;
+ if (resourceTemplate) {
+ resourceTemplate.originalValue = this.config.record.template;
}
- var pcmb = this.getForm().findField('parent-cmb');
- if (pcmb && Ext.isEmpty(this.config.record.parent_pagetitle)) {
- pcmb.setValue('');
- } else if (pcmb) {
- pcmb.setValue(this.config.record.parent_pagetitle+' ('+this.config.record.parent+')');
+ if (parentFieldCmp && Ext.isEmpty(this.config.record.parent_pagetitle)) {
+ parentFieldCmp.setValue('');
+ } else if (parentFieldCmp) {
+ parentFieldCmp.setValue(`${this.config.record.parent_pagetitle} (${this.config.record.parent})`);
}
this.formatMainPanelTitle('resource', this.config.record);
@@ -81,9 +88,9 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
this.config.translitloading = false;
if (!Ext.isEmpty(this.config.record.resourceGroups)) {
- var g = Ext.getCmp('modx-grid-resource-security');
+ const g = Ext.getCmp('modx-grid-resource-security');
if (g && Ext.isEmpty(g.config.url)) {
- var s = g.getStore();
+ const s = g.getStore();
if (s) { s.loadData(this.config.record.resourceGroups); }
}
}
@@ -91,24 +98,26 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
this.defaultClassKey = this.config.record.class_key || this.defaultClassKey;
this.defaultValues = this.config.record || {};
- if ((this.config.record && this.config.record.richtext) || MODx.request.reload || MODx.request.activeSave == 1) {
+ if ((this.config.record && this.config.record.richtext) || MODx.request.reload || MODx.request.activeSave === 1) {
this.markDirty();
}
// Prevent accidental navigation when stuff has not been saved
- if (MODx.config.confirm_navigation == 1) {
- var panel = this;
+ if (MODx.config.confirm_navigation === 1) {
+ const panel = this;
window.onbeforeunload = function() {
- if (panel.warnUnsavedChanges) return _('unsaved_changes');
+ if (panel.warnUnsavedChanges) {
+ return _('unsaved_changes');
+ }
};
}
}
if (MODx.config.use_editor && MODx.loadRTE) {
- var f = this.getForm().findField('richtext');
- if (f && f.getValue() == 1 && !this.rteLoaded) {
+ const f = this.getForm().findField('richtext');
+ if (f && f.getValue() === 1 && !this.rteLoaded) {
MODx.loadRTE(this.rteElements);
this.rteLoaded = true;
- } else if (f && f.getValue() == 0 && this.rteLoaded) {
+ } else if (f && f.getValue() === 0 && this.rteLoaded) {
if (MODx.unloadRTE) {
MODx.unloadRTE(this.rteElements);
}
@@ -123,15 +132,16 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
MODx.sleep(4); /* delay load event to allow FC rules to move before loading RTE */
if (MODx.afterTVLoad) { MODx.afterTVLoad(); }
this.fireEvent('load');
- }
+ },
/**
* Handle the preview button visibility according to the resource "deleted" status
*
- * @param {string} action The action to perform on the preview button (hide/show)
+ * @param {string} deleted The Resource's current deleted value
+ * @deprecated Migrate to updatePreviewButton, noting the difference in param type
*/
- ,handlePreview: function(deleted) {
- var previewBtn = Ext.getCmp('modx-abtn-preview');
+ handlePreview: function(deleted) {
+ const previewBtn = Ext.getCmp('modx-abtn-preview');
if (previewBtn) {
if (deleted) {
previewBtn.hide();
@@ -139,18 +149,41 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
previewBtn.show();
}
}
- }
+ },
+
+ /**
+ * Set preview button visibility based on validity/deleted status of Resource
+ *
+ * @param {Object} record The data object of the Resource to be previewed
+ */
+ updatePreviewButton: function(record) {
+ const previewBtn = Ext.getCmp('modx-abtn-preview');
+ if (previewBtn && record) {
+ if (record.deleted) {
+ previewBtn.hide();
+ } else {
+ previewBtn.show();
+ if (record.preview_url && record.preview_url.startsWith('http')) {
+ previewBtn.enable();
+ } else {
+ previewBtn.disable();
+ }
+ }
+ }
+ },
- ,handleDeleted: function(isDeleted) {
+ handleDeleted: function(isDeleted) {
const canDelete = this.config.canDelete === 1 && !this.config.locked;
if (!canDelete) {
return;
}
- const deleteButton = Ext.getCmp('modx-abtn-delete');
- const unDeleteButton = Ext.getCmp('modx-abtn-undelete');
- const purgeButton = Ext.getCmp('modx-abtn-purge');
+ const
+ deleteButton = Ext.getCmp('modx-abtn-delete'),
+ unDeleteButton = Ext.getCmp('modx-abtn-undelete'),
+ purgeButton = Ext.getCmp('modx-abtn-purge')
+ ;
if (deleteButton && unDeleteButton && purgeButton) {
if (isDeleted) {
@@ -165,226 +198,241 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
}
Ext.getCmp('modx-resource-deleted')?.setValue(isDeleted);
- }
+ },
- ,updateTree: function() {
- var t = Ext.getCmp('modx-resource-tree');
-
- if (t) {
- var ctx = Ext.getCmp('modx-resource-context-key').getValue();
- var pa = Ext.getCmp('modx-resource-parent-hidden').getValue();
- var pao = Ext.getCmp('modx-resource-parent-old-hidden').getValue();
- var v = ctx+'_'+pa;
- var n = t.getNodeById(v);
- if(pa !== pao) {
- t.refresh();
- Ext.getCmp('modx-resource-parent-old-hidden').setValue(pa);
+ updateTree: function() {
+ const tree = Ext.getCmp('modx-resource-tree');
+ if (tree) {
+ const
+ contextKey = Ext.getCmp('modx-resource-context-key').getValue(),
+ parentHidden = Ext.getCmp('modx-resource-parent-hidden').getValue(),
+ oldParentHidden = Ext.getCmp('modx-resource-parent-old-hidden').getValue(),
+ nodeId = `${contextKey}_${parentHidden}`,
+ node = tree.getNodeById(nodeId)
+ ;
+ if (parentHidden !== oldParentHidden) {
+ tree.refresh();
+ Ext.getCmp('modx-resource-parent-old-hidden').setValue(parentHidden);
} else {
- if(typeof n!=="undefined"){
- n.leaf = false;
+ if (typeof node !== 'undefined') {
+ node.leaf = false;
}
- t.refreshNode(v,true);
+ tree.refreshNode(nodeId, true);
}
}
- }
+ },
- ,beforeDestroy: function(){
- if (this.rteLoaded && MODx.unloadRTE){
+ beforeDestroy: function() {
+ if (this.rteLoaded && MODx.unloadRTE) {
MODx.unloadRTE(this.rteElements);
this.rteLoaded = false;
}
MODx.panel.Resource.superclass.beforeDestroy.call(this);
- }
+ },
- ,beforeSubmit: function(o) {
- var ta = Ext.get(this.contentField);
- if (ta) {
- var v = ta.dom.value;
- var hc = Ext.getCmp('hiddenContent');
- if (hc) { hc.setValue(v); }
+ beforeSubmit: function(o) {
+ const
+ contentEl = Ext.get(this.contentField),
+ resourceGroupsGrid = Ext.getCmp('modx-grid-resource-security')
+ ;
+ if (contentEl) {
+ const
+ contentValue = contentEl.dom.value,
+ hiddenContentCmp = Ext.getCmp('hiddenContent')
+ ;
+ if (hiddenContentCmp) {
+ hiddenContentCmp.setValue(contentValue);
+ }
+ this.cleanupEditor();
}
- var g = Ext.getCmp('modx-grid-resource-security');
- if (g) {
- Ext.apply(o.form.baseParams,{
- resource_groups: g.encode()
+ if (resourceGroupsGrid) {
+ Ext.apply(o.form.baseParams, {
+ resource_groups: resourceGroupsGrid.encode()
});
}
- if (ta) {
- this.cleanupEditor();
- }
- if(this.getForm().baseParams.action == 'Resource/Create') {
- var btn = Ext.getCmp('modx-abtn-save');
- if (btn) { btn.disable(); }
+ if (this.getForm().baseParams.action === 'Resource/Create') {
+ const btn = Ext.getCmp('modx-abtn-save');
+ if (btn) {
+ btn.disable();
+ }
}
- return this.fireEvent('save',{
- values: this.getForm().getValues()
- ,stay: Ext.state.Manager.get('modx.stay.'+MODx.request.a,'stay')
+ return this.fireEvent('save', {
+ values: this.getForm().getValues(),
+ stay: Ext.state.Manager.get(`modx.stay.${MODx.request.a}`, 'stay')
});
- }
+ },
- ,success: function(o) {
+ success: function(o) {
this.warnUnsavedChanges = false;
- var g = Ext.getCmp('modx-grid-resource-security');
- if (g) { g.getStore().commitChanges(); }
+ const resourceGroupsGrid = Ext.getCmp('modx-grid-resource-security');
+ if (resourceGroupsGrid) { resourceGroupsGrid.getStore().commitChanges(); }
- var object = o.result.object;
+ const { object } = o.result;
// object.parent is undefined on template changing.
- if (this.config.resource && object.parent !== undefined && (object.class_key != this.defaultClassKey || object.parent != this.defaultValues.parent)) {
- location.reload();
+ if (
+ this.config.resource && object.parent !== undefined
+ && (object.class_key !== this.defaultClassKey || object.parent !== this.defaultValues.parent)
+ ) {
+ window.location.reload();
} else {
if (object.deleted !== this.record.deleted) {
- if (object.deleted) {
- var action = 'hide';
- } else {
- action = 'show';
- }
- this.handlePreview(object.deleted);
this.handleDeleted(object.deleted);
}
-
+ this.updatePreviewButton(object);
this.updateTree();
-
this.record = object;
this.getForm().setValues(object);
Ext.getCmp('modx-page-update-resource').config.preview_url = object.preview_url;
}
- }
+ },
- ,freezeUri: function(cb) {
- var uri = Ext.getCmp('modx-resource-uri');
- if (!uri) { return false; }
- if (cb.checked) {
- uri.show();
+ freezeUri: function(cmp) {
+ const uriCmp = Ext.getCmp('modx-resource-uri');
+ if (!uriCmp) { return false; }
+ if (cmp.checked) {
+ uriCmp.show();
} else {
- uri.hide();
+ uriCmp.hide();
}
- }
+ },
// used for realtime-alias transliteration
- ,translitAlias: function(string) {
+ translitAlias: function(string) {
if (!this.config.translitloading) {
this.config.translitloading = true;
MODx.Ajax.request({
- url: MODx.config.connector_url
- ,params: {
- action: 'Resource/Translit'
- ,string: string
- }
- ,listeners: {
- 'success': {fn:function(r) {
- var alias = Ext.getCmp('modx-resource-alias');
- if (!Ext.isEmpty(r.object.transliteration)) {
- alias.setValue(r.object.transliteration);
- this.config.translitloading = false;
- }
- },scope:this}
+ url: MODx.config.connector_url,
+ params: {
+ action: 'Resource/Translit',
+ string: string
+ },
+ listeners: {
+ success: {
+ fn: function(response) {
+ const alias = Ext.getCmp('modx-resource-alias');
+ if (!Ext.isEmpty(response.object.transliteration)) {
+ alias.setValue(response.object.transliteration);
+ this.config.translitloading = false;
+ }
+ },
+ scope: this
+ }
}
});
}
- }
+ },
- ,generateAliasRealTime: function(title) {
+ generateAliasRealTime: function(title) {
// check some system settings before doing real time alias transliteration
- if (parseInt(MODx.config.friendly_alias_realtime) && parseInt(MODx.config.automatic_alias)) {
+ if (parseInt(MODx.config.friendly_alias_realtime, 10) && parseInt(MODx.config.automatic_alias, 10)) {
// handles the realtime-alias transliteration
if (this.config.aliaswasempty && title !== '') {
this.translitAlias(title);
}
}
- }
+ },
- ,templateWarning: function() {
- var t = Ext.getCmp('modx-resource-template');
- if (!t) { return false; }
- if(t.getValue() !== t.originalValue) {
+ templateWarning: function() {
+ const resourceTemplate = Ext.getCmp('modx-resource-template');
+ if (!resourceTemplate) { return false; }
+ if (resourceTemplate.getValue() !== resourceTemplate.originalValue) {
Ext.Msg.confirm(_('warning'), _('resource_change_template_confirm'), function(e) {
- if (e == 'yes') {
- var nt = t.getValue();
- var f = Ext.getCmp('modx-page-update-resource');
- f.config.action = 'Resource/Reload';
+ if (e === 'yes') {
+ const form = Ext.getCmp('modx-page-update-resource');
+ form.config.action = 'Resource/Reload';
this.warnUnsavedChanges = false;
MODx.activePage.submitForm({
- success: {fn:function(r) {
- MODx.loadPage(r.result.object.action, 'id='+(r.result.object.id || 0)+'&reload='+r.result.object.reload + '&class_key='+ r.result.object.class_key + '&context_key='+ r.result.object.context_key);
- },scope:this}
- },{
+ success: {
+ fn: function(response) {
+ const {
+ action,
+ id,
+ reload,
+ class_key: classKey,
+ context_key: contextKey
+ } = response.result.object;
+ MODx.loadPage(action, `id=${id || 0}&reload=${reload}&class_key=${classKey}&context_key=${contextKey}`);
+ },
+ scope: this
+ }
+ }, {
bypassValidCheck: true
- },{
+ }, {
reloadOnly: true
});
} else {
- t.setValue(this.config.record.template);
+ resourceTemplate.setValue(this.config.record.template);
}
- },this);
+ }, this);
}
- }
+ },
- ,onFieldChange: function(o) {
- //a11y - Set Active Input
+ onFieldChange: function(o) {
+ // a11y - Set Active Input
if (o && o.field) {
Ext.state.Manager.set('curFocus', o.field.id);
-
if (o.field.name === 'syncsite') {
return;
}
}
-
if (this.isReady || MODx.request.reload) {
this.warnUnsavedChanges = true;
}
- }
+ },
- ,cleanupEditor: function() {
+ cleanupEditor: function() {
if (MODx.onSaveEditor) {
- var fld = Ext.getCmp('ta');
- if (fld) { MODx.onSaveEditor(fld); }
+ const contentEl = Ext.getCmp('ta');
+ if (contentEl) {
+ MODx.onSaveEditor(contentEl);
+ }
}
- }
+ },
- ,getFields: function(config) {
- var it = [];
- it.push({
- title: _(this.classLexiconKey)
- ,id: 'modx-resource-settings'
- ,cls: 'modx-resource-tab'
- ,labelAlign: 'top'
- ,bodyCssClass: 'tab-panel-wrapper main-wrapper'
- ,autoHeight: true
- ,items: this.getMainFields(config)
+ getFields: function(config) {
+ const tabsItems = [];
+ tabsItems.push({
+ title: _(this.classLexiconKey),
+ id: 'modx-resource-settings',
+ cls: 'modx-resource-tab',
+ labelAlign: 'top',
+ bodyCssClass: 'tab-panel-wrapper main-wrapper',
+ autoHeight: true,
+ items: this.getMainFields(config)
});
- if (config.show_tvs && MODx.config.tvs_below_content != 1) {
- it.push(this.getTemplateVariablesPanel(config));
+ if (config.show_tvs && MODx.config.tvs_below_content !== 1) {
+ tabsItems.push(this.getTemplateVariablesPanel(config));
}
- it.push({
- id: 'modx-page-settings'
- ,title: _('settings')
- ,cls: 'modx-resource-tab'
- ,layout: 'form'
- ,forceLayout: true
- ,deferredRender: false
- ,labelWidth: 200
- ,bodyCssClass: 'main-wrapper'
- ,autoHeight: true
- ,defaults: {
+ tabsItems.push({
+ id: 'modx-page-settings',
+ title: _('settings'),
+ cls: 'modx-resource-tab',
+ layout: 'form',
+ forceLayout: true,
+ deferredRender: false,
+ labelWidth: 200,
+ bodyCssClass: 'main-wrapper',
+ autoHeight: true,
+ defaults: {
border: false,
msgTarget: 'under'
- }
- ,items: this.getSettingFields(config)
+ },
+ items: this.getSettingFields(config)
});
if (MODx.perm.resourcegroup_resource_list) {
- it.push(this.getAccessPermissionsTab(config));
+ tabsItems.push(this.getAccessPermissionsTab(config));
}
- var its = [];
- its.push(this.getPageHeader(config),{
- id:'modx-resource-tabs'
- ,xtype: 'modx-tabs'
- ,forceLayout: true
- ,deferredRender: false
- ,collapsible: false
- ,animCollapse: false
- ,itemId: 'tabs'
- ,items: it
- ,listeners: {
+ const pageItems = [];
+ pageItems.push(this.getPageHeader(config), {
+ id: 'modx-resource-tabs',
+ xtype: 'modx-tabs',
+ forceLayout: true,
+ deferredRender: false,
+ collapsible: false,
+ animCollapse: false,
+ itemId: 'tabs',
+ items: tabsItems,
+ listeners: {
tabchange: function(tabPanel, tab) {
/*
In certain scenarios, such as when form customization and/or a plugin adds a tab,
@@ -397,52 +445,53 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
}
}
});
- if (MODx.config.tvs_below_content == 1) {
- var tvs = this.getTemplateVariablesPanel(config);
- its.push(tvs);
+ if (MODx.config.tvs_below_content === 1) {
+ const tvs = this.getTemplateVariablesPanel(config);
+ pageItems.push(tvs);
}
- return its;
- }
+ return pageItems;
+ },
- ,getPageHeader: function(config) {
- config = config || {record:{}};
- var header = {
- html: config.record && config.record.pagetitle || config.default_title
- ,id: 'modx-resource-header'
- ,xtype: 'modx-header'
+ getPageHeader: function(config) {
+ config = config || { record: {} };
+ const header = {
+ html: (config.record && config.record.pagetitle) || config.default_title,
+ id: 'modx-resource-header',
+ xtype: 'modx-header'
};
// Add breadcrumbs with parents
- if (config.record['parents'] && config.record['parents'].length) {
- var parents = config.record['parents'];
- var trail = [];
-
- for (var i = 0; i < parents.length; i++) {
+ if (config.record.parents && config.record.parents.length) {
+ const
+ { parents } = config.record,
+ trail = []
+ ;
+ for (let i = 0; i < parents.length; i++) {
if (parents[i].id) {
- if (parents[i].parent && i == 1) {
+ if (parents[i].parent && i === 1) {
trail.push({
- text: parents[i].parent && i == 1 ? '...' : parents[i].pagetitle
- ,href: false
+ text: parents[i].parent && i === 1 ? '...' : parents[i].pagetitle,
+ href: false
});
}
trail.push({
- text: parents[i].pagetitle
- ,href: MODx.config.manager_url + '?a=resource/update&id=' + parents[i].id
- ,cls: function(data) {
- var cls = [];
+ text: parents[i].pagetitle,
+ href: `${MODx.config.manager_url}?a=resource/update&id=${parents[i].id}`,
+ cls: (function(data) {
+ const classes = [];
if (!data.published) {
- cls.push('not_published');
+ classes.push('not_published');
}
if (data.hidemenu) {
- cls.push('menu_hidden');
+ classes.push('menu_hidden');
}
- return cls.join(' ');
- }(parents[i])
+ return classes.join(' ');
+ }(parents[i]))
});
} else {
trail.push({
- text: parents[i].name || parents[i].key
- ,href: false
+ text: parents[i].name || parents[i].key,
+ href: false
});
}
}
@@ -451,53 +500,53 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
}
return header;
- }
+ },
- ,getTemplateVariablesPanel: function(config) {
+ getTemplateVariablesPanel: function(config) {
return {
- xtype: 'modx-panel-resource-tv'
- ,collapsed: false
- ,resource: config.resource
- ,class_key: config.record.class_key || 'MODX\\Revolution\\modDocument'
- ,template: config.record.template
- ,anchor: '100%'
- ,border: true
- ,style: 'visibility: visible'
+ xtype: 'modx-panel-resource-tv',
+ collapsed: false,
+ resource: config.resource,
+ class_key: config.record.class_key || 'MODX\\Revolution\\modDocument',
+ template: config.record.template,
+ anchor: '100%',
+ border: true,
+ style: 'visibility: visible'
};
- }
+ },
- ,getMainFields: function(config) {
- config = config || {record:{}};
+ getMainFields: function(config) {
+ config = config || { record: {} };
return [{
- layout:'column'
- ,id: 'modx-resource-main-columns'
- ,defaults: {
+ layout: 'column',
+ id: 'modx-resource-main-columns',
+ defaults: {
layout: 'form'
- }
- ,items:[{
- columnWidth: .75
- ,id: 'modx-resource-main-left'
- ,cls: 'modx-resource-panel'
- ,defaults: {
+ },
+ items: [{
+ columnWidth: 0.75,
+ id: 'modx-resource-main-left',
+ cls: 'modx-resource-panel',
+ defaults: {
layout: 'form',
anchor: '100%',
validationEvent: 'change',
labelSeparator: '',
- msgTarget: 'under',
- }
- ,collapsible: true
- ,stateful: true
- ,stateEvents: ['collapse', 'expand']
- ,getState: function() {
+ msgTarget: 'under'
+ },
+ collapsible: true,
+ stateful: true,
+ stateEvents: ['collapse', 'expand'],
+ getState: function() {
return { collapsed: this.collapsed };
- }
- ,title: _('resource')
- ,items: this.getMainLeftFields(config)
- },{
- columnWidth: .25
- ,id: 'modx-resource-main-right'
- ,style: 'margin-right: 0'
- ,defaults: {
+ },
+ title: _('resource'),
+ items: this.getMainLeftFields(config)
+ }, {
+ columnWidth: 0.25,
+ id: 'modx-resource-main-right',
+ style: 'margin-right: 0',
+ defaults: {
layout: 'form',
anchor: '100%',
validationEvent: 'change',
@@ -508,58 +557,59 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
validationEvent: 'change',
msgTarget: 'under'
}
- }
- ,items: this.getMainRightFields(config)
+ },
+ items: this.getMainRightFields(config)
}]
- },{
+ }, {
html: MODx.onDocFormRender, border: false
- },{
- xtype: 'hidden'
- ,name: 'id'
- ,id: 'modx-resource-id'
- ,value: config.resource || config.record.id
- },{
- xtype: 'hidden'
- ,name: 'type'
- ,value: 'document'
- },{
- xtype: 'hidden'
- ,name: 'context_key'
- ,id: 'modx-resource-context-key'
- ,value: config.record.context_key || MODx.config.default_context
- },{
- xtype: 'hidden'
- ,name: 'content'
- ,id: 'hiddenContent'
- ,value: (config.record.content || config.record.ta) || ''
- },{
- xtype: 'hidden'
- ,name: 'create-resource-token'
- ,id: 'modx-create-resource-token'
- ,value: config.record.create_resource_token || ''
- },{
- xtype: 'hidden'
- ,name: 'reloaded'
- ,value: !Ext.isEmpty(MODx.request.reload) ? 1 : 0
- },{
- xtype: 'hidden'
- ,name: 'parent'
- ,value: config.record.parent || 0
- ,id: 'modx-resource-parent-hidden'
- },{
- xtype: 'hidden'
- ,name: 'parent-original'
- ,value: config.record.parent || 0
- ,id: 'modx-resource-parent-old-hidden'
+ }, {
+ xtype: 'hidden',
+ name: 'id',
+ id: 'modx-resource-id',
+ value: config.resource || config.record.id
+ }, {
+ xtype: 'hidden',
+ name: 'type',
+ value: 'document'
+ }, {
+ xtype: 'hidden',
+ name: 'context_key',
+ id: 'modx-resource-context-key',
+ value: config.record.context_key || MODx.config.default_context
+ }, {
+ xtype: 'hidden',
+ name: 'content',
+ id: 'hiddenContent',
+ value: (config.record.content || config.record.ta) || ''
+ }, {
+ xtype: 'hidden',
+ name: 'create-resource-token',
+ id: 'modx-create-resource-token',
+ value: config.record.create_resource_token || ''
+ }, {
+ xtype: 'hidden',
+ name: 'reloaded',
+ value: !Ext.isEmpty(MODx.request.reload) ? 1 : 0
+ }, {
+ xtype: 'hidden',
+ name: 'parent',
+ value: config.record.parent || 0,
+ id: 'modx-resource-parent-hidden'
+ }, {
+ xtype: 'hidden',
+ name: 'parent-original',
+ value: config.record.parent || 0,
+ id: 'modx-resource-parent-old-hidden'
}];
- }
+ },
- ,getMainLeftFields: function(config) {
- config = config || {record:{}};
- const aliasLength = ~~MODx.config['friendly_alias_max_length'] || 0;
+ getMainLeftFields: function(config) {
+ config = config || { record: {} };
+ let maxLength = parseInt(MODx.config.friendly_alias_max_length, 10);
+ maxLength = (maxLength && maxLength > 0) || 0;
return [{
- layout: 'column'
- ,defaults: {
+ layout: 'column',
+ defaults: {
layout: 'form',
labelSeparator: '',
defaults: {
@@ -567,21 +617,21 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
anchor: '100%',
validationEvent: 'change',
msgTarget: 'under'
- }
- }
- ,items: [{
- columnWidth: .7
- ,items: [{
- xtype: 'textfield'
- ,fieldLabel: _('resource_pagetitle')
- ,required: true
- ,description: '[[*pagetitle]]
'+_('resource_pagetitle_help')
- ,name: 'pagetitle'
- ,id: 'modx-resource-pagetitle'
- ,maxLength: 191
- ,allowBlank: false
- ,enableKeyEvents: true
- ,listeners: {
+ }
+ },
+ items: [{
+ columnWidth: 0.7,
+ items: [{
+ xtype: 'textfield',
+ fieldLabel: _('resource_pagetitle'),
+ required: true,
+ description: `[[*pagetitle]]
${_('resource_pagetitle_help')}`,
+ name: 'pagetitle',
+ id: 'modx-resource-pagetitle',
+ maxLength: 191,
+ allowBlank: false,
+ enableKeyEvents: true,
+ listeners: {
keyup: {
fn: function(cmp) {
const title = this.formatMainPanelTitle('resource', this.config.record, cmp.getValue(), true);
@@ -596,10 +646,10 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
}
},
scope: this
- }
+ },
// also do realtime transliteration of alias on blur of pagetitle field
// as sometimes (when typing very fast) the last letter(s) are not caught
- ,blur: {
+ blur: {
fn: function(cmp, e) {
const title = Ext.util.Format.stripTags(cmp.getValue());
this.generateAliasRealTime(title);
@@ -608,38 +658,41 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
}
}
}]
- },{
- columnWidth: .3
- ,items: [{
- xtype: 'textfield'
- ,fieldLabel: _('resource_alias')
- ,description: '[[*alias]]
'+_('resource_alias_help')
- ,name: 'alias'
- ,id: 'modx-resource-alias'
- ,maxLength: (aliasLength > 191 || aliasLength === 0) ? 191 : aliasLength
- ,value: config.record.alias || ''
- ,listeners: {
- change: {fn: function(f,e) {
- // when the alias is manually cleared, enable real time alias
+ }, {
+ columnWidth: 0.3,
+ items: [{
+ xtype: 'textfield',
+ fieldLabel: _('resource_alias'),
+ description: `[[*alias]]
${_('resource_alias_help')}`,
+ name: 'alias',
+ id: 'modx-resource-alias',
+ maxLength: (maxLength > 191 || maxLength === 0) ? 191 : maxLength,
+ value: config.record.alias || '',
+ listeners: {
+ change: {
+ fn: function(f, e) {
+ // when the alias is manually cleared, enable real time alias
if (Ext.isEmpty(f.getValue())) {
this.config.aliaswasempty = true;
}
- }, scope: this}
+ },
+ scope: this
+ }
}
}]
}]
- },{
- xtype: 'textfield'
- ,fieldLabel: _('resource_longtitle')
- ,description: '[[*longtitle]]
'+_('resource_longtitle_help')
- ,name: 'longtitle'
- ,id: 'modx-resource-longtitle'
- ,maxLength: 191
- ,value: config.record.longtitle || ''
- },{
- layout: 'column'
- ,defaults: {
+ }, {
+ xtype: 'textfield',
+ fieldLabel: _('resource_longtitle'),
+ description: `[[*longtitle]]
${_('resource_longtitle_help')}`,
+ name: 'longtitle',
+ id: 'modx-resource-longtitle',
+ maxLength: 191,
+ value: config.record.longtitle || ''
+ }, {
+ layout: 'column',
+ defaults: {
labelSeparator: '',
layout: 'form',
defaults: {
@@ -647,36 +700,35 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
grow: true,
validationEvent: 'change',
msgTarget: 'under'
- }
- }
- ,items: [{
- columnWidth: .5
- ,items: [{
- xtype: 'textarea'
- ,fieldLabel: _('resource_description')
- ,description: '[[*description]]
'+_('resource_description_help')
- ,name: 'description'
- ,id: 'modx-resource-description'
- ,value: config.record.description || ''
+ }
+ },
+ items: [{
+ columnWidth: 0.5,
+ items: [{
+ xtype: 'textarea',
+ fieldLabel: _('resource_description'),
+ description: `[[*description]]
${_('resource_description_help')}`,
+ name: 'description',
+ id: 'modx-resource-description',
+ value: config.record.description || ''
}]
- },{
- columnWidth: .5
- ,items: [{
- xtype: 'textarea'
- ,fieldLabel: _('resource_summary')
- ,description: '[[*introtext]]
'+_('resource_summary_help')
- ,name: 'introtext'
- ,id: 'modx-resource-introtext'
- ,value: config.record.introtext || ''
+ }, {
+ columnWidth: 0.5,
+ items: [{
+ xtype: 'textarea',
+ fieldLabel: _('resource_summary'),
+ description: `[[*introtext]]
${_('resource_summary_help')}`,
+ name: 'introtext',
+ id: 'modx-resource-introtext',
+ value: config.record.introtext || ''
}]
}]
}, this.getContentField(config)];
- }
+ },
- ,getMainRightFields: function(config) {
- config = config || {};
+ getMainRightFields: function(config = {}) {
return [{
defaults: {
layout: 'form',
@@ -690,167 +742,168 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
validationEvent: 'change',
msgTarget: 'under'
}
- }
- ,id: 'modx-resource-main-right-top'
- ,cls: 'modx-resource-panel'
- ,title: _('resource_right_top_title')
- ,collapsible: true
- ,stateful: true
- ,stateEvents: ['collapse', 'expand']
- ,getState: function() {
+ },
+ id: 'modx-resource-main-right-top',
+ cls: 'modx-resource-panel',
+ title: _('resource_right_top_title'),
+ collapsible: true,
+ stateful: true,
+ stateEvents: ['collapse', 'expand'],
+ getState: function() {
return { collapsed: this.collapsed };
- }
- ,items: [{
+ },
+ items: [{
items: [{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_published')
- ,hideLabel: true
- ,description: '[[*published]]
'+_('resource_published_help')
- ,name: 'published'
- ,id: 'modx-resource-published'
- ,inputValue: 1
- ,checked: parseInt(config.record.published)
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('deleted')
- ,description: '[[*deleted]]
'+_('resource_delete')
- ,hideLabel: true
- ,cls: 'danger'
- ,name: 'deleted'
- ,id: 'modx-resource-deleted'
- ,inputValue: 1
- ,checked: parseInt(config.record.deleted) || false
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_published'),
+ hideLabel: true,
+ description: `[[*published]]
${_('resource_published_help')}`,
+ name: 'published',
+ id: 'modx-resource-published',
+ inputValue: 1,
+ checked: parseInt(config.record.published, 10)
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('deleted'),
+ description: `[[*deleted]]
${_('resource_delete')}`,
+ hideLabel: true,
+ cls: 'danger',
+ name: 'deleted',
+ id: 'modx-resource-deleted',
+ inputValue: 1,
+ checked: parseInt(config.record.deleted, 10) || false
}]
- },{
- xtype: 'xdatetime'
- ,fieldLabel: _('resource_publishedon')
- ,description: '[[*publishedon]]
'+_('resource_publishedon_help')
- ,name: 'publishedon'
- ,id: 'modx-resource-publishedon'
- ,allowBlank: true
- ,dateFormat: MODx.config.manager_date_format
- ,timeFormat: MODx.config.manager_time_format
- ,startDay: parseInt(MODx.config.manager_week_start)
- ,dateWidth: '100%'
- ,timeWidth: '100%'
- ,offset_time: MODx.config.server_offset_time
- ,value: config.record.publishedon
- },{
- xtype: MODx.config.publish_document ? 'xdatetime' : 'hidden'
- ,fieldLabel: _('resource_publishdate')
- ,description: '[[*pub_date]]
'+_('resource_publishdate_help')
- ,name: 'pub_date'
- ,id: 'modx-resource-pub-date'
- ,allowBlank: true
- ,dateFormat: MODx.config.manager_date_format
- ,timeFormat: MODx.config.manager_time_format
- ,startDay: parseInt(MODx.config.manager_week_start)
- ,dateWidth: '100%'
- ,timeWidth: '100%'
- ,offset_time: MODx.config.server_offset_time
- ,value: config.record.pub_date
- },{
- xtype: MODx.config.publish_document ? 'xdatetime' : 'hidden'
- ,fieldLabel: _('resource_unpublishdate')
- ,description: '[[*unpub_date]]
'+_('resource_unpublishdate_help')
- ,name: 'unpub_date'
- ,id: 'modx-resource-unpub-date'
- ,allowBlank: true
- ,dateFormat: MODx.config.manager_date_format
- ,timeFormat: MODx.config.manager_time_format
- ,startDay: parseInt(MODx.config.manager_week_start)
- ,dateWidth: '100%'
- ,timeWidth: '100%'
- ,offset_time: MODx.config.server_offset_time
- ,value: config.record.unpub_date
+ }, {
+ xtype: 'xdatetime',
+ fieldLabel: _('resource_publishedon'),
+ description: `[[*publishedon]]
${_('resource_publishedon_help')}`,
+ name: 'publishedon',
+ id: 'modx-resource-publishedon',
+ allowBlank: true,
+ dateFormat: MODx.config.manager_date_format,
+ timeFormat: MODx.config.manager_time_format,
+ startDay: parseInt(MODx.config.manager_week_start, 10),
+ dateWidth: '100%',
+ timeWidth: '100%',
+ offset_time: MODx.config.server_offset_time,
+ value: config.record.publishedon
+ }, {
+ xtype: MODx.config.publish_document ? 'xdatetime' : 'hidden',
+ fieldLabel: _('resource_publishdate'),
+ description: `[[*pub_date]]
${_('resource_publishdate_help')}`,
+ name: 'pub_date',
+ id: 'modx-resource-pub-date',
+ allowBlank: true,
+ dateFormat: MODx.config.manager_date_format,
+ timeFormat: MODx.config.manager_time_format,
+ startDay: parseInt(MODx.config.manager_week_start, 10),
+ dateWidth: '100%',
+ timeWidth: '100%',
+ offset_time: MODx.config.server_offset_time,
+ value: config.record.pub_date
+ }, {
+ xtype: MODx.config.publish_document ? 'xdatetime' : 'hidden',
+ fieldLabel: _('resource_unpublishdate'),
+ description: `[[*unpub_date]]
${_('resource_unpublishdate_help')}`,
+ name: 'unpub_date',
+ id: 'modx-resource-unpub-date',
+ allowBlank: true,
+ dateFormat: MODx.config.manager_date_format,
+ timeFormat: MODx.config.manager_time_format,
+ startDay: parseInt(MODx.config.manager_week_start, 10),
+ dateWidth: '100%',
+ timeWidth: '100%',
+ offset_time: MODx.config.server_offset_time,
+ value: config.record.unpub_date
}]
- },{
- id: 'modx-resource-main-right-middle'
- ,cls: 'modx-resource-panel'
- ,title: _('resource_right_middle_title')
- ,collapsible: true
- ,stateful: true
- ,stateEvents: ['collapse', 'expand']
- ,getState: function() {
+ }, {
+ id: 'modx-resource-main-right-middle',
+ cls: 'modx-resource-panel',
+ title: _('resource_right_middle_title'),
+ collapsible: true,
+ stateful: true,
+ stateEvents: ['collapse', 'expand'],
+ getState: function() {
return { collapsed: this.collapsed };
- }
- ,items: [{
- xtype: 'modx-combo-template'
- ,fieldLabel: _('resource_template')
- ,description: '[[*template]]
'+_('resource_template_help')
- ,name: 'template'
- ,id: 'modx-resource-template'
- ,listeners: {
- 'select': {fn: this.templateWarning,scope: this}
- }}]
- },{
- id: 'modx-resource-main-right-bottom'
- ,cls: 'modx-resource-panel'
- ,title: _('resource_right_bottom_title')
- ,collapsible: true
- ,stateful: true
- ,stateEvents: ['collapse', 'expand']
- ,getState: function() {
+ },
+ items: [{
+ xtype: 'modx-combo-template',
+ fieldLabel: _('resource_template'),
+ description: `[[*template]]
${_('resource_template_help')}`,
+ name: 'template',
+ id: 'modx-resource-template',
+ listeners: {
+ select: { fn: this.templateWarning, scope: this }
+ }
+ }]
+ }, {
+ id: 'modx-resource-main-right-bottom',
+ cls: 'modx-resource-panel',
+ title: _('resource_right_bottom_title'),
+ collapsible: true,
+ stateful: true,
+ stateEvents: ['collapse', 'expand'],
+ getState: function() {
return { collapsed: this.collapsed };
- }
- ,items: [{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_hide_from_menus')
- ,hideLabel: true
- ,cls: 'warning'
- ,description: '[[*hidemenu]]
'+_('resource_hide_from_menus_help')
- ,name: 'hidemenu'
- ,id: 'modx-resource-hidemenu'
- ,inputValue: 1
- ,checked: parseInt(config.record.hidemenu) || false
- },{
- xtype: 'textfield'
- ,fieldLabel: _('resource_menutitle')
- ,description: '[[*menutitle]]
'+_('resource_menutitle_help')
- ,name: 'menutitle'
- ,id: 'modx-resource-menutitle'
- ,maxLength: 255
- ,value: config.record.menutitle || ''
- },{
- xtype: 'textfield'
- ,fieldLabel: _('resource_link_attributes')
- ,description: '[[*link_attributes]]
'+_('resource_link_attributes_help')
- ,name: 'link_attributes'
- ,id: 'modx-resource-link-attributes'
- ,maxLength: 255
- ,value: config.record.link_attributes || ''
- },{
- xtype: 'numberfield'
- ,fieldLabel: _('resource_menuindex')
- ,description: '[[*menuindex]]
'+_('resource_menuindex_help')
- ,name: 'menuindex'
- ,id: 'modx-resource-menuindex'
- ,allowNegative: false
- ,allowDecimals: false
- ,enableKeyEvents: true
- ,value: parseInt(config.record.menuindex) || 0
- ,listeners: {
+ },
+ items: [{
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_hide_from_menus'),
+ hideLabel: true,
+ cls: 'warning',
+ description: `[[*hidemenu]]
${_('resource_hide_from_menus_help')}`,
+ name: 'hidemenu',
+ id: 'modx-resource-hidemenu',
+ inputValue: 1,
+ checked: parseInt(config.record.hidemenu, 10) || false
+ }, {
+ xtype: 'textfield',
+ fieldLabel: _('resource_menutitle'),
+ description: `[[*menutitle]]
${_('resource_menutitle_help')}`,
+ name: 'menutitle',
+ id: 'modx-resource-menutitle',
+ maxLength: 255,
+ value: config.record.menutitle || ''
+ }, {
+ xtype: 'textfield',
+ fieldLabel: _('resource_link_attributes'),
+ description: `[[*link_attributes]]
${_('resource_link_attributes_help')}`,
+ name: 'link_attributes',
+ id: 'modx-resource-link-attributes',
+ maxLength: 255,
+ value: config.record.link_attributes || ''
+ }, {
+ xtype: 'numberfield',
+ fieldLabel: _('resource_menuindex'),
+ description: `[[*menuindex]]
${_('resource_menuindex_help')}`,
+ name: 'menuindex',
+ id: 'modx-resource-menuindex',
+ allowNegative: false,
+ allowDecimals: false,
+ enableKeyEvents: true,
+ value: parseInt(config.record.menuindex, 10) || 0,
+ listeners: {
specialkey: function(field, e) {
- const currentVal = parseInt(field.value);
- if (e.getKey() == e.UP) {
+ const currentVal = parseInt(field.value, 10);
+ if (e.getKey() === e.UP) {
field.setValue(currentVal + 1);
- } else if (currentVal >= 1 && e.getKey() == e.DOWN) {
+ } else if (currentVal >= 1 && e.getKey() === e.DOWN) {
field.setValue(currentVal - 1);
}
}
}
}]
- }]
- }
+ }];
+ },
- ,getSettingFields: function(config) {
- config = config || {record:{}};
+ getSettingFields: function(config) {
+ config = config || { record: {} };
return [{
- layout:'column'
- ,defaults: {
+ layout: 'column',
+ defaults: {
defaults: {
layout: 'form',
labelAlign: 'top',
@@ -859,244 +912,244 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
validationEvent: 'change',
anchor: '100%',
msgTarget: 'under'
- }
+ }
}
- }
- ,items:[{
- columnWidth: .5
- ,items: [{
- id: 'modx-page-settings-left'
- ,items: this.getSettingLeftFields(config)
- },{
- id: 'modx-page-settings-box-left'
- ,items: this.getSettingRightFieldsetLeft(config)
+ },
+ items: [{
+ columnWidth: 0.5,
+ items: [{
+ id: 'modx-page-settings-left',
+ items: this.getSettingLeftFields(config)
+ }, {
+ id: 'modx-page-settings-box-left',
+ items: this.getSettingRightFieldsetLeft(config)
}]
- },{
- columnWidth: .5
- ,items: [{
- id: 'modx-page-settings-right'
- ,items: this.getSettingRightFields(config)
- },{
- id: 'modx-page-settings-box-right'
- ,items: this.getSettingRightFieldsetRight(config)
+ }, {
+ columnWidth: 0.5,
+ items: [{
+ id: 'modx-page-settings-right',
+ items: this.getSettingRightFields(config)
+ }, {
+ id: 'modx-page-settings-box-right',
+ items: this.getSettingRightFieldsetRight(config)
}]
}]
}];
- }
+ },
- ,getSettingLeftFields: function(config) {
+ getSettingLeftFields: function(config) {
return [{
- xtype: 'modx-combo-class-derivatives'
- ,fieldLabel: _('resource_type')
- ,description: '[[*class_key]]
'
- ,name: 'class_key'
- ,hiddenName: 'class_key'
- ,id: 'modx-resource-class-key'
- ,allowBlank: false
- ,value: config.record.class_key || 'MODX\\Revolution\\modDocument'
- },{
- xtype: 'modx-combo-content-type'
- ,fieldLabel: _('resource_content_type')
- ,description: '[[*content_type]]
'+_('resource_content_type_help')
- ,name: 'content_type'
- ,hiddenName: 'content_type'
- ,id: 'modx-resource-content-type'
- ,allowBlank: false
- ,value: config.record.content_type || (MODx.config.default_content_type || 1)
+ xtype: 'modx-combo-class-derivatives',
+ fieldLabel: _('resource_type'),
+ description: '[[*class_key]]
',
+ name: 'class_key',
+ hiddenName: 'class_key',
+ id: 'modx-resource-class-key',
+ allowBlank: false,
+ value: config.record.class_key || 'MODX\\Revolution\\modDocument'
+ }, {
+ xtype: 'modx-combo-content-type',
+ fieldLabel: _('resource_content_type'),
+ description: `[[*content_type]]
${_('resource_content_type_help')}`,
+ name: 'content_type',
+ hiddenName: 'content_type',
+ id: 'modx-resource-content-type',
+ allowBlank: false,
+ value: config.record.content_type || (MODx.config.default_content_type || 1)
}];
- }
+ },
- ,getSettingRightFields: function(config) {
+ getSettingRightFields: function(config) {
return [{
- xtype: 'modx-field-parent-change'
- ,fieldLabel: _('resource_parent')
- ,description: '[[*parent]]
'+_('resource_parent_help')
- ,name: 'parent-cmb'
- ,id: 'modx-resource-parent'
- ,value: config.record.parent || 0
- },{
- xtype: 'modx-combo-content-disposition'
- ,fieldLabel: _('resource_contentdispo')
- ,description: '[[*content_dispo]]
'+_('resource_contentdispo_help')
- ,name: 'content_dispo'
- ,hiddenName: 'content_dispo'
- ,id: 'modx-resource-content-dispo'
- ,value: config.record.content_dispo || 0
+ xtype: 'modx-field-parent-change',
+ fieldLabel: _('resource_parent'),
+ description: `[[*parent]]
${_('resource_parent_help')}`,
+ name: 'parent-cmb',
+ id: 'modx-resource-parent',
+ value: config.record.parent || 0
+ }, {
+ xtype: 'modx-combo-content-disposition',
+ fieldLabel: _('resource_contentdispo'),
+ description: `[[*content_dispo]]
${_('resource_contentdispo_help')}`,
+ name: 'content_dispo',
+ hiddenName: 'content_dispo',
+ id: 'modx-resource-content-dispo',
+ value: config.record.content_dispo || 0
}];
- }
+ },
- ,getSettingRightFieldsetLeft: function(config) {
+ getSettingRightFieldsetLeft: function(config) {
return [{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_folder')
- ,description: '[[*isfolder]]
'+_('resource_folder_help')
- ,hideLabel: false
- ,name: 'isfolder'
- ,id: 'modx-resource-isfolder'
- ,inputValue: 1
- ,checked: parseInt(config.record.isfolder) || 0
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_show_in_tree')
- ,description: '[[*show_in_tree]]
'+_('resource_show_in_tree_help')
- ,hideLabel: true
- ,name: 'show_in_tree'
- ,id: 'modx-resource-show-in-tree'
- ,inputValue: 1
- ,checked: parseInt(config.record.show_in_tree)
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_folder'),
+ description: `[[*isfolder]]
${_('resource_folder_help')}`,
+ hideLabel: false,
+ name: 'isfolder',
+ id: 'modx-resource-isfolder',
+ inputValue: 1,
+ checked: parseInt(config.record.isfolder, 10) || 0
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_show_in_tree'),
+ description: `[[*show_in_tree]]
${_('resource_show_in_tree_help')}`,
+ hideLabel: true,
+ name: 'show_in_tree',
+ id: 'modx-resource-show-in-tree',
+ inputValue: 1,
+ checked: parseInt(config.record.show_in_tree, 10)
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_hide_children_in_tree')
- ,description: '[[*hide_children_in_tree]]
'+_('resource_hide_children_in_tree_help')
- ,hideLabel: true
- ,name: 'hide_children_in_tree'
- ,id: 'modx-resource-hide-children-in-tree'
- ,cls: 'warning'
- ,inputValue: 1
- ,checked: parseInt(config.record.hide_children_in_tree)
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_alias_visible')
- ,description: '[[*alias_visible]]
'+_('resource_alias_visible_help')
- ,hideLabel: true
- ,name: 'alias_visible'
- ,id: 'modx-resource-alias-visible'
- ,inputValue: 1
- ,checked: parseInt(config.record.alias_visible) || 1
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_uri_override')
- ,description: _('resource_uri_override_help')
- ,hideLabel: true
- ,name: 'uri_override'
- ,value: 1
- ,checked: parseInt(config.record.uri_override) ? true : false
- ,id: 'modx-resource-uri-override'
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_hide_children_in_tree'),
+ description: `[[*hide_children_in_tree]]
${_('resource_hide_children_in_tree_help')}`,
+ hideLabel: true,
+ name: 'hide_children_in_tree',
+ id: 'modx-resource-hide-children-in-tree',
+ cls: 'warning',
+ inputValue: 1,
+ checked: parseInt(config.record.hide_children_in_tree, 10)
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_alias_visible'),
+ description: `[[*alias_visible]]
${_('resource_alias_visible_help')}`,
+ hideLabel: true,
+ name: 'alias_visible',
+ id: 'modx-resource-alias-visible',
+ inputValue: 1,
+ checked: parseInt(config.record.alias_visible, 10) || 1
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_uri_override'),
+ description: _('resource_uri_override_help'),
+ hideLabel: true,
+ name: 'uri_override',
+ value: 1,
+ checked: config.record.uri_override,
+ id: 'modx-resource-uri-override'
- },{
- xtype: 'textfield'
- ,fieldLabel: _('resource_uri')
- ,description: '[[*uri]]
'+_('resource_uri_help')
- ,name: 'uri'
- ,id: 'modx-resource-uri'
- ,maxLength: 255
- ,value: config.record.uri || ''
- ,hidden: !config.record.uri_override
+ }, {
+ xtype: 'textfield',
+ fieldLabel: _('resource_uri'),
+ description: `[[*uri]]
${_('resource_uri_help')}`,
+ name: 'uri',
+ id: 'modx-resource-uri',
+ maxLength: 255,
+ value: config.record.uri || '',
+ hidden: !config.record.uri_override
}];
- }
+ },
- ,getSettingRightFieldsetRight: function(config) {
+ getSettingRightFieldsetRight: function(config) {
return [{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_richtext')
- ,description: '[[*richtext]]
'+_('resource_richtext_help')
- ,hideLabel: false
- ,name: 'richtext'
- ,id: 'modx-resource-richtext'
- ,inputValue: 1
- ,checked: parseInt(config.record.richtext)
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_searchable')
- ,description: '[[*searchable]]
'+_('resource_searchable_help')
- ,hideLabel: true
- ,name: 'searchable'
- ,id: 'modx-resource-searchable'
- ,inputValue: 1
- ,checked: parseInt(config.record.searchable)
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_cacheable')
- ,description: '[[*cacheable]]
'+_('resource_cacheable_help')
- ,hideLabel: true
- ,name: 'cacheable'
- ,id: 'modx-resource-cacheable'
- ,inputValue: 1
- ,checked: parseInt(config.record.cacheable)
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_richtext'),
+ description: `[[*richtext]]
${_('resource_richtext_help')}`,
+ hideLabel: false,
+ name: 'richtext',
+ id: 'modx-resource-richtext',
+ inputValue: 1,
+ checked: parseInt(config.record.richtext, 10)
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_searchable'),
+ description: `[[*searchable]]
${_('resource_searchable_help')}`,
+ hideLabel: true,
+ name: 'searchable',
+ id: 'modx-resource-searchable',
+ inputValue: 1,
+ checked: parseInt(config.record.searchable, 10)
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_cacheable'),
+ description: `[[*cacheable]]
${_('resource_cacheable_help')}`,
+ hideLabel: true,
+ name: 'cacheable',
+ id: 'modx-resource-cacheable',
+ inputValue: 1,
+ checked: parseInt(config.record.cacheable, 10)
- },{
- xtype: 'xcheckbox'
- ,ctCls: 'display-switch'
- ,boxLabel: _('resource_syncsite')
- ,description: _('resource_syncsite_help')
- ,hideLabel: true
- ,name: 'syncsite'
- ,id: 'modx-resource-syncsite'
- ,inputValue: 1
- ,checked: config.record.syncsite !== undefined && config.record.syncsite !== null ? parseInt(config.record.syncsite) : true
+ }, {
+ xtype: 'xcheckbox',
+ ctCls: 'display-switch',
+ boxLabel: _('resource_syncsite'),
+ description: _('resource_syncsite_help'),
+ hideLabel: true,
+ name: 'syncsite',
+ id: 'modx-resource-syncsite',
+ inputValue: 1,
+ checked: config.record.syncsite !== undefined && config.record.syncsite !== null ? parseInt(config.record.syncsite, 10) : true
}];
- }
+ },
- ,getContentField: function(config) {
+ getContentField: function(config) {
return {
- id: 'modx-resource-content'
- ,layout: 'form'
- ,autoHeight: true
- ,hideMode: 'offsets'
- ,items: [{
- id: 'modx-content-above'
- ,border: false
- },{
- xtype: 'textarea'
- ,name: 'ta'
- ,id: 'ta'
- ,fieldLabel: _('resource_content')
- ,anchor: '100%'
- ,height: 488
- ,grow: false
- ,value: (config.record.content || config.record.ta) || ''
- },{
- id: 'modx-content-below'
- ,border: false
+ id: 'modx-resource-content',
+ layout: 'form',
+ autoHeight: true,
+ hideMode: 'offsets',
+ items: [{
+ id: 'modx-content-above',
+ border: false
+ }, {
+ xtype: 'textarea',
+ name: 'ta',
+ id: 'ta',
+ fieldLabel: _('resource_content'),
+ anchor: '100%',
+ height: 488,
+ grow: false,
+ value: (config.record.content || config.record.ta) || ''
+ }, {
+ id: 'modx-content-below',
+ border: false
}]
};
- }
+ },
- ,getAccessPermissionsTab: function(config) {
+ getAccessPermissionsTab: function(config) {
return {
- id: 'modx-resource-access-permissions'
- ,autoHeight: true
- ,title: _('resource_groups')
- ,layout: 'form'
- ,anchor: '100%'
- ,items: [{
- html: '
'+_('resource_access_message')+'
' - ,xtype: 'modx-description' - },{ - xtype: 'modx-grid-resource-security' - ,cls: 'main-wrapper' - ,preventRender: true - ,resource: config.resource - ,mode: config.mode || 'update' - ,parent: config.record['parent'] || 0 - ,token: config.record.create_resource_token - ,reloaded: !Ext.isEmpty(MODx.request.reload) - ,listeners: { - afteredit: {fn:this.fieldChangeEvent,scope:this} + id: 'modx-resource-access-permissions', + autoHeight: true, + title: _('resource_groups'), + layout: 'form', + anchor: '100%', + items: [{ + html: `${_('resource_access_message')}
`, + xtype: 'modx-description' + }, { + xtype: 'modx-grid-resource-security', + cls: 'main-wrapper', + preventRender: true, + resource: config.resource, + mode: config.mode || 'update', + parent: config.record.parent || 0, + token: config.record.create_resource_token, + reloaded: !Ext.isEmpty(MODx.request.reload), + listeners: { + afteredit: { fn: this.fieldChangeEvent, scope: this } } }] }; } }); -Ext.reg('modx-panel-resource',MODx.panel.Resource); +Ext.reg('modx-panel-resource', MODx.panel.Resource); -var triggerDirtyField = function(fld) { +const triggerDirtyField = function(fld) { Ext.getCmp('modx-panel-resource').fieldChangeEvent(fld); }; MODx.triggerRTEOnChange = function() { triggerDirtyField(Ext.getCmp('ta')); }; -MODx.fireResourceFormChange = function(f,nv,ov) { +MODx.fireResourceFormChange = function(f, nv, ov) { Ext.getCmp('modx-panel-resource').fireEvent('fieldChange'); }; diff --git a/manager/assets/modext/widgets/resource/modx.tree.resource.js b/manager/assets/modext/widgets/resource/modx.tree.resource.js index 046bf498783..05ead71dcfd 100644 --- a/manager/assets/modext/widgets/resource/modx.tree.resource.js +++ b/manager/assets/modext/widgets/resource/modx.tree.resource.js @@ -6,195 +6,212 @@ * @param {Object} config An object of options. * @xtype modx-tree-resource */ -MODx.tree.Resource = function(config) { - config = config || {}; - Ext.applyIf(config,{ - url: MODx.config.connector_url - ,action: 'Resource/GetNodes' - ,title: '' - ,rootVisible: false - ,expandFirst: true - ,enableDD: (MODx.config.enable_dragdrop != '0') ? true : false - ,ddGroup: 'modx-treedrop-dd' - ,sortAction: 'Resource/Sort' - ,sortBy: this.getDefaultSortBy(config) - ,tbarCfg: { - id: config.id ? config.id+'-tbar' : 'modx-tree-resource-tbar' - } - ,baseParams: { - sortBy: this.getDefaultSortBy(config) - ,currentResource: MODx.request.id || 0 - ,currentAction: MODx.request.a || 0 +MODx.tree.Resource = function(config = {}) { + Ext.applyIf(config, { + url: MODx.config.connector_url, + action: 'Resource/GetNodes', + title: '', + rootVisible: false, + expandFirst: true, + enableDD: (parseInt(MODx.config.enable_dragdrop, 10) !== 0), + ddGroup: 'modx-treedrop-dd', + sortAction: 'Resource/Sort', + sortBy: this.getDefaultSortBy(config), + tbarCfg: { + id: config.id ? `${config.id}-tbar` : 'modx-tree-resource-tbar' + }, + baseParams: { + sortBy: this.getDefaultSortBy(config), + currentResource: MODx.request.id || 0, + currentAction: MODx.request.a || 0 } }); - MODx.tree.Resource.superclass.constructor.call(this,config); + MODx.tree.Resource.superclass.constructor.call(this, config); this.addEvents('loadCreateMenus', 'emptyTrash'); - this.on('afterSort',this._handleAfterDrop,this); + this.on('afterSort', this._handleAfterDrop, this); }; -Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{ - forms: {} - ,windows: {} - ,stores: {} +Ext.extend(MODx.tree.Resource, MODx.tree.Tree, { + forms: {}, + windows: {}, + stores: {}, - ,getToolbar: function() { + getToolbar: function() { return []; - } + }, - ,_initExpand: function() { - var treeState = Ext.state.Manager.get(this.treestate_id); + _initExpand: function() { + const treeState = Ext.state.Manager.get(this.treestate_id); if ((Ext.isString(treeState) || Ext.isEmpty(treeState)) && this.root) { - if (this.root) {this.root.expand();} - var wn = this.getNodeById('web_0'); - if (wn && this.config.expandFirst) { - wn.select(); - wn.expand(); + if (this.root) { + this.root.expand(); + } + const defaultNode = this.getNodeById('web_0'); + if (defaultNode && this.config.expandFirst) { + defaultNode.select(); + defaultNode.expand(); } } else { // If we have disabled context sort, make sure dragging and dropping is disabled on the root elements // in the tree. This corresponds to the context nodes. - if (MODx.config.context_tree_sort !== '1') { - if (typeof(this.root) !== 'undefined' && typeof(this.root.childNodes) !== 'undefined') { - for (var i = 0; i < this.root.childNodes.length; i++) { + if (parseInt(MODx.config.context_tree_sort, 10) !== 1) { + if (typeof this.root !== 'undefined' && typeof this.root.childNodes !== 'undefined') { + for (let i = 0; i < this.root.childNodes.length; i++) { this.root.childNodes[i].draggable = false; } } } - for (var i=0;i