File size: 3,755 Bytes
bd98362 | 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | window.ProjectIssuesView = BaseView.extend({
template: _.template($('#project_issues_underscore').html()),
events: {
"click .close-backlog": "closeBacklog",
"click .open-backlog": "openBacklog",
},
initialize: function() {
_.bindAll(this, 'doRender');
this.listenTo(this.model, 'change', this.doRender);
this.ignores = 0;
},
closeBacklog: function(ev) {
var that = this;
ev.preventDefault();
that.$('.state-col').each(function(ind, e) {
var el = $(e);
el.removeClass('col-md-3').addClass('col-md-4');
});
that.$('.backlog-col').addClass('hidden');
that.$('.glyphicon-folder-close').removeClass('hidden');
},
openBacklog: function(ev) {
var that = this;
ev.preventDefault();
that.$('.state-col').each(function(ind, e) {
var el = $(e);
el.removeClass('col-md-4').addClass('col-md-3');
});
that.$('.backlog-col').removeClass('hidden');
that.$('.glyphicon-folder-close').addClass('hidden');
},
render: function() {
var that = this;
window.session.nav.setPath([
{
label: that.model.get('Name'),
path: '/projects/' + that.model.get('Id'),
},
{
label: 'Issues',
path: '/projects/' + that.model.get('Id') + '/issues',
},
]);
window.session.nav.setCollaborators(that.model.collaborators.models);
that.$el.html(that.template({
model: that.model,
}));
that.$('.issue-list').css('height', '' + ($(window).height() - 150) + 'px');
that.model.issues.each(function(issue) {
var state = issue.getState();
if (state == 'Ready') {
that.$('.ready-issues').append(new IssueView({
project: that.model,
parent: that,
model: issue,
}).doRender().el);
} else if (state == 'Doing') {
that.$('.doing-issues').append(new IssueView({
project: that.model,
parent: that,
model: issue,
}).doRender().el);
} else if (state == 'Done') {
that.$('.done-issues').append(new IssueView({
project: that.model,
parent: that,
model: issue,
}).doRender().el);
} else if (state == 'Backlog') {
that.$('.backlog-issues').append(new IssueView({
project: that.model,
parent: that,
model: issue,
}).doRender().el);
}
});
var updateFunc = function(ev, ui) {
if (that.ignores > 0) {
that.ignores--;
$(ev.target).sortable('cancel');
return
}
var issueElement = $(ev.toElement).closest('.issue');
if (issueElement.length == 1) {
var issue = $(ev.toElement).closest('.issue')[0].issue;
var before = issueElement.prev('.issue');
var after = issueElement.next('.issue');
var changedPrio = false;
var newPrio = issue.getPrio();
if (before.length == 0 && after.length == 1) {
newPrio = after[0].issue.getPrio() - 1;
} else if (before.length == 1 && after.length == 0) {
newPrio = before[0].issue.getPrio() + 1;
} else if (before.length == 1 && after.length == 1) {
newPrio = (before[0].issue.getPrio() + after[0].issue.getPrio()) / 2.0;
}
changedPrio = issue.setPrio(newPrio);
var el = $(ev.target);
var changedState = false;
if (el.hasClass('ready-issues')) {
changedState = issue.setState('Ready');
} else if (el.hasClass('doing-issues')) {
changedState = issue.setState('Doing');
} else if (el.hasClass('done-issues')) {
changedState = issue.setState('Done');
} else if (el.hasClass('backlog-issues')) {
changedState = issue.setState('Backlog');
}
if (changedState || changedPrio) {
issue.updateBody();
}
if (changedState) {
that.model.updateStates();
}
}
};
that.$('.issue-list').sortable({
connectWith: '.issue-list',
stop: updateFunc,
receive: updateFunc,
});
return that;
},
});
|