Merge pull request #52 from Smile-SA/master

Manage DateTime CustomField format provided by redmine_datetime_custom_field
This commit is contained in:
Hugo Zilliox 2019-10-20 12:10:54 +02:00 committed by GitHub
commit 06fe6256c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 553 additions and 517 deletions

View File

@ -11,12 +11,16 @@ var _CONF_EXCLUDED_FIELD_ID = _CONF_EXCLUDED_FIELD_ID || [];
* See https://github.com/Ilogeek/redmine_issue_dynamic_edit/commit/26684a2dd9b12dcc7377afd79e9fe5c142d26ebd for more info
*/
var LOCATION_HREF = typeof custom_location_href !== 'undefined' ? custom_location_href : window.location.href;
if(_CONF_FORCE_HTTPS) { LOCATION_HREF = LOCATION_HREF.replace(/^http:\/\//i, 'https://'); }
if (_CONF_FORCE_HTTPS) {
LOCATION_HREF = LOCATION_HREF.replace(/^http:\/\//i, 'https://');
}
/* FontAwesome inclusion */
var cssId = 'fontAwesome';
if (!document.getElementById(cssId))
{
if (!document.getElementById(cssId)) {
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
@ -29,6 +33,7 @@ var cssId = 'fontAwesome';
$(document).on(_CONF_LISTENER_TYPE, function(e) {
$('.issue .attributes .attribute .value').removeClass('edited');
if ($(e.target).closest('a').length) { return; }
if ($(e.target).closest('.' + _CONF_LISTENER_TARGET).length) {
// avoid text selection if dblclick
@ -43,6 +48,7 @@ $(document).on(_CONF_LISTENER_TYPE, function(e){
sel.empty();
}
}
// we show the edit box
$(e.target).closest('.value').addClass('edited');
}
@ -52,23 +58,28 @@ function isExcluded(elmt_id) {
return _CONF_EXCLUDED_FIELD_ID.indexOf(elmt_id) > -1;
}
function initEditFields()
{
function initEditFields() {
/* Put new dropdown lists in the detailed info block */
if ($('#statusListDropdown').length > 0 && !isExcluded('statusListDropdown')) {
var htmlCopy = $('#statusListDropdown').get(0).outerHTML;
$('#statusListDropdown').remove();
$('.details .attributes .status.attribute .value').html( '<span class="showValue">' +
$('.details .attributes .status.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy);
$('.details .attributes .status.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .status.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy
);
}
if ($('#prioritiesListDropdown').length > 0 && !isExcluded('prioritiesListDropdown')) {
var htmlCopy = $('#prioritiesListDropdown').get(0).outerHTML;
$('#prioritiesListDropdown').remove();
$('.details .attributes .priority.attribute .value').html( '<span class="showValue">' +
$('.details .attributes .priority.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy);
$('.details .attributes .priority.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .priority.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy
);
}
if ($('#doneRatioListDropdown').length > 0 && !isExcluded('doneRatioListDropdown')) {
@ -82,25 +93,34 @@ function initEditFields()
if ($('#EstimatedTimeInput').length > 0 && !isExcluded('EstimatedTimeInput')) {
var htmlCopy = $('#EstimatedTimeInput').get(0).outerHTML;
$('#EstimatedTimeInput').remove();
$('.details .attributes .estimated-hours.attribute .value').html('<span class="showValue">' +
$('.details .attributes .estimated-hours.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy);
$('.details .attributes .estimated-hours.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .estimated-hours.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy
);
}
if ($('#StartDateInput').length > 0 && !isExcluded('StartDateInput')) {
var htmlCopy = $('#StartDateInput').get(0).outerHTML;
$('#StartDateInput').remove();
$('.details .attributes .start-date.attribute .value').html('<span class="showValue">' +
$('.details .attributes .start-date.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy);
$('.details .attributes .start-date.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .start-date.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy
);
}
if ($('#DueDateInput').length > 0 && !isExcluded('DueDateInput')) {
var htmlCopy = $('#DueDateInput').get(0).outerHTML;
$('#DueDateInput').remove();
$('.details .attributes .due-date.attribute .value').html('<span class="showValue">' +
$('.details .attributes .due-date.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy);
$('.details .attributes .due-date.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .due-date.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy
);
}
if ($('#TitleInput').length > 0 && !isExcluded('TitleInput')) {
@ -113,12 +133,14 @@ function initEditFields()
if ($('#DescriptionInput').length > 0 && !isExcluded('DescriptionInput')) {
var htmlCopy = $('#DescriptionInput').get(0).outerHTML;
$('#DescriptionInput').remove();
$('div.description .wiki').html(' <i class="fa fa-pencil fa-fw" aria-hidden="true" style="float:right;"></i><span class="showValue">' + $('div.description .wiki').html() + '</span>' +
htmlCopy).addClass('value');
$('div.description .wiki').html(
' <i class="fa fa-pencil fa-fw" aria-hidden="true" style="float:right;"></i><span class="showValue">' +
$('div.description .wiki').html() + '</span>' +
htmlCopy
).addClass('value');
}
if($('select#issue_assigned_to_id').length > 0 && !isExcluded('issue_assigned_to_id'))
{
if ($('select#issue_assigned_to_id').length > 0 && !isExcluded('issue_assigned_to_id')) {
var htmlCopy = $('select#issue_assigned_to_id').get(0).outerHTML;
// 2 technics with simple or double quote (safety first)
htmlCopy = htmlCopy.replace(/id="/g, 'id="dynamic_').replace(/id='/g, "id='dynamic_");
@ -128,13 +150,15 @@ function initEditFields()
editHTML += " <a href='#' class='btn btn-primary close' aria-label='" + _TXT_CANCEL_BTN + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a>";
editHTML += "</span>";
$('.details .attributes .assigned-to.attribute .value').html('<span class="showValue">' +
$('.details .attributes .assigned-to.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
editHTML);
$('.details .attributes .assigned-to.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .assigned-to.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
editHTML
);
}
if($('select#issue_fixed_version_id').length > 0 && !isExcluded('issue_fixed_version_id'))
{
if ($('select#issue_fixed_version_id').length > 0 && !isExcluded('issue_fixed_version_id')) {
var htmlCopy = $('select#issue_fixed_version_id').get(0).outerHTML;
// 2 technics with simple or double quote (safety first)
htmlCopy = htmlCopy.replace(/id="/g, 'id="dynamic_').replace(/id='/g, "id='dynamic_");
@ -144,48 +168,65 @@ function initEditFields()
editHTML += " <a href='#' class='btn btn-primary close' aria-label='" + _TXT_CANCEL_BTN + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a>";
editHTML += "</span>";
$('.details .attributes .fixed-version.attribute .value').html('<span class="showValue">' +
$('.details .attributes .fixed-version.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
editHTML);
$('.details .attributes .fixed-version.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .fixed-version.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
editHTML
);
}
for(var i = 0 ; i < CF_VALUE_JSON.length ; i++)
{
for (var i = 0 ; i < CF_VALUE_JSON.length ; i++) {
var info = CF_VALUE_JSON[i].custom_field;
var value = CF_VALUE_JSON[i].value;
if(info.visible && info.editable && !isExcluded("issue_custom_field_values_" + info.id))
{
if($('.details .attributes .cf_' + info.id + '.attribute .value').length
&& $('#issue_custom_field_values_' + info.id).length )
{
if (info.visible && info.editable && !isExcluded("issue_custom_field_values_" + info.id)) {
if (
$('.details .attributes .cf_' + info.id + '.attribute .value').length &&
$('#issue_custom_field_values_' + info.id).length
) {
var htmlCopy = $('#issue_custom_field_values_' + info.id).get(0).outerHTML;
if(info.field_format == "version" && info.format_store.edit_tag_style == "check_box")
{
if (info.field_format == "version" && info.format_store.edit_tag_style == "check_box") {
htmlCopy = $('#issue_custom_field_values_' + info.id).parents('span').html();
}
// 2 technics with simple or double quote (safety first)
htmlCopy = htmlCopy.replace(/id="/g, 'id="dynamic_').replace(/id='/g, "id='dynamic_");
htmlCopy = htmlCopy.replace(/class="/g, 'class="cf_' + info.id + ' ').replace(/class='/g, "class='cf_" + info.id + " ");
var editHTML = "<span class='dynamicEdit " + info.field_format + "' id='dynamic_edit_cf_" + info.id + "'>";
editHTML += htmlCopy;
editHTML += " <a href='#' class='btn btn-primary validate' aria-label='" + _TXT_VALIDATION_BTN + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>";
editHTML += " <a href='#' class='btn btn-primary close' aria-label='" + _TXT_CANCEL_BTN + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a>";
editHTML += "</span>";
$('.details .attributes .cf_' + info.id + '.attribute .value').html('<span class="showValue">' +
$('.details .attributes .cf_' + info.id + '.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
editHTML);
$('.details .attributes .cf_' + info.id + '.attribute .value').html(
'<span class="showValue">' +
$('.details .attributes .cf_' + info.id + '.attribute .value').html() +
'</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
editHTML
);
if(info.field_format == "date")
{
if( $('body').find('#dynamic_issue_custom_field_values_' + info.id).length
&& $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback instanceof Function
&& typeof datepickerOptions !== 'undefined')
{
if (info.field_format == "date") {
if (
$('body').find('#dynamic_issue_custom_field_values_' + info.id).length &&
$('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback instanceof Function &&
typeof datepickerOptions !== 'undefined'
) {
$('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback(datepickerOptions);
}
}
cf_datetime = $('body').find('#dynamic_issue_custom_field_values_' + info.id);
if (info.field_format == "datetime") {
if (
cf_datetime.length &&
typeof datetimepickerOptions !== 'undefined'
) {
cf_datetime.datetimepicker(datetimepickerOptions);
}
}
}
}
}
@ -194,11 +235,14 @@ function initEditFields()
initEditFields();
/* Add required style to attributes */
function updateRequiredFields(reqFieldsArray)
{
function updateRequiredFields(reqFieldsArray) {
for (var i = 0; i < reqFieldsArray.length; i++) {
var htmlLabel = reqFieldsArray[i].replace(/_/g, '-');
$('.issue.details .attribute.' + htmlLabel + ' .label').html('<span title=\"' + _TXT_REQUIRED_FIELD + '\" class=\"field-description\">' + $('.issue.details .attribute.' + htmlLabel + ' .label').html() + '</span> <span class=\"required\"> *</span>');
$('.issue.details .attribute.' + htmlLabel + ' .label').html(
'<span title=\"' + _TXT_REQUIRED_FIELD + '\" class=\"field-description\">' +
$('.issue.details .attribute.' + htmlLabel + ' .label').html() +
'</span> <span class=\"required\"> *</span>'
);
}
}
@ -206,7 +250,6 @@ if($('#required_field_array').length) {
updateRequiredFields(JSON.parse($('#required_field_array').html()));
}
$('body.controller-issues.action-show').on('click', '.btn.close', function(e) {
e.preventDefault();
$(e.target).closest('.value').removeClass('edited');
@ -216,6 +259,8 @@ $('body.controller-issues.action-show').on('click', '.btn.close', function(e){
function getLastLockVersion() {
var token = $("meta[name=csrf-token]").attr('content');
var lock_version = $('#issue_lock_version').val();
jQuery.ajax({
type: 'GET',
url: LOCATION_HREF,
@ -234,7 +279,6 @@ function getLastLockVersion() {
}
function issueDynamicUpdate(field_name, field_value, type, cssClass) {
/* hide edit field */
$('.details .' + cssClass + ' .value').removeClass('edited');
@ -243,24 +287,19 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
/* update value displayed */
$('.details .' + cssClass + ' .showValue').html(function() {
if(type == "select")
{
if (type == "select") {
return $('.details .' + cssClass + ' .value select option:selected').html()
} else if (type == "input")
{
} else if (type == "input") {
return $('.details .' + cssClass + ' .value input').val()
} else if(type == "textarea")
{
} else if (type == "textarea") {
return $('.details .' + cssClass + ' .value textarea').val()
} else if(type == "date")
{
} else if (type == "date") {
return "XXXX/XX/XX";
}
});
/* lost focus on element */
if( type != "select")
{
if (type != "select") {
$('.details .' + cssClass + ' .value input').blur();
}
@ -272,6 +311,7 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
$('#issue_lock_version').val(lastLockVersion);
var formData = $('#issue-form').serialize();
jQuery.ajax({
type: 'POST',
url: LOCATION_HREF,
@ -286,15 +326,13 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
var error = $(parsed).find("#errorExplanation");
if(error.length)
{
if($('html').find("#errorExplanation").length == 0)
{
if (error.length) {
if ($('html').find("#errorExplanation").length == 0) {
$('.issue.details').before("<div id='errorExplanation'>" + error.html() + "</div>");
} else
{
} else {
$('html').find("#errorExplanation").html(error.html());
}
/* data updated, remove spin and add success icon for 2sec */
setTimeout(function() {
$('.details .' + cssClass + ' i.fa-spin').removeClass('fa-refresh fa-spin').addClass('fa-times statusKo');
@ -303,6 +341,7 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
}, 2000);
}, 500);
jQuery.ajax({
type: 'GET',
url: LOCATION_HREF,
@ -316,12 +355,9 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
parsed = $.parseHTML(msg);
}
});
} else {
/* removing error div if exists */
$('html').find("#errorExplanation").remove();
}
/* we update the details block */
@ -354,13 +390,13 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
}, 500);
//set datepicker fallback for input type date
if( $('body').find('input[type=date]').length
&& $('body').find('input[type=date]').datepickerFallback instanceof Function
&& typeof datepickerOptions !== 'undefined')
{
if (
$('body').find('input[type=date]').length &&
$('body').find('input[type=date]').datepickerFallback instanceof Function &&
typeof datepickerOptions !== 'undefined'
) {
$('body').find('input[type=date]').datepickerFallback(datepickerOptions);
}
},
error: function(xhr, msg, error) {
/* error and no update, info logged into console */
@ -372,6 +408,7 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
console.log('%c error data: ', 'background: black; color: white;');;
console.log(error);
console.log('%c ---------------------------------------------------------- ', 'background: #ff0000; color: white; font-weight:900');
$('.details .' + cssClass + ' i.fa-spin').removeClass('fa-refresh fa-spin').addClass('fa-times').html(" " + _TXT_ERROR_AJAX_CALL);
setTimeout(function(){
$('.details .' + cssClass + ' i.fa-times').remove();
@ -381,8 +418,7 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
};
/* Listeners foreach attribute */
function initEditFieldListeners()
{
function initEditFieldListeners() {
var domSelectStatus = $('body').find('#statusListDropdown select');
domSelectStatus.on('change', function(e) {
issueDynamicUpdate('status_id', domSelectStatus.val(), 'select', 'status');
@ -414,18 +450,18 @@ function initEditFieldListeners()
}); /* end on change domSelectRatio */
var domInputEstimatedTime = $('body').find('#EstimatedTimeInput input');
$('#EstimatedTimeInput a.btn.validate').on('click', function(e)
{
$('#EstimatedTimeInput a.btn.validate').on('click', function(e) {
e.preventDefault();
$('.estimated-hours .value .error').remove();
var estimatedTime = parseFloat(domInputEstimatedTime.val());
if(estimatedTime >= 0)
{
if (estimatedTime >= 0) {
issueDynamicUpdate('estimated_hours', estimatedTime, 'input', 'estimated-hours');
} else {
/* estimated time must be > 0 */
$('.estimated-hours .value').append('<span class="error"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> ' + _TXT_ERROR_POSITIVE_NUMBER + '</span>');
}
return false;
});
@ -433,14 +469,14 @@ function initEditFieldListeners()
$('.details .attributes .estimated-hours.attribute .selectedValue span').html(
$('.details .attributes .estimated-hours.attribute .value input').val()
);
if (e.keyCode == 13) {
$('#EstimatedTimeInput a.btn.validate').click();
}
});/* end EstimatedTime */
var domInputStartDate = $('body').find('#StartDateInput input');
$('#StartDateInput a.btn.validate').on('click', function(e)
{
$('#StartDateInput a.btn.validate').on('click', function(e) {
e.preventDefault();
$('.start-date .value .error').remove();
if (new Date(domInputStartDate.val()).getTime() <= new Date($('body').find('#DueDateInput input').val()).getTime() || $('body').find('#DueDateInput input').val() == "")
@ -450,6 +486,7 @@ function initEditFieldListeners()
/* start date must be < due date */
$('.start-date .value').append('<span class="error"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> ' + _TXT_ERROR_START_DATE + '</span>');
}
return false;
});
@ -460,10 +497,10 @@ function initEditFieldListeners()
});/* end StartDate */
var domInputDueDate = $('body').find('#DueDateInput input');
$('#DueDateInput a.btn.validate').on('click', function(e)
{
$('#DueDateInput a.btn.validate').on('click', function(e) {
e.preventDefault();
$('.due-date .value .error').remove();
if(new Date($('body').find('#StartDateInput input').val()).getTime() <= new Date(domInputDueDate.val()).getTime() || $('body').find('#StartDateInput input').val() == "" )
{
issueDynamicUpdate('due_date', domInputDueDate.val(), 'date', 'due-date');
@ -481,8 +518,7 @@ function initEditFieldListeners()
});/* end StartDate */
var domInputTitle = $('body').find('#TitleInput input');
$('#TitleInput a.btn.validate').on('click', function(e)
{
$('#TitleInput a.btn.validate').on('click', function(e) {
e.preventDefault();
issueDynamicUpdate('subject', domInputTitle.val(), 'input', 'subject');
@ -497,15 +533,15 @@ function initEditFieldListeners()
var domInputDescription = $('body').find('#DescriptionInput textarea');
if(domInputDescription.length)
{
$('#DescriptionInput a.btn.validate').on('click', function(e)
{
if(domInputDescription.length) {
$('#DescriptionInput a.btn.validate').on('click', function(e) {
e.preventDefault();
var new_value = domInputDescription.val();
if(typeof(CKEDITOR) === "object"
&& typeof(CKEDITOR.instances['description_textarea'].getData) === typeof(Function)){
if (
typeof(CKEDITOR) === "object" &&
typeof(CKEDITOR.instances['description_textarea'].getData) === typeof(Function)
) {
new_value = CKEDITOR.instances['description_textarea'].getData();
}
@ -514,8 +550,7 @@ function initEditFieldListeners()
return false;
});
if(typeof(jsToolBar) === typeof(Function))
{
if (typeof(jsToolBar) === typeof(Function)) {
var wikiToolbar = new jsToolBar(document.getElementById('description_textarea')); wikiToolbar.draw();
} else if (typeof(CKEDITOR) === "object" && typeof(CKEDITOR.replace) === typeof(Function)) {
CKEDITOR.replace('description_textarea', { height: 100 });
@ -524,8 +559,7 @@ function initEditFieldListeners()
var dynamic_edit_assigned_to_id = $('body').find('#dynamic_edit_assigned_to_id select');
if(dynamic_edit_assigned_to_id.length)
{
if (dynamic_edit_assigned_to_id.length) {
dynamic_edit_assigned_to_id.on('change', function(e){
issueDynamicUpdate('assigned_to_id', dynamic_edit_assigned_to_id.val(), 'select', 'assigned-to');
});
@ -533,8 +567,7 @@ function initEditFieldListeners()
var dynamic_edit_fixed_version = $('body').find('#dynamic_edit_fixed_version select');
if(dynamic_edit_fixed_version.length)
{
if (dynamic_edit_fixed_version.length) {
dynamic_edit_fixed_version.on('change', function(e){
issueDynamicUpdate('fixed_version_id', dynamic_edit_fixed_version.val(), 'select', 'fixed-version');
});
@ -543,16 +576,15 @@ function initEditFieldListeners()
/* end Description */
/* Custom fields */
for(var i = 0 ; i < CF_VALUE_JSON.length ; i++)
{
(function() {
for (var i = 0 ; i < CF_VALUE_JSON.length ; i++) {
(
function() {
var info = CF_VALUE_JSON[i].custom_field;
var value = CF_VALUE_JSON[i].value;
if(info.visible && info.editable)
{
if (info.visible && info.editable) {
var inputType = "input";
switch (info.field_format)
{
switch (info.field_format) {
case "bool":
case "user":
case "list":
@ -563,12 +595,10 @@ function initEditFieldListeners()
case "text":
inputType = "textarea";
break;
}
// Specific case : version field with checkboxes
if(info.field_format == "version" && info.format_store.edit_tag_style == "check_box")
{
if (info.field_format == "version" && info.format_store.edit_tag_style == "check_box") {
inputType = "version";
$('body').find('#dynamic_edit_cf_' + info.id + ' input').on('click', function(e) {
$('label[for=issue_custom_field_values_' + info.id + ']').next().find('input[value=' + $(this).val() + ']').click();
@ -576,8 +606,7 @@ function initEditFieldListeners()
}
var domInputField = $('body').find('#dynamic_issue_custom_field_values_' + info.id);
$('body').find('#dynamic_edit_cf_' + info.id + ' a.btn.validate').on('click', function(e)
{
$('body').find('#dynamic_edit_cf_' + info.id + ' a.btn.validate').on('click', function(e) {
var new_value = domInputField.val();
issueDynamicUpdate('custom_field_values_' + info.id , new_value, inputType, 'cf_' + info.id);
@ -590,11 +619,10 @@ function initEditFieldListeners()
$('body').find('#dynamic_edit_cf_' + info.id + ' a.btn.validate').click();
}
});
}
}()); // closure FTW
}()
); // closure FTW
}
}
initEditFieldListeners();

View File

@ -1,5 +1,4 @@
class DetailsIssueHooks < Redmine::Hook::ViewListener
def protect_against_forgery?
false
end
@ -10,16 +9,16 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
end
def view_layouts_base_html_head(context)
if current_is_detail_page(context)
return unless current_is_detail_page(context)
stylesheet_link_tag('issue_dynamic_edit.css', :plugin => :redmine_issue_dynamic_edit)
end
end
def view_layouts_base_body_bottom(context)
if current_is_detail_page(context)
return unless current_is_detail_page(context)
javascript_include_tag('issue_dynamic_edit_configuration_file.js', 'issue_dynamic_edit.js', :plugin => :redmine_issue_dynamic_edit)
end
end
def view_issues_show_details_bottom(context = {})
project = context[:project]
@ -29,7 +28,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
o = ''
if (issue_id)
if issue_id
issue = Issue.find(issue_id)
readOnlyAttributes = issue.read_only_attribute_names(User.current)
requiredAttributes = issue.required_attribute_names(User.current)
@ -38,20 +37,23 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
allRequiredFieldsFilled = true
requiredAttributes.each do |attr|
if(issue.read_attribute(attr).to_s.empty?)
if issue.read_attribute(attr).to_s.empty?
allRequiredFieldsFilled = false
end
end
if (issue)
if (User.current.allowed_to?(:edit_issues, project))
if issue
if User.current.allowed_to?(:edit_issues, project)
# if there's a JS error, we hide the generated values
o << '<div style="display:none">'
# Status dropdown
statuses = issue.new_statuses_allowed_to(User.current)
if (!statuses.empty? && !(readOnlyAttributes.include? 'status_id') && allRequiredFieldsFilled)
if (
!statuses.empty? &&
!readOnlyAttributes.include?('status_id') &&
allRequiredFieldsFilled
)
o << "<span class='dynamicEdit' id='statusListDropdown'>"
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
statuses.each do |s|
@ -61,14 +63,19 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
o << "<option value='#{s.id}' selected>#{s.name}</option>"
end
end
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
end
# Users dropdown
assignables = project.assignable_users
if (!assignables.empty? && !(readOnlyAttributes.include? 'assigned_to_id'))
if (
!assignables.empty? &&
!readOnlyAttributes.include?('assigned_to_id')
)
o << "<span class='dynamicEdit' id='usersListDropdown'>"
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
assignables.each do |u|
if (u != issue.assigned_to)
o << "<option value='#{u.id}'>#{u.name}</option>"
@ -76,14 +83,17 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
o << "<option value='#{u.id}' selected>#{u.name}</option>"
end
end
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
end
# Priorities dropdown
priorities = IssuePriority.all
if(!priorities.empty? && !(readOnlyAttributes.include? 'priority_id'))
if !priorities.empty? && !(readOnlyAttributes.include? 'priority_id')
o << "<span class='dynamicEdit' id='prioritiesListDropdown'>"
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
priorities.each do |p|
if (p != issue.priority)
o << "<option value='#{p.id}'>#{p.name}</option>"
@ -91,30 +101,31 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
o << "<option value='#{p.id}' selected>#{p.name}</option>"
end
end
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
end
# %done dropdown
if(!(readOnlyAttributes.include? 'done_ratio'))
if ! readOnlyAttributes.include?('done_ratio')
percent = 0
o << "<span class='dynamicEdit' id='doneRatioListDropdown'>"
o << "<select data-issue='#{issue_id}'><option disabled='disabled' selected> </option>"
loop do
if (percent == issue.done_ratio)
if percent == issue.done_ratio
o << "<option value='#{percent}' selected>#{percent}%</option>"
else
o << "<option value='#{percent}'>#{percent}%</option>"
end
percent += 10
if percent == 110
break
end
break if percent == 110
end
o << "</select> <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></span>"
end
# Estimated_time dropdown
if(!(readOnlyAttributes.include? 'estimated_hours'))
if ! readOnlyAttributes.include?('estimated_hours')
o << "<span class='dynamicEdit' id='EstimatedTimeInput'>"
o << " <input type='text' value='#{issue.estimated_hours}' size='6'/>"
o << "<a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
@ -123,7 +134,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
end
# Start date
if(!(readOnlyAttributes.include? 'start_date'))
if ! readOnlyAttributes.include?('start_date')
o << "<span class='dynamicEdit' id='StartDateInput'>"
o << " <input size=\"10\" value=\"#{issue.start_date}\" type=\"date\" max=\"#{issue.due_date}\">"
o << " <a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
@ -139,7 +150,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
end
# Due date
if(!(readOnlyAttributes.include? 'due_date'))
if ! readOnlyAttributes.include?('due_date')
o << "<span class='dynamicEdit' id='DueDateInput'>"
o << " <input size=\"10\" value=\"#{issue.due_date}\" type=\"date\" min=\"#{issue.start_date}\">"
o << " <a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
@ -169,7 +180,6 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
o << " <div style='display:block; text-align:right; margin-top:10px;'><a href='#' class='btn btn-primary validate' aria-label='" + l(:ide_txt_validation_btn) + "'><i class='fa fa-check fa-fw' aria-hidden='true'></i></a>"
o << " <a href='#' class='btn btn-primary close' aria-label='" + l(:ide_txt_cancel_btn) + "'><i class='fa fa-times fa-fw' aria-hidden='true'></i></a></div>"
o << "</span>"
end
end
@ -191,15 +201,13 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
o << " var _TXT_REQUIRED_FIELD = \"" + l(:ide_txt_required_field) + "\";\n"
o << "</script>\n"
o << "<div style='display:none' id='required_field_array'>#{requiredAttributes.to_json}</div>\n"
# closing the display none div parent
o << "</div>"
return o
end
end
end
end
end