customize.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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/highlight" method="post" class="form-horizontal" id="cutomhighlightSettingForm" 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:highlight]" onChange="selectHighlight()">
  135. <option value="atom-one-dark">Atom One Dark</option>
  136. <option value="atom-one-light">Atom One Light</option>
  137. <option value="github-gist">Github Gist</option>
  138. <option value="github">Github</option>
  139. <option value="hybrid">Hybrid</option>
  140. <option value="monokai">Monokai</option>
  141. <option value="tomorrow-night">Tomorrow Night</option>
  142. <option value="vs">Vs</option>
  143. <option value="vs2015">Vs 2015</option>
  144. <option value="xcode">Xcode</option>
  145. </select>
  146. </div>
  147. </div>
  148. <pre><code class="highlight-demo">function $initHighlight(block, cls) {
  149. try {
  150. if (cls.search(/\bno\-highlight\b/) != -1)
  151. return process(block, true, 0x0F) +
  152. ` class="${cls}"`;
  153. } catch (e) {
  154. /* handle exception */
  155. }
  156. for (var i = 0 / 2; i < classes.length; i++) {
  157. if (checkCondition(classes[i]) === undefined)
  158. console.log('undefined');
  159. }
  160. }
  161. export $initHighlight;</code></pre>
  162. <div class="form-group">
  163. <div class="col-xs-offset-5 col-xs-6">
  164. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  165. <button type="submit" class="btn btn-primary">更新</button>
  166. </div>
  167. </div>
  168. </fieldset>
  169. </form>
  170. <form action="/_api/admin/customize/features" method="post" class="form-horizontal" id="customfeaturesSettingForm" role="form">
  171. <fieldset>
  172. <legend>{{ t('customize_page.Function') }}</legend>
  173. <p class="well">{{ t("customize_page.function_choose") }}</p>
  174. <div class="form-group">
  175. <label for="settingForm[customize:isEnabledTimeline]" class="col-xs-3 control-label">{{ t('customize_page.Timeline function') }}</label>
  176. <div class="col-xs-9">
  177. <div class="btn-group btn-toggle" data-toggle="buttons">
  178. <label class="btn btn-default {% if settingForm['customize:isEnabledTimeline'] %}active{% endif %}" data-active-class="primary">
  179. <input name="settingForm[customize:isEnabledTimeline]" value="true" type="radio"
  180. {% if true === settingForm['customize:isEnabledTimeline'] %}checked{% endif %}> {{ t('Valid') }}
  181. </label>
  182. <label class="btn btn-default {% if !settingForm['customize:isEnabledTimeline'] %}active{% endif %}" data-active-class="primary">
  183. <input name="settingForm[customize:isEnabledTimeline]" value="false" type="radio"
  184. {% if !settingForm['customize:isEnabledTimeline'] %}checked{% endif %}> {{ t('Invalid') }}
  185. </label>
  186. </div>
  187. <p class="help-block">
  188. {{ t("customize_page.subpage_display") }}
  189. </p>
  190. <p class="help-block">
  191. {{ t("customize_page.performance_decrease") }}<br>
  192. {{ t("customize_page.list_page_display") }}
  193. </p>
  194. </div>
  195. </div>
  196. <div class="form-group">
  197. <label for="settingForm[customize:isSavedStatesOfTabChanges]" class="col-xs-3 control-label">{{ t("customize_page.tab_switch") }}</label>
  198. <div class="col-xs-9">
  199. <div class="btn-group btn-toggle" data-toggle="buttons">
  200. <label class="btn btn-default {% if settingForm['customize:isSavedStatesOfTabChanges'] %}active{% endif %}" data-active-class="primary">
  201. <input name="settingForm[customize:isSavedStatesOfTabChanges]" value="true" type="radio"
  202. {% if true === settingForm['customize:isSavedStatesOfTabChanges'] %}checked{% endif %}> {{ t('Valid') }}
  203. </label>
  204. <label class="btn btn-default {% if !settingForm['customize:isSavedStatesOfTabChanges'] %}active{% endif %}" data-active-class="primary">
  205. <input name="settingForm[customize:isSavedStatesOfTabChanges]" value="false" type="radio"
  206. {% if !settingForm['customize:isSavedStatesOfTabChanges'] %}checked{% endif %}> {{ t('Invalid') }}
  207. </label>
  208. </div>
  209. <p class="help-block">
  210. {{ t("customize_page.save_edit") }}<br>
  211. {{ t("customize_page.by_invalidating") }}
  212. </p>
  213. </div>
  214. </div>
  215. <div class="form-group">
  216. <div class="col-xs-offset-3 col-xs-6">
  217. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  218. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  219. </div>
  220. </div>
  221. </fieldset>
  222. </form>
  223. <form action="/_api/admin/customize/header" method="post" class="form-horizontal" id="cutomheaderSettingForm" role="form">
  224. <fieldset>
  225. <legend>カスタムヘッダーHTML</legend>
  226. <p class="well">
  227. システム全体に適用される HTML を記述できます。<code>&lt;header&gt;</code> タグ内の他の <code>&lt;script&gt;</code> タグ読み込み前に展開されます。<br>
  228. 変更の反映はページの更新が必要です。
  229. </p>
  230. <p class="help-block">
  231. Examples:
  232. <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>
  233. </p>
  234. <div class="form-group">
  235. <div class="col-xs-12">
  236. <div id="custom-header-editor"></div>
  237. <input type="hidden" id="inputCustomHeader" name="settingForm[customize:header]" value="{{ settingForm['customize:header'] }}">
  238. </div>
  239. <div class="col-xs-12">
  240. <p class="help-block text-right">
  241. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  242. Ctrl+Space でコード補完
  243. </p>
  244. </div>
  245. </div>
  246. <div class="form-group">
  247. <div class="col-xs-offset-5 col-xs-6">
  248. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  249. <button type="submit" class="btn btn-primary">更新</button>
  250. </div>
  251. </div>
  252. </fieldset>
  253. </form>
  254. <form action="/_api/admin/customize/css" method="post" class="form-horizontal" id="cutomcssSettingForm" role="form">
  255. <fieldset>
  256. <legend>{{ t('customize_page.Custom CSS') }}</legend>
  257. <p class="well">
  258. {{ t("customize_page.write_CSS") }}<br>
  259. {{ t("customize_page.reflect_change") }}
  260. </p>
  261. <div class="form-group">
  262. <div class="col-xs-12">
  263. <div id="custom-css-editor"></div>
  264. <input type="hidden" id="inputCustomCss" name="settingForm[customize:css]" value="{{ settingForm['customize:css'] }}">
  265. </div>
  266. <div class="col-xs-12">
  267. <p class="help-block text-right">
  268. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  269. {{ t("customize_page.ctrl_space") }}
  270. </p>
  271. </div>
  272. </div>
  273. <div class="form-group">
  274. <div class="col-xs-offset-5 col-xs-6">
  275. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  276. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  277. </div>
  278. </div>
  279. </fieldset>
  280. </form>
  281. <form action="/_api/admin/customize/script" method="post" class="form-horizontal" id="cutomscriptSettingForm" role="form">
  282. <fieldset>
  283. <legend>{{ t('customize_page.Custom script') }}</legend>
  284. <p class="well">
  285. {{ t("customize_page.write_java") }}<br>
  286. {{ t("customize_page.reflect_change") }}
  287. </p>
  288. <p class="help-block">
  289. Placeholders:<br>
  290. (Available after <code>load</code> event)
  291. <dl class="dl-horizontal">
  292. <dt><code>$</code></dt>
  293. <dd>jQuery instance</dd>
  294. <dt><code>crowi</code></dt>
  295. <dd>Crowi context instance</dd>
  296. <dt><code>Crowi</code></dt>
  297. <dd>Crowi legacy instance (jQuery based)</dd>
  298. <dt><code>crowiRenderer</code></dt>
  299. <dd>Crowi Renderer instance</dd>
  300. <dt><code>crowiPlugin</code></dt>
  301. <dd>crowi-plus plugin manager instance</dd>
  302. </dl>
  303. </p>
  304. <p class="help-block">
  305. Examples:
  306. <pre><code>console.log($('.main-container'));
  307. window.addEventListener('load', (event) => {
  308. console.log('config: ', crowi.config);
  309. });</code></pre>
  310. </p>
  311. <div class="form-group">
  312. <div class="col-xs-12">
  313. <div id="custom-script-editor"></div>
  314. <input type="hidden" id="inputCustomScript" name="settingForm[customize:script]" value="{{ settingForm['customize:script'] }}">
  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. {{ t("customize_page.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">{{ t('Update') }}</button>
  327. </div>
  328. </div>
  329. </fieldset>
  330. </form>
  331. </div>
  332. </div>
  333. <script>
  334. $('#cutomcssSettingForm, #cutomscriptSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm, #customfeaturesSettingForm, #cutomheaderSettingForm, #cutomhighlightSettingForm').each(function() {
  335. $(this).submit(function()
  336. {
  337. function showMessage(formId, msg, status) {
  338. $('#' + formId + ' .alert').remove();
  339. if (!status) {
  340. status = 'success';
  341. }
  342. var $message = $('<p class="alert"></p>');
  343. $message.addClass('alert-' + status);
  344. $message.html(msg.replace('\n', '<br>'));
  345. $message.insertAfter('#' + formId + ' legend');
  346. if (status == 'success') {
  347. setTimeout(function()
  348. {
  349. $message.fadeOut({
  350. complete: function() {
  351. $message.remove();
  352. }
  353. });
  354. }, 5000);
  355. }
  356. }
  357. var $form = $(this);
  358. var $id = $form.attr('id');
  359. var $button = $('button', this);
  360. $button.attr('disabled', 'disabled');
  361. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  362. {
  363. if (data.status) {
  364. showMessage($id, '更新しました');
  365. } else {
  366. showMessage($id, data.message, 'danger');
  367. }
  368. })
  369. .fail(function() {
  370. showMessage($id, 'エラーが発生しました', 'danger');
  371. })
  372. .always(function() {
  373. $button.prop('disabled', false);
  374. });
  375. return false;
  376. });
  377. });
  378. // highlight.js 有効化
  379. hljs.initHighlighting()
  380. // 保存した highlight の値を selector に復元する
  381. $('#cutomhighlightSettingForm select').val('{{ highlightType() }}');
  382. function selectHighlight() {
  383. // selecter で選択された値
  384. var val = $('#cutomhighlightSettingForm select').val()
  385. // 追加する style の DOM
  386. var style = `<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/${val}.css">`;
  387. // body の最後に追加 layout.html は body に読み込まれてるため、body の一番下に追加しないと上書きされない
  388. $('body link:last').after(style);
  389. // demo の部分だけ highlight.js 再読み込み
  390. hljs.highlightBlock($(".highlight-demo")[0]);
  391. }
  392. </script>
  393. </div>
  394. {% endblock content_main %}
  395. {% block content_footer %}
  396. {% endblock content_footer %}