PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/applications/noviusos_page/views/admin/popup_duplicate.view.php

https://github.com/jay3/core
PHP | 198 lines | 168 code | 21 blank | 9 comment | 15 complexity | 49257225a2c4b69598d1b0afc0850c68 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('noviusos_page::common', 'nos::common');
  11. $id = $uniqid = uniqid('form_');
  12. $item_contexts = $item->find_context('all');
  13. $context_count = count($item_contexts);
  14. $children = array();
  15. $children_context = array();
  16. // Count the number of children in each context
  17. foreach ($item_contexts as $item_context) {
  18. $children_context[$item_context->get_context()] = 1;
  19. foreach ($item_context->find_children_recursive(false) as $child) {
  20. $children[$child->page_context_common_id] = true;
  21. $children_context[$item_context->get_context()]++;
  22. }
  23. }
  24. $children_count = count($children);
  25. $context_or_language = count(Nos\Tools_Context::sites()) == 1 ? 'language' : 'context';
  26. if ($children_count > 0 || $context_count > 1) {
  27. $deletion_summary = array();
  28. if ($context_count > 1) {
  29. $deletion_summary[] = 'N '.$context_or_language.'s';
  30. }
  31. if ($children_count > 0) {
  32. $deletion_summary[] = $children_count == 1 ? '1 child' : 'N children';
  33. }
  34. $deletion_summary = $crud['i18n']['deleting with '.implode(' and ', $deletion_summary)];
  35. $deletion_summary = strtr($deletion_summary, array(
  36. '{{'.$context_or_language.'_count}}' => $context_count,
  37. '{{children_count}}' => $children_count,
  38. '{{title}}' => $item->title_item(),
  39. ));
  40. ?>
  41. <p style="margin: 1em 0;"><?= $deletion_summary ?></p>
  42. <?php
  43. }
  44. ?>
  45. <form class="fieldset standalone" id="<?= $id ?>">
  46. <?php
  47. if ($context_count > 1 || $children_count > 0) {
  48. $contexts = \Nos\Tools_Context::contexts();
  49. $contexts_list = array();
  50. ?>
  51. <p><label><input type="checkbox" class="include_children" name="include_children" value="1" checked /> <?= __('Duplicate sub-pages'); ?></label></p>
  52. <div class="single">
  53. <table>
  54. <?php
  55. foreach ($item_contexts as $item_context) {
  56. $context = $item_context->get_context();
  57. $count = $children_context[$context];
  58. ?>
  59. <tr>
  60. <td><?= Nos\Tools_Context::contextLabel($item_context->get_context()) ?></td>
  61. <td><?= strtr($crud['i18n']['1 item'], array('{{count}}' => $count)) ?></td>
  62. <td><input type="checkbox" name="contexts_single[]" data-count="<?= 1 ?>" value="<?= $context ?>" checked /></td>
  63. </tr>
  64. <?php
  65. }
  66. ?>
  67. </table>
  68. </div>
  69. <div class="multi">
  70. <table>
  71. <?php
  72. foreach ($item_contexts as $item_context) {
  73. $context = $item_context->get_context();
  74. $count = $children_context[$context];
  75. ?>
  76. <tr>
  77. <td><?= Nos\Tools_Context::contextLabel($item_context->get_context()) ?></td>
  78. <td><?= strtr($crud['i18n'][$count == 1 ? '1 item' : 'N items'], array('{{count}}' => $count)) ?></td>
  79. <td><input type="checkbox" name="contexts_multi[]" data-count="<?= $children_context[$context] ?>" value="<?= $context ?>" checked /></td>
  80. </tr>
  81. <?php
  82. }
  83. ?>
  84. </table>
  85. </div>
  86. <?php
  87. }
  88. ?>
  89. <p style="margin: 1em 0;">
  90. <button type="submit" class="ui-priority-primary ui-state-default" data-texts="<?= htmlspecialchars(\Format::forge()->to_json(array(
  91. '0' => __('Nothing to duplicate'),
  92. '1' => __('Duplicate this page'),
  93. '+' => __('Duplicate these {{count}} pages'),
  94. ))) ?>"><?= __('Duplicate') ?></button>
  95. <span><?= __('or') ?></span>
  96. <a href="#"><?= __('Cancel') ?></a>
  97. </p>
  98. </form>
  99. <script type="text/javascript">
  100. require(['jquery-nos'],
  101. function ($) {
  102. $(function () {
  103. var $form = $('#<?= $id ?>'),
  104. $tables = $form.find('table'),
  105. $checkboxes,
  106. $confirmButton = $form.find(':submit'),
  107. $cancelButton = $form.find('a:last');
  108. $tables.wijgrid({
  109. selectionMode: 'none',
  110. highlightCurrentCell: false,
  111. columns: [
  112. {},
  113. {},
  114. {
  115. cellFormatter: function(args) {
  116. if (args.row.type & $.wijmo.wijgrid.rowType.data) {
  117. args.$container.css({
  118. textAlign: 'center'
  119. });
  120. }
  121. }
  122. }
  123. ],
  124. rendered: function(args) {
  125. $(args.target).closest('.wijmo-wijgrid').find('thead').hide();
  126. }
  127. });
  128. $form.nosFormUI();
  129. $checkboxes = $tables.find(':checkbox');
  130. $checkboxes.change(function() {
  131. var sum = 0;
  132. $checkboxes.filter(':checked').filter(':visible').each(function() {
  133. sum += +$(this).data('count');
  134. });
  135. $confirmButton[sum == 0 ? 'addClass' : 'removeClass']('ui-state-disabled');
  136. $confirmButton.find('.ui-button-text').text(
  137. $.nosDataReplace($confirmButton.data('texts')[(sum > 1 ? '+' : sum).toString()], {
  138. 'count': sum.toString()
  139. })
  140. );
  141. $(this).removeClass('ui-state-focus');
  142. });
  143. $form.find('.include_children').change(function() {
  144. var checked = $(this).is(':checked');
  145. if (checked) {
  146. $form.find('.single').hide();
  147. $form.find('.multi').show();
  148. } else {
  149. $form.find('.multi').hide();
  150. $form.find('.single').show();
  151. }
  152. $checkboxes.first().triggerHandler('change')
  153. }).triggerHandler('change');
  154. $tables.find('tr').css({cursor: 'pointer'}).click(function(e) {
  155. if (!$(e.target).is(':checkbox')) {
  156. $(this).find(':checkbox').click();
  157. }
  158. });
  159. $confirmButton.click(function(e) {
  160. e.preventDefault();
  161. if ($(this).hasClass('ui-state-disabled')) {
  162. return;
  163. }
  164. $form.nosAjax({
  165. url : <?= \Format::forge($action)->to_json() ?>,
  166. method : 'POST',
  167. data : $form.serialize()
  168. });
  169. $form.nosDialog('close');
  170. });
  171. $cancelButton.click(function(e) {
  172. e.preventDefault();
  173. $form.nosDialog('close');
  174. });
  175. });
  176. });
  177. </script>