customize.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}{{ t('Customize') }} {% endblock %}
  3. {% block style_css_block %}
  4. <link rel="stylesheet" href="{{ webpack_asset('style').css }}">
  5. <link rel="stylesheet" id="jssDefault" {# append id for theme selector #} href="{{ webpack_asset('style-theme-default').css }}">
  6. {% endblock %}
  7. {% block html_additional_headers %}
  8. {% parent %}
  9. <!-- CodeMirror -->
  10. <link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.ui/1.11.4/jquery-ui.min.css">
  11. <style>
  12. .CodeMirror {
  13. border: 1px solid #eee;
  14. }
  15. </style>
  16. {% endblock %}
  17. {% block content_header %}
  18. <div class="header-wrap">
  19. <header id="page-header">
  20. <h1 class="title" id="">{{ t('Customize') }} </h1>
  21. </header>
  22. </div>
  23. {% endblock %}
  24. {% block content_main %}
  25. <div class="content-main admin-customize">
  26. {% set smessage = req.flash('successMessage') %}
  27. {% if smessage.length %}
  28. <div class="alert alert-success">
  29. {{ smessage }}
  30. </div>
  31. {% endif %}
  32. {% set emessage = req.flash('errorMessage') %}
  33. {% if emessage.length %}
  34. <div class="alert alert-danger">
  35. {{ emessage }}
  36. </div>
  37. {% endif %}
  38. <div class="row">
  39. <div class="col-md-3">
  40. {% include './widget/menu.html' with {current: 'customize'} %}
  41. </div>
  42. <div class="col-md-9">
  43. <form action="/_api/admin/customize/theme" method="post" class="form-horizontal" id="customthemeSettingForm" role="form">
  44. <fieldset>
  45. <legend>{{ t('customize_page.Theme') }}</legend>
  46. <div id="themeOptions" class="d-flex">
  47. <a href="#" class="default" onclick="selectTheme('default')"
  48. data-theme="{{ webpack_asset('style-theme-default').css }}">
  49. {% include 'widget/theme-colorbox.html' %}
  50. </a>
  51. <a href="#" class="default-dark" onclick="selectTheme('default-dark')"
  52. data-theme="{{ webpack_asset('style-theme-default-dark').css }}">
  53. {% include 'widget/theme-colorbox.html' %}
  54. </a>
  55. </div>
  56. <div class="form-group">
  57. <div class="col-xs-offset-5 col-xs-6">
  58. <input type="hidden" id="hiddenInputTheme" name="settingForm[customize:theme]" value="{{ settingForm['customize:theme'] }}">
  59. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  60. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  61. </div>
  62. </div>
  63. </fieldset>
  64. </form>
  65. <form action="/_api/admin/customize/behavior" method="post" class="form-horizontal" id="cutombehaviorSettingForm" role="form">
  66. <fieldset>
  67. <legend>{{ t('customize_page.Behavior') }}</legend>
  68. <div class="form-group">
  69. <div class="col-xs-6">
  70. <h4>
  71. <input type="radio" name="settingForm[customize:behavior]" value="crowi"
  72. {% if !settingForm['customize:behavior'] || 'crowi' === settingForm['customize:behavior'] %}checked="checked"{% endif %}>
  73. Official Crowi Behavior
  74. </h4>
  75. <ul>
  76. <li><code>/page</code> shows the page</li>
  77. <li><code>/page/</code> shows the list of sub pages</li>
  78. <ul>
  79. <li>If portal is applied to <code>/page/</code> , the portal and the list of sub pages are shown</li>
  80. </ul>
  81. <li><code>/nonexistent_page</code> shows editing form</li>
  82. <li><code>/nonexistent_page/</code> the list of sub pages</li>
  83. </ul>
  84. </div>
  85. <div class="col-xs-6">
  86. <h4>
  87. <input type="radio" name="settingForm[customize:behavior]" value="crowi-plus"
  88. {% if 'crowi-plus' === settingForm['customize:behavior'] %}checked="checked"{% endif %}>
  89. crowi-plus Simplified Behavior <small class="text-success">(Recommended)</small>
  90. </h4>
  91. <ul>
  92. <li>Both of <code>/page</code> and <code>/page/</code> shows the same page</li>
  93. <li><code>/nonexistent_page</code> shows editing form</li>
  94. <li>All pages shows the list of sub pages when using <b>crowi-plus Enhanced Layout</b></li>
  95. </ul>
  96. </div>
  97. </div>
  98. <div class="form-group">
  99. <div class="col-xs-offset-5 col-xs-6">
  100. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  101. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  102. </div>
  103. </div>
  104. </fieldset>
  105. </form>
  106. <form action="/_api/admin/customize/layout" method="post" class="form-horizontal" id="cutomlayoutSettingForm" role="form">
  107. <fieldset>
  108. <legend>{{ t('customize_page.Layout') }}</legend>
  109. <div class="form-group">
  110. <div class="col-xs-6">
  111. <h4>
  112. <input type="radio" name="settingForm[customize:layout]" value="crowi"
  113. {% if !settingForm['customize:layout'] || 'crowi' === settingForm['customize:layout'] %}checked="checked"{% endif %}>
  114. Official Crowi Classic Layout
  115. </h4>
  116. <a href="/images/admin/customize/layout-classic.gif" class="ss-container">
  117. <img src="/images/admin/customize/layout-classic-thumb.gif" width="240px">
  118. </a>
  119. <ul>
  120. <li>Functional</li>
  121. <ul>
  122. <li>Collapsible Sidebar</li>
  123. <li>Show and post comments in Sidebar</li>
  124. <li>Collapsible Table-of-contents</li>
  125. </ul>
  126. </ul>
  127. </div>
  128. <div class="col-xs-6">
  129. <h4>
  130. <input type="radio" name="settingForm[customize:layout]" value="crowi-plus"
  131. {% if 'crowi-plus' === settingForm['customize:layout'] %}checked="checked"{% endif %}>
  132. crowi-plus Enhanced Layout <small class="text-success">(Recommended)</small>
  133. </h4>
  134. <a href="/images/admin/customize/layout-crowi-plus.gif" class="ss-container">
  135. <img src="/images/admin/customize/layout-crowi-plus-thumb.gif" width="240px">
  136. </a>
  137. <ul>
  138. <li>Simple and Clear</li>
  139. <ul>
  140. <li>Show and post comments from the bottom of the page</li>
  141. <li>Affix Table-of-contents</li>
  142. </ul>
  143. </ul>
  144. </div>
  145. </div>
  146. <div class="form-group">
  147. <div class="col-xs-offset-5 col-xs-6">
  148. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  149. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  150. </div>
  151. </div>
  152. </fieldset>
  153. </form>
  154. <form action="/_api/admin/customize/features" method="post" class="form-horizontal" id="customfeaturesSettingForm" role="form">
  155. <fieldset>
  156. <legend>{{ t('customize_page.Function') }}</legend>
  157. <p class="well">{{ t("customize_page.function_choose") }}</p>
  158. <div class="form-group">
  159. <label for="settingForm[customize:isEnabledTimeline]" class="col-xs-3 control-label">{{ t('customize_page.Timeline function') }}</label>
  160. <div class="col-xs-9">
  161. <div class="btn-group btn-toggle" data-toggle="buttons">
  162. <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:isEnabledTimeline'] %}active{% endif %}" data-active-class="primary">
  163. <input name="settingForm[customize:isEnabledTimeline]" value="true" type="radio"
  164. {% if true === settingForm['customize:isEnabledTimeline'] %}checked{% endif %}> ON
  165. </label>
  166. <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:isEnabledTimeline'] %}active{% endif %}" data-active-class="default">
  167. <input name="settingForm[customize:isEnabledTimeline]" value="false" type="radio"
  168. {% if !settingForm['customize:isEnabledTimeline'] %}checked{% endif %}> OFF
  169. </label>
  170. </div>
  171. <p class="help-block">
  172. {{ t("customize_page.subpage_display") }}
  173. </p>
  174. <p class="help-block">
  175. {{ t("customize_page.performance_decrease") }}<br>
  176. {{ t("customize_page.list_page_display") }}
  177. </p>
  178. </div>
  179. </div>
  180. <div class="form-group">
  181. <label for="settingForm[customize:isSavedStatesOfTabChanges]" class="col-xs-3 control-label">{{ t("customize_page.tab_switch") }}</label>
  182. <div class="col-xs-9">
  183. <div class="btn-group btn-toggle" data-toggle="buttons">
  184. <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:isSavedStatesOfTabChanges'] %}active{% endif %}" data-active-class="primary">
  185. <input name="settingForm[customize:isSavedStatesOfTabChanges]" value="true" type="radio"
  186. {% if true === settingForm['customize:isSavedStatesOfTabChanges'] %}checked{% endif %}> ON
  187. </label>
  188. <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:isSavedStatesOfTabChanges'] %}active{% endif %}" data-active-class="default">
  189. <input name="settingForm[customize:isSavedStatesOfTabChanges]" value="false" type="radio"
  190. {% if !settingForm['customize:isSavedStatesOfTabChanges'] %}checked{% endif %}> OFF
  191. </label>
  192. </div>
  193. <p class="help-block">
  194. {{ t("customize_page.save_edit") }}<br>
  195. {{ t("customize_page.by_invalidating") }}
  196. </p>
  197. </div>
  198. </div>
  199. <div class="form-group">
  200. <div class="col-xs-offset-3 col-xs-6">
  201. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  202. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  203. </div>
  204. </div>
  205. </fieldset>
  206. </form>
  207. <form action="/_api/admin/customize/highlightJsStyle" method="post" class="form-horizontal" id="cutomhighlightJsStyleSettingForm" role="form">
  208. <fieldset>
  209. <legend>{{ t('customize_page.Code Highlight') }}</legend>
  210. <div class="form-group">
  211. <label for="settingForm[customize:highlightJsStyle]" class="col-xs-3 control-label">{{ t('customize_page.Theme') }}</label>
  212. <div class="col-xs-9">
  213. <select class="form-control selectpicker" name="settingForm[customize:highlightJsStyle]" onChange="selectHighlightJsStyle(event)">
  214. {% for key in Object.keys(highlightJsCssSelectorOptions) %}
  215. <option value={{key}} {% if key == highlightJsStyle() %} selected {% endif %}>{{highlightJsCssSelectorOptions[key].name}}</option>
  216. {% endfor %}
  217. </select>
  218. </div>
  219. </div>
  220. <div class="form-group">
  221. <label for="settingForm[customize:highlightJsStyleBorder]" class="col-xs-3 control-label">(TBD) Border</label>
  222. <div class="col-xs-9">
  223. <div class="btn-group btn-toggle" data-toggle="buttons">
  224. <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:highlightJsStyleBorder'] %}active{% endif %}" data-active-class="primary">
  225. <input name="settingForm[customize:highlightJsStyleBorder]" value="true" type="radio"
  226. {% if true === settingForm['customize:highlightJsStyleBorder'] %}checked{% endif %}> ON
  227. </label>
  228. <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:highlightJsStyleBorder'] %}active{% endif %}" data-active-class="default">
  229. <input name="settingForm[customize:highlightJsStyleBorder]" value="false" type="radio"
  230. {% if !settingForm['customize:highlightJsStyleBorder'] %}checked{% endif %}> OFF
  231. </label>
  232. </div>
  233. </div>
  234. </div>
  235. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/{{ highlightJsStyle() }}.css" class="highlightJsCss">
  236. <p class="help-block">
  237. Examples:
  238. <pre class="hljs"><code class="highlightjs-demo">function $initHighlight(block, cls) {
  239. try {
  240. if (cls.search(/\bno\-highlight\b/) != -1)
  241. return process(block, true, 0x0F) +
  242. ` class="${cls}"`;
  243. } catch (e) {
  244. /* handle exception */
  245. }
  246. for (var i = 0 / 2; i < classes.length; i++) {
  247. if (checkCondition(classes[i]) === undefined)
  248. console.log('undefined');
  249. }
  250. }
  251. export $initHighlight;</code></pre>
  252. </p>
  253. <div class="form-group">
  254. <div class="col-xs-offset-5 col-xs-6">
  255. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  256. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  257. </div>
  258. </div>
  259. </fieldset>
  260. </form>
  261. <form action="/_api/admin/customize/header" method="post" class="form-horizontal" id="cutomheaderSettingForm" role="form">
  262. <fieldset>
  263. <legend>カスタムヘッダーHTML</legend>
  264. <p class="well">
  265. システム全体に適用される HTML を記述できます。<code>&lt;header&gt;</code> タグ内の他の <code>&lt;script&gt;</code> タグ読み込み前に展開されます。<br>
  266. 変更の反映はページの更新が必要です。
  267. </p>
  268. <p class="help-block">
  269. Examples:
  270. <pre class="hljs"><code>&lt;script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.12.0/build/languages/yaml.min.js" defer&gt;&lt;/script&gt;</code></pre>
  271. </p>
  272. <div class="form-group">
  273. <div class="col-xs-12">
  274. <div id="custom-header-editor"></div>
  275. <input type="hidden" id="inputCustomHeader" name="settingForm[customize:header]" value="{{ settingForm['customize:header'] }}">
  276. </div>
  277. <div class="col-xs-12">
  278. <p class="help-block text-right">
  279. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  280. Ctrl+Space でコード補完
  281. </p>
  282. </div>
  283. </div>
  284. <div class="form-group">
  285. <div class="col-xs-offset-5 col-xs-6">
  286. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  287. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  288. </div>
  289. </div>
  290. </fieldset>
  291. </form>
  292. <form action="/_api/admin/customize/css" method="post" class="form-horizontal" id="cutomcssSettingForm" role="form">
  293. <fieldset>
  294. <legend>{{ t('customize_page.Custom CSS') }}</legend>
  295. <p class="well">
  296. {{ t("customize_page.write_CSS") }}<br>
  297. {{ t("customize_page.reflect_change") }}
  298. </p>
  299. <div class="form-group">
  300. <div class="col-xs-12">
  301. <div id="custom-css-editor"></div>
  302. <input type="hidden" id="inputCustomCss" name="settingForm[customize:css]" value="{{ settingForm['customize:css'] }}">
  303. </div>
  304. <div class="col-xs-12">
  305. <p class="help-block text-right">
  306. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  307. {{ t("customize_page.ctrl_space") }}
  308. </p>
  309. </div>
  310. </div>
  311. <div class="form-group">
  312. <div class="col-xs-offset-5 col-xs-6">
  313. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  314. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  315. </div>
  316. </div>
  317. </fieldset>
  318. </form>
  319. <form action="/_api/admin/customize/script" method="post" class="form-horizontal" id="cutomscriptSettingForm" role="form">
  320. <fieldset>
  321. <legend>{{ t('customize_page.Custom script') }}</legend>
  322. <p class="well">
  323. {{ t("customize_page.write_java") }}<br>
  324. {{ t("customize_page.reflect_change") }}
  325. </p>
  326. <p class="help-block">
  327. Placeholders:<br>
  328. (Available after <code>load</code> event)
  329. <dl class="dl-horizontal">
  330. <dt><code>$</code></dt>
  331. <dd>jQuery instance</dd>
  332. <dt><code>crowi</code></dt>
  333. <dd>Crowi context instance</dd>
  334. <dt><code>Crowi</code></dt>
  335. <dd>Crowi legacy instance (jQuery based)</dd>
  336. <dt><code>crowiRenderer</code></dt>
  337. <dd>Crowi Renderer instance</dd>
  338. <dt><code>crowiPlugin</code></dt>
  339. <dd>crowi-plus plugin manager instance</dd>
  340. </dl>
  341. </p>
  342. <p class="help-block">
  343. Examples:
  344. <pre class="hljs"><code>console.log($('.main-container'));
  345. window.addEventListener('load', (event) => {
  346. console.log('config: ', crowi.config);
  347. });</code></pre>
  348. </p>
  349. <div class="form-group">
  350. <div class="col-xs-12">
  351. <div id="custom-script-editor"></div>
  352. <input type="hidden" id="inputCustomScript" name="settingForm[customize:script]" value="{{ settingForm['customize:script'] }}">
  353. </div>
  354. <div class="col-xs-12">
  355. <p class="help-block text-right">
  356. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  357. {{ t("customize_page.ctrl_space") }}
  358. </p>
  359. </div>
  360. </div>
  361. <div class="form-group">
  362. <div class="col-xs-offset-5 col-xs-6">
  363. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  364. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  365. </div>
  366. </div>
  367. </fieldset>
  368. </form>
  369. </div>
  370. </div>
  371. {% endblock content_main %}
  372. {% block body_end %}
  373. {% parent %}
  374. <script>
  375. $(`#customthemeSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm, #cutomhighlightJsStyleSettingForm,
  376. #customfeaturesSettingForm, #cutomheaderSettingForm, #cutomcssSettingForm, #cutomscriptSettingForm`
  377. ).each(function() {
  378. $(this).submit(function()
  379. {
  380. function showMessage(formId, msg, status) {
  381. $('#' + formId + ' .alert').remove();
  382. if (!status) {
  383. status = 'success';
  384. }
  385. var $message = $('<p class="alert"></p>');
  386. $message.addClass('alert-' + status);
  387. $message.html(msg.replace('\n', '<br>'));
  388. $message.insertAfter('#' + formId + ' legend');
  389. if (status == 'success') {
  390. setTimeout(function()
  391. {
  392. $message.fadeOut({
  393. complete: function() {
  394. $message.remove();
  395. }
  396. });
  397. }, 5000);
  398. }
  399. }
  400. var $form = $(this);
  401. var $id = $form.attr('id');
  402. var $button = $('button', this);
  403. $button.attr('disabled', 'disabled');
  404. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  405. {
  406. if (data.status) {
  407. showMessage($id, '更新しました');
  408. } else {
  409. showMessage($id, data.message, 'danger');
  410. }
  411. })
  412. .fail(function() {
  413. showMessage($id, 'エラーが発生しました', 'danger');
  414. })
  415. .always(function() {
  416. $button.prop('disabled', false);
  417. });
  418. return false;
  419. });
  420. });
  421. /*
  422. * highlight.js style switcher
  423. */
  424. hljs.initHighlightingOnLoad()
  425. function selectHighlightJsStyle(event) {
  426. var highlightJsCssDOM = $(".highlightJsCss")[0]
  427. // selected value
  428. var val = event.target.value
  429. // replace css url
  430. // see https://regex101.com/r/gBNZYu/4
  431. highlightJsCssDOM.href = highlightJsCssDOM.href.replace(/[^/]+\.css$/, `${val}.css`);
  432. }
  433. /*
  434. * Theme Selector
  435. */
  436. options = {
  437. hasPreview: false,
  438. fullPath: '',
  439. cookie: {
  440. isManagingLoad: false
  441. }
  442. };
  443. $(document).ready(function() {
  444. $('#themeOptions').styleSwitcher(options);
  445. });
  446. function selectTheme(theme) {
  447. // update hidden
  448. $('#hiddenInputTheme').val(theme);
  449. }
  450. </script>
  451. </div>
  452. {% endblock %}
  453. {% block content_footer %}
  454. {% endblock content_footer %}