customize.html 17 KB

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