summaryrefslogtreecommitdiff
path: root/assets/js/src/Task.js
blob: 06419207c6a247377fecd47c88e653a28879f80e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Kanboard.Task = function(app) {
    this.app = app;
};

Kanboard.Task.prototype.keyboardShortcuts = function() {
    var taskView = $("#task-view");
    var self = this;

    if (this.app.hasId("task-view")) {
        Mousetrap.bind("e", function() {
            self.app.get("Popover").open(taskView.data("edit-url"));
        });

        Mousetrap.bind("c", function() {
            self.app.get("Popover").open(taskView.data("comment-url"));
        });

        Mousetrap.bind("s", function() {
            self.app.get("Popover").open(taskView.data("subtask-url"));
        });

        Mousetrap.bind("l", function() {
            self.app.get("Popover").open(taskView.data("internal-link-url"));
        });
    }
};

Kanboard.Task.prototype.onPopoverOpened = function() {
    var self = this;
    var reloadingProjectId = 0;

    self.renderColorPicker();

    // Assign to me
    $(document).on("click", ".assign-me", function(e) {
        var currentId = $(this).data("current-id");
        var dropdownId = "#" + $(this).data("target-id");

        e.preventDefault();

        if ($(dropdownId + ' option[value=' + currentId + ']').length) {
            $(dropdownId).val(currentId);
        }
    });

    // Reload page when a destination project is changed
    $(document).on("change", "select.task-reload-project-destination", function() {
        if (reloadingProjectId > 0) {
            $(this).val(reloadingProjectId);
        }
        else {
            reloadingProjectId = $(this).val();
            var url = $(this).data("redirect").replace(/PROJECT_ID/g, reloadingProjectId);

            $(".loading-icon").show();

            $.ajax({
                type: "GET",
                url: url,
                success: function(data, textStatus, request) {
                    reloadingProjectId = 0;
                    $(".loading-icon").hide();
                    self.app.get("Popover").ajaxReload(data, request, self.app.get("Popover"));
                }
            });
        }
    });
};

Kanboard.Task.prototype.renderColorPicker = function() {
    function renderColorOption(color) {
        return $(
            '<div class="color-picker-option">' +
            '<div class="color-picker-square color-' + color.id + '"></div>' +
            '<div class="color-picker-label">' + color.text + '</div>' +
            '</div>'
        );
    }

    $(".color-picker").select2({
        minimumResultsForSearch: Infinity,
        templateResult: renderColorOption,
        templateSelection: renderColorOption
    });
};