Skip to content

Commit

Permalink
TA-58 Develop a custom workflow capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen The Tuyen committed Aug 6, 2015
1 parent 2d84dd1 commit f72f904
Show file tree
Hide file tree
Showing 14 changed files with 977 additions and 462 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
public interface StatusService {

List<String> getDefaultStatus();

Status getStatusById(long statusId);

Status createStatus(Project project, String status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public List<String> getDefaultStatus() {
return Arrays.asList(DEFAULT_STATUS);
}

@Override
public Status getStatusById(long statusId) {
return daoHandler.getStatusHandler().find(statusId);
}

@Override
@Transactional
public Status createStatus(Project project, String name) {
Expand Down Expand Up @@ -125,8 +130,12 @@ public Status deleteStatus(long statusID) throws StatusNotFoundException, NotAll
t.setStatus(altStatus);
daoHandler.getTaskHandler().update(t);
}

//
st.getTasks().clear();
project.getStatus().remove(st);
st.setProject(null);

handler.delete(st);
return st;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// TODO: Move juzu-ajax, mentionsPlugin module into task management project if need
require(['project-menu', 'ta_edit_inline', 'SHARED/jquery',
require(['taskManagementApp', 'project-menu', 'ta_edit_inline', 'SHARED/jquery',
'SHARED/juzu-ajax', 'SHARED/mentionsPlugin', 'SHARED/bts_modal', 'SHARED/bts_tab', 'SHARED/task_ck_editor'
], function(pMenu, editInline, $) {
var taApp = {};

console.warn($.fn.ckeditor);
], function(taApp, pMenu, editInline, $) {
/*var taApp = {};
taApp.getUI = function() {
var $taskManagement = $('#taskManagement');
Expand Down Expand Up @@ -118,7 +116,7 @@ require(['project-menu', 'ta_edit_inline', 'SHARED/jquery',
console.error && console.error('update failure: ' + jqXHR.responseText);
}
});
}
}*/

$(document).ready(function() {
var ui = taApp.getUI();
Expand Down Expand Up @@ -148,8 +146,8 @@ $(document).ready(function() {
});

var taskLoadedCallback = function(taskId, isAjax) {
var $li = $centerPanel.find('li[data-taskid="'+taskId+'"]');
$centerPanel.find('li.selected').removeClass('selected');
var $li = $centerPanel.find('[data-taskid="'+taskId+'"]');
$centerPanel.find('[data-taskid].selected').removeClass('selected');
$li.addClass('selected');
editInline.initEditInline(taskId);
var $permalink = $rightPanelContent.find('.taskPermalink');
Expand Down Expand Up @@ -186,11 +184,11 @@ $(document).ready(function() {
}
});

if (isAjax) {
/*if (isAjax) {
if(window.history.pushState) {
window.history.pushState('', '', link);
}
}
}*/

return false;
};
Expand Down Expand Up @@ -439,14 +437,19 @@ $(document).ready(function() {
if (filter == undefined) {
filter = '';
}
var viewType = $projectListView.find('[name="viewType"]').val();
if (viewType == undefined) {
viewType = 'list';
}
var keyword = $projectListView.closest('.projectListView').find('input[name="keyword"]').val();
$centerPanelContent.jzLoad('TaskController.listTasks()',
{
projectId: projectId,
keyword: keyword,
groupBy: groupBy,
orderBy: orderBy,
filter: filter
filter: filter,
viewType: viewType
},
function() {
taApp.hideRightPanel($centerPanel, $rightPanel, $rightPanelContent);
Expand Down Expand Up @@ -481,6 +484,16 @@ $(document).ready(function() {
$('[name="filter"]').val($a.data('taskfilter'));
submitFilter(e);
});
$centerPanel.on('click', 'a[data-viewtype]', function(e) {
var $a = $(e.target || e.srcElement).closest('[data-viewtype]');
var $li = $a.parent();
if ($li.hasClass('disabled') || $li.hasClass('active')) {
return;
}
var viewType = $a.data('viewtype');
$('[name="viewType"]').val(viewType);
submitFilter(e);
});

//show hide the search box for responsive
$centerPanel.on('click', '.action-search' ,function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
define('taskBoardView', ['jquery', 'taskManagementApp', 'SHARED/edit_inline_js'],
function($, taApp, editinline) {

var boardView = {};
boardView.init = function() {
taApp.onReady(function($) {
boardView.initDomEventListener();
boardView.initEditInline();
});
};

boardView.initDomEventListener = function() {
var ui = taApp.getUI();
var $centerPanelContent = ui.$centerPanelContent;
var $centerPanel = ui.$centerPanel;
$centerPanel.off('click', '[data-statusid] .actionRemoveStatus').on('click', '[data-statusid] .actionRemoveStatus', function(e) {
if ($centerPanel.find('[data-statusid]').length < 2) {
alert('There are only one status. It can not be deleted');
return;
}
var $status = $(e.target).closest('[data-statusid]');
var status = $status.data('statusid');
if (status > 0) {
$centerPanelContent.jzAjax('TaskController.removeStatus()', {
data: {statusId: status},
method: 'POST',
success: function(response) {
$centerPanelContent.html(response);
}
});
} else {
$centerPanel.find('.col.col-new').hide();
}
});

$centerPanel.off('click', '.actionAddStatus').on('click', '.actionAddStatus', function(e) {
$centerPanel.find('.col.col-new').show();
$centerPanel.find('[name="statusName"]').focus();
});
$centerPanel.off('submit', '.formCreateNewStatus').on('submit', '.formCreateNewStatus', function(e) {
var $form = $(e.target).closest('form');
var statusName = $form.find('[name="statusName"]').val();
var projectId = $form.closest('[data-projectid]').data('projectid');
if (projectId == undefined || projectId <= 0) {
alert('Can not create status for undefined project');
return;
}
if (statusName == undefined || statusName == '') {
alert('status name is required');
return false;
} else {
$centerPanelContent.jzAjax('TaskController.createStatus()', {
data: {
name: statusName,
projectId: projectId
},
method: 'POST',
success: function(response) {
$centerPanelContent.html(response);
}
});
}
return false;
});
};

boardView.initEditInline = function() {
var ui = taApp.getUI();
var $centerPanelContent = ui.$centerPanelContent;
var saveStatusFunction = function(params) {
var d = new $.Deferred;
var data = {
id: params.pk,
name: params.value
};
$centerPanelContent.jzAjax('StatusController.updateStatus()',{
data: data,
method: 'POST',
success: function(response) {
d.resolve();
},
error: function(jqXHR, textStatus, errorThrown ) {
d.reject('update failure: ' + jqXHR.responseText);
}
});
return d.promise();
};
var options = {
url: saveStatusFunction,
toggle: 'dblclick',
mode: 'inline',
showbuttons: false,
onblur: 'submit',
emptyclass: 'muted',
highlight: false,
inputclass: 'blackLarge',
clear: false
};
$centerPanelContent.find('.taskBoardView .editable').each(function() {
var $this = $(this);
$this.editable(options);
$this.on('shown', function(e, editable) {
$this.parent().removeClass('inactive').addClass('active');
}).on('hidden', function(e, editable) {
$this.parent().removeClass('active').addClass('inactive');
});
});
};

return boardView;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
define('taskManagementApp', ['jquery', 'SHARED/juzu-ajax'],
function($) {

var taApp = {};

var isDomReadyExcuted = false;
$(document).ready(function($) {
isDomReadyExcuted = true;
});

taApp.onReady = function(callback) {
if (isDomReadyExcuted) {
callback();
} else {
$(document).ready(callback);
}
};

var taskUI = false;
taApp.getUI = function() {
if (!taskUI) {
var $taskManagement = $('#taskManagement');
var $leftPanel = $('#taskManagement > .leftPanel');
var $centerPanel = $('#taskManagement > .centerPanel');
var $rightPanel = $('#taskManagement > .rightPanel');
var $rightPanelContent = $rightPanel.find('.rightPanelContent');
var $centerPanelContent = $centerPanel.find('.centerPanelContent');

taskUI = {
'$taskManagement' : $taskManagement,
'$leftPanel' : $leftPanel,
'$centerPanel' : $centerPanel,
'$rightPanel' : $rightPanel,
'$rightPanelContent' : $rightPanelContent,
'$centerPanelContent' : $centerPanelContent
};
}
return taskUI;
}

taApp.showDialog = function(controllerURL, data) {
var $modalPlace = $('.modalPlace');
$modalPlace.jzLoad(controllerURL, data, function() {
var $dialog = $modalPlace.children().first();
$dialog.modal({'backdrop': false});
});
}

taApp.showOneTimePopover = function($popover) {
if ($popover.data('content')) {
$popover.popover('show');
$(document).one('click', function() {
$popover.popover('hide');
$popover.popover('destroy');
});
}
}

taApp.showRightPanel = function($centerPanel, $rightPanel) {
$centerPanel.removeClass('span9').addClass('span5');
$rightPanel.show();
$rightPanel.find('[data-toggle="tooltip"]').tooltip();
$rightPanel.find('*[rel="tooltip"]').tooltip({
placement: 'top'
});
};

taApp.hideRightPanel = function($centerPanel, $rightPanel, $rightPanelContent) {
$rightPanelContent.html('');
$rightPanel.hide();
$centerPanel.removeClass('span5').addClass('span9');
};

taApp.reloadTaskList = function(projectId, filter, callback) {
var $centerPanelContent = taApp.getUI().$centerPanelContent;
if ($.isFunction(filter)) {
filter = '';
callback = filter;
}
if (typeof filter !== 'string') {
filter = '';
}
var data = {projectId: projectId, filter: filter};
$centerPanelContent.jzLoad('TaskController.listTasks()', data, function() {
if (callback) {
callback();
}
});
}

taApp.reloadProjectTree = function(id) {
var $leftPanel = taApp.getUI().$leftPanel;
var $listProject = $leftPanel.find('ul.list-projects.projectTree');
$listProject.jzLoad('ProjectController.projectTree()', function() {
if (id) {
$listProject.find('a.project-name[data-id="' + id+ '"]').click();
} else {
if ($listProject.find('a.project-name').length > 0) {
$listProject.find('.project-name').first().click();
} else {
$leftPanel.find('.project-name[data-id="0"]').first().click();
}
}
});
}

taApp.setTaskComplete = function(taskId, isCompleted) {
var ui = taApp.getUI();
var $taskItem = ui.$centerPanel.find('.taskItem[data-taskid="' + taskId + '"]');
var $next = $taskItem.next('.taskItem').first();
if ($next.length == 0) {
$next.prev('.taskItem').first();
}

var data = {taskId: taskId, completed: isCompleted};
//
$taskItem.jzAjax('TaskController.updateCompleted()', {
data: data,
success: function(message) {
if (isCompleted) {
$taskItem.fadeOut(500, function() {
$taskItem.remove();
});
if ($next.length == 0) {
ui.$leftPanel.find('.active .project-name').click();
} else {
$next.click();
}
}
},
error : function(jqXHR, textStatus, errorThrown) {
console.error && console.error('update failure: ' + jqXHR.responseText);
}
});
}

return taApp;
});
Loading

0 comments on commit f72f904

Please sign in to comment.