create.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. /**
  11. * Load create template page
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class ElementTemplateCreateManagerController extends modManagerController {
  17. public $category;
  18. public $onTempFormRender = '';
  19. public $onTempFormPrerender = '';
  20. /**
  21. * Check for any permissions or requirements to load page
  22. * @return bool
  23. */
  24. public function checkPermissions() {
  25. return $this->modx->hasPermission('new_template');
  26. }
  27. /**
  28. * Register custom CSS/JS for the page
  29. * @return void
  30. */
  31. public function loadCustomCssJs() {
  32. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  33. $this->addJavascript($mgrUrl.'assets/modext/widgets/core/modx.grid.local.property.js');
  34. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.grid.element.properties.js');
  35. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.grid.template.tv.js');
  36. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.panel.template.js');
  37. $this->addJavascript($mgrUrl.'assets/modext/sections/element/template/create.js');
  38. $this->addHtml('
  39. <script type="text/javascript">
  40. // <![CDATA[
  41. MODx.onTempFormRender = "'.$this->onTempFormRender.'";
  42. MODx.perm.unlock_element_properties = "'.($this->modx->hasPermission('unlock_element_properties') ? 1 : 0).'";
  43. Ext.onReady(function() {
  44. MODx.load({
  45. xtype: "modx-page-template-create"
  46. ,record: {
  47. category: "'.($this->category ? $this->category->get('id') : 0).'"
  48. }
  49. });
  50. });
  51. // ]]>
  52. </script>');
  53. }
  54. /**
  55. * Custom logic code here for setting placeholders, etc
  56. * @param array $scriptProperties
  57. * @return mixed
  58. */
  59. public function process(array $scriptProperties = array()) {
  60. $placeholders = array();
  61. /* grab category if preset */
  62. if (isset($scriptProperties['category'])) {
  63. $this->category = $this->modx->getObject('modCategory',$scriptProperties['category']);
  64. if ($this->category != null) {
  65. $placeholders['category'] = $this->category;
  66. }
  67. }
  68. /* invoke OnTempFormRender event */
  69. $placeholders['onTempFormRender'] = $this->fireRenderEvent();
  70. return $placeholders;
  71. }
  72. /**
  73. * Invoke OnTempFormPrerender event
  74. * @return void
  75. */
  76. public function firePreRenderEvents() {
  77. /* PreRender events inject directly into the HTML, as opposed to the JS-based Render event which injects HTML
  78. into the panel */
  79. $this->onTempFormPrerender = $this->modx->invokeEvent('OnTempFormPrerender',array(
  80. 'id' => 0,
  81. 'mode' => modSystemEvent::MODE_NEW,
  82. ));
  83. if (is_array($this->onTempFormPrerender)) $this->onTempFormPrerender = implode('',$this->onTempFormPrerender);
  84. $this->setPlaceholder('onTempFormPrerender', $this->onTempFormPrerender);
  85. }
  86. /**
  87. * Invoke OnTempFormRender event
  88. * @return string
  89. */
  90. public function fireRenderEvent() {
  91. $this->onTempFormRender = $this->modx->invokeEvent('OnTempFormRender',array(
  92. 'id' => 0,
  93. 'mode' => modSystemEvent::MODE_NEW,
  94. ));
  95. if (is_array($this->onTempFormRender)) $this->onTempFormRender = implode('',$this->onTempFormRender);
  96. $this->onTempFormRender = str_replace(array('"',"\n","\r"),array('\"','',''),$this->onTempFormRender);
  97. return $this->onTempFormRender;
  98. }
  99. /**
  100. * Return the pagetitle
  101. *
  102. * @return string
  103. */
  104. public function getPageTitle() {
  105. return $this->modx->lexicon('template_new');
  106. }
  107. /**
  108. * Return the location of the template file
  109. * @return string
  110. */
  111. public function getTemplateFile() {
  112. return 'element/template/create.tpl';
  113. }
  114. /**
  115. * Specify the language topics to load
  116. * @return array
  117. */
  118. public function getLanguageTopics() {
  119. return array('template','category','propertyset','element','tv');
  120. }
  121. /**
  122. * Get the Help URL
  123. * @return string
  124. */
  125. public function getHelpUrl() {
  126. return 'Templates';
  127. }
  128. }