LoginSignup
3

More than 3 years have passed since last update.

Redmineの新規チケット起票時に選択したトラッカーによってプライベートチケットON/OFFする方法【View customizes Plugin】

Last updated at Posted at 2018-01-10

やりたいこと

新規チケット起票時にトラッカーによってプライベートチケットのデフォルトON/OFFを行いたい。

・トラッカーが「申請」の場合はデフォルトでプライベートチケットにチェックがついている。
・トラッカーが「問い合わせ」の場合はデフォルトでプライベートチケットにチェックがついていない。
こんなことできないだろうか?

動作環境

Redmine3.4.3
View Customize plugin 1.1.4

やり方

Redmineのプラグイン「view customize plugin」を利用します。

下記の設定をview customizeで設定します。
今回は上の例のように「申請」と「問い合わせ」のトラッカーが存在して、
「申請」を選択するとプライベートチケットにチェックが付くようにします。
Code文中にある「// トラッカー名毎に処理を分ける」より下を追加していくことで
複数のトラッカーで処理を変更することが可能です。

  • Path pattern
/projects/{プロジェクトID}/issues/new
  • Type
JavaScript
  • Code
$(function() {
  var trackerChanged = false;  // トラッカー変更有無

  // トラッカー変更イベントによりフラグの状態制御
  $(document).on('change', '#issue_tracker_id', function() {
    trackerChanged = true;
  });

  // デフォルトのreplaceIssueFormWithを置き換え
  var _replaceIssueFormWith = replaceIssueFormWith;
  replaceIssueFormWith = function(html){

    _replaceIssueFormWith(html);
    // トラッカー変更時にデフォルト設定処理を実行
    if (trackerChanged) {
      setDefalutStatus();
    }

    trackerChanged = false;
  };

  // トラッカーのデフォルト設定処理
  var setDefalutStatus = function() {
    // トラッカー名毎に処理を分ける
    switch($('#issue_tracker_id option:selected').text()) {
      case "申請":
        $("#issue_is_private").prop('checked',true);
        break;
      default:
        $("#issue_is_private").prop('checked',false);
        break;
    }
  }

  // 初回表示処理にもデフォルト値設定処理を実行
  setDefalutStatus();
});

参考サイト

Enjoy*Study:Redmineでトラッカー毎にデフォルトステータスを変える(View customize plugin)
新規チケットをデフォルトでプライベートにしたい。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3