Configuration file added (https settings, target and action listener choices, field exclusion) (#30 #35 #41)

This commit is contained in:
Hugo 2019-04-13 23:29:20 +02:00
parent 3ef47ab625
commit 1fb2a0519c
3 changed files with 72 additions and 14 deletions

View File

@ -1,8 +1,17 @@
/*
* OPTIONS DEFINED FROM CONFIGURATION FILE
*/
var _CONF_FORCE_HTTPS = _CONF_FORCE_HTTPS || false;
var _CONF_LISTENER_TYPE = _CONF_LISTENER_TYPE || "click";
var _CONF_LISTENER_TARGET = _CONF_LISTENER_TARGET || "value";
var _CONF_EXCLUDED_FIELD_ID = _CONF_EXCLUDED_FIELD_ID || [];
/*
* Allow inclusion from other page
* 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://'); }
/* FontAwesome inclusion */
var cssId = 'fontAwesome';
@ -18,18 +27,32 @@ var cssId = 'fontAwesome';
head.appendChild(link);
}
$(document).on('click', function(e){
$(document).on(_CONF_LISTENER_TYPE, function(e){
$('.issue .attributes .attribute .value').removeClass('edited');
if($(e.target).closest('a').length){ return; }
if($(e.target).closest('.value').length) {
if($(e.target).closest('.' + _CONF_LISTENER_TARGET).length) {
// avoid text selection if dblclick
var sel = window.getSelection ? window.getSelection() : document.selection;
if (sel) {
if (sel.removeAllRanges) {
sel.removeAllRanges();
} else if (sel.empty) {
sel.empty();
}
}
// we show the edit box
$(e.target).closest('.value').addClass('edited');
}
});
function isExcluded(elmt_id) {
return _CONF_EXCLUDED_FIELD_ID.indexOf(elmt_id) > -1;
}
function initEditFields()
{
/* Put new dropdown lists in the detailed info block */
if($('#statusListDropdown').length > 0) {
if($('#statusListDropdown').length > 0 && !isExcluded('statusListDropdown')) {
var htmlCopy = $('#statusListDropdown').get(0).outerHTML;
$('#statusListDropdown').remove();
$('.details .attributes .status.attribute .value').html( '<span class="showValue">' +
@ -37,7 +60,7 @@ function initEditFields()
htmlCopy);
}
if($('#prioritiesListDropdown').length > 0) {
if($('#prioritiesListDropdown').length > 0 && !isExcluded('prioritiesListDropdown')) {
var htmlCopy = $('#prioritiesListDropdown').get(0).outerHTML;
$('#prioritiesListDropdown').remove();
$('.details .attributes .priority.attribute .value').html( '<span class="showValue">' +
@ -45,7 +68,7 @@ function initEditFields()
htmlCopy);
}
if($('#doneRatioListDropdown').length > 0) {
if($('#doneRatioListDropdown').length > 0 && !isExcluded('doneRatioListDropdown')) {
var htmlCopy = $('#doneRatioListDropdown').get(0).outerHTML;
$('#doneRatioListDropdown').remove();
$('.details .attributes .progress.attribute .value').html('<span class="showValue">' +
@ -53,7 +76,7 @@ function initEditFields()
htmlCopy);
}
if($('#EstimatedTimeInput').length > 0) {
if($('#EstimatedTimeInput').length > 0 && !isExcluded('EstimatedTimeInput')) {
var htmlCopy = $('#EstimatedTimeInput').get(0).outerHTML;
$('#EstimatedTimeInput').remove();
$('.details .attributes .estimated-hours.attribute .value').html('<span class="showValue">' +
@ -61,7 +84,7 @@ function initEditFields()
htmlCopy);
}
if($('#StartDateInput').length > 0) {
if($('#StartDateInput').length > 0 && !isExcluded('StartDateInput')) {
var htmlCopy = $('#StartDateInput').get(0).outerHTML;
$('#StartDateInput').remove();
$('.details .attributes .start-date.attribute .value').html('<span class="showValue">' +
@ -69,7 +92,7 @@ function initEditFields()
htmlCopy);
}
if($('#DueDateInput').length > 0) {
if($('#DueDateInput').length > 0 && !isExcluded('DueDateInput')) {
var htmlCopy = $('#DueDateInput').get(0).outerHTML;
$('#DueDateInput').remove();
$('.details .attributes .due-date.attribute .value').html('<span class="showValue">' +
@ -77,21 +100,21 @@ function initEditFields()
htmlCopy);
}
if($('#TitleInput').length > 0) {
if($('#TitleInput').length > 0 && !isExcluded('TitleInput')) {
var htmlCopy = $('#TitleInput').get(0).outerHTML;
$('#TitleInput').remove();
$('.subject h3').html('<span class="showValue">' + $('.subject h3').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy).addClass('value');
}
if($('#DescriptionInput').length > 0) {
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');
}
if($('select#issue_assigned_to_id').length > 0)
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)
@ -107,7 +130,7 @@ function initEditFields()
editHTML);
}
if($('select#issue_fixed_version_id').length > 0)
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)
@ -127,7 +150,7 @@ function initEditFields()
{
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 && !isExcluded("issue_custom_field_values_" + info.id))
{
if($('.details .attributes .cf_' + info.id + '.attribute .value').length
&& $('#issue_custom_field_values_' + info.id).length )

View File

@ -0,0 +1,35 @@
/*
* CONFIGURATION FILE
* More info on https://github.com/Ilogeek/redmine_issue_dynamic_edit
*/
/*
* _CONF_FORCE_HTTPS (boolean)
* Will force AJAX call performed by the plugin to be done with https protocol
* Use this value if you encounter some difficulties with "Mixed content" issues
* Allowed values : false (default), true
*/
var _CONF_FORCE_HTTPS = false;
/*
* _CONF_LISTENER_TYPE (string)
* Choose which action will trigger the apparition of the edition block
* Allowed values : click (default), dblclick
*/
var _CONF_LISTENER_TYPE = "click";
/*
* _CONF_LISTENER_TARGET (string)
* Choose which area will trigger the apparition of the edition block
* "value" will target the whole line, "fa-pencil" will only target the pencil icon
* Allowed values : value (default), fa-pencil
*/
var _CONF_LISTENER_TARGET = "value";
/*
* _CONF_EXCLUDED_FIELD_ID (string array)
* Choose which fields to exclude. They won't have the edit block and pencil
* Custom fields have an unique ID and this ID must be prefixed by "issue_custom_field_values_". Eg : "issue_custom_field_values_4" is an allowed value
* Allowed values : array of any ID selector (css). Eg : ["statusListDropdown", "StartDateInput", "TitleInput", "issue_custom_field_values_4"]
*/
var _CONF_EXCLUDED_FIELD_ID = [];

View File

@ -17,7 +17,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener
def view_layouts_base_body_bottom(context)
if current_is_detail_page(context)
javascript_include_tag('issue_dynamic_edit.js', :plugin => :redmine_issue_dynamic_edit)
javascript_include_tag('issue_dynamic_edit_configuration_file.js', 'issue_dynamic_edit.js', :plugin => :redmine_issue_dynamic_edit)
end
end