customize.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}{{ t('Customize') }} {% endblock %}
  3. {% block style_css_block %}
  4. <link rel="stylesheet" href="{{ webpack_asset('style').css }}">
  5. <link rel="stylesheet" id="jssDefault" {# append id for style-switcher #} href="{{ webpack_asset('style-theme-default').css }}">
  6. {% endblock %}
  7. {% block html_additional_headers %}
  8. {% parent %}
  9. <!-- CodeMirror -->
  10. <link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.ui/1.11.4/jquery-ui.min.css">
  11. <style>
  12. .CodeMirror {
  13. border: 1px solid #eee;
  14. }
  15. </style>
  16. {% endblock %}
  17. {% block content_header %}
  18. <div class="header-wrap">
  19. <header id="page-header">
  20. <h1 class="title" id="">{{ t('Customize') }} </h1>
  21. </header>
  22. </div>
  23. {% endblock %}
  24. {% block content_main %}
  25. <div class="content-main admin-customize">
  26. {% set smessage = req.flash('successMessage') %}
  27. {% if smessage.length %}
  28. <div class="alert alert-success">
  29. {{ smessage }}
  30. </div>
  31. {% endif %}
  32. {% set emessage = req.flash('errorMessage') %}
  33. {% if emessage.length %}
  34. <div class="alert alert-danger">
  35. {{ emessage }}
  36. </div>
  37. {% endif %}
  38. <div class="row">
  39. <div class="col-md-3">
  40. {% include './widget/menu.html' with {current: 'customize'} %}
  41. </div>
  42. <div class="col-md-9">
  43. <form action="/_api/admin/customize/theme" method="post" class="form-horizontal" id="cutomthemeSettingForm" role="form">
  44. <fieldset>
  45. <legend>{{ t('customize_page.Theme') }}</legend>
  46. <!-- <div class="form-group">
  47. <label for="settingForm[customize:highlightJsStyle]" class="col-xs-3 control-label">{{ t('customize_page.Theme') }}</label>
  48. <div class="col-xs-9">
  49. <select class="form-control selectpicker" name="settingForm[customize:highlightJsStyle]" onChange="selectHighlightJsStyle(event)">
  50. {% for key in Object.keys(highlightJsCssSelectorOptions) %}
  51. <option value={{key}} {% if key == highlightJsStyle() %} selected {% endif %}>{{highlightJsCssSelectorOptions[key].name}}</option>
  52. {% endfor %}
  53. </select>
  54. </div>
  55. </div> -->
  56. <script type="text/javascript">
  57. // $(document).ready(function() {
  58. // $('#styleOptions').styleSwitcher();
  59. // });
  60. </script>
  61. <ul id="styleOptions">
  62. <li>
  63. <a href="javascript: void(0)" data-theme="{{ webpack_asset('style-theme-default').css }}">Default</a>
  64. </li>
  65. <li>
  66. <a href="javascript: void(0)" data-theme="{{ webpack_asset('style-theme-default-dark').css }}">Default Dark</a>
  67. </li>
  68. </ul>
  69. <div class="form-group">
  70. <div class="col-xs-offset-5 col-xs-6">
  71. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  72. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  73. </div>
  74. </div>
  75. </fieldset>
  76. </form>
  77. <form action="/_api/admin/customize/behavior" method="post" class="form-horizontal" id="cutombehaviorSettingForm" role="form">
  78. <fieldset>
  79. <legend>{{ t('customize_page.Behavior') }}</legend>
  80. <div class="form-group">
  81. <div class="col-xs-6">
  82. <h4>
  83. <input type="radio" name="settingForm[customize:behavior]" value="crowi"
  84. {% if !settingForm['customize:behavior'] || 'crowi' === settingForm['customize:behavior'] %}checked="checked"{% endif %}>
  85. Official Crowi Behavior
  86. </h4>
  87. <ul>
  88. <li><code>/page</code> shows the page</li>
  89. <li><code>/page/</code> shows the list of sub pages</li>
  90. <ul>
  91. <li>If portal is applied to <code>/page/</code> , the portal and the list of sub pages are shown</li>
  92. </ul>
  93. <li><code>/nonexistent_page</code> shows editing form</li>
  94. <li><code>/nonexistent_page/</code> the list of sub pages</li>
  95. </ul>
  96. </div>
  97. <div class="col-xs-6">
  98. <h4>
  99. <input type="radio" name="settingForm[customize:behavior]" value="crowi-plus"
  100. {% if 'crowi-plus' === settingForm['customize:behavior'] %}checked="checked"{% endif %}>
  101. crowi-plus Simplified Behavior <small class="text-success">(Recommended)</small>
  102. </h4>
  103. <ul>
  104. <li>Both of <code>/page</code> and <code>/page/</code> shows the same page</li>
  105. <li><code>/nonexistent_page</code> shows editing form</li>
  106. <li>All pages shows the list of sub pages when using <b>crowi-plus Enhanced Layout</b></li>
  107. </ul>
  108. </div>
  109. </div>
  110. <div class="form-group">
  111. <div class="col-xs-offset-5 col-xs-6">
  112. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  113. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  114. </div>
  115. </div>
  116. </fieldset>
  117. </form>
  118. <form action="/_api/admin/customize/layout" method="post" class="form-horizontal" id="cutomlayoutSettingForm" role="form">
  119. <fieldset>
  120. <legend>{{ t('customize_page.Layout') }}</legend>
  121. <div class="form-group">
  122. <div class="col-xs-6">
  123. <h4>
  124. <input type="radio" name="settingForm[customize:layout]" value="crowi"
  125. {% if !settingForm['customize:layout'] || 'crowi' === settingForm['customize:layout'] %}checked="checked"{% endif %}>
  126. Official Crowi Classic Layout
  127. </h4>
  128. <a href="/images/admin/customize/layout-classic.gif" class="ss-container">
  129. <img src="/images/admin/customize/layout-classic-thumb.gif" width="240px">
  130. </a>
  131. <ul>
  132. <li>Functional</li>
  133. <ul>
  134. <li>Collapsible Sidebar</li>
  135. <li>Show and post comments in Sidebar</li>
  136. <li>Collapsible Table-of-contents</li>
  137. </ul>
  138. </ul>
  139. </div>
  140. <div class="col-xs-6">
  141. <h4>
  142. <input type="radio" name="settingForm[customize:layout]" value="crowi-plus"
  143. {% if 'crowi-plus' === settingForm['customize:layout'] %}checked="checked"{% endif %}>
  144. crowi-plus Enhanced Layout <small class="text-success">(Recommended)</small>
  145. </h4>
  146. <a href="/images/admin/customize/layout-crowi-plus.gif" class="ss-container">
  147. <img src="/images/admin/customize/layout-crowi-plus-thumb.gif" width="240px">
  148. </a>
  149. <ul>
  150. <li>Simple and Clear</li>
  151. <ul>
  152. <li>Show and post comments from the bottom of the page</li>
  153. <li>Affix Table-of-contents</li>
  154. </ul>
  155. </ul>
  156. </div>
  157. </div>
  158. <div class="form-group">
  159. <div class="col-xs-offset-5 col-xs-6">
  160. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  161. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  162. </div>
  163. </div>
  164. </fieldset>
  165. </form>
  166. <form action="/_api/admin/customize/features" method="post" class="form-horizontal" id="customfeaturesSettingForm" role="form">
  167. <fieldset>
  168. <legend>{{ t('customize_page.Function') }}</legend>
  169. <p class="well">{{ t("customize_page.function_choose") }}</p>
  170. <div class="form-group">
  171. <label for="settingForm[customize:isEnabledTimeline]" class="col-xs-3 control-label">{{ t('customize_page.Timeline function') }}</label>
  172. <div class="col-xs-9">
  173. <div class="btn-group btn-toggle" data-toggle="buttons">
  174. <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:isEnabledTimeline'] %}active{% endif %}" data-active-class="primary">
  175. <input name="settingForm[customize:isEnabledTimeline]" value="true" type="radio"
  176. {% if true === settingForm['customize:isEnabledTimeline'] %}checked{% endif %}> ON
  177. </label>
  178. <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:isEnabledTimeline'] %}active{% endif %}" data-active-class="default">
  179. <input name="settingForm[customize:isEnabledTimeline]" value="false" type="radio"
  180. {% if !settingForm['customize:isEnabledTimeline'] %}checked{% endif %}> OFF
  181. </label>
  182. </div>
  183. <p class="help-block">
  184. {{ t("customize_page.subpage_display") }}
  185. </p>
  186. <p class="help-block">
  187. {{ t("customize_page.performance_decrease") }}<br>
  188. {{ t("customize_page.list_page_display") }}
  189. </p>
  190. </div>
  191. </div>
  192. <div class="form-group">
  193. <label for="settingForm[customize:isSavedStatesOfTabChanges]" class="col-xs-3 control-label">{{ t("customize_page.tab_switch") }}</label>
  194. <div class="col-xs-9">
  195. <div class="btn-group btn-toggle" data-toggle="buttons">
  196. <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:isSavedStatesOfTabChanges'] %}active{% endif %}" data-active-class="primary">
  197. <input name="settingForm[customize:isSavedStatesOfTabChanges]" value="true" type="radio"
  198. {% if true === settingForm['customize:isSavedStatesOfTabChanges'] %}checked{% endif %}> ON
  199. </label>
  200. <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:isSavedStatesOfTabChanges'] %}active{% endif %}" data-active-class="default">
  201. <input name="settingForm[customize:isSavedStatesOfTabChanges]" value="false" type="radio"
  202. {% if !settingForm['customize:isSavedStatesOfTabChanges'] %}checked{% endif %}> OFF
  203. </label>
  204. </div>
  205. <p class="help-block">
  206. {{ t("customize_page.save_edit") }}<br>
  207. {{ t("customize_page.by_invalidating") }}
  208. </p>
  209. </div>
  210. </div>
  211. <div class="form-group">
  212. <div class="col-xs-offset-3 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/highlightJsStyle" method="post" class="form-horizontal" id="cutomhighlightJsStyleSettingForm" role="form">
  220. <fieldset>
  221. <legend>{{ t('customize_page.Code Highlight') }}</legend>
  222. <div class="form-group">
  223. <label for="settingForm[customize:highlightJsStyle]" class="col-xs-3 control-label">{{ t('customize_page.Theme') }}</label>
  224. <div class="col-xs-9">
  225. <select class="form-control selectpicker" name="settingForm[customize:highlightJsStyle]" onChange="selectHighlightJsStyle(event)">
  226. {% for key in Object.keys(highlightJsCssSelectorOptions) %}
  227. <option value={{key}} {% if key == highlightJsStyle() %} selected {% endif %}>{{highlightJsCssSelectorOptions[key].name}}</option>
  228. {% endfor %}
  229. </select>
  230. </div>
  231. </div>
  232. <div class="form-group">
  233. <label for="settingForm[customize:highlightJsStyleBorder]" class="col-xs-3 control-label">(TBD) Border</label>
  234. <div class="col-xs-9">
  235. <div class="btn-group btn-toggle" data-toggle="buttons">
  236. <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:highlightJsStyleBorder'] %}active{% endif %}" data-active-class="primary">
  237. <input name="settingForm[customize:highlightJsStyleBorder]" value="true" type="radio"
  238. {% if true === settingForm['customize:highlightJsStyleBorder'] %}checked{% endif %}> ON
  239. </label>
  240. <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:highlightJsStyleBorder'] %}active{% endif %}" data-active-class="default">
  241. <input name="settingForm[customize:highlightJsStyleBorder]" value="false" type="radio"
  242. {% if !settingForm['customize:highlightJsStyleBorder'] %}checked{% endif %}> OFF
  243. </label>
  244. </div>
  245. </div>
  246. </div>
  247. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/{{ highlightJsStyle() }}.css" class="highlightJsCss">
  248. <p class="help-block">
  249. Examples:
  250. <pre class="hljs"><code class="highlightjs-demo">function $initHighlight(block, cls) {
  251. try {
  252. if (cls.search(/\bno\-highlight\b/) != -1)
  253. return process(block, true, 0x0F) +
  254. ` class="${cls}"`;
  255. } catch (e) {
  256. /* handle exception */
  257. }
  258. for (var i = 0 / 2; i < classes.length; i++) {
  259. if (checkCondition(classes[i]) === undefined)
  260. console.log('undefined');
  261. }
  262. }
  263. export $initHighlight;</code></pre>
  264. </p>
  265. <div class="form-group">
  266. <div class="col-xs-offset-5 col-xs-6">
  267. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  268. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  269. </div>
  270. </div>
  271. </fieldset>
  272. </form>
  273. <form action="/_api/admin/customize/header" method="post" class="form-horizontal" id="cutomheaderSettingForm" role="form">
  274. <fieldset>
  275. <legend>カスタムヘッダーHTML</legend>
  276. <p class="well">
  277. システム全体に適用される HTML を記述できます。<code>&lt;header&gt;</code> タグ内の他の <code>&lt;script&gt;</code> タグ読み込み前に展開されます。<br>
  278. 変更の反映はページの更新が必要です。
  279. </p>
  280. <p class="help-block">
  281. Examples:
  282. <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>
  283. </p>
  284. <div class="form-group">
  285. <div class="col-xs-12">
  286. <div id="custom-header-editor"></div>
  287. <input type="hidden" id="inputCustomHeader" name="settingForm[customize:header]" value="{{ settingForm['customize:header'] }}">
  288. </div>
  289. <div class="col-xs-12">
  290. <p class="help-block text-right">
  291. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  292. Ctrl+Space でコード補完
  293. </p>
  294. </div>
  295. </div>
  296. <div class="form-group">
  297. <div class="col-xs-offset-5 col-xs-6">
  298. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  299. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  300. </div>
  301. </div>
  302. </fieldset>
  303. </form>
  304. <form action="/_api/admin/customize/css" method="post" class="form-horizontal" id="cutomcssSettingForm" role="form">
  305. <fieldset>
  306. <legend>{{ t('customize_page.Custom CSS') }}</legend>
  307. <p class="well">
  308. {{ t("customize_page.write_CSS") }}<br>
  309. {{ t("customize_page.reflect_change") }}
  310. </p>
  311. <div class="form-group">
  312. <div class="col-xs-12">
  313. <div id="custom-css-editor"></div>
  314. <input type="hidden" id="inputCustomCss" name="settingForm[customize:css]" value="{{ settingForm['customize:css'] }}">
  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. <form action="/_api/admin/customize/script" method="post" class="form-horizontal" id="cutomscriptSettingForm" role="form">
  332. <fieldset>
  333. <legend>{{ t('customize_page.Custom script') }}</legend>
  334. <p class="well">
  335. {{ t("customize_page.write_java") }}<br>
  336. {{ t("customize_page.reflect_change") }}
  337. </p>
  338. <p class="help-block">
  339. Placeholders:<br>
  340. (Available after <code>load</code> event)
  341. <dl class="dl-horizontal">
  342. <dt><code>$</code></dt>
  343. <dd>jQuery instance</dd>
  344. <dt><code>crowi</code></dt>
  345. <dd>Crowi context instance</dd>
  346. <dt><code>Crowi</code></dt>
  347. <dd>Crowi legacy instance (jQuery based)</dd>
  348. <dt><code>crowiRenderer</code></dt>
  349. <dd>Crowi Renderer instance</dd>
  350. <dt><code>crowiPlugin</code></dt>
  351. <dd>crowi-plus plugin manager instance</dd>
  352. </dl>
  353. </p>
  354. <p class="help-block">
  355. Examples:
  356. <pre class="hljs"><code>console.log($('.main-container'));
  357. window.addEventListener('load', (event) => {
  358. console.log('config: ', crowi.config);
  359. });</code></pre>
  360. </p>
  361. <div class="form-group">
  362. <div class="col-xs-12">
  363. <div id="custom-script-editor"></div>
  364. <input type="hidden" id="inputCustomScript" name="settingForm[customize:script]" value="{{ settingForm['customize:script'] }}">
  365. </div>
  366. <div class="col-xs-12">
  367. <p class="help-block text-right">
  368. <i class="fa fa-fw fa-keyboard-o" aria-hidden="true"></i>
  369. {{ t("customize_page.ctrl_space") }}
  370. </p>
  371. </div>
  372. </div>
  373. <div class="form-group">
  374. <div class="col-xs-offset-5 col-xs-6">
  375. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  376. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  377. </div>
  378. </div>
  379. </fieldset>
  380. </form>
  381. </div>
  382. </div>
  383. {% endblock content_main %}
  384. {% block body_end %}
  385. {% parent %}
  386. <script>
  387. $('#cutomcssSettingForm, #cutomscriptSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm, #customfeaturesSettingForm, #cutomheaderSettingForm, #cutomhighlightJsStyleSettingForm').each(function() {
  388. $(this).submit(function()
  389. {
  390. function showMessage(formId, msg, status) {
  391. $('#' + formId + ' .alert').remove();
  392. if (!status) {
  393. status = 'success';
  394. }
  395. var $message = $('<p class="alert"></p>');
  396. $message.addClass('alert-' + status);
  397. $message.html(msg.replace('\n', '<br>'));
  398. $message.insertAfter('#' + formId + ' legend');
  399. if (status == 'success') {
  400. setTimeout(function()
  401. {
  402. $message.fadeOut({
  403. complete: function() {
  404. $message.remove();
  405. }
  406. });
  407. }, 5000);
  408. }
  409. }
  410. var $form = $(this);
  411. var $id = $form.attr('id');
  412. var $button = $('button', this);
  413. $button.attr('disabled', 'disabled');
  414. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  415. {
  416. if (data.status) {
  417. showMessage($id, '更新しました');
  418. } else {
  419. showMessage($id, data.message, 'danger');
  420. }
  421. })
  422. .fail(function() {
  423. showMessage($id, 'エラーが発生しました', 'danger');
  424. })
  425. .always(function() {
  426. $button.prop('disabled', false);
  427. });
  428. return false;
  429. });
  430. });
  431. /*
  432. * highlight.js style switcher
  433. */
  434. hljs.initHighlightingOnLoad()
  435. function selectHighlightJsStyle(event) {
  436. var highlightJsCssDOM = $(".highlightJsCss")[0]
  437. // selected value
  438. var val = event.target.value
  439. // replace css url
  440. // see https://regex101.com/r/gBNZYu/4
  441. highlightJsCssDOM.href = highlightJsCssDOM.href.replace(/[^/]+\.css$/, `${val}.css`);
  442. }
  443. /*
  444. * Theme switcher
  445. */
  446. options = {
  447. hasPreview: false,
  448. fullPath: '',
  449. cookie: {
  450. isManagingLoad: false
  451. }
  452. };
  453. $(document).ready(function() {
  454. $('#styleOptions').styleSwitcher(options);
  455. });
  456. </script>
  457. </div>
  458. {% endblock %}
  459. {% block content_footer %}
  460. {% endblock content_footer %}