update.class.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. class StaticResourceUpdateManagerController extends ResourceUpdateManagerController {
  11. /**
  12. * Register custom CSS/JS for the page
  13. * @return void
  14. */
  15. public function loadCustomCssJs() {
  16. $managerUrl = $this->context->getOption('manager_url', MODX_MANAGER_URL, $this->modx->_userConfig);
  17. $this->addJavascript($managerUrl.'assets/modext/widgets/element/modx.panel.tv.renders.js');
  18. $this->addJavascript($managerUrl.'assets/modext/widgets/resource/modx.grid.resource.security.local.js');
  19. $this->addJavascript($managerUrl.'assets/modext/widgets/resource/modx.panel.resource.tv.js');
  20. $this->addJavascript($managerUrl.'assets/modext/widgets/resource/modx.panel.resource.js');
  21. $this->addJavascript($managerUrl.'assets/modext/widgets/resource/modx.panel.resource.static.js');
  22. $this->addJavascript($managerUrl.'assets/modext/sections/resource/update.js');
  23. $this->addJavascript($managerUrl.'assets/modext/sections/resource/static/update.js');
  24. $this->addHtml('<script type="text/javascript">
  25. // <![CDATA[
  26. MODx.config.publish_document = "'.$this->canPublish.'";
  27. MODx.onDocFormRender = "'.$this->onDocFormRender.'";
  28. MODx.ctx = "'.$this->resource->get('context_key').'";
  29. Ext.onReady(function() {
  30. MODx.load({
  31. xtype: "modx-page-static-update"
  32. ,resource: "'.$this->resource->get('id').'"
  33. ,record: '.$this->modx->toJSON($this->resourceArray).'
  34. ,publish_document: "'.$this->canPublish.'"
  35. ,preview_url: "'.$this->previewUrl.'"
  36. ,locked: '.($this->locked ? 1 : 0).'
  37. ,lockedText: "'.$this->lockedText.'"
  38. ,canSave: '.($this->canSave ? 1 : 0).'
  39. ,canEdit: "'.($this->modx->hasPermission('edit_document') ? 1 : 0).'"
  40. ,canCreate: "'.($this->modx->hasPermission('new_document') ? 1 : 0).'"
  41. ,canDelete: "'.($this->modx->hasPermission('delete_document') ? 1 : 0).'"
  42. ,show_tvs: '.(!empty($this->tvCounts) ? 1 : 0).'
  43. });
  44. });
  45. // ]]>
  46. </script>');
  47. /* load RTE */
  48. $this->loadRichTextEditor();
  49. }
  50. /**
  51. * Used to set values on the resource record sent to the template for derivative classes
  52. *
  53. * @return void|string
  54. */
  55. public function prepareResource() {
  56. /* get openTo directory */
  57. $baseUrlRelative = false;
  58. $wctx = $this->resource->get('context_key');
  59. if (!empty($wctx)) {
  60. $workingContext = $this->modx->getContext($wctx);
  61. if (!$workingContext) {
  62. return $this->failure($this->modx->lexicon('permission_denied'));
  63. }
  64. } else {
  65. $workingContext =& $this->modx->context;
  66. }
  67. $this->modx->getService('fileHandler','modFileHandler', '', array('context' => $workingContext->get('key')));
  68. $baseUrl = $this->modx->fileHandler->getBaseUrl();
  69. if (!empty($this->resourceArray['content'])) {
  70. $this->resourceArray['openTo'] = str_replace($baseUrl,'',dirname($this->resourceArray['content']).'/');
  71. } else {
  72. $this->resourceArray['openTo'] = '/';
  73. }
  74. }
  75. /**
  76. * Return the location of the template file
  77. * @return string
  78. */
  79. public function getTemplateFile() {
  80. return 'resource/staticresource/update.tpl';
  81. }
  82. }