Просмотр файла htmly-2.9.8/system/admin/views/menu.html.php

Размер файла: 9.98Kb
  1. <?php if (!defined('HTMLY')) die('HTMLy'); ?>
  2. <?php
  3. $menu = '';
  4. $filename = "content/data/menu.json";
  5. if (file_exists($filename)) {
  6. $json = json_decode(file_get_contents('content/data/menu.json', true));
  7. $menus = json_decode($json);
  8. if (!empty($menus)) {
  9. $menu = parseMenus($menus);
  10. }
  11. }
  12.  
  13. function parseMenus($menus) {
  14. $ol = '<ol class="dd-list">';
  15. foreach ($menus as $menu) {
  16. $ol .= parseMenu($menu);
  17. }
  18. $ol .= '</ol>';
  19. return $ol;
  20. }
  21.  
  22. function parseMenu($menu) {
  23. $li = '<li class="dd-item" data-class="'. $menu->class .'" data-id="'. $menu->id .'" data-name="'.$menu->name.'" data-slug="'.htmlspecialchars($menu->slug, FILTER_SANITIZE_URL).'">';
  24. $li .= '<div class="dd-handle">'.$menu->name.'</div>';
  25. $li .= '<span class="button-delete btn btn-danger btn-xs" style="margin-right:0.5rem" data-owner-id="'.$menu->id.'">'.i18n('Delete').'</span>';
  26. $li .= '<span class="button-edit btn btn-primary btn-xs" data-owner-id="'.$menu->id.'">'.i18n('Edit').'</span>';
  27. if (isset($menu->children)) {
  28. $li .= parseMenus($menu->children);
  29. }
  30. $li .= '</li>';
  31. return $li;
  32. }
  33.  
  34. ?>
  35.  
  36. <div class="row">
  37. <div class="col-md-6">
  38. <div class="dd nestable"><?php if (!empty($menu)) {echo '<h2>Drag & Drop</h2><br>'. $menu;} else {echo '<span>'.i18n('At_the_moment_you_are_using_auto_generated_menu').'</span><ol class="dd-list"></ol>';}?></div>
  39. </div>
  40.  
  41. <div class="col-md-6">
  42. <form id="menu-add">
  43. <h4><?php echo i18n('Add_menu');?></h4>
  44. <div class="form-group">
  45. <label for="addInputName"><?php echo i18n('Name');?></label>
  46. <input type="text" class="form-control" id="addInputName" placeholder="<?php echo i18n('Link_name')?>" required>
  47. </div>
  48. <div class="form-group">
  49. <label for="addInputSlug"><?php echo i18n('Slug');?></label>
  50. <input type="text" class="form-control" id="addInputSlug" placeholder="<?php echo i18n('item_slug');?>" required>
  51. </div>
  52. <div class="form-group">
  53. <label for="addInputClass"><?php echo i18n('CSS_Class_Optional');?></label>
  54. <input type="text" class="form-control" id="addInputClass" placeholder="<?php echo i18n('item_class');?>">
  55. </div>
  56. <button class="btn btn-primary btn-sm" id="addButton"><?php echo i18n('Add_link');?></button>
  57. </form>
  58. <form id="menu-editor" style="display: none;">
  59. <h4>Editing <span id="currentEditName"></span></h4>
  60. <div class="form-group">
  61. <label for="addInputName"><?php echo i18n('Name')?></label>
  62. <input type="text" class="form-control" id="editInputName" placeholder="<?php echo i18n('Link_name')?>" required>
  63. </div>
  64. <div class="form-group">
  65. <label for="addInputSlug"><?php echo i18n('Slug');?></label>
  66. <input type="text" class="form-control" id="editInputSlug" placeholder="<?php echo i18n('item_slug');?>">
  67. </div>
  68. <div class="form-group">
  69. <label for="addInputClass"><?php echo i18n('CSS_Class_Optional');?></label>
  70. <input type="text" class="form-control" id="editInputClass" placeholder="<?php echo i18n('item_class');?>">
  71. </div>
  72. <button class="btn btn-primary btn-sm" id="editButton"><?php echo i18n('Save_Edit');?></button>
  73. </form>
  74. </div>
  75. </div>
  76.  
  77. <div class="row">
  78. <div class="output-container">
  79. <div class="col">
  80. <button class="btn btn-primary" id="saveButton"><?php echo i18n('Save_Menu');?></button>
  81. <form class="form" style="display:none;">
  82. <textarea class="form-control" id="json-output" rows="5"></textarea>
  83. </form>
  84. </div>
  85. </div>
  86. </div>
  87. <script src="<?php echo site_url() ?>system/resources/js/jquery.nestable.js"></script>
  88. <script src="<?php echo site_url() ?>system/resources/js/jquery.nestable++.js"></script>
  89. <script>
  90. $('.dd.nestable').nestable({
  91. maxDepth: 2
  92. })
  93. .on('change', updateOutput);
  94.  
  95. $('#addMenu').click(function() {
  96. $('#menu-add').fadeIn();
  97. });
  98. $("#saveButton").click(function(){
  99. updateOutput($('.dd.nestable').data('output', $('#json-output')));
  100. var js = $('#json-output').val();
  101. $.ajax({
  102. type: 'POST',
  103. url: '<?php echo site_url();?>admin/menu',
  104. dataType: 'json',
  105. data: {'json': js},
  106. success: function (response) {
  107. alert(response.message);
  108. location.reload();
  109. },
  110. });
  111. });
  112. </script>
  113. <style>
  114. /**
  115. * Nestable css
  116. */
  117. .dd {
  118. position: relative;
  119. display: block;
  120. margin: 0;
  121. padding: 0;
  122. max-width: 600px;
  123. list-style: none;
  124. font-size: 13px;
  125. line-height: 20px;
  126. }
  127.  
  128. .dd-list {
  129. display: block;
  130. position: relative;
  131. margin: 0;
  132. padding: 0;
  133. list-style: none;
  134. }
  135.  
  136. .dd-list .dd-list {
  137. padding-left: 30px;
  138. }
  139.  
  140. .dd-collapsed .dd-list {
  141. display: none;
  142. }
  143.  
  144. .dd-item,
  145. .dd-empty,
  146. .dd-placeholder {
  147. display: block;
  148. position: relative;
  149. margin: 0;
  150. padding: 0;
  151. min-height: 20px;
  152. font-size: 13px;
  153. line-height: 20px;
  154. }
  155.  
  156. .dd-handle {
  157. display: block;
  158. margin: 5px 0;
  159. padding: 5px 10px;
  160. color: #333;
  161. text-decoration: none;
  162. font-weight: bold;
  163. border: 1px solid #ccc;
  164. background: #fafafa;
  165. background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
  166. background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
  167. background: linear-gradient(top, #fafafa 0%, #eee 100%);
  168. -webkit-border-radius: 3px;
  169. border-radius: 3px;
  170. box-sizing: border-box;
  171. -moz-box-sizing: border-box;
  172. cursor: move;
  173. }
  174.  
  175. .dd-handle:hover {
  176. color: #2ea8e5;
  177. background: #fff;
  178. }
  179.  
  180. .dd-item > button {
  181. display: block;
  182. position: relative;
  183. cursor: pointer;
  184. float: left;
  185. width: 25px;
  186. height: 20px;
  187. margin: 5px 0;
  188. padding: 0;
  189. text-indent: 100%;
  190. white-space: nowrap;
  191. overflow: hidden;
  192. border: 0;
  193. background: transparent;
  194. font-size: 12px;
  195. line-height: 1;
  196. text-align: center;
  197. font-weight: bold;
  198. }
  199.  
  200. .dd-item > button:before {
  201. content: '+';
  202. display: block;
  203. position: absolute;
  204. width: 100%;
  205. text-align: center;
  206. text-indent: 0;
  207. }
  208.  
  209. .dd-item > button[data-action="collapse"]:before {
  210. content: '-';
  211. }
  212.  
  213. .dd-placeholder,
  214. .dd-empty {
  215. margin: 5px 0;
  216. padding: 0;
  217. min-height: 30px;
  218. background: #f2fbff;
  219. border: 1px dashed #b6bcbf;
  220. box-sizing: border-box;
  221. -moz-box-sizing: border-box;
  222. }
  223.  
  224. .dd-empty {
  225. border: 1px dashed #bbb;
  226. min-height: 100px;
  227. background-color: #e5e5e5;
  228. background-image: -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  229. -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  230. background-image: -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  231. -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  232. background-image: linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  233. linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  234. background-size: 60px 60px;
  235. background-position: 0 0, 30px 30px;
  236. }
  237.  
  238. .dd-dragel {
  239. position: absolute;
  240. pointer-events: none;
  241. z-index: 9999;
  242. }
  243.  
  244. .dd-dragel > .dd-item .dd-handle {
  245. margin-top: 0;
  246. }
  247.  
  248. .dd-dragel .dd-handle {
  249. -webkit-box-shadow: 2px 4px 6px 0 rgba(0, 0, 0, .1);
  250. box-shadow: 2px 4px 6px 0 rgba(0, 0, 0, .1);
  251. }
  252.  
  253. /**
  254. * Nestable Extras
  255. */
  256. .nestable-lists {
  257. display: block;
  258. clear: both;
  259. padding: 30px 0;
  260. width: 100%;
  261. border: 0;
  262. border-top: 2px solid #ddd;
  263. border-bottom: 2px solid #ddd;
  264. }
  265.  
  266. #nestable-menu {
  267. padding: 0;
  268. margin: 20px 0;
  269. }
  270.  
  271. #nestable-output,
  272. #nestable2-output {
  273. width: 100%;
  274. height: 7em;
  275. font-size: 0.75em;
  276. line-height: 1.333333em;
  277. font-family: Consolas, monospace;
  278. padding: 5px;
  279. box-sizing: border-box;
  280. -moz-box-sizing: border-box;
  281. }
  282.  
  283. #nestable2 .dd-handle {
  284. color: #fff;
  285. border: 1px solid #999;
  286. background: #bbb;
  287. background: -webkit-linear-gradient(top, #bbb 0%, #999 100%);
  288. background: -moz-linear-gradient(top, #bbb 0%, #999 100%);
  289. background: linear-gradient(top, #bbb 0%, #999 100%);
  290. }
  291.  
  292. #nestable2 .dd-handle:hover {
  293. background: #bbb;
  294. }
  295.  
  296. #nestable2 .dd-item > button:before {
  297. color: #fff;
  298. }
  299.  
  300. .dd {
  301. // float: left;
  302. // width: 48 %;
  303. width: 80%;
  304. }
  305.  
  306. .dd + .dd {
  307. margin-left: 2%;
  308. }
  309.  
  310. .dd-hover > .dd-handle {
  311. background: #2ea8e5 !important;
  312. }
  313.  
  314. /**
  315. * Nestable Draggable Handles
  316. */
  317. .dd3-content {
  318. display: block;
  319. height: 30px;
  320. margin: 5px 0;
  321. padding: 5px 10px 5px 40px;
  322. color: #333;
  323. text-decoration: none;
  324. font-weight: bold;
  325. border: 1px solid #ccc;
  326. background: #fafafa;
  327. background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
  328. background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
  329. background: linear-gradient(top, #fafafa 0%, #eee 100%);
  330. -webkit-border-radius: 3px;
  331. border-radius: 3px;
  332. box-sizing: border-box;
  333. -moz-box-sizing: border-box;
  334. }
  335.  
  336. .dd3-content:hover {
  337. color: #2ea8e5;
  338. background: #fff;
  339. }
  340.  
  341. .dd-dragel > .dd3-item > .dd3-content {
  342. margin: 0;
  343. }
  344.  
  345. .dd3-item > button {
  346. margin-left: 30px;
  347. }
  348.  
  349. .dd3-handle {
  350. position: absolute;
  351. margin: 0;
  352. left: 0;
  353. top: 0;
  354. cursor: pointer;
  355. width: 30px;
  356. text-indent: 100%;
  357. white-space: nowrap;
  358. overflow: hidden;
  359. border: 1px solid #aaa;
  360. background: #ddd;
  361. background: -webkit-linear-gradient(top, #ddd 0%, #bbb 100%);
  362. background: -moz-linear-gradient(top, #ddd 0%, #bbb 100%);
  363. background: linear-gradient(top, #ddd 0%, #bbb 100%);
  364. border-top-right-radius: 0;
  365. border-bottom-right-radius: 0;
  366. }
  367.  
  368. .dd3-handle:before {
  369. content: '≡';
  370. display: block;
  371. position: absolute;
  372. left: 0;
  373. top: 3px;
  374. width: 100%;
  375. text-align: center;
  376. text-indent: 0;
  377. color: #fff;
  378. font-size: 20px;
  379. font-weight: normal;
  380. }
  381.  
  382. .dd3-handle:hover {
  383. background: #ddd;
  384. }
  385.  
  386.  
  387. /*
  388. * Nestable++
  389. */
  390. .button-delete {
  391. position: absolute;
  392. top: 4px;
  393. right: 40px;
  394. }
  395.  
  396. .button-edit {
  397. position: absolute;
  398. top: 4px;
  399. right: 5px;
  400. }
  401.  
  402. #saveButton {
  403. padding-right: 30px;
  404. padding-left: 30px;
  405. }
  406.  
  407. .output-container {
  408. margin-top: 20px;
  409. }
  410.  
  411. #json-output {
  412. margin-top: 20px;
  413. }
  414. </style>