Skip to content

Commit

Permalink
Change event status and update event info
Browse files Browse the repository at this point in the history
  • Loading branch information
gorkalaucirica committed Sep 11, 2015
1 parent 0f923a4 commit ab02dd6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
21 changes: 21 additions & 0 deletions Bundle/WebBundle/Resources/public/js/models/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class Issue extends Backbone.Model {
return Config.baseUrl + '/issues';
}

urlTransition() {
return Config.baseUrl + '/issues/' + this.id + '/transitions';
}

defaults() {
return {
title: '',
Expand Down Expand Up @@ -54,6 +58,23 @@ export class Issue extends Backbone.Model {
return data;
}

doTransition(transitionId, options = {}) {
var defaultOptions = {
success: null,
error: null
};

options = $.extend(defaultOptions, options);
Backbone.$.ajax(this.urlTransition(), {
method: 'PATCH',
data: {
'transition': transitionId
},
success: options.success,
error: options.error
});
}

getAllowedTransitions() {
var projectHref = this.attributes._links.project.href;
var projectId = projectHref.substring(projectHref.lastIndexOf('/') + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export class IssuePreviewView extends Backbone.Marionette.ItemView {
this.listenTo(App.vent, 'issue:highlight', (issueId) => {
this.highlightIssue(issueId);
});

this.listenTo(App.vent, 'issue:updated', (issue) => {
if(this.model.id === issue.id) {
this.model.set(issue);
this.render();
}
});
}

showFullIssue() {
Expand Down
20 changes: 17 additions & 3 deletions Bundle/WebBundle/Resources/public/js/views/page/issue/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ export class IssueShowView extends Backbone.Marionette.ItemView {
this.template = '#issue-show-template';

this.ui = {
'tabContent': '.full-issue-tab-content'
'tabContent': '.full-issue-tab-content',
'transitions': '.full-issue-transitions'
};

this.events = {
'click .full-issue-edit': 'editClicked',
'click .full-issue-tab': 'tabClicked'
'click .full-issue-tab': 'tabClicked',
'click .full-issue-transition': 'doTransition'
};

super(options);

this.model.on('sync', this.render, this);
this.model.on('change', this.render, this);

App.vent.trigger('issue:highlight', this.model.id);
}
Expand All @@ -49,4 +51,16 @@ export class IssueShowView extends Backbone.Marionette.ItemView {

return false;
}

doTransition(ev) {
this.ui.transitions.hide();
this.model.doTransition($($(ev)[0].currentTarget).attr('data-transition'), {
success : (data) => {
this.model.set(data);
App.vent.trigger('issue:updated', data)
}
});

return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</section>
<section class="full-issue-transitions">
<% transitions.forEach(function(transition) { %>
<a href="button green full-issue-edit">
<button class="button green full-issue-transition" data-transition="<%= transition.id %>">
<%= transition.name %>
</a>
</button>
<% }) %>
</section>
<section class="full-issue-dashboard">
Expand Down

0 comments on commit ab02dd6

Please sign in to comment.