PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/views/crud/blank_slate.view.php

https://github.com/jay3/core
PHP | 175 lines | 153 code | 13 blank | 9 comment | 13 complexity | a7394aa2e380b4d039a72470d1dab2e9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * NOVIUS OS - Web OS for digital communication
  4. *
  5. * @copyright 2011 Novius
  6. * @license GNU Affero General Public License v3 or (at your option) any later version
  7. * http://www.gnu.org/licenses/agpl-3.0.html
  8. * @link http://www.novius-os.org
  9. */
  10. \Nos\I18n::current_dictionary('nos::application');
  11. $uniqid = uniqid(str_replace(':', '_', $context).'_');
  12. $labels = array();
  13. $possible = $item->get_possible_context();
  14. $main_context = $item->find_main_context();
  15. if (!empty($main_context)) {
  16. $common_id = $main_context->{$crud['behaviours']['twinnable']['common_id_property']};
  17. } else {
  18. $common_id = false;
  19. }
  20. $view_params['container_id'] = $uniqid;
  21. echo View::forge('nos::crud/tab', $view_params, false);
  22. $context_or_language = count(Nos\Tools_Context::sites()) == 1 ? 'language' : 'context';
  23. ?>
  24. <div id="<?= $uniqid ?>" class="" style="padding:0;">
  25. <div class="blank_slate">
  26. <?php
  27. if (!in_array($context, $possible)) {
  28. echo '<p>&nbsp;</p>';
  29. $parent = $crud['behaviours']['tree'] ? $item->get_parent() : null;
  30. if (!empty($parent)) {
  31. $uniqid_parent = uniqid('parent_');
  32. echo strtr($crud['config']['i18n']['translate error parent not available in '.$context_or_language], array(
  33. '{{'.$context_or_language.'}}' => \Nos\Tools_Context::contextLabel($context),
  34. '<a>' => '<a href="javascript:void;" id="'.$uniqid_parent.'">',
  35. ));
  36. ?>
  37. <script type="text/javascript">
  38. require(['jquery-nos'], function($) {
  39. $('#<?= $uniqid_parent ?>').click(function() {
  40. $(this).nosTabs('open', <?= \Format::forge()->to_json(array('url' => $crud['url_insert_update'].'/'.$parent->id.'?context='.$context)) ?>);
  41. });
  42. });
  43. </script>
  44. <?php
  45. } else {
  46. echo strtr($crud['config']['i18n']['translate error impossible context'], array('{{context}}' => \Nos\Tools_Context::contextLabel($context)));
  47. }
  48. } else {
  49. foreach ($possible as $possible_context) {
  50. $item_context = $item->find_context($possible_context);
  51. if (!empty($item_context)) {
  52. $context_label = \Nos\Tools_Context::contextLabel($possible_context);
  53. // Note to translator: this is an action (button)
  54. $labels[$item_context->id] = strtr(__('Translate from {{context}}'), array(
  55. '{{context}}' => $context_label,
  56. ));
  57. }
  58. }
  59. $locale_item = \Nos\Tools_Context::localeCode($item->get_context());
  60. $locale_new = \Nos\Tools_Context::localeCode($context);
  61. if ($locale_item === $locale_new) {
  62. $label = __('Add ‘{{item}}’ to {{context}}');
  63. } else {
  64. $label = __('Translate ‘{{item}}’ into {{context}}');
  65. }
  66. echo '<h1>', strtr($label, array('{{item}}' => $item->title_item(), '{{context}}' => \Nos\Tools_Context::contextLabel($context))), '</h1>';
  67. ?>
  68. <p>&nbsp;</p>
  69. <p><?= __('You have two options:') ?></p>
  70. <p>&nbsp;</p>
  71. <ul style="margin-left:1em;">
  72. <li>
  73. <span style="display:inline-block; width:2em;"></span>
  74. <form action="<?= $crud['url_form'] ?>" style="display:inline-block;">
  75. <?= Form::hidden('context', $context) ?>
  76. <?= Form::hidden('common_id', $common_id) ?>
  77. <button type="submit" class="ui-priority-primary" data-icon="plus"><?= __('Start from scratch') ?></button>
  78. </form>
  79. <p style="font-style: italic; padding: 5px 0 2em 4em;"><?= __('(Blank form)') ?></p>
  80. </li>
  81. <li>
  82. <span class="faded" style="display:inline-block; width:2em;"><?= __('OR') ?></span>
  83. <form action="<?= $crud['url_form'] ?>" style="display:inline-block;">
  84. <?= Form::hidden('context', $context) ?>
  85. <?= Form::hidden('common_id', $common_id) ?>
  86. <?php
  87. $uniqid_create_from_id = 'create_from_id_'.$uniqid;
  88. $uniqid_wijmenu = 'wijmenu_'.$uniqid;
  89. echo '<input id="'.$uniqid_create_from_id.'" type="hidden" name="create_from_id" value="'.htmlspecialchars(key($labels)).'" />';
  90. if (count($labels) == 1) {
  91. echo '<button type="submit" class="ui-priority-primary" data-icon="plus">'.current($labels).'</button>';
  92. } else {
  93. echo '<div class="buttonset">
  94. <button type="submit" class="ui-priority-primary" data-icon="plus">'.current($labels).'</button>
  95. <button id="'.$uniqid_wijmenu.'" type="button" class="ui-priority-primary without-text" data-icon="carat-1-s primary">&nbsp;</button>
  96. </div>';
  97. echo '<ul class="wijmenu">';
  98. foreach ($labels as $context => $label) {
  99. echo '<li data-create_from_id="'.htmlspecialchars($context).'"><a>'.$label.'</a></li>';
  100. }
  101. echo '</ul>';
  102. }
  103. ?>
  104. </form>
  105. <p style="font-style: italic; padding: 5px 0 2em 4em;"><?= __('(Form filled with the contents from the original version)') ?></p>
  106. </li>
  107. </ul>
  108. <?php
  109. }
  110. ?>
  111. </div>
  112. </div>
  113. <script type="text/javascript">
  114. require(['jquery-nos'], function ($) {
  115. $(function () {
  116. var $container = $('#<?= $uniqid ?>').nosFormUI();
  117. var $wijmenu = $container.find('ul.wijmenu');
  118. $container.find('.buttonset').buttonset();
  119. $container.find('ul.wijmenu')
  120. .wijmenu({
  121. orientation: 'vertical',
  122. animation: {
  123. animated:"slide",
  124. option: {
  125. direction: "up"
  126. },
  127. duration: 50,
  128. easing: null
  129. },
  130. hideAnimation: {
  131. animated:"slide",
  132. option: {
  133. direction: "up"
  134. },
  135. duration: 0,
  136. easing: null
  137. },
  138. direction: 'rtl',
  139. trigger: '#<?= $uniqid_wijmenu ?>',
  140. shown: function (event, item) {
  141. var $contextMenu = $(item.element);
  142. $contextMenu.parent()
  143. .css({
  144. maxHeight: '200px',
  145. width: $contextMenu.outerWidth(true) + 20,
  146. overflowY: 'auto',
  147. overflowX: 'hidden'
  148. })
  149. },
  150. select: function(e, data) {
  151. $('#<?= $uniqid_create_from_id ?>').val($(data.item.element).data('create_from_id'));
  152. $container.find('form').submit();
  153. }
  154. });
  155. $container.find('form').submit(function(e) {
  156. e.preventDefault();
  157. var $form = $(this);
  158. $container.load($form.get(0).action, $form.serialize());
  159. });
  160. });
  161. });
  162. </script>