add-template.php
См. документацию.
1 <?php
2 
3 /**
4  * @file
5  * @brief окно добавления нового шаблона
6  */
7 
8 isset($user) or require $_SERVER['DOCUMENT_ROOT'] . '/page/404.php';
9 
10 ?>
11 <div class="modal fade" id="<?= $basename ?>" tabindex="-1" data-backdrop="static" data-keyboard="false">
12  <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
13  <div class="modal-content">
14  <div class="modal-header">
15  <h5 class="modal-title"><i class="fa fa-columns mr-2"></i>Добавить шаблон</h5>
16  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
17  <span aria-hidden="true">&times;</span>
18  </button>
19  </div>
20  <div class="modal-body">
21  <form action="<?= Wrong\Models\Actions::find(18)->request ?>">
22  <div class="border px-2 py-1 rounded bg-light-info">
23  <small>Группы доступа <a onclick="if(~~this.dataset.checked){$(this).html('отметить все');this.dataset.checked=0;$(this).parents('form').find('[name^=groups]').prop('checked', false);}else{$(this).html('снять все');this.dataset.checked=1;$(this).parents('form').find('[name^=groups]').prop('checked', true);}return false;" href="#">отметить все</a></small>
24  <?php
25  foreach (Wrong\Rights\Group::$groups_not_system as $row) {
26  echo '<div class="custom-control custom-checkbox small">
27  <input type="checkbox" name="groups[' . $row->id . ']" class="custom-control-input" id="check-group-' . $row->id . '">
28  <label class="custom-control-label" for="check-group-' . $row->id . '">' . Wrong\Rights\Group::text($row->id) . '</label>
29  </div>';
30  }
31  ?>
32  </div>
33  <div class="input-group input-group-sm mt-2">
34  <div class="input-group-prepend w-50">
35  <span class="input-group-text w-100">Группа владелец</span>
36  </div>
37  <select name="owner_group" class="custom-select">
38  <?php
39  foreach ($user->subordinate_groups as $id) {
40  $row = Wrong\Rights\Group::row($id);
41  echo '<option data-path="' . $row->path . '" value="' . $row->id . '" ' . ($row->id == $user->main_group_id ? ' selected' : '') . '>' . Wrong\Rights\Group::text($row->id) . '</option>';
42  }
43  ?>
44  </select>
45  </div>
46  <div class="input-group input-group-sm mt-2">
47  <div class="input-group-prepend w-50">
48  <span class="input-group-text w-100">Название</span>
49  </div>
50  <input type="text" name="name" class="form-control" value="" autocomplete="off" placeholder="Название">
51  </div>
52  <div class="input-group input-group-sm mt-2">
53  <div class="input-group-prepend w-50">
54  <span class="input-group-text w-100">Тип шаблона</span>
55  </div>
56  <select name="type" class="custom-select">
57  <option value="page">page</option>
58  <option value="incode">incode</option>
59  <option value="modal">modal</option>
60  <option value="select">select</option>
61  <option value="action">action</option>
62  </select>
63  </div>
64  <div class="input-group input-group-sm mt-2">
65  <div class="input-group-prepend w-50">
66  <span class="input-group-text w-100">Файл шаблона</span>
67  </div>
68  <input title="Доступные каталоги: modal, page, incode, select, action" type="text" name="file" class="form-control" value="/../templates/page/<?= Wrong\Rights\Group::row($user->main_group_id)->path ?>/template.php" placeholder="/../templates/page/<?= Wrong\Rights\Group::row($user->main_group_id)->path ?>/template.php" autocomplete="off" required>
69  </div>
70  <button type="submit" class="btn btn-sm btn-block btn-success mt-3">Сохранить</button>
71  </form>
72  </div>
73  </div>
74  </div>
75  <script>
76  $("#<?= $basename ?> form").submit(function(e) {
77  lockSubmit($("#<?= $basename ?> form [type=submit]"));
78  e.preventDefault();
79  $.ajax({
80  type: "POST",
81  url: $(this).attr("action"),
82  data: $(this).serialize(),
83  dataType: "json",
84  statusCode: {
85  404: errorToast,
86  403: errorToast
87  }
88  })
89  .done(response => {
90  if (response.error) {
91  errorToast(response.error);
92  return;
93  }
94  $('.dataTable').DataTable().ajax.reload(null, false);
95  $('.toast').toast('hide');
96  successToast(response.message);
97  $("#<?= $basename ?>").modal("hide");
98  })
99  .always(() => {
100  unlockSubmit($("#<?= $basename ?> form [type=submit]"));
101  });
102  });
103 
104  $(function() {
105  function setPath() {
106  let path = $('#<?= $basename ?> [name="type"]').val();
107  let path2 = $('#<?= $basename ?> [name="owner_group"] option:selected').data('path');
108  let file = $("#<?= $basename ?> form [name=file]").val();
109  file = file.replace(/^(\/\.\.\/templates\/)[^/]+\/[^/]+/, '$1' + path + '/' + path2);
110  $("#<?= $basename ?> form [name=file]").val(file);
111  }
112  $('#<?= $basename ?> [name="type"], #<?= $basename ?> [name="owner_group"]').on('change', setPath);
113  $('#<?= $basename ?> [name="type"]').trigger('change');
114  });
115  </script>
116 </div>
static row($id)
Definition: Group.php:245
static text($id)
Definition: Group.php:233
$user
Definition: from-user.php:38
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' $_SERVER['HTTP_HOST']
Definition: from-user.php:36
href
Definition: main.php:21