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