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 { + fn: data => { const deletedCount = +data.object.deletedCount; Ext.getCmp('modx-trash-link')?.updateState(deletedCount); const nodeUI = node.getUI(); nodeUI.addClass('deleted'); - node.cascade((childNode) => childNode.getUI().addClass('deleted'), this); + node.cascade(childNode => childNode.getUI().addClass('deleted'), this); // Refresh the trash manager if possible Ext.getCmp('modx-trash-resources')?.refresh(); @@ -205,23 +222,26 @@ Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{ const updatePanel = Ext.getCmp('modx-panel-resource'); if (updatePanel && MODx.request.a === 'resource/update' && MODx.request.id === id) { updatePanel.handleDeleted(true); + updatePanel.updatePreviewButton(data.object); } + node.attributes.preview_url = data.object.preview_url; }, - scope: this, - }, + scope: this + } } }); - } - - ,undeleteDocument: function() { - const node = this.cm.activeNode; - const id = node.id.split('_')[1]; + }, + undeleteDocument: function() { + const + node = this.cm.activeNode, + id = node.id.split('_')[1] + ; MODx.Ajax.request({ url: MODx.config.connector_url, params: { action: 'Resource/Undelete', - id, + id: id }, listeners: { success: { @@ -232,7 +252,7 @@ Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{ const activeNodeUI = node.getUI(); activeNodeUI.removeClass('deleted'); - node.cascade((childNode) => childNode.getUI().removeClass('deleted'), this); + node.cascade(childNode => childNode.getUI().removeClass('deleted'), this); const trashResourcesPanel = Ext.getCmp('modx-trash-resources'); if (trashResourcesPanel) { @@ -244,22 +264,25 @@ Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{ const updatePanel = Ext.getCmp('modx-panel-resource'); if (updatePanel && MODx.request.a === 'resource/update' && MODx.request.id === id) { updatePanel.handleDeleted(false); + updatePanel.updatePreviewButton(response.object); } + node.attributes.preview_url = response.object.preview_url; }, scope: this } } }); - } - - ,purgeDocument: function(itm,e) { - const node = this.cm.activeNode; - const id = node.id.split('_')[1]; - const name = Ext.util.Format.htmlEncode(node.ui.textNode.innerText); - + }, + + purgeDocument: function(itm, e) { + const + node = this.cm.activeNode, + id = node.id.split('_')[1], + name = Ext.util.Format.htmlEncode(node.ui.textNode.innerText) + ; MODx.msg.confirm({ - text: _('resource_purge_confirm',{ - resource: name + ' ('+ id + ')' + text: _('resource_purge_confirm', { + resource: `${name} (${id})` }), url: MODx.config.connector_url, params: { @@ -288,125 +311,145 @@ Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{ MODx.msg.status({ title: _('success'), - message: data.message, + message: data.message }); }, - scope: this, - }, - }, + scope: this + } + } }); - } + }, - ,publishDocument: function(itm,e) { - var node = this.cm.activeNode; - var id = node.id.split('_');id = id[1]; + publishDocument: function(itm, e) { + const + node = this.cm.activeNode, + id = node.id.split('_')[1] + ; MODx.msg.confirm({ - title: _('resource_publish') - ,text: _('resource_publish_confirm') - ,url: MODx.config.connector_url - ,params: { - action: 'Resource/Publish' - ,id: id - } - ,listeners: { - 'success': {fn:function() { - var ui = this.cm.activeNode.getUI(); - ui.removeClass('unpublished'); - Ext.get(ui.getEl()).frame(); - },scope:this} + title: _('resource_publish'), + text: _('resource_publish_confirm'), + url: MODx.config.connector_url, + params: { + action: 'Resource/Publish', + id: id + }, + listeners: { + success: { + fn: function() { + const ui = this.cm.activeNode.getUI(); + ui.removeClass('unpublished'); + Ext.get(ui.getEl()).frame(); + }, + scope: this + } } }); - } + }, - ,unpublishDocument: function(itm,e) { - var node = this.cm.activeNode; - var id = node.id.split('_');id = id[1]; + unpublishDocument: function(itm, e) { + const + node = this.cm.activeNode, + id = node.id.split('_')[1] + ; MODx.msg.confirm({ - title: _('resource_unpublish') - ,text: _('resource_unpublish_confirm') - ,url: MODx.config.connector_url - ,params: { - action: 'Resource/Unpublish' - ,id: id - } - ,listeners: { - 'success': {fn:function() { - var ui = this.cm.activeNode.getUI(); - ui.addClass('unpublished'); - Ext.get(ui.getEl()).frame(); - },scope:this} + title: _('resource_unpublish'), + text: _('resource_unpublish_confirm'), + url: MODx.config.connector_url, + params: { + action: 'Resource/Unpublish', + id: id + }, + listeners: { + success: { + fn: function() { + const ui = this.cm.activeNode.getUI(); + ui.addClass('unpublished'); + Ext.get(ui.getEl()).frame(); + }, + scope: this + } } }); - } + }, - ,getDefaultSortBy: function(config) { - var v = 'menuindex'; + getDefaultSortBy: function(config) { + let sortBy = 'menuindex'; if (!Ext.isEmpty(config) && !Ext.isEmpty(config.sortBy)) { - v = config.sortBy; + sortBy = config.sortBy; } else { - var d = Ext.state.Manager.get(this.treestate_id+'-sort-default'); - if (d != MODx.config.tree_default_sort) { - v = MODx.config.tree_default_sort; - Ext.state.Manager.set(this.treestate_id+'-sort-default',v); - Ext.state.Manager.set(this.treestate_id+'-sort',v); + const savedSort = Ext.state.Manager.get(`${this.treestate_id}-sort-default`); + if (savedSort !== MODx.config.tree_default_sort) { + sortBy = MODx.config.tree_default_sort; + Ext.state.Manager.set(`${this.treestate_id}-sort-default`, sortBy); + Ext.state.Manager.set(`${this.treestate_id}-sort`, sortBy); } else { - v = Ext.state.Manager.get(this.treestate_id+'-sort') || MODx.config.tree_default_sort; + sortBy = Ext.state.Manager.get(`${this.treestate_id}-sort`) || MODx.config.tree_default_sort; } } - return v; - } + return sortBy; + }, - ,filterSort: function(itm, e) { + filterSort: function(itm, e) { this.getLoader().baseParams = { - action: this.config.action - ,sortBy: itm.sortBy - ,sortDir: itm.sortDir - ,node: this.cm.activeNode.ide + action: this.config.action, + sortBy: itm.sortBy, + sortDir: itm.sortDir, + node: this.cm.activeNode.ide }; - this.refreshActiveNode() - } - + this.refreshActiveNode(); + }, - ,hideFilter: function(itm,e) { + hideFilter: function(itm, e) { this.filterBar.destroy(); this._filterVisible = false; - } - - ,_handleAfterDrop: function(o,r) { - var targetNode = o.event.target; - var dropNode = o.event.dropNode; - if (o.event.point == 'append' && targetNode) { - var ui = targetNode.getUI(); + }, + + _handleAfterDrop: function(o, r) { + const + targetNode = o.event.target, + { dropNode } = o.event + ; + if (o.event.point === 'append' && targetNode) { + const ui = targetNode.getUI(); ui.addClass('haschildren'); ui.removeClass('icon-resource'); } - if((MODx.request.a === 'resource/update')){ - if(dropNode.attributes.pk == MODx.request.id) { - var parentFieldCmb = Ext.getCmp('modx-resource-parent'); - var parentFieldHidden = Ext.getCmp('modx-resource-parent-hidden'); - if(parentFieldCmb && parentFieldHidden){ + if ((MODx.request.a === 'resource/update')) { + if (dropNode.attributes.pk === MODx.request.id) { + const + parentFieldCmb = Ext.getCmp('modx-resource-parent'), + parentFieldHidden = Ext.getCmp('modx-resource-parent-hidden') + ; + if (parentFieldCmb && parentFieldHidden) { parentFieldHidden.setValue(dropNode.parentNode.attributes.pk); - parentFieldCmb.setValue(dropNode.parentNode.attributes.text.replace(/(<([^>]+)>)/ig,"")); + parentFieldCmb.setValue(dropNode.parentNode.attributes.text.replace(/(<([^>]+)>)/ig, '')); } } - var menuindexField = Ext.getCmp('modx-resource-menuindex'); - if(menuindexField && o.result.object.menuindex !== undefined){ + const + menuindexField = Ext.getCmp('modx-resource-menuindex'), + isfolderFieldCmb = Ext.getCmp('modx-resource-isfolder') + ; + if (menuindexField && o.result.object.menuindex !== undefined) { menuindexField.setValue(o.result.object.menuindex); } - var isfolderFieldCmb = Ext.getCmp('modx-resource-isfolder'); - if(isfolderFieldCmb && typeof o.result.object.isfolder === 'boolean'){ + if (isfolderFieldCmb && typeof o.result.object.isfolder === 'boolean') { isfolderFieldCmb.setValue(o.result.object.isfolder); } } - } + }, - ,_handleDrop: function(e){ - var dropNode = e.dropNode; - var targetParent = e.target; - - if (targetParent.findChild('id',dropNode.attributes.id) !== null) {return false;} + _handleDrop: function(e) { + const + { dropNode } = e, + targetParent = e.target; + if (targetParent.findChild('id', dropNode.attributes.id) !== null) { + return false; + } - if (dropNode.attributes.type == 'modContext' && (targetParent.getDepth() > 1 || (targetParent.attributes.id == targetParent.attributes.pk + '_0' && e.point == 'append'))) { + if ( + dropNode.attributes.type === 'modContext' + && (targetParent.getDepth() > 1 || (targetParent.attributes.id === `${targetParent.attributes.pk}_0` && e.point === 'append')) + ) { return false; } @@ -414,966 +457,1046 @@ Ext.extend(MODx.tree.Resource,MODx.tree.Tree,{ return false; } - if (MODx.config.resource_classes_drop[targetParent.attributes.classKey] == undefined) { - if (targetParent.attributes.hide_children_in_tree) { return false; } - } else if (MODx.config.resource_classes_drop[targetParent.attributes.classKey] == 0) { + /** @var {String|Number} resourceTypeAllowsDrop Value, if present, indicates whether the class of the currently dragged Resource (fully-qualified path, e.g., Collections\Model\CollectionContainer) allows drop behavior; applies to custom Resource classes only */ + const resourceTypeAllowsDrop = MODx.config.resource_classes_drop[targetParent.attributes.classKey]; + if (resourceTypeAllowsDrop === undefined) { + if (targetParent.attributes.hide_children_in_tree) { + return false; + } + } else if (parseInt(resourceTypeAllowsDrop, 10) === 0) { return false; } - return dropNode.attributes.text != 'root' && dropNode.attributes.text !== '' - && targetParent.attributes.text != 'root' && targetParent.attributes.text !== ''; - } + return dropNode.attributes.text !== 'root' && dropNode.attributes.text !== '' + && targetParent.attributes.text !== 'root' && targetParent.attributes.text !== ''; + }, - ,getContextSettingForNode: function(node,ctx,setting,dv) { - var val = dv || null; - if (node.attributes.type != 'modContext') { - var t = node.getOwnerTree(); - var rn = t.getRootNode(); - var cn = rn.findChild('ctx',ctx,false); - if (cn) { - val = cn.attributes.settings[setting]; + /** + * Gets the value of the specified system setting based the setting in the Resource's + * Context (or the Context itself if it was clicked on). Return value is used specifically for the + * Quick Create contextual action to automatically apply it in the editing form. + * + * @param {Ext.tree.AsyncTreeNode} node The node being right-clicked on to initiate Quick Create + * @param {String} contextKey The Context being acted on (e.g., web) + * @param {String} setting The requested setting name (e.g., default_template) + * @param {?String|?Number} defaultValue The global system setting value + * @returns {?String|?Number} + */ + getContextSettingForNode: function(node, contextKey, setting, defaultValue) { + let value = defaultValue || null; + + /** @todo 2025-09-26 Check whether this if/else check actually does anything; when a Context is clicked on, the type is 'MODX\Revolution\modContext' not 'modContext'. Probably only need what is inside the if block */ + if (node.attributes.type !== 'modContext') { + const + tree = node.getOwnerTree(), + rootNode = tree.getRootNode(), + contextNode = rootNode.findChild('ctx', contextKey, false); + if (contextNode) { + value = contextNode.attributes.settings[setting]; } } else { - val = node.attributes.settings[setting]; + value = node.attributes.settings[setting]; } - return val; - } + return value; + }, - ,quickCreate: function(itm,e,cls,ctx,p) { + quickCreate: function(itm, e, cls, ctx, p) { cls = cls || 'MODX\\Revolution\\modDocument'; - var r = { - class_key: cls - ,context_key: ctx || 'web' - ,'parent': p || 0 - ,'template': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'default_template',MODx.config.default_template)) - ,'richtext': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'richtext_default',MODx.config.richtext_default)) - ,'hidemenu': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'hidemenu_default',MODx.config.hidemenu_default)) - ,'searchable': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'search_default',MODx.config.search_default)) - ,'cacheable': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'cache_default',MODx.config.cache_default)) - ,'published': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'publish_default',MODx.config.publish_default)) - ,'content_type': parseInt(this.getContextSettingForNode(this.cm.activeNode,ctx,'default_content_type',MODx.config.default_content_type)) - }; - if (this.cm.activeNode.attributes.type != 'modContext') { - var t = this.cm.activeNode.getOwnerTree(); - var rn = t.getRootNode(); - var cn = rn.findChild('ctx',ctx,false); - if (cn) { - r['template'] = cn.attributes.settings.default_template; + const + { activeNode } = this.cm, + record = { + class_key: cls, + context_key: ctx || 'web', + parent: p || 0 + }, + settings = { + template: 'default_template', + richtext: 'richtext_default', + hidemenu: 'hidemenu_default', + searchable: 'search_default', + cacheable: 'cache_default', + published: 'publish_default', + content_type: 'default_content_type' } - } else { - r['template'] = this.cm.activeNode.attributes.settings.default_template; - } + ; + + Object.keys(settings).forEach(key => { + const recordValue = this.getContextSettingForNode(activeNode, ctx, settings[key], MODx.config[settings[key]]); + record[key] = !Ext.isEmpty(recordValue) + ? parseInt(recordValue, 10) + : recordValue + ; + }); - var w = MODx.load({ - xtype: 'modx-window-quick-create-modResource' - ,record: r - ,listeners: { - 'success':{ + const window = MODx.load({ + xtype: 'modx-window-quick-create-modResource', + record: record, + listeners: { + success: { fn: function() { this.refreshNode(this.cm.activeNode.id, this.cm.activeNode.childNodes.length > 0); + }, + scope: this + }, + hide: { + fn: function() { + this.destroy(); + } + }, + show: { + fn: function() { + this.center(); } - ,scope: this} - ,'hide':{fn:function() {this.destroy();}} - ,'show':{fn:function() {this.center();}} + } } }); - w.setValues(r); - w.show(e.target,function() { - Ext.isSafari ? w.setPosition(null,30) : w.center(); - },this); - } - - ,quickUpdate: function(itm,e,cls) { + window.setValues(record); + window.show(e.target, () => { + // eslint-disable-next-line no-unused-expressions + Ext.isSafari ? window.setPosition(null, 30) : window.center(); + }, this); + }, + + quickUpdate: function(itm, e, cls) { MODx.Ajax.request({ - url: MODx.config.connector_url - ,params: { - action: 'Resource/Get' - ,id: this.cm.activeNode.attributes.pk - ,skipFormatDates: true - } - ,listeners: { - 'success': {fn:function(r) { - var pr = r.object; - pr.class_key = cls; - - var w = MODx.load({ - xtype: 'modx-window-quick-update-modResource' - ,record: pr - ,listeners: { - 'success':{fn:function(r) { - this.refreshNode(this.cm.activeNode.id); - var newTitle = '' + r.f.findField('pagetitle').getValue() + ' (' + w.record.id + ')'; - w.setTitle(w.title.replace(//, newTitle)); - },scope:this} - ,'hide':{fn:function() {this.destroy();}} - } - }); - w.title += ': ' + Ext.util.Format.htmlEncode(w.record.pagetitle) + ' ('+ w.record.id + ')'; - w.setValues(r.object); - w.show(e.target,function() { - Ext.isSafari ? w.setPosition(null,30) : w.center(); - },this); - },scope:this} + url: MODx.config.connector_url, + params: { + action: 'Resource/Get', + id: this.cm.activeNode.attributes.pk, + skipFormatDates: true + }, + listeners: { + success: { + fn: function(response) { + const resourceRecord = response.object; + resourceRecord.class_key = cls; + + const window = MODx.load({ + xtype: 'modx-window-quick-update-modResource', + record: resourceRecord, + listeners: { + success: { + fn: function(windowResponse) { + this.refreshNode(this.cm.activeNode.id); + const + pageTitle = windowResponse.f.findField('pagetitle').getValue(), + newTitle = `${pageTitle} (${window.record.id})` + ; + window.setTitle(window.title.replace(//, newTitle)); + }, + scope: this + }, + hide: { fn: function() { this.destroy(); } } + } + }); + window.title += `: ${Ext.util.Format.htmlEncode(window.record.pagetitle)} (${window.record.id})`; + window.setValues(response.object); + window.show(e.target, () => { + // eslint-disable-next-line no-unused-expressions + Ext.isSafari ? window.setPosition(null, 30) : window.center(); + }, this); + }, + scope: this + } } }); - } - - ,_getModContextMenu: function(n) { - var a = n.attributes; - var ui = n.getUI(); - var m = []; - - m.push({ - text: ''+a.text+' ('+a.ctx+')' - ,handler: function() {return false;} - ,header: true + }, + + _getModContextMenu: function(node) { + const + nodeAttributes = node.attributes, + ui = node.getUI(), + menu = [] + ; + menu.push({ + text: `${nodeAttributes.text} (${nodeAttributes.ctx})`, + handler: function() { + return false; + }, + header: true }); - m.push('-'); - m.push({ - text: _('refresh_context') - ,handler: function() { - this.refreshNode(this.cm.activeNode.id,true); + menu.push('-'); + menu.push({ + text: _('refresh_context'), + handler: function() { + this.refreshNode(this.cm.activeNode.id, true); } }); if (ui.hasClass('pedit')) { - m.push({ - text: _('edit_context') - ,handler: function() { - var at = this.cm.activeNode.attributes; - this.loadAction('a=context/update&key='+at.pk); + menu.push({ + text: _('edit_context'), + handler: function() { + const { attributes } = this.cm.activeNode; + this.loadAction(`a=context/update&key=${attributes.pk}`); } }); } if (ui.hasClass('pnew')) { - m.push({ - text: _('duplicate_context') - ,handler: this.duplicateContext + menu.push({ + text: _('duplicate_context'), + handler: this.duplicateContext }); } if (ui.hasClass('pdelete')) { - m.push('-'); - m.push({ - text: _('remove_context') - ,handler: this.removeContext + menu.push('-'); + menu.push({ + text: _('remove_context'), + handler: this.removeContext }); } if (ui.hasClass('pnewdoc')) { - m.push('-'); - this._getCreateMenus(m,'0',ui); + menu.push('-'); + this._getCreateMenus(menu, '0', ui); } - if(!ui.hasClass('x-tree-node-leaf')) { - m.push('-'); - m.push(this._getSortMenu()); + if (!ui.hasClass('x-tree-node-leaf')) { + menu.push('-'); + menu.push(this._getSortMenu()); } - return m; - } - - ,overviewResource: function() {this.loadAction('a=resource/data')} - - ,quickUpdateResource: function(itm,e) { - this.quickUpdate(itm,e,itm.classKey); - } - - ,editResource: function() {this.loadAction('a=resource/update');} - - ,_getModResourceMenu: function(n) { - var a = n.attributes; - var ui = n.getUI(); - var m = []; - m.push({ - text: ''+a.text+'' - ,handler: function() {return false;} - ,header: true + return menu; + }, + + overviewResource: function() { + this.loadAction('a=resource/data'); + }, + + quickUpdateResource: function(itm, e) { + this.quickUpdate(itm, e, itm.classKey); + }, + + editResource: function() { + this.loadAction('a=resource/update'); + }, + + _getModResourceMenu: function(node) { + const + nodeAttributes = node.attributes, + ui = node.getUI(), + menu = [] + ; + menu.push({ + text: `${nodeAttributes.text}`, + handler: function() { return false; }, + header: true }); - m.push('-'); + menu.push('-'); if (ui.hasClass('pview')) { - m.push({ - text: _('resource_overview') - ,handler: this.overviewResource + menu.push({ + text: _('resource_overview'), + handler: this.overviewResource }); } if (ui.hasClass('pedit')) { - m.push({ - text: _('resource_edit') - ,handler: this.editResource + menu.push({ + text: _('resource_edit'), + handler: this.editResource }); } if (ui.hasClass('pqupdate')) { - m.push({ - text: _('quick_update_resource') - ,classKey: a.classKey - ,handler: this.quickUpdateResource + menu.push({ + text: _('quick_update_resource'), + classKey: nodeAttributes.classKey, + handler: this.quickUpdateResource }); } if (ui.hasClass('pduplicate')) { - m.push({ - text: _('resource_duplicate') - ,handler: this.duplicateResource + menu.push({ + text: _('resource_duplicate'), + handler: this.duplicateResource }); } - m.push({ - text: _('resource_refresh') - ,handler: this.refreshResource - ,scope: this + menu.push({ + text: _('resource_refresh'), + handler: this.refreshResource, + scope: this }); if (ui.hasClass('pnew')) { - m.push('-'); - this._getCreateMenus(m,null,ui); + menu.push('-'); + this._getCreateMenus(menu, null, ui); } if (ui.hasClass('psave')) { - m.push('-'); + menu.push('-'); if (ui.hasClass('ppublish') && ui.hasClass('unpublished')) { - m.push({ - text: _('resource_publish') - ,handler: this.publishDocument + menu.push({ + text: _('resource_publish'), + handler: this.publishDocument }); } else if (ui.hasClass('punpublish')) { - m.push({ - text: _('resource_unpublish') - ,handler: this.unpublishDocument + menu.push({ + text: _('resource_unpublish'), + handler: this.unpublishDocument }); } if (ui.hasClass('pundelete') && ui.hasClass('deleted')) { - m.push({ - text: _('resource_undelete') - ,handler: this.undeleteDocument + menu.push({ + text: _('resource_undelete'), + handler: this.undeleteDocument }); - m.push({ - text: _('resource_purge') - ,handler: this.purgeDocument + menu.push({ + text: _('resource_purge'), + handler: this.purgeDocument }); } else if (ui.hasClass('pdelete') && !ui.hasClass('deleted')) { - m.push({ - text: _('resource_delete') - ,handler: this.deleteDocument + menu.push({ + text: _('resource_delete'), + handler: this.deleteDocument }); } } - if(!ui.hasClass('x-tree-node-leaf')) { - m.push('-'); - m.push(this._getSortMenu()); + if (!ui.hasClass('x-tree-node-leaf')) { + menu.push('-'); + menu.push(this._getSortMenu()); } - if (ui.hasClass('pview') && a.preview_url != '') { - m.push('-'); - m.push({ - text: _('resource_view') - ,handler: this.preview + if (ui.hasClass('pview') && nodeAttributes.preview_url !== '') { + menu.push('-'); + menu.push({ + text: _('resource_view'), + handler: this.preview }); } - return m; - } + return menu; + }, - ,refreshResource: function() { + refreshResource: function() { this.refreshNode(this.cm.activeNode.id); - } - - ,createResourceHere: function(itm) { - - var at = this.cm.activeNode.attributes; - var parent = itm.usePk ? itm.usePk : at.pk; - - if (parseInt(MODx.config.enable_template_picker_in_tree)) { + }, + + createResourceHere: function(itm) { + const + nodeAttributes = this.cm.activeNode.attributes, + parentId = itm.usePk ? itm.usePk : nodeAttributes.pk + ; + if (parseInt(MODx.config.enable_template_picker_in_tree, 10)) { MODx.createResource({ - 'class_key': itm.classKey, - 'parent': parent, - 'context_key': at.ctx || MODx.config.default_context + class_key: itm.classKey, + parent: parentId, + context_key: nodeAttributes.ctx || MODx.config.default_context }); } else { this.loadAction( - 'a=resource/create&class_key=' + itm.classKey + '&parent=' + parent + (at.ctx ? '&context_key='+at.ctx : '') + `a=resource/create&class_key=${itm.classKey}&parent=${parentId}${nodeAttributes.ctx ? `&context_key=${nodeAttributes.ctx}` : ''}` ); } - } - - ,createResource: function(itm,e) { - var at = this.cm.activeNode.attributes; - var p = itm.usePk ? itm.usePk : at.pk; - this.quickCreate(itm,e,itm.classKey,at.ctx,p); - } - - ,_getCreateMenus: function(m,pk,ui) { - var types = MODx.config.resource_classes; - var o = this.fireEvent('loadCreateMenus',types); + }, + + createResource: function(itm, e) { + const + nodeAttributes = this.cm.activeNode.attributes, + parentId = itm.usePk ? itm.usePk : nodeAttributes.pk + ; + this.quickCreate(itm, e, itm.classKey, nodeAttributes.ctx, parentId); + }, + + _getCreateMenus: function(menu, pk, ui) { + const + /** @var {Object} types Contains a set of Resource class types (e.g., MODX\Revolution\modDocument) with menu text config for each */ + types = MODx.config.resource_classes, + o = this.fireEvent('loadCreateMenus', types) + ; if (Ext.isObject(o)) { - Ext.apply(types,o); + Ext.apply(types, o); } - var coreTypes = ['MODX\Revolution\modDocument','MODX\Revolution\modWebLink','MODX\Revolution\modSymLink','MODX\Revolution\modStaticResource']; - var ct = []; - var qct = []; - for (var k in types) { - if (coreTypes.indexOf(k) != -1) { - if (!ui.hasClass('pnew_'+k)) { - continue; + const + coreTypes = [ + 'MODX\\Revolution\\modDocument', + 'MODX\\Revolution\\modWebLink', + 'MODX\\Revolution\\modSymLink', + 'MODX\\Revolution\\modStaticResource' + ], + createMenuItems = [], + quickCreateMenuItems = [] + ; + Object.keys(types).forEach(resourceType => { + const shortType = resourceType.split('\\').pop(); + if (coreTypes.includes(resourceType)) { + if (!ui.hasClass(`pnew_${shortType}`)) { + /** @todo 2025-09-26 May not need this if check, as it looks like only the permitted Resource classes are made available in MODx.config.resource_classes */ + return; } } - ct.push({ - text: types[k]['text_create_here'] - ,classKey: k - ,usePk: pk ? pk : false - ,handler: this.createResourceHere - ,scope: this + createMenuItems.push({ + text: types[resourceType].text_create_here, + classKey: resourceType, + usePk: !Ext.isEmpty(pk) ? pk : false, + handler: this.createResourceHere, + scope: this }); if (ui && ui.hasClass('pqcreate')) { - qct.push({ - text: types[k]['text_create'] - ,classKey: k - ,handler: this.createResource - ,scope: this + quickCreateMenuItems.push({ + text: types[resourceType].text_create, + classKey: resourceType, + handler: this.createResource, + scope: this }); } - } - m.push({ - text: _('create') - ,handler: function() {return false;} - ,menu: {items: ct} + }); + menu.push({ + text: _('create'), + handler: function() { + return false; + }, + menu: { + items: createMenuItems + } }); if (ui && ui.hasClass('pqcreate')) { - m.push({ - text: _('quick_create') - ,handler: function() {return false;} - ,menu: {items: qct} + menu.push({ + text: _('quick_create'), + handler: function() { + return false; + }, + menu: { + items: quickCreateMenuItems + } }); } - - return m; - } + return menu; + }, /** * Handles all drag events into the tree. * @param {Object} dropEvent The node dropped on the parent node. */ - ,_handleDrag: function(dropEvent) { + _handleDrag: function(dropEvent) { function simplifyNodes(node) { - var resultNode = {}; - var kids = node.childNodes; - var len = kids.length; - for (var i = 0; i < len; i++) { - resultNode[kids[i].id] = simplifyNodes(kids[i]); + const + resultNode = {}, + { childNodes } = node, + countChildNodes = childNodes.length + ; + for (let i = 0; i < countChildNodes; i++) { + resultNode[childNodes[i].id] = simplifyNodes(childNodes[i]); } return resultNode; } - var encNodes = Ext.encode(simplifyNodes(dropEvent.tree.root)); - this.fireEvent('beforeSort',encNodes); + const encNodes = Ext.encode(simplifyNodes(dropEvent.tree.root)); + this.fireEvent('beforeSort', encNodes); MODx.Ajax.request({ - url: this.config.url - ,params: { - target: dropEvent.target.attributes.id - ,activeTarget: MODx.request.a === 'resource/update' ? MODx.request.id : '' - ,source: dropEvent.source.dragData.node.attributes.id - ,point: dropEvent.point - ,data: encodeURIComponent(encNodes) - ,action: this.config.sortAction || 'sort' - } - ,listeners: { - 'success': {fn:function(r) { - var el = dropEvent.dropNode.getUI().getTextEl(); - if (el) {Ext.get(el).frame();} - this.fireEvent('afterSort',{event:dropEvent,result:r}); - },scope:this} - ,'failure': {fn:function(r) { - MODx.form.Handler.errorJSON(r); - this.refresh(); - return false; - },scope:this} + url: this.config.url, + params: { + target: dropEvent.target.attributes.id, + activeTarget: MODx.request.a === 'resource/update' ? MODx.request.id : '', + source: dropEvent.source.dragData.node.attributes.id, + point: dropEvent.point, + data: encodeURIComponent(encNodes), + action: this.config.sortAction || 'sort' + }, + listeners: { + success: { + fn: function(response) { + const el = dropEvent.dropNode.getUI().getTextEl(); + if (el) { + Ext.get(el).frame(); + } + this.fireEvent('afterSort', { + event: dropEvent, + result: response + }); + }, + scope: this + }, + failure: { + fn: function(response) { + MODx.form.Handler.errorJSON(response); + this.refresh(); + return false; + }, + scope: this + } } }); - } + }, - ,_getSortMenu: function(){ + _getSortMenu: function() { return [{ - text: _('sort_by') - ,handler: function() {return false;} - ,menu: { - items:[{ - text: _('tree_order') - ,sortBy: 'menuindex' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('recently_updated') - ,sortBy: 'editedon' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('newest') - ,sortBy: 'createdon' - ,sortDir: 'DESC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('oldest') - ,sortBy: 'createdon' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('publish_date') - ,sortBy: 'pub_date' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('unpublish_date') - ,sortBy: 'unpub_date' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('publishedon') - ,sortBy: 'publishedon' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('title') - ,sortBy: 'pagetitle' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this - },{ - text: _('alias') - ,sortBy: 'alias' - ,sortDir: 'ASC' - ,handler: this.filterSort - ,scope: this + text: _('sort_by'), + handler: function() { return false; }, + menu: { + items: [{ + text: _('tree_order'), + sortBy: 'menuindex', + sortDir: 'ASC', + handler: this.filterSort, + scope: this + }, { + text: _('recently_updated'), + sortBy: 'editedon', + sortDir: 'ASC', + handler: this.filterSort, + scope: this + }, { + text: _('newest'), + sortBy: 'createdon', + sortDir: 'DESC', + handler: this.filterSort, + scope: this + }, { + text: _('oldest'), + sortBy: 'createdon', + sortDir: 'ASC', + handler: this.filterSort, + scope: this + }, { + text: _('publish_date'), + sortBy: 'pub_date', + sortDir: 'ASC', + handler: this.filterSort, + scope: this + }, { + text: _('unpublish_date'), + sortBy: 'unpub_date', + sortDir: 'ASC', + handler: this.filterSort, + scope: this + }, { + text: _('publishedon'), + sortBy: 'publishedon', + sortDir: 'ASC', + handler: this.filterSort, + scope: this + }, { + text: _('title'), + sortBy: 'pagetitle', + sortDir: 'ASC', + handler: this.filterSort, + scope: this + }, { + text: _('alias'), + sortBy: 'alias', + sortDir: 'ASC', + handler: this.filterSort, + scope: this }] } }]; - } + }, - ,handleCreateClick: function(node){ + handleCreateClick: function(node) { this.cm.activeNode = node; - var itm = { - usePk: '0' - ,classKey: 'MODX\\Revolution\\modDocument' + const itm = { + usePk: '0', + classKey: 'MODX\\Revolution\\modDocument' }; this.createResourceHere(itm); - } + }, - ,handleDirectCreateClick: function(node){ + handleDirectCreateClick: function(node) { this.cm.activeNode = node; this.createResourceHere({ classKey: 'MODX\\Revolution\\modDocument' }); - } + }, /** * Renders the item text without any special formatting. The Resource/GetNodes processor already protects against XSS. */ - ,renderItemText: function(item) { + renderItemText: function(item) { return item.text; } }); -Ext.reg('modx-tree-resource',MODx.tree.Resource); - - - -MODx.window.QuickCreateResource = function(config) { - config = config || {}; - this.ident = config.ident || 'qcr'+Ext.id(); - Ext.applyIf(config,{ - title: _('quick_create_resource') - ,id: this.ident - ,bwrapCssClass: 'x-window-with-tabs' - ,width: 700 - ,layout: 'anchor' - ,url: MODx.config.connector_url - ,action: 'Resource/Create' - ,fields: [{ - xtype: 'modx-tabs' - ,bodyStyle: { background: 'transparent' } - ,border: true - ,deferredRender: false - ,autoHeight: false - ,autoScroll: false - ,anchor: '100% 100%' - ,items: [{ - title: _('resource') - ,layout: 'form' - ,cls: 'modx-panel' - ,autoHeight: false - ,anchor: '100% 100%' - ,labelWidth: 100 - ,items: [{ - xtype: 'hidden' - ,name: 'id' - },{ - layout: 'column' - ,border: false - ,items: [{ - columnWidth: .6 - ,border: false - ,layout: 'form' - ,items: [{ - xtype: 'textfield' - ,name: 'pagetitle' - ,id: 'modx-'+this.ident+'-pagetitle' - ,fieldLabel: _('resource_pagetitle') - ,description: '[[*pagetitle]]
'+_('resource_pagetitle_help') - ,anchor: '100%' - ,allowBlank: false - },{ - xtype: 'textfield' - ,name: 'longtitle' - ,id: 'modx-'+this.ident+'-longtitle' - ,fieldLabel: _('resource_longtitle') - ,description: '[[*longtitle]]
'+_('resource_longtitle_help') - ,anchor: '100%' - },{ - xtype: 'textarea' - ,name: 'description' - ,id: 'modx-'+this.ident+'-description' - ,fieldLabel: _('resource_description') - ,description: '[[*description]]
'+_('resource_description_help') - ,anchor: '100%' - ,grow: false - ,height: 50 - },{ - xtype: 'textarea' - ,name: 'introtext' - ,id: 'modx-'+this.ident+'-introtext' - ,fieldLabel: _('resource_summary') - ,description: '[[*introtext]]
'+_('resource_summary_help') - ,anchor: '100%' - ,height: 50 +Ext.reg('modx-tree-resource', MODx.tree.Resource); + +MODx.window.QuickCreateResource = function(config = {}) { + this.ident = config.ident || `window-quick-create-resource-${Ext.id()}`; + Ext.applyIf(config, { + title: _('quick_create_resource'), + id: this.ident, + bwrapCssClass: 'x-window-with-tabs', + width: 700, + layout: 'anchor', + url: MODx.config.connector_url, + action: 'Resource/Create', + fields: [{ + xtype: 'modx-tabs', + bodyStyle: { background: 'transparent' }, + border: true, + deferredRender: false, + autoHeight: false, + autoScroll: false, + anchor: '100% 100%', + items: [{ + title: _('resource'), + layout: 'form', + cls: 'modx-panel', + autoHeight: false, + anchor: '100% 100%', + labelWidth: 100, + items: [{ + xtype: 'hidden', + name: 'id' + }, { + layout: 'column', + border: false, + items: [{ + columnWidth: 0.6, + border: false, + layout: 'form', + items: [{ + xtype: 'textfield', + name: 'pagetitle', + id: `modx-${this.ident}-pagetitle`, + fieldLabel: _('resource_pagetitle'), + description: `[[*pagetitle]]
${_('resource_pagetitle_help')}`, + anchor: '100%', + allowBlank: false + }, { + xtype: 'textfield', + name: 'longtitle', + id: `modx-${this.ident}-longtitle`, + fieldLabel: _('resource_longtitle'), + description: `[[*longtitle]]
${_('resource_longtitle_help')}`, + anchor: '100%' + }, { + xtype: 'textarea', + name: 'description', + id: `modx-${this.ident}-description`, + fieldLabel: _('resource_description'), + description: `[[*description]]
${_('resource_description_help')}`, + anchor: '100%', + grow: false, + height: 50 + }, { + xtype: 'textarea', + name: 'introtext', + id: `modx-${this.ident}-introtext`, + fieldLabel: _('resource_summary'), + description: `[[*introtext]]
${_('resource_summary_help')}`, + anchor: '100%', + height: 50 }] - },{ - columnWidth: .4 - ,border: false - ,layout: 'form' - ,items: [{ - xtype: 'modx-combo-template' - ,name: 'template' - ,id: 'modx-'+this.ident+'-template' - ,fieldLabel: _('resource_template') - ,description: '[[*template]]
'+_('resource_template_help') - ,editable: false - ,anchor: '100%' - ,baseParams: { - action: 'Element/Template/GetList' - ,combo: true - } - ,value: MODx.config.default_template - },{ - xtype: 'textfield' - ,name: 'alias' - ,id: 'modx-'+this.ident+'-alias' - ,fieldLabel: _('resource_alias') - ,description: '[[*alias]]
'+_('resource_alias_help') - ,anchor: '100%' - },{ - xtype: 'textfield' - ,name: 'menutitle' - ,id: 'modx-'+this.ident+'-menutitle' - ,fieldLabel: _('resource_menutitle') - ,description: '[[*menutitle]]
'+_('resource_menutitle_help') - ,anchor: '100%' - },{ - xtype: 'textfield' - ,fieldLabel: _('resource_link_attributes') - ,description: '[[*link_attributes]]
'+_('resource_link_attributes_help') - ,name: 'link_attributes' - ,id: 'modx-'+this.ident+'-attributes' - ,maxLength: 255 - ,anchor: '100%' - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_hide_from_menus') - ,description: '[[*hidemenu]]
'+_('resource_hide_from_menus_help') - ,hideLabel: true - ,name: 'hidemenu' - ,id: 'modx-'+this.ident+'-hidemenu' - ,inputValue: 1 - ,checked: MODx.config.hidemenu_default == '1' ? 1 : 0 - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_published') - ,description: '[[*published]]
'+_('resource_published_help') - ,hideLabel: true - ,name: 'published' - ,id: 'modx-'+this.ident+'-published' - ,inputValue: 1 - ,checked: MODx.config.publish_default == '1' ? 1 : 0 - },{ - xtype: 'xcheckbox' - ,boxLabel: _('deleted') - ,description: '[[*deleted]]
'+_('resource_delete') - ,hideLabel: true - ,name: 'deleted' - ,id: 'modx-'+this.ident+'-deleted' - ,inputValue: 1 - ,checked: MODx.config.deleted_default == '1' ? 1 : 0 + }, { + columnWidth: 0.4, + border: false, + layout: 'form', + items: [{ + xtype: 'modx-combo-template', + name: 'template', + id: `modx-${this.ident}-template`, + fieldLabel: _('resource_template'), + description: `[[*template]]
${_('resource_template_help')}`, + editable: false, + anchor: '100%', + baseParams: { + action: 'Element/Template/GetList', + combo: true + }, + value: MODx.config.default_template + }, { + xtype: 'textfield', + name: 'alias', + id: `modx-${this.ident}-alias`, + fieldLabel: _('resource_alias'), + description: `[[*alias]]
${_('resource_alias_help')}`, + anchor: '100%' + }, { + xtype: 'textfield', + name: 'menutitle', + id: `modx-${this.ident}-menutitle`, + fieldLabel: _('resource_menutitle'), + description: `[[*menutitle]]
${_('resource_menutitle_help')}`, + anchor: '100%' + }, { + xtype: 'textfield', + fieldLabel: _('resource_link_attributes'), + description: `[[*link_attributes]]
${_('resource_link_attributes_help')}`, + name: 'link_attributes', + id: `modx-${this.ident}-attributes`, + maxLength: 255, + anchor: '100%' + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_hide_from_menus'), + description: `[[*hidemenu]]
${_('resource_hide_from_menus_help')}`, + hideLabel: true, + name: 'hidemenu', + id: `modx-${this.ident}-hidemenu`, + inputValue: 1, + checked: parseInt(MODx.config.hidemenu_default, 10) === 1 ? 1 : 0 + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_published'), + description: `[[*published]]
${_('resource_published_help')}`, + hideLabel: true, + name: 'published', + id: `modx-${this.ident}-published`, + inputValue: 1, + checked: parseInt(MODx.config.publish_default, 10) === 1 ? 1 : 0 + }, { + xtype: 'xcheckbox', + boxLabel: _('deleted'), + description: `[[*deleted]]
${_('resource_delete')}`, + hideLabel: true, + name: 'deleted', + id: `modx-${this.ident}-deleted`, + inputValue: 1, + checked: parseInt(MODx.config.deleted_default, 10) === 1 ? 1 : 0 }] }] - },MODx.getQRContentField(this.ident,config.record.class_key)] - },{ - id: 'modx-'+this.ident+'-settings' - ,title: _('settings') - ,layout: 'form' - ,cls: 'modx-panel' - ,autoHeight: true - ,forceLayout: true - ,labelWidth: 100 - ,defaults: { - autoHeight: true - ,border: false - } - ,items: MODx.getQRSettings(this.ident,config.record) + }, MODx.getQuickCreateResourceContentField(this.ident, config.record.class_key)] + }, { + id: `modx-${this.ident}-settings`, + title: _('settings'), + layout: 'form', + cls: 'modx-panel', + autoHeight: true, + forceLayout: true, + labelWidth: 100, + defaults: { + autoHeight: true, + border: false + }, + items: MODx.getQuickCreateResourceSettingsFields(this.ident, config.record) }] - }] - ,keys: [{ - key: Ext.EventObject.ENTER - ,shift: true - ,fn: this.submit - ,scope: this + }], + keys: [{ + key: Ext.EventObject.ENTER, + shift: true, + fn: this.submit, + scope: this }] }); - MODx.window.QuickCreateResource.superclass.constructor.call(this,config); + MODx.window.QuickCreateResource.superclass.constructor.call(this, config); }; -Ext.extend(MODx.window.QuickCreateResource,MODx.Window); -Ext.reg('modx-window-quick-create-modResource',MODx.window.QuickCreateResource); - -MODx.window.QuickUpdateResource = function(config) { - config = config || {}; - this.ident = config.ident || 'qur'+Ext.id(); - Ext.applyIf(config,{ - title: _('quick_update_resource') - ,id: this.ident - ,action: 'Resource/Update' - ,buttons: [{ - text: config.cancelBtnText || _('cancel') - ,scope: this - ,handler: function() { this.hide(); } - },{ - text: config.saveBtnText || _('save') - ,scope: this - ,handler: function() { this.submit(false); } - },{ - text: config.saveBtnText || _('save_and_close') - ,cls: 'primary-button' - ,scope: this - ,handler: this.submit +Ext.extend(MODx.window.QuickCreateResource, MODx.Window); +Ext.reg('modx-window-quick-create-modResource', MODx.window.QuickCreateResource); + +MODx.window.QuickUpdateResource = function(config = {}) { + this.ident = config.ident || `window-quick-update-resource-${Ext.id()}`; + Ext.applyIf(config, { + title: _('quick_update_resource'), + id: this.ident, + action: 'Resource/Update', + buttons: [{ + text: config.cancelBtnText || _('cancel'), + scope: this, + handler: function() { this.hide(); } + }, { + text: config.saveBtnText || _('save'), + scope: this, + handler: function() { this.submit(false); } + }, { + text: config.saveBtnText || _('save_and_close'), + cls: 'primary-button', + scope: this, + handler: this.submit }] }); - MODx.window.QuickUpdateResource.superclass.constructor.call(this,config); + MODx.window.QuickUpdateResource.superclass.constructor.call(this, config); }; -Ext.extend(MODx.window.QuickUpdateResource,MODx.window.QuickCreateResource); -Ext.reg('modx-window-quick-update-modResource',MODx.window.QuickUpdateResource); +Ext.extend(MODx.window.QuickUpdateResource, MODx.window.QuickCreateResource); +Ext.reg('modx-window-quick-update-modResource', MODx.window.QuickUpdateResource); - -MODx.getQRContentField = function(id,cls) { - id = id || 'qur'; - cls = cls || 'MODX\\Revolution\\modDocument'; - var dm = Ext.getBody().getViewSize(); - var o = {}; +MODx.getQuickCreateResourceContentField = function(id = 'quick-update-resource', cls = 'MODX\\Revolution\\modDocument') { + let field = {}; switch (cls) { case 'MODX\\Revolution\\modSymLink': - o = { - xtype: 'textfield' - ,fieldLabel: _('symlink') - ,name: 'content' - ,id: 'modx-'+id+'-content' - ,anchor: '100%' - ,maxLength: 255 + field = { + xtype: 'textfield', + fieldLabel: _('symlink'), + name: 'content', + id: `modx-${id}-content`, + anchor: '100%', + maxLength: 255 }; break; case 'MODX\\Revolution\\modWebLink': - o = { - xtype: 'textfield' - ,fieldLabel: _('weblink') - ,name: 'content' - ,id: 'modx-'+id+'-content' - ,anchor: '100%' - ,maxLength: 255 - ,value: '' + field = { + xtype: 'textfield', + fieldLabel: _('weblink'), + name: 'content', + id: `modx-${id}-content`, + anchor: '100%', + maxLength: 255, + value: '' }; break; case 'MODX\\Revolution\\modStaticResource': - o = { - xtype: 'modx-combo-browser' - ,browserEl: 'modx-browser' - ,prependPath: false - ,prependUrl: false - ,fieldLabel: _('static_resource') - ,name: 'content' - ,id: 'modx-'+id+'-content' - ,anchor: '100%' - ,maxLength: 255 - ,value: '' - ,listeners: { - 'select':{fn:function(data) { - if (data.url.substring(0,1) == '/') { - Ext.getCmp('modx-'+id+'-content').setValue(data.url.substring(1)); - } - },scope:this} + field = { + xtype: 'modx-combo-browser', + browserEl: 'modx-browser', + prependPath: false, + prependUrl: false, + fieldLabel: _('static_resource'), + name: 'content', + id: `modx-${id}-content`, + anchor: '100%', + maxLength: 255, + value: '', + listeners: { + select: { + fn: function(data) { + if (data.url.substring(0, 1) === '/') { + Ext.getCmp(`modx-${id}-content`).setValue(data.url.substring(1)); + } + }, + scope: this + } } }; break; case 'MODX\\Revolution\\modResource': case 'MODX\\Revolution\\modDocument': default: - o = { - xtype: 'textarea' - ,name: 'content' - ,id: 'modx-'+id+'-content' - ,fieldLabel: _('content') - ,labelSeparator: '' - ,anchor: '100%' - ,style: 'min-height: 200px' - ,grow: true + field = { + xtype: 'textarea', + name: 'content', + id: `modx-${id}-content`, + fieldLabel: _('content'), + labelSeparator: '', + anchor: '100%', + style: 'min-height: 200px', + grow: true }; break; } - return o; + return field; }; -MODx.getQRSettings = function(id,va) { - id = id || 'qur'; +/** + * Gets the form fields for the Quick Create Resource settings tab + * + * @param {String} id The currently-active quick create window id + * @param {Object} parentData Subset of record data relating to the clicked upon Resource or Context + * @returns Ext configuration for settings fields + */ +MODx.getQuickCreateResourceSettingsFields = function(id, parentData) { + id = id || 'window-quick-create-resource-default'; return [{ - layout: 'column' - ,border: false - ,anchor: '100%' - ,defaults: { - labelSeparator: '' - ,labelAlign: 'top' - ,border: false - ,layout: 'form' - } - ,items: [{ - columnWidth: .5 - ,items: [{ - xtype: 'hidden' - ,name: 'parent' - ,id: 'modx-'+id+'-parent' - ,value: va['parent'] - },{ - xtype: 'hidden' - ,name: 'context_key' - ,id: 'modx-'+id+'-context_key' - ,value: va['context_key'] - },{ - xtype: 'hidden' - ,name: 'class_key' - ,id: 'modx-'+id+'-class_key' - ,value: va['class_key'] - },{ - xtype: 'hidden' - ,name: 'publishedon' - ,id: 'modx-'+id+'-publishedon' - ,value: va['publishedon'] - },{ - xtype: 'modx-field-parent-change' - ,fieldLabel: _('resource_parent') - ,description: '[[*parent]]
'+_('resource_parent_help') - ,name: 'parent-cmb' - ,id: 'modx-'+id+'-parent-change' - ,value: va['parent'] || 0 - ,anchor: '100%' - ,parentcmp: 'modx-'+id+'-parent' - ,contextcmp: 'modx-'+id+'-context_key' - ,currentid: va['id'] || 0 - },{ - xtype: 'modx-combo-class-derivatives' - ,fieldLabel: _('resource_type') - ,description: '[[*class_key]]
' - ,name: 'class_key' - ,hiddenName: 'class_key' - ,id: 'modx-'+id+'-class-key' - ,anchor: '100%' - ,value: va['class_key'] != undefined ? va['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-'+id+'-type' - ,anchor: '100%' - ,value: va['content_type'] != undefined ? va['content_type'] : (MODx.config.default_content_type || 1) - - },{ - xtype: 'modx-combo-content-disposition' - ,fieldLabel: _('resource_contentdispo') - ,description: '[[*content_dispo]]
'+_('resource_contentdispo_help') - ,name: 'content_dispo' - ,hiddenName: 'content_dispo' - ,id: 'modx-'+id+'-dispo' - ,anchor: '100%' - ,value: va['content_dispo'] != undefined ? va['content_dispo'] : 0 - },{ - xtype: 'numberfield' - ,fieldLabel: _('resource_menuindex') - ,description: '[[*menuindex]]
'+_('resource_menuindex_help') - ,name: 'menuindex' - ,id: 'modx-'+id+'-menuindex' - ,width: 75 - ,value: va['menuindex'] || 0 + layout: 'column', + border: false, + anchor: '100%', + defaults: { + labelSeparator: '', + labelAlign: 'top', + border: false, + layout: 'form' + }, + items: [{ + columnWidth: 0.5, + items: [{ + xtype: 'hidden', + name: 'parent', + id: `modx-${id}-parent`, + value: parentData.parent + }, { + xtype: 'hidden', + name: 'context_key', + id: `modx-${id}-context_key`, + value: parentData.context_key + }, { + xtype: 'hidden', + name: 'class_key', + id: `modx-${id}-class_key`, + value: parentData.class_key + }, { + xtype: 'hidden', + name: 'publishedon', + id: `modx-${id}-publishedon`, + value: parentData.publishedon + }, { + xtype: 'modx-field-parent-change', + fieldLabel: _('resource_parent'), + description: `[[*parent]]
${_('resource_parent_help')}`, + name: 'parent-cmb', + id: `modx-${id}-parent-change`, + value: parentData.parent || 0, + anchor: '100%', + parentcmp: `modx-${id}-parent`, + contextcmp: `modx-${id}-context_key`, + currentid: parentData.id || 0 + }, { + xtype: 'modx-combo-class-derivatives', + fieldLabel: _('resource_type'), + description: '[[*class_key]]
', + name: 'class_key', + hiddenName: 'class_key', + id: `modx-${id}-class-key`, + anchor: '100%', + value: parentData.class_key !== undefined ? parentData.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-${id}-type`, + anchor: '100%', + value: parentData.content_type !== undefined ? parentData.content_type : (MODx.config.default_content_type || 1) + + }, { + xtype: 'modx-combo-content-disposition', + fieldLabel: _('resource_contentdispo'), + description: `[[*content_dispo]]
${_('resource_contentdispo_help')}`, + name: 'content_dispo', + hiddenName: 'content_dispo', + id: `modx-${id}-dispo`, + anchor: '100%', + value: parentData.content_dispo !== undefined ? parentData.content_dispo : 0 + }, { + xtype: 'numberfield', + fieldLabel: _('resource_menuindex'), + description: `[[*menuindex]]
${_('resource_menuindex_help')}`, + name: 'menuindex', + id: `modx-${id}-menuindex`, + width: 75, + value: parentData.menuindex || 0 }] - },{ - columnWidth: .5 - ,items: [{ - xtype: 'xdatetime' - ,fieldLabel: _('resource_publishedon') - ,description: '[[*publishedon]]
'+_('resource_publishedon_help') - ,name: 'publishedon' - ,id: 'modx-'+id+'-publishedon' - ,allowBlank: true - ,dateFormat: MODx.config.manager_date_format - ,timeFormat: MODx.config.manager_time_format - ,startDay: parseInt(MODx.config.manager_week_start) - ,dateWidth: 153 - ,timeWidth: 153 - ,offset_time: MODx.config.server_offset_time - ,value: va['publishedon'] - },{ - xtype: va['canpublish'] ? 'xdatetime' : 'hidden' - ,fieldLabel: _('resource_publishdate') - ,description: '[[*pub_date]]
'+_('resource_publishdate_help') - ,name: 'pub_date' - ,id: 'modx-'+id+'-pub-date' - ,allowBlank: true - ,dateFormat: MODx.config.manager_date_format - ,timeFormat: MODx.config.manager_time_format - ,startDay: parseInt(MODx.config.manager_week_start) - ,dateWidth: 153 - ,timeWidth: 153 - ,offset_time: MODx.config.server_offset_time - ,value: va['pub_date'] - },{ - xtype: va['canpublish'] ? 'xdatetime' : 'hidden' - ,fieldLabel: _('resource_unpublishdate') - ,description: '[[*unpub_date]]
'+_('resource_unpublishdate_help') - ,name: 'unpub_date' - ,id: 'modx-'+id+'-unpub-date' - ,allowBlank: true - ,dateFormat: MODx.config.manager_date_format - ,timeFormat: MODx.config.manager_time_format - ,startDay: parseInt(MODx.config.manager_week_start) - ,dateWidth: 153 - ,timeWidth: 153 - ,offset_time: MODx.config.server_offset_time - ,value: va['unpub_date'] - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_folder') - ,description: _('resource_folder_help') - ,hideLabel: true - ,name: 'isfolder' - ,id: 'modx-'+id+'-isfolder' - ,inputValue: 1 - ,checked: va['isfolder'] != undefined ? va['isfolder'] : false - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_show_in_tree') - ,description: _('resource_show_in_tree_help') - ,hideLabel: true - ,name: 'show_in_tree' - ,id: 'modx-'+id+'-show_in_tree' - ,inputValue: 1 - ,checked: va['show_in_tree'] != undefined ? va['show_in_tree'] : 1 - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_hide_children_in_tree') - ,description: _('resource_hide_children_in_tree_help') - ,hideLabel: true - ,name: 'hide_children_in_tree' - ,id: 'modx-'+id+'-hide_children_in_tree' - ,inputValue: 1 - ,checked: va['hide_children_in_tree'] != undefined ? va['hide_children_in_tree'] : false - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_alias_visible') - ,description: _('resource_alias_visible_help') - ,hideLabel: true - ,name: 'alias_visible' - ,id: 'modx-'+id+'-alias-visible' - ,inputValue: 1 - ,checked: va['alias_visible'] != undefined ? va['alias_visible'] : 1 - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_uri_override') - ,description: _('resource_uri_override_help') - ,hideLabel: true - ,name: 'uri_override' - ,id: 'modx-'+id+'-uri-override' - ,value: 1 - ,checked: parseInt(va['uri_override']) ? true : false - ,listeners: {'check': {fn:MODx.handleFreezeUri}} - },{ - xtype: 'textfield' - ,fieldLabel: _('resource_uri') - ,description: '[[*uri]]
'+_('resource_uri_help') - ,name: 'uri' - ,id: 'modx-'+id+'-uri' - ,maxLength: 255 - ,anchor: '100%' - ,value: va['uri'] || '' - ,hidden: !va['uri_override'] - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_richtext') - ,description: _('resource_richtext_help') - ,hideLabel: true - ,name: 'richtext' - ,id: 'modx-'+id+'-richtext' - ,inputValue: 1 - ,checked: va['richtext'] !== undefined ? (va['richtext'] ? 1 : 0) : (MODx.config.richtext_default == '1' ? 1 : 0) - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_searchable') - ,description: _('resource_searchable_help') - ,hideLabel: true - ,name: 'searchable' - ,id: 'modx-'+id+'-searchable' - ,inputValue: 1 - ,checked: va['searchable'] !== undefined ? (va['searchable'] ? 1 : 0) : (MODx.config.search_default == '1' ? 1 : 0) - ,listeners: {'check': {fn:MODx.handleQUCB}} - },{ - xtype: 'xcheckbox' - ,boxLabel: _('resource_cacheable') - ,description: _('resource_cacheable_help') - ,hideLabel: true - ,name: 'cacheable' - ,id: 'modx-'+id+'-cacheable' - ,inputValue: 1 - ,checked: va['cacheable'] !== undefined ? (va['cacheable'] ? 1 : 0) : (MODx.config.cache_default == '1' ? 1 : 0) - },{ - xtype: 'xcheckbox' - ,name: 'clearCache' - ,id: 'modx-'+id+'-clearcache' - ,boxLabel: _('resource_syncsite') - ,description: _('resource_syncsite_help') - ,hideLabel: true - ,inputValue: 1 - ,checked: va['clearCache'] !== undefined ? (va['clearCache'] ? 1 : 0) : (MODx.config.syncsite_default == '1' ? 1 : 0) + }, { + columnWidth: 0.5, + items: [{ + xtype: 'xdatetime', + fieldLabel: _('resource_publishedon'), + description: `[[*publishedon]]
${_('resource_publishedon_help')}`, + name: 'publishedon', + id: `modx-${id}-publishedon`, + allowBlank: true, + dateFormat: MODx.config.manager_date_format, + timeFormat: MODx.config.manager_time_format, + startDay: parseInt(MODx.config.manager_week_start, 10), + dateWidth: 153, + timeWidth: 153, + offset_time: MODx.config.server_offset_time, + value: parentData.publishedon + }, { + xtype: parentData.canpublish ? 'xdatetime' : 'hidden', + fieldLabel: _('resource_publishdate'), + description: `[[*pub_date]]
${_('resource_publishdate_help')}`, + name: 'pub_date', + id: `modx-${id}-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: 153, + timeWidth: 153, + offset_time: MODx.config.server_offset_time, + value: parentData.pub_date + }, { + xtype: parentData.canpublish ? 'xdatetime' : 'hidden', + fieldLabel: _('resource_unpublishdate'), + description: `[[*unpub_date]]
${_('resource_unpublishdate_help')}`, + name: 'unpub_date', + id: `modx-${id}-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: 153, + timeWidth: 153, + offset_time: MODx.config.server_offset_time, + value: parentData.unpub_date + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_folder'), + description: _('resource_folder_help'), + hideLabel: true, + name: 'isfolder', + id: `modx-${id}-isfolder`, + inputValue: 1, + checked: parentData.isfolder !== undefined ? parentData.isfolder : false + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_show_in_tree'), + description: _('resource_show_in_tree_help'), + hideLabel: true, + name: 'show_in_tree', + id: `modx-${id}-show_in_tree`, + inputValue: 1, + checked: parentData.show_in_tree !== undefined ? parentData.show_in_tree : 1 + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_hide_children_in_tree'), + description: _('resource_hide_children_in_tree_help'), + hideLabel: true, + name: 'hide_children_in_tree', + id: `modx-${id}-hide_children_in_tree`, + inputValue: 1, + checked: parentData.hide_children_in_tree !== undefined ? parentData.hide_children_in_tree : false + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_alias_visible'), + description: _('resource_alias_visible_help'), + hideLabel: true, + name: 'alias_visible', + id: `modx-${id}-alias-visible`, + inputValue: 1, + checked: parentData.alias_visible !== undefined ? parentData.alias_visible : 1 + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_uri_override'), + description: _('resource_uri_override_help'), + hideLabel: true, + name: 'uri_override', + id: `modx-${id}-uri-override`, + value: 1, + checked: parseInt(parentData.uri_override, 10) === 1, + listeners: { + check: { + fn: MODx.handleFreezeUri + } + } + }, { + xtype: 'textfield', + fieldLabel: _('resource_uri'), + description: `[[*uri]]
${_('resource_uri_help')}`, + name: 'uri', + id: `modx-${id}-uri`, + maxLength: 255, + anchor: '100%', + value: parentData.uri || '', + hidden: !parentData.uri_override + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_richtext'), + description: _('resource_richtext_help'), + hideLabel: true, + name: 'richtext', + id: `modx-${id}-richtext`, + inputValue: 1, + checked: (parentData.richtext !== undefined && parentData.richtext) || parseInt(MODx.config.richtext_default, 10) === 1 ? 1 : 0 + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_searchable'), + description: _('resource_searchable_help'), + hideLabel: true, + name: 'searchable', + id: `modx-${id}-searchable`, + inputValue: 1, + checked: (parentData.searchable !== undefined && parentData.searchable) || parseInt(MODx.config.search_default, 10) === 1 ? 1 : 0 + }, { + xtype: 'xcheckbox', + boxLabel: _('resource_cacheable'), + description: _('resource_cacheable_help'), + hideLabel: true, + name: 'cacheable', + id: `modx-${id}-cacheable`, + inputValue: 1, + checked: (parentData.cacheable !== undefined && parentData.cacheable) || parseInt(MODx.config.cache_default, 10) === 1 ? 1 : 0 + }, { + xtype: 'xcheckbox', + name: 'clearCache', + id: `modx-${id}-clearcache`, + boxLabel: _('resource_syncsite'), + description: _('resource_syncsite_help'), + hideLabel: true, + inputValue: 1, + checked: (parentData.clearCache !== undefined && parentData.clearCache) || parseInt(MODx.config.syncsite_default, 10) === 1 ? 1 : 0 }] }] }]; }; -MODx.handleQUCB = function(cb) { - var h = Ext.getCmp(cb.id+'-hd'); - if (cb.checked && h) { - cb.setValue(1); - h.setValue(1); - } else if (h) { - cb.setValue(0); - h.setValue(0); - } -}; - MODx.handleFreezeUri = function(cb) { - var uri = Ext.getCmp(cb.id.replace('-override', '')); - if (!uri) { return false; } + const uri = Ext.getCmp(cb.id.replace('-override', '')); + if (!uri) { + return false; + } if (cb.checked) { uri.show(); } else { @@ -1381,12 +1504,6 @@ MODx.handleFreezeUri = function(cb) { } }; -Ext.override(Ext.tree.AsyncTreeNode,{ - - listeners: { - click: {fn: function(){ - console.log('Clicked me!',arguments); - return false; - },scope: this} - } -}); +// Reference old class names to new +MODx.getQRContentField = MODx.getQuickCreateResourceContentField; +MODx.getQRSettings = MODx.getQuickCreateResourceSettingsFields; diff --git a/manager/controllers/default/resource/data.class.php b/manager/controllers/default/resource/data.class.php index 887fb1965c2..4c203faa196 100644 --- a/manager/controllers/default/resource/data.class.php +++ b/manager/controllers/default/resource/data.class.php @@ -85,6 +85,7 @@ public function process(array $scriptProperties = []) return $this->modx->lexicon('resource_err_nfs', ['id' => $this->scriptProperties['id']]); } + /** @disregard P1013 */ if (!$this->resource->checkPolicy('view')) { $this->failure($this->modx->lexicon('access_denied')); @@ -100,6 +101,7 @@ public function process(array $scriptProperties = []) $this->resource->set('editedon_adjusted', strftime('%c', $this->resource->get('editedon') + $server_offset_time)); $this->resource->_contextKey = $this->resource->get('context_key'); + /** @disregard P1013 */ $buffer = $this->modx->cacheManager->get($this->resource->getCacheKey(), [ xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_resource_key', null, 'resource'), xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_resource_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)), @@ -111,8 +113,8 @@ public function process(array $scriptProperties = []) // assign resource to smarty $placeholders['resource'] = $this->resource; - // make preview url - $this->getPreviewUrl(); + /** @disregard P1013 */ + $this->previewUrl = $this->resource->getPreviewUrl(); $placeholders['_ctx'] = $this->resource->get('context_key'); return $placeholders; @@ -120,16 +122,15 @@ public function process(array $scriptProperties = []) } /** - * @return string + * Creates a full preview URL for the current or target (in the case of Weblinks) Resource + * + * @deprecated Remove in MODX 4.0. Method now available in modResource */ - public function getPreviewUrl() + public function getPreviewUrl(): string { - $this->previewUrl = $this->modx->makeUrl($this->resource->get('id'), $this->resource->get('context_key')); - - return $this->previewUrl; + return $this->resource->getPreviewUrl(); } - /** * Return the pagetitle * diff --git a/manager/controllers/default/resource/update.class.php b/manager/controllers/default/resource/update.class.php index 71f61497d70..be438758e3b 100644 --- a/manager/controllers/default/resource/update.class.php +++ b/manager/controllers/default/resource/update.class.php @@ -1,4 +1,5 @@ modx->lexicon('resource_err_nfs', ['id' => $this->scriptProperties['id']]); } + /** @disregard P1013 */ if (!$this->resource->checkPolicy('save')) { $this->canSave = false; } @@ -105,7 +106,6 @@ public function process(array $scriptProperties = []) $loaded = $this->getResource(); if ($loaded !== true) { $this->failure($loaded); - return []; } if (is_array($reloadData) && !empty($reloadData)) { @@ -116,7 +116,6 @@ public function process(array $scriptProperties = []) $this->setContext(); if (!$this->context) { $this->failure($this->modx->lexicon('access_denied')); - return []; } @@ -124,7 +123,9 @@ public function process(array $scriptProperties = []) $this->checkForLocks(); // set template overrides - if (isset($scriptProperties['template'])) $this->resource->set('template', $scriptProperties['template']); + if (isset($scriptProperties['template'])) { + $this->resource->set('template', $scriptProperties['template']); + } $this->setParent(); @@ -147,8 +148,7 @@ public function process(array $scriptProperties = []) if (isset($this->resourceArray['syncsite'])) { $this->resourceArray['syncsite'] = !empty($this->resourceArray['syncsite']); } else { - $syncsiteDefault = $this->context->getOption('syncsite_default', 1, - $this->modx->_userConfig); + $syncsiteDefault = $this->context->getOption('syncsite_default', 1, $this->modx->_userConfig); $this->resourceArray['syncsite'] = !empty($syncsiteDefault); } if (!empty($this->resourceArray['parent'])) { @@ -186,7 +186,7 @@ public function process(array $scriptProperties = []) $this->prepareResource(); $this->loadTVs($reloadData); - $this->getPreviewUrl(); + $this->previewUrl = $this->resource->getPreviewUrl(); // Single-use token for reloading resource $this->setResourceToken(); $this->setPlaceholder('resource', $this->resource); @@ -196,30 +196,15 @@ public function process(array $scriptProperties = []) /** - * Get url for resource for preview window + * Creates a full preview URL for the current or target (in the case of Weblinks) Resource * - * @return string + * @deprecated Remove in MODX 4.0. Method now available in modResource */ - public function getPreviewUrl() + public function getPreviewUrl(): string { - if (!$this->resource->get('deleted')) { - $this->modx->setOption('cache_alias_map', false); - $sessionEnabled = ''; - $ctxSetting = $this->modx->getObject(modContextSetting::class, [ - 'context_key' => $this->resource->get('context_key'), - 'key' => 'session_enabled', - ]); - if ($ctxSetting) { - $sessionEnabled = $ctxSetting->get('value') == 0 ? ['preview' => 'true'] : ''; - } - - $this->previewUrl = $this->modx->makeUrl($this->resource->get('id'), $this->resource->get('context_key'), $sessionEnabled, 'full', ['xhtml_urls' => false]); - } - - return $this->previewUrl; + return $this->resource->getPreviewUrl(); } - /** * Check for locks on the Resource *