customize.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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]}}</option>
  190. {% endfor %}
  191. </select>
  192. </div>
  193. </div>
  194. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/{{ highlightJsStyle() }}.css" class="highlightJsCss">
  195. <p class="help-block">
  196. Examples:
  197. <pre class="hljs"><code class="highlightjs-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. </p>
  212. <div class="form-group">
  213. <div class="col-xs-offset-5 col-xs-6">
  214. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  215. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  216. </div>
  217. </div>
  218. </fieldset>
  219. </form>
  220. <form action="/_api/admin/customize/header" method="post" class="form-horizontal" id="cutomheaderSettingForm" role="form">
  221. <fieldset>
  222. <legend>カスタムヘッダーHTML</legend>
  223. <p class="well">
  224. システム全体に適用される HTML を記述できます。<code>&lt;header&gt;</code> タグ内の他の <code>&lt;script&gt;</code> タグ読み込み前に展開されます。<br>
  225. 変更の反映はページの更新が必要です。
  226. </p>
  227. <p class="help-block">
  228. Examples:
  229. <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>
  230. </p>
  231. <div class="form-group">
  232. <div class="col-xs-12">
  233. <div id="custom-header-editor"></div>
  234. <input type="hidden" id="inputCustomHeader" name="settingForm[customize:header]" value="{{ settingForm['customize:header'] }}">
  235. </div>
  236. <div class="col-xs-12">
  237. <p class="help-block text-right">
  238. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  239. Ctrl+Space でコード補完
  240. </p>
  241. </div>
  242. </div>
  243. <div class="form-group">
  244. <div class="col-xs-offset-5 col-xs-6">
  245. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  246. <button type="submit" class="btn btn-primary">更新</button>
  247. </div>
  248. </div>
  249. </fieldset>
  250. </form>
  251. <form action="/_api/admin/customize/css" method="post" class="form-horizontal" id="cutomcssSettingForm" role="form">
  252. <fieldset>
  253. <legend>{{ t('customize_page.Custom CSS') }}</legend>
  254. <p class="well">
  255. {{ t("customize_page.write_CSS") }}<br>
  256. {{ t("customize_page.reflect_change") }}
  257. </p>
  258. <div class="form-group">
  259. <div class="col-xs-12">
  260. <div id="custom-css-editor"></div>
  261. <input type="hidden" id="inputCustomCss" name="settingForm[customize:css]" value="{{ settingForm['customize:css'] }}">
  262. </div>
  263. <div class="col-xs-12">
  264. <p class="help-block text-right">
  265. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  266. {{ t("customize_page.ctrl_space") }}
  267. </p>
  268. </div>
  269. </div>
  270. <div class="form-group">
  271. <div class="col-xs-offset-5 col-xs-6">
  272. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  273. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  274. </div>
  275. </div>
  276. </fieldset>
  277. </form>
  278. <form action="/_api/admin/customize/script" method="post" class="form-horizontal" id="cutomscriptSettingForm" role="form">
  279. <fieldset>
  280. <legend>{{ t('customize_page.Custom script') }}</legend>
  281. <p class="well">
  282. {{ t("customize_page.write_java") }}<br>
  283. {{ t("customize_page.reflect_change") }}
  284. </p>
  285. <p class="help-block">
  286. Placeholders:<br>
  287. (Available after <code>load</code> event)
  288. <dl class="dl-horizontal">
  289. <dt><code>$</code></dt>
  290. <dd>jQuery instance</dd>
  291. <dt><code>crowi</code></dt>
  292. <dd>Crowi context instance</dd>
  293. <dt><code>Crowi</code></dt>
  294. <dd>Crowi legacy instance (jQuery based)</dd>
  295. <dt><code>crowiRenderer</code></dt>
  296. <dd>Crowi Renderer instance</dd>
  297. <dt><code>crowiPlugin</code></dt>
  298. <dd>crowi-plus plugin manager instance</dd>
  299. </dl>
  300. </p>
  301. <p class="help-block">
  302. Examples:
  303. <pre class="hljs"><code>console.log($('.main-container'));
  304. window.addEventListener('load', (event) => {
  305. console.log('config: ', crowi.config);
  306. });</code></pre>
  307. </p>
  308. <div class="form-group">
  309. <div class="col-xs-12">
  310. <div id="custom-script-editor"></div>
  311. <input type="hidden" id="inputCustomScript" name="settingForm[customize:script]" value="{{ settingForm['customize:script'] }}">
  312. </div>
  313. <div class="col-xs-12">
  314. <p class="help-block text-right">
  315. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  316. {{ t("customize_page.ctrl_space") }}
  317. </p>
  318. </div>
  319. </div>
  320. <div class="form-group">
  321. <div class="col-xs-offset-5 col-xs-6">
  322. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  323. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  324. </div>
  325. </div>
  326. </fieldset>
  327. </form>
  328. </div>
  329. </div>
  330. <script>
  331. $('#cutomcssSettingForm, #cutomscriptSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm, #customfeaturesSettingForm, #cutomheaderSettingForm, #cutomhighlightJsStyleSettingForm').each(function() {
  332. $(this).submit(function()
  333. {
  334. function showMessage(formId, msg, status) {
  335. $('#' + formId + ' .alert').remove();
  336. if (!status) {
  337. status = 'success';
  338. }
  339. var $message = $('<p class="alert"></p>');
  340. $message.addClass('alert-' + status);
  341. $message.html(msg.replace('\n', '<br>'));
  342. $message.insertAfter('#' + formId + ' legend');
  343. if (status == 'success') {
  344. setTimeout(function()
  345. {
  346. $message.fadeOut({
  347. complete: function() {
  348. $message.remove();
  349. }
  350. });
  351. }, 5000);
  352. }
  353. }
  354. var $form = $(this);
  355. var $id = $form.attr('id');
  356. var $button = $('button', this);
  357. $button.attr('disabled', 'disabled');
  358. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  359. {
  360. if (data.status) {
  361. showMessage($id, '更新しました');
  362. } else {
  363. showMessage($id, data.message, 'danger');
  364. }
  365. })
  366. .fail(function() {
  367. showMessage($id, 'エラーが発生しました', 'danger');
  368. })
  369. .always(function() {
  370. $button.prop('disabled', false);
  371. });
  372. return false;
  373. });
  374. });
  375. // init highlight.js
  376. hljs.initHighlightingOnLoad()
  377. function selectHighlightJsStyle(event) {
  378. var highlightJsCssDOM = $(".highlightJsCss")[0]
  379. // selected value
  380. var val = event.target.value
  381. // replace css url
  382. // see https://regex101.com/r/gBNZYu/3
  383. highlightJsCssDOM.href = highlightJsCssDOM.href.replace(/[^/]+\.css$/, `${val}.css`);
  384. }
  385. </script>
  386. </div>
  387. {% endblock content_main %}
  388. {% block content_footer %}
  389. {% endblock content_footer %}