customize.html 20 KB

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