Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Handle dialogue group states with no assigned group better
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvdm committed May 12, 2014
1 parent c774d13 commit 78639b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion go/base/static/js/src/apps/dialogue/states/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
e.preventDefault();
var key = $(e.target).val();

if (key !== "none") {
if (key === 'unassigned') {
this.model.set('group', null, {silent: true});
} else if (key !== 'none') {
this.model.set('group', {key: key}, {silent: true});
}

}
}, DialogueStateEditView.prototype.events)
});
Expand Down
18 changes: 18 additions & 0 deletions go/base/static/js/test/apps/dialogue/states/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ describe("go.apps.dialogue.states.group", function() {
});

it("should not try change the state's group", function() {
diagram.model.set('groups', []);
state.edit();

assert.equal(
state.model.get('group').get('key'),
'group1');
Expand Down Expand Up @@ -68,6 +71,21 @@ describe("go.apps.dialogue.states.group", function() {
'group2');
});
});

describe("when the current group is unassigned", function() {
it("should update the state's model", function() {
assert.equal(
state.model.get('group').get('key'),
'group1');

editMode
.$('.contact-group')
.val('unassigned')
.change();

assert.isNull(state.model.get('group'));
});
});
});

describe(".GroupStatePreviewView", function() {
Expand Down
9 changes: 7 additions & 2 deletions go/base/static/templates/apps/dialogue/states/group/edit.jst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

<select class="contact-group form-control">
<% if (model.get('dialogue').get('groups').length) { %>
<option value="none" selected>(No group)</option>
<option value="unassigned">(No group)</option>
<% model.get('dialogue').get('groups').each(function(group) { %>
<option value="<%= group.get('key') %>"><%= group.get('name') %></option>
<option
value="<%= group.get('key') %>"
<% if (group === model.get('group')) { %>
selected
<% } %>
><%= group.get('name') %></option>
<% }); %>
<% } else { %>
<option value="none" selected>No groups available</option>
Expand Down

0 comments on commit 78639b6

Please sign in to comment.