customize.html 22 KB

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