customize.html 17 KB

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