2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Redmine でチケット更新時にフォームの値からウォッチャーを追加

Posted at

対象

  • Redmine : 3.3.1
  • クライアント : Linux, Firefox 50.1.0

やりたいこと

ユーザー選択のフィールドを持つチケットを更新するときに、選択したユーザーをついでにウォッチャーに追加したい場合がある。
ウォッチャーの追加を自動にしたい。

方法

View Customize Plugin (https://github.com/onozaty/redmine-view-customize) を使う。

/issues/\d+$
$(document).on("submit", "#issue-form", function() {
    var trackerId = "1";
    var statusId = "1";
    var userFieldIds = [
        "issue_custom_field_values_1",
        "issue_custom_field_values_2"
    ];

    if ($("#issue_tracker_id").length > 0) {
        if ($("#issue_tracker_id").val() !== trackerId) {
            return;
        }
    } else {
        if (!$("#content > div.issue").hasClass("tracker-" + trackerId)) {
            return;
        }
    }

    if ($("#issue_status_id").val() !== statusId) {
        return;
    }

    var userIds = [];

    for (var i = 0; i < userFieldIds.length; i++) {
        $("#" + userFieldIds[i]).each(function() {
            var $this = $(this);

            if ($this.is("select")) {
                if ($this.prop("multiple")) {
                    userIds = userIds.concat($this.val() || []);
                } else {
                    userIds.push($this.val());
                }
            } else if ($this.is("input")) {
                $("input[name='" + $this.attr("name") + "'][value!='']:checked").each(function() {
                    userIds.push($(this).val());
                });
            }
        });
    }

    if (!userIds) {
        return;
    }

    $.post(location.href + "/watchers", { "watcher": { "user_ids": userIds } });
});
2
3
0

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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?