customize.html 17 KB

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