Merge pull request #1384 from opf/feature/settings-disabled-actions

Feature/settings disabled actions
pull/1393/head
Till Breuer 11 years ago
commit b10fe6860f
  1. 50
      app/assets/javascripts/angular/directives/work_packages/options-dropdown-directive.js
  2. 3
      app/assets/stylesheets/layout/_drop_down.sass
  3. 7
      karma.conf.js
  4. 104
      karma/tests/directives/work_packages/options-dropdown-directive-test.js
  5. 18
      public/templates/work_packages.html

@ -51,9 +51,9 @@ angular.module('openproject.workPackages.directives')
// Modals
scope.showExportModal = exportModal.activate;
scope.showSaveModal = function(saveAs){
scope.$emit('hideAllDropdowns');
if( saveAs || scope.query.isNew() ){
scope.saveQuery = function(){
if(scope.query.isNew()){
scope.$emit('hideAllDropdowns');
saveModal.activate();
} else {
QueryService.saveQuery()
@ -63,8 +63,8 @@ angular.module('openproject.workPackages.directives')
}
};
scope.deleteQuery = function(){
if( deleteConfirmed() ){
scope.deleteQuery = function(event){
if( preventDisabledAction(event) && deleteConfirmed() ){
QueryService.deleteQuery()
.then(function(data){
settingsModal.deactivate();
@ -74,38 +74,56 @@ angular.module('openproject.workPackages.directives')
}
};
scope.showColumnsModal = function(){
showModal.call(columnsModal);
scope.showSaveAsModal = function(event){
showExistingQueryModal.call(saveModal, event);
};
scope.showSortingModal = function(){
showModal.call(sortingModal);
scope.showShareModal = function(event){
showExistingQueryModal.call(shareModal, event);
}
scope.showSettingsModal = function(event){
showExistingQueryModal.call(settingsModal, event);
};
scope.showSettingsModal = function(){
showModal.call(settingsModal);
scope.showColumnsModal = function(){
showModal.call(columnsModal);
};
scope.showGroupingModal = function(){
showModal.call(groupingModal);
};
scope.showShareModal = function() {
scope.$emit('hideAllDropdowns');
shareModal.activate({projectIdentifier: scope.projectIdentifier});
// TODO once client-side routing allows for changing the project context make sure it gets updated within this directive
};
scope.showSortingModal = function(){
showModal.call(sortingModal);
}
scope.toggleDisplaySums = function(){
scope.$emit('hideAllDropdowns');
scope.query.displaySums = !scope.query.displaySums;
};
function preventDisabledAction(event){
if (event && scope.query.isNew()) {
event.preventDefault();
event.stopPropagation();
return false;
}
return true;
}
function showModal() {
scope.$emit('hideAllDropdowns');
this.activate();
}
function showExistingQueryModal(event) {
if( preventDisabledAction(event) ){
scope.$emit('hideAllDropdowns');
this.activate();
}
}
function deleteConfirmed() {
return $window.confirm(I18n.t('js.text_query_destroy_confirmation'));
}

@ -115,6 +115,9 @@
background-color: #F0F0F0
cursor: pointer
.dropdown .dropdown-menu LI > A.inactive
color: #999999
.dropdown LI > A.dropdown-menu-hasicons
display: block
color: #555

@ -93,6 +93,13 @@ module.exports = function(config) {
"app/assets/javascripts/angular/controllers/timelines-controller.js",
"app/assets/javascripts/angular/controllers/work-packages-controller.js",
"app/assets/javascripts/angular/controllers/work-package-details-controller.js",
"app/assets/javascripts/angular/controllers/dialogs/columns.js",
"app/assets/javascripts/angular/controllers/dialogs/export.js",
"app/assets/javascripts/angular/controllers/dialogs/group-by.js",
"app/assets/javascripts/angular/controllers/dialogs/save.js",
"app/assets/javascripts/angular/controllers/dialogs/settings.js",
"app/assets/javascripts/angular/controllers/dialogs/share.js",
"app/assets/javascripts/angular/controllers/dialogs/sorting.js",
'app/assets/javascripts/date-en-US.js',

@ -0,0 +1,104 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
//
// 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.
//++
describe('optionsDropdown Directive', function() {
var compile, element, rootScope, scope;
beforeEach(angular.mock.module('openproject.workPackages.directives'));
beforeEach(module('templates', 'openproject.models', 'openproject.workPackages.controllers'));
beforeEach(inject(function($rootScope, $compile) {
var optionsDropdownHtml;
optionsDropdownHtml = '<div options-dropdown><a href ng-click="showSaveAsModal($event)" ng-class="{\'inactive\': query.isNew()}"></a></div>';
element = angular.element(optionsDropdownHtml);
rootScope = $rootScope;
scope = $rootScope.$new();
compile = function() {
$compile(element)(scope);
scope.$digest();
};
}));
describe('element', function() {
it('should render a div', function() {
expect(element.prop('tagName')).to.equal('DIV');
});
describe('inactive options', function(){
beforeEach(function(){
var query = new Query({
});
scope.query = query;
compile();
});
it('should have an inactive save as option', function() {
var saveAsLink = element.find('a').first();
expect(saveAsLink.hasClass('inactive')).to.be.ok;
});
it('should not open save as modal', function() {
var saveAsLink = element.find('a').first();
saveAsLink.click();
expect(jQuery('.ng-modal-window').length).to.equal(0);
});
});
describe('active options', function(){
beforeEach(function(){
var query = new Query({
id: 1
});
scope.query = query;
compile();
})
it('should have an active save as option', function() {
var saveAsLink = element.find('a').first();
expect(saveAsLink.hasClass('inactive')).to.not.be.ok;
});
it('should open save as modal', function() {
var saveAsLink = element.find('a').first();
saveAsLink.click();
expect(jQuery('.ng-modal-window').length).to.equal(1);
var modal = jQuery(jQuery('.ng-modal-window')[0]);
expect(modal.find('h3').text()).to.equal('Save as');
});
});
});
});

@ -63,11 +63,19 @@
<li><a href ng-click="showGroupingModal()"><i class="icon-action-menu no-icon"></i>{{ I18n.t('js.toolbar.settings.group_by') }}</a></li>
<li><a href ng-click="toggleDisplaySums()"><i ng-if="query.displaySums" class="icon-action-menu icon-yes"></i><i ng-if="!query.displaySums" class="icon-action-menu no-icon"></i>{{ I18n.t('js.toolbar.settings.display_sums') }}</a></li>
<li class="dropdown-divider"></li>
<li><a href ng-click="showSaveModal()"><i class="icon-action-menu icon-save1"></i>{{ I18n.t('js.toolbar.settings.save') }}</a></li>
<li ng-show="!query.isNew()"><a href ng-click="showSaveModal(true)"><i class="icon-action-menu icon-save1"></i>{{ I18n.t('js.toolbar.settings.save_as') }}</a></li>
<li ng-show="!query.isNew()"><a href ng-click="deleteQuery()"><i class="icon-action-menu icon-delete"></i>{{ I18n.t('js.toolbar.settings.delete') }}</a></li>
<li ng-show="!query.isNew()"><a href ng-click="showShareModal()"><i class="icon-action-menu icon-publish"></i>{{ I18n.t('js.toolbar.settings.share') }}</a></li>
<li ng-show="!query.isNew()"><a href ng-click="showSettingsModal()"><i class="icon-action-menu icon-settings"></i>{{ I18n.t('js.toolbar.settings.page_settings') }}</a></li>
<li><a href ng-click="saveQuery()"><i class="icon-action-menu icon-save1"></i>{{ I18n.t('js.toolbar.settings.save') }}</a></li>
<li><a href ng-click="showSaveAsModal($event)" ng-class="{'inactive': query.isNew()}">
<i class="icon-action-menu icon-save1"></i>{{ I18n.t('js.toolbar.settings.save_as') }}</a>
</li>
<li><a href ng-click="showShareModal($event)" ng-class="{'inactive': query.isNew()}">
<i class="icon-action-menu icon-publish"></i>{{ I18n.t('js.toolbar.settings.share') }}</a>
</li>
<li><a href ng-click="deleteQuery($event)" ng-class="{'inactive': query.isNew()}">
<i class="icon-action-menu icon-delete"></i>{{ I18n.t('js.toolbar.settings.delete') }}</a>
</li>
<li><a href ng-click="showSettingsModal($event)" ng-class="{'inactive': query.isNew()}">
<i class="icon-action-menu icon-settings"></i>{{ I18n.t('js.toolbar.settings.page_settings') }}</a>
</li>
</ul>
</div>

Loading…
Cancel
Save