customize.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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/css" method="post" class="form-horizontal" id="cutomcssSettingForm" role="form">
  267. <fieldset>
  268. <legend>{{ t('customize_page.Custom CSS') }}</legend>
  269. <p class="well">
  270. {{ t("customize_page.write_CSS") }}<br>
  271. {{ t("customize_page.reflect_change") }}
  272. </p>
  273. <div class="form-group">
  274. <div class="col-xs-12">
  275. <div id="custom-css-editor"></div>
  276. <input type="hidden" id="inputCustomCss" name="settingForm[customize:css]" value="{{ settingForm['customize:css'] }}">
  277. </div>
  278. <div class="col-xs-12">
  279. <p class="help-block text-right">
  280. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  281. {{ t("customize_page.ctrl_space") }}
  282. </p>
  283. </div>
  284. </div>
  285. <div class="form-group">
  286. <div class="col-xs-offset-5 col-xs-6">
  287. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  288. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  289. </div>
  290. </div>
  291. </fieldset>
  292. </form>
  293. <form action="/_api/admin/customize/script" method="post" class="form-horizontal" id="cutomscriptSettingForm" role="form">
  294. <fieldset>
  295. <legend>{{ t('customize_page.Custom script') }}</legend>
  296. <p class="well">
  297. {{ t("customize_page.write_java") }}<br>
  298. {{ t("customize_page.reflect_change") }}
  299. </p>
  300. <p class="help-block">
  301. Placeholders:<br>
  302. (Available after <code>load</code> event)
  303. <dl class="dl-horizontal">
  304. <dt><code>$</code></dt>
  305. <dd>jQuery instance</dd>
  306. <dt><code>crowi</code></dt>
  307. <dd>Crowi context instance</dd>
  308. <dt><code>Crowi</code></dt>
  309. <dd>Crowi legacy instance (jQuery based)</dd>
  310. <dt><code>crowiRenderer</code></dt>
  311. <dd>Crowi Renderer instance</dd>
  312. <dt><code>crowiPlugin</code></dt>
  313. <dd>crowi-plus plugin manager instance</dd>
  314. </dl>
  315. </p>
  316. <p class="help-block">
  317. Examples:
  318. <pre class="hljs"><code>console.log($('.main-container'));
  319. window.addEventListener('load', (event) => {
  320. console.log('config: ', crowi.config);
  321. });</code></pre>
  322. </p>
  323. <div class="form-group">
  324. <div class="col-xs-12">
  325. <div id="custom-script-editor"></div>
  326. <input type="hidden" id="inputCustomScript" name="settingForm[customize:script]" value="{{ settingForm['customize:script'] }}">
  327. </div>
  328. <div class="col-xs-12">
  329. <p class="help-block text-right">
  330. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  331. {{ t("customize_page.ctrl_space") }}
  332. </p>
  333. </div>
  334. </div>
  335. <div class="form-group">
  336. <div class="col-xs-offset-5 col-xs-6">
  337. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  338. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  339. </div>
  340. </div>
  341. </fieldset>
  342. </form>
  343. </div>
  344. </div>
  345. <script>
  346. $('#cutomcssSettingForm, #cutomscriptSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm, #customfeaturesSettingForm, #cutomheaderSettingForm, #cutomhighlightJsStyleSettingForm').each(function() {
  347. $(this).submit(function()
  348. {
  349. function showMessage(formId, msg, status) {
  350. $('#' + formId + ' .alert').remove();
  351. if (!status) {
  352. status = 'success';
  353. }
  354. var $message = $('<p class="alert"></p>');
  355. $message.addClass('alert-' + status);
  356. $message.html(msg.replace('\n', '<br>'));
  357. $message.insertAfter('#' + formId + ' legend');
  358. if (status == 'success') {
  359. setTimeout(function()
  360. {
  361. $message.fadeOut({
  362. complete: function() {
  363. $message.remove();
  364. }
  365. });
  366. }, 5000);
  367. }
  368. }
  369. var $form = $(this);
  370. var $id = $form.attr('id');
  371. var $button = $('button', this);
  372. $button.attr('disabled', 'disabled');
  373. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  374. {
  375. if (data.status) {
  376. showMessage($id, '更新しました');
  377. } else {
  378. showMessage($id, data.message, 'danger');
  379. }
  380. })
  381. .fail(function() {
  382. showMessage($id, 'エラーが発生しました', 'danger');
  383. })
  384. .always(function() {
  385. $button.prop('disabled', false);
  386. });
  387. return false;
  388. });
  389. });
  390. // init highlight.js
  391. hljs.initHighlightingOnLoad()
  392. function selectHighlightJsStyle(event) {
  393. var highlightJsCssDOM = $(".highlightJsCss")[0]
  394. // selected value
  395. var val = event.target.value
  396. // replace css url
  397. // see https://regex101.com/r/gBNZYu/3
  398. highlightJsCssDOM.href = highlightJsCssDOM.href.replace(/[^/]+\.css$/, `${val}.css`);
  399. }
  400. </script>
  401. </div>
  402. {% endblock content_main %}
  403. {% block content_footer %}
  404. {% endblock content_footer %}