customize.html 17 KB

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