kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
248 lines
7.7 KiB
248 lines
7.7 KiB
10 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
10 years ago
|
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
10 years ago
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
//++
|
||
|
|
||
8 years ago
|
import {opWorkPackagesModule} from '../../../angular-modules';
|
||
|
|
||
|
function SettingsDropdownMenuController($scope,
|
||
|
$window,
|
||
|
$state,
|
||
|
$timeout,
|
||
|
I18n,
|
||
|
columnsModal,
|
||
|
exportModal,
|
||
|
saveModal,
|
||
|
settingsModal,
|
||
|
shareModal,
|
||
|
sortingModal,
|
||
|
groupingModal,
|
||
|
QueryService,
|
||
|
AuthorisationService,
|
||
|
NotificationsService) {
|
||
|
$scope.$watch('query.displaySums', function (newValue) {
|
||
|
$timeout(function () {
|
||
10 years ago
|
$scope.displaySumsLabel = (newValue) ? I18n.t('js.toolbar.settings.hide_sums')
|
||
8 years ago
|
: I18n.t('js.toolbar.settings.display_sums');
|
||
10 years ago
|
});
|
||
|
});
|
||
|
|
||
8 years ago
|
$scope.saveQuery = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
10 years ago
|
if (!$scope.query.isDirty()) {
|
||
|
return;
|
||
|
}
|
||
8 years ago
|
if ($scope.query.isNew()) {
|
||
|
if (allowQueryAction(event, 'create')) {
|
||
10 years ago
|
emitClosingEvents($scope);
|
||
10 years ago
|
saveModal.activate();
|
||
|
}
|
||
|
} else {
|
||
8 years ago
|
if (allowQueryAction(event, 'update')) {
|
||
10 years ago
|
QueryService.saveQuery()
|
||
8 years ago
|
.then(function (data) {
|
||
9 years ago
|
if (data.status.isError) {
|
||
9 years ago
|
NotificationsService.addError(data.status.text);
|
||
9 years ago
|
}
|
||
|
else {
|
||
|
NotificationsService.addSuccess(data.status.text);
|
||
|
$state.go('work-packages.list',
|
||
8 years ago
|
{'query_id': $scope.query.id, 'query_props': null},
|
||
|
{notify: false});
|
||
9 years ago
|
}
|
||
10 years ago
|
});
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.deleteQuery = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
8 years ago
|
if (allowQueryAction(event, 'delete') && preventNewQueryAction(event) && deleteConfirmed()) {
|
||
10 years ago
|
QueryService.deleteQuery()
|
||
8 years ago
|
.then(function (data) {
|
||
9 years ago
|
if (data.status.isError) {
|
||
8 years ago
|
NotificationsService.addError(data.status.text);
|
||
9 years ago
|
}
|
||
|
else {
|
||
|
NotificationsService.addSuccess(data.status.text);
|
||
|
$state.go('work-packages.list',
|
||
8 years ago
|
{'query_id': null, 'query_props': null},
|
||
|
{reload: true});
|
||
9 years ago
|
}
|
||
10 years ago
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Modals
|
||
8 years ago
|
$scope.showSaveAsModal = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
8 years ago
|
if (allowQueryAction(event, 'create')) {
|
||
10 years ago
|
showExistingQueryModal.call(saveModal, event);
|
||
9 years ago
|
updateFocusInModal('save-query-name');
|
||
10 years ago
|
}
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.showShareModal = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
10 years ago
|
if (allowQueryAction(event, 'publicize') || allowQueryAction(event, 'star')) {
|
||
|
showExistingQueryModal.call(shareModal, event);
|
||
9 years ago
|
updateFocusInModal('show-public');
|
||
10 years ago
|
}
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.showSettingsModal = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
8 years ago
|
if (allowQueryAction(event, 'update')) {
|
||
10 years ago
|
showExistingQueryModal.call(settingsModal, event);
|
||
9 years ago
|
updateFocusInModal('query_name');
|
||
10 years ago
|
}
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.showExportModal = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
8 years ago
|
if (allowWorkPackageAction(event, 'export')) {
|
||
10 years ago
|
showModal.call(exportModal);
|
||
8 years ago
|
setTimeout(function () {
|
||
9 years ago
|
updateFocusInModal(jQuery("[id^='export-']").first().attr('id'));
|
||
|
});
|
||
10 years ago
|
}
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.showColumnsModal = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
10 years ago
|
showModal.call(columnsModal);
|
||
8 years ago
|
setTimeout(function () {
|
||
9 years ago
|
updateFocusInModal(jQuery("[id^='column-']").first().attr('id'));
|
||
|
});
|
||
10 years ago
|
};
|
||
|
|
||
8 years ago
|
$scope.showGroupingModal = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
10 years ago
|
showModal.call(groupingModal);
|
||
9 years ago
|
updateFocusInModal('selected_columns_new');
|
||
10 years ago
|
};
|
||
|
|
||
8 years ago
|
$scope.showSortingModal = function (event) {
|
||
10 years ago
|
event.stopPropagation();
|
||
10 years ago
|
showModal.call(sortingModal);
|
||
9 years ago
|
updateFocusInModal('modal-sorting-attribute-0');
|
||
10 years ago
|
};
|
||
|
|
||
8 years ago
|
$scope.toggleDisplaySums = function () {
|
||
10 years ago
|
emitClosingEvents($scope);
|
||
10 years ago
|
$scope.query.displaySums = !$scope.query.displaySums;
|
||
|
|
||
|
// This eventually calls the resize event handler defined in the
|
||
|
// WorkPackagesTable directive and ensures that the sum row at the
|
||
|
// table footer is properly displayed.
|
||
|
angular.element($window).trigger('resize');
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.showSettingsModalInvalid = function () {
|
||
10 years ago
|
return AuthorisationService.cannot('query', 'update');
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.showShareModalInvalid = function () {
|
||
10 years ago
|
return (AuthorisationService.cannot('query', 'publicize') &&
|
||
8 years ago
|
AuthorisationService.cannot('query', 'star'));
|
||
10 years ago
|
};
|
||
|
|
||
8 years ago
|
$scope.showExportModalInvalid = function () {
|
||
10 years ago
|
return AuthorisationService.cannot('work_package', 'export');
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.deleteQueryInvalid = function () {
|
||
10 years ago
|
return AuthorisationService.cannot('query', 'delete');
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.showSaveModalInvalid = function () {
|
||
10 years ago
|
return $scope.query.isNew() || AuthorisationService.cannot('query', 'create');
|
||
|
};
|
||
|
|
||
8 years ago
|
$scope.saveQueryInvalid = function () {
|
||
10 years ago
|
return (!$scope.query.isDirty()) ||
|
||
|
(
|
||
8 years ago
|
$scope.query.isDirty() && !$scope.query.isNew() &&
|
||
10 years ago
|
AuthorisationService.cannot('query', 'update')
|
||
|
) ||
|
||
10 years ago
|
($scope.query.isNew() && AuthorisationService.cannot('query', 'create'));
|
||
10 years ago
|
};
|
||
|
|
||
8 years ago
|
function preventNewQueryAction(event) {
|
||
10 years ago
|
if (event && $scope.query.isNew()) {
|
||
|
event.stopPropagation();
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
function showModal() {
|
||
10 years ago
|
emitClosingEvents($scope);
|
||
10 years ago
|
this.activate();
|
||
|
}
|
||
|
|
||
|
function showExistingQueryModal(event) {
|
||
8 years ago
|
if (preventNewQueryAction(event)) {
|
||
10 years ago
|
emitClosingEvents($scope);
|
||
10 years ago
|
this.activate();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function allowQueryAction(event, action) {
|
||
|
return allowAction(event, 'query', action);
|
||
|
}
|
||
|
|
||
|
function allowWorkPackageAction(event, action) {
|
||
|
return allowAction(event, 'work_package', action);
|
||
|
}
|
||
|
|
||
|
function allowAction(event, modelName, action) {
|
||
8 years ago
|
if (AuthorisationService.can(modelName, action)) {
|
||
10 years ago
|
return true;
|
||
|
} else {
|
||
|
event.stopPropagation();
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
function emitClosingEvents($scope) {
|
||
|
$scope.$emit('hideAllDropdowns');
|
||
|
$scope.$root.$broadcast('openproject.dropdown.closeDropdowns', true);
|
||
|
}
|
||
|
|
||
10 years ago
|
function deleteConfirmed() {
|
||
|
return $window.confirm(I18n.t('js.text_query_destroy_confirmation'));
|
||
|
}
|
||
9 years ago
|
|
||
|
function updateFocusInModal(element_id) {
|
||
8 years ago
|
setTimeout(function () {
|
||
9 years ago
|
jQuery('#' + element_id).focus();
|
||
|
}, 100);
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
opWorkPackagesModule.controller('SettingsDropdownMenuController', SettingsDropdownMenuController);
|