customize.html 20 KB

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