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.
203 lines
6.9 KiB
203 lines
6.9 KiB
9 years ago
|
// -- copyright
|
||
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2015 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.
|
||
|
// ++
|
||
|
|
||
9 years ago
|
angular
|
||
|
.module('openproject.inplace-edit')
|
||
|
.directive('inplaceEditorDateRange', inplaceEditorDateRange);
|
||
9 years ago
|
|
||
9 years ago
|
function inplaceEditorDateRange($timeout, TimezoneService, WorkPackageFieldService,
|
||
9 years ago
|
EditableFieldsState, Datepicker, inplaceEditAll, responsiveView, ConfigurationService) {
|
||
9 years ago
|
|
||
9 years ago
|
return {
|
||
|
restrict: 'E',
|
||
|
transclude: true,
|
||
|
replace: true,
|
||
9 years ago
|
templateUrl: '/components/inplace-edit/field-directives/edit-date-range/' +
|
||
9 years ago
|
'edit-date-range.directive.html',
|
||
9 years ago
|
|
||
9 years ago
|
controller: angular.noop,
|
||
9 years ago
|
controllerAs: 'customEditorController',
|
||
9 years ago
|
|
||
9 years ago
|
link: function(scope, element) {
|
||
|
var field = scope.field;
|
||
9 years ago
|
var customDateFormat = 'YYYY-MM-DD';
|
||
9 years ago
|
|
||
9 years ago
|
function getTitle(labelName) {
|
||
|
return I18n.t('js.inplace.button_edit', {
|
||
|
attribute: WorkPackageFieldService.getLabel(
|
||
|
EditableFieldsState.workPackage,
|
||
|
labelName
|
||
|
)
|
||
9 years ago
|
});
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
function getDateLabel(labelName) {
|
||
|
return I18n.t('js.label_date_with_format', {
|
||
|
date_attribute: WorkPackageFieldService.getLabel(
|
||
|
EditableFieldsState.workPackage,
|
||
|
labelName
|
||
|
),
|
||
|
format: customDateFormat
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* The directive may be used with date pickers in accessibility mode,
|
||
|
* thus avoid setting it up when it is actually disabled
|
||
|
*/
|
||
|
function includeDatePicker() {
|
||
|
|
||
|
startDatepicker = new Datepicker(divStart, inputStart, scope.startDate);
|
||
|
endDatepicker = new Datepicker(divEnd, inputEnd, scope.endDate);
|
||
|
startDatepicker.onChange = function(date) {
|
||
|
scope.startDate = field.value.startDate = date;
|
||
|
if (startDatepicker.prevDate.isAfter(endDatepicker.prevDate)) {
|
||
|
scope.startDateIsChanged = true;
|
||
|
scope.endDate = field.value.dueDate = scope.startDate;
|
||
|
endDatepicker.setDate(scope.endDate);
|
||
|
}
|
||
|
};
|
||
|
scope.onStartEdit = function() {
|
||
|
scope.startDateIsChanged = scope.endDateIsChanged = false;
|
||
|
startDatepicker.onEdit();
|
||
|
};
|
||
|
endDatepicker.onChange = function(date) {
|
||
|
scope.endDate = field.value.dueDate = date;
|
||
|
if (endDatepicker.prevDate.isBefore(startDatepicker.prevDate)) {
|
||
|
scope.endDateIsChanged = true;
|
||
|
scope.startDate = field.value.startDate = scope.endDate;
|
||
|
startDatepicker.setDate(scope.startDate);
|
||
|
}
|
||
|
};
|
||
|
scope.onEndEdit = function() {
|
||
|
scope.startDateIsChanged = scope.endDateIsChanged = false;
|
||
|
endDatepicker.onEdit();
|
||
|
};
|
||
|
|
||
|
startDatepicker.onDone = endDatepicker.onDone = function() {
|
||
|
$timeout(function() {
|
||
|
form.scope().editPaneController.discardEditing();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
startDatepicker.textbox.on('click focusin', function() {
|
||
|
if (scope.hideDatePicker) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (divStart.is(':hidden') || divEnd.is(':visible')) {
|
||
|
endDatepicker.hide();
|
||
|
startDatepicker.show();
|
||
|
}
|
||
|
scope.startDateIsChanged = scope.endDateIsChanged = false;
|
||
|
});
|
||
|
|
||
|
endDatepicker.textbox.on('click focusin', function() {
|
||
|
if (scope.hideDatePicker) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (divEnd.is(':hidden') || divStart.is(':visible')) {
|
||
|
endDatepicker.show();
|
||
|
startDatepicker.hide();
|
||
|
}
|
||
|
scope.startDateIsChanged = scope.endDateIsChanged = false;
|
||
|
});
|
||
|
|
||
9 years ago
|
angular.element('#content').on('click', function(e) {
|
||
9 years ago
|
var target = angular.element(e.target);
|
||
|
if (!target.is('.inplace-edit--date-range input') &&
|
||
|
target.parents('.hasDatepicker').length <= 0 &&
|
||
|
target.parents('.ui-datepicker-header').length <= 0) {
|
||
|
startDatepicker.hide();
|
||
|
endDatepicker.hide();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
startDatepicker.setState(!responsiveView.isSmall());
|
||
|
endDatepicker.setState(!responsiveView.isSmall());
|
||
|
|
||
|
responsiveView.onResize(function () {
|
||
|
startDatepicker.setState(!responsiveView.isSmall());
|
||
|
endDatepicker.setState(!responsiveView.isSmall());
|
||
|
});
|
||
|
|
||
|
$timeout(function() {
|
||
|
inplaceEditAll.state || startDatepicker.focus();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
|
||
9 years ago
|
scope.startDate = field.value.startDate;
|
||
|
scope.endDate = field.value.dueDate;
|
||
9 years ago
|
|
||
9 years ago
|
scope.dateFormat = customDateFormat;
|
||
|
|
||
|
scope.startDateLabel = getDateLabel('startDate');
|
||
|
scope.endDateLabel = getDateLabel('dueDate');
|
||
|
|
||
|
scope.startDateTitle = getTitle('startDate');
|
||
|
scope.endDateTitle = getTitle('dueDate');
|
||
9 years ago
|
|
||
9 years ago
|
var form = element.parents('.inplace-edit--form'),
|
||
|
inputStart = element.find('.inplace-edit--date-range-start-date'),
|
||
|
inputEnd = element.find('.inplace-edit--date-range-end-date'),
|
||
|
divStart = element.find('.inplace-edit--date-range-start-date-picker'),
|
||
|
divEnd = element.find('.inplace-edit--date-range-end-date-picker'),
|
||
|
startDatepicker, endDatepicker;
|
||
9 years ago
|
|
||
9 years ago
|
scope.startDateIsChanged = scope.endDateIsChanged = false;
|
||
|
|
||
|
if (scope.endDate) {
|
||
|
scope.endDate = TimezoneService.formattedISODate(scope.endDate);
|
||
|
}
|
||
|
if (scope.startDate) {
|
||
|
scope.startDate = TimezoneService.formattedISODate(scope.startDate);
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
scope.execute = function() {
|
||
9 years ago
|
form.scope().editPaneController.submit();
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
if (ConfigurationService.accessibilityModeEnabled()) {
|
||
|
scope.onStartEdit = function() {
|
||
|
field.value.startDate = scope.startDate;
|
||
|
};
|
||
9 years ago
|
|
||
9 years ago
|
scope.onEndEdit = function() {
|
||
|
field.value.dueDate = scope.endDate;
|
||
|
};
|
||
|
|
||
|
} else {
|
||
|
includeDatePicker();
|
||
|
}
|
||
9 years ago
|
|
||
|
}
|
||
|
};
|
||
|
}
|