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

Commit

Permalink
Due Date Message will be changed when Due date is changed.
Browse files Browse the repository at this point in the history
Cause:
Although `Due date` is changed, `Due Date Message` is not changed.

Solutions:
When `Due date` is changed, a server returns `isOverDue` and `DueDateMsg` values as JSON. In `yobi.Issue.View.js` these values are used and shown properly.

Private-issue: 1779
  • Loading branch information
laziel authored and ChangsungKim committed Sep 16, 2014
1 parent 88b1238 commit f312c87
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
14 changes: 11 additions & 3 deletions app/controllers/IssueApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,17 @@ public static Result massUpdate(String ownerName, String projectName) {

// Determine type of response with Accept header
if (HttpUtil.isJSONPreferred(request())){
// jQuery treats as error if response text empty
// on dataType is json
return ok("{}");
if (issueMassUpdate.isDueDateChanged) {
Issue issue = issueMassUpdate.issues.get(0);
ObjectNode result = Json.newObject();
result.put("isOverDue", issue.isOverDueDate());
result.put("dueDateMsg", issue.isOverDueDate() ? Messages.get("issue.dueDate.overdue") : issue.until());
return ok(result);
} else {
// jQuery treats as error if response text empty
// on dataType is json
return ok("{}");
}
} else {
return redirect(request().getHeader("Referer"));
}
Expand Down
4 changes: 2 additions & 2 deletions app/views/issue/view.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@
<dl>
<dt>
@Messages("issue.dueDate")
<span class="duedate-status @if(issue.isOverDueDate) {overdue}">
@if(issue.dueDate != null) {
<span class="@if(issue.isOverDueDate) {overdue}">
@if(issue.isOverDueDate) {
(@Messages("issue.dueDate.overdue"))
} else {
(@issue.until)
}
</span>
}
</span>
</dt>
<dd>
@if(isAllowed(UserApp.currentUser(), issue.asResource(), Operation.UPDATE)) {
Expand Down
68 changes: 45 additions & 23 deletions public/javascripts/service/yobi.issue.View.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@

elements.btnWatch = $('#watch-button');
elements.issueInfoWrap = $(".issue-info");
elements.dueDateStatus = elements.issueInfoWrap.find(".duedate-status");

elements.timelineWrap = $("#timeline");
elements.timelineList = elements.timelineWrap.find(".timeline-list");

elements.dueDate = $("#issueDueDate");

elements.btnVoteComment = $(options.btnVoteComment || '[data-request-type="comment-vote"]');
}

/**
Expand Down Expand Up @@ -99,7 +102,7 @@

// Update issue info
elements.issueInfoWrap.on("change", "[data-toggle=select2]", _onChangeIssueInfo);
elements.issueInfoWrap.on("change", "[data-toggle=calendar]", _onChangeIssueInfo);
elements.issueInfoWrap.on("change", "[data-toggle=calendar]", _onChangeDueDate);
elements.issueInfoWrap.on("select2-selecting", '[name="assignee.user.id"]', _onSelectingAssignee);

// Detect textarea events for autoUpdate timeline
Expand Down Expand Up @@ -131,6 +134,37 @@
}
}

/**
* on change dueDate input field
*
* @param evt
* @private
*/
function _onChangeDueDate(evt){
var element = $(this);
var dueDate = $.trim(element.val());

// if dueDate is not empty and invalid
if(dueDate && !moment(dueDate).isValid()){
$yobi.notify(Messages("issue.error.invalid.duedate"), 3000);
element.focus();
return;
}

if(element.data("oval") !== element.val()){
element.data("oval", element.val());
}

_requestUpdateIssue(evt, function(res){
elements.dueDateStatus.html("(" + res.dueDateMsg + ")");
if (res.isOverDue) {
elements.dueDateStatus.addClass("overdue");
} else {
elements.dueDateStatus.removeClass("overdue");
}
});
}

/**
* "change" event handler of issue info select2 fields.
*
Expand All @@ -146,26 +180,10 @@
* like as assignee.id, milestone.id and labelIds.
*
* @param evt
* @param callback
* @private
*/
function _requestUpdateIssue(evt){
var elDueDate = elements.issueInfoWrap.find("[data-toggle='calendar']");
var sDueDate = $yobi.getTrim($(elDueDate).val());

if(sDueDate && !moment(sDueDate).isValid()){
$yobi.notify(Messages("issue.error.invalid.duedate"), 3000);
elDueDate.focus();
return;
}

if(elDueDate.get(0) == evt.target) {
if(elDueDate.data("oval") == elDueDate.val()){
return;
}else{
elDueDate.data("oval", elDueDate.val());
}
}

function _requestUpdateIssue(evt, callback){
var field = $(evt.target);
var fieldName = field.data("fieldName") || field.prop("name");
var fieldValue = field.data("select2") ? field.data("select2").val() : field.val();
Expand All @@ -176,19 +194,23 @@
"dataType": "json",
"data" : _getUpdateIssueRequestData(fieldName, fieldValue, evt)
})
.done(function(){
.done(function(res){
_updateTimeline();

$yobi.notify(Messages("issue.update." + fieldName), 3000);

if(field.data("select2")){
field.data("select2").val(fieldValue);
}

_updateTimeline();
if(typeof callback === "function"){
callback(res, fieldName, fieldValue, evt);
}
})
.fail(function(oRes){
.fail(function(res){
$yobi.notify(Messages("error.failedTo",
Messages("issue.update." + fieldName),
oRes.status, oRes.statusText));
res.status, res.statusText));
});
}

Expand Down

0 comments on commit f312c87

Please sign in to comment.