syntax refactorings

modifié :         assets/javascripts/issue_dynamic_edit.js
This commit is contained in:
Lxc 2019-09-25 22:27:56 +02:00
parent 693f60ce1b
commit 7eb6aaf05c

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 * 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; 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 */ /* FontAwesome inclusion */
var cssId = 'fontAwesome'; var cssId = 'fontAwesome';
if (!document.getElementById(cssId))
{ if (!document.getElementById(cssId)) {
var head = document.getElementsByTagName('head')[0]; var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link'); var link = document.createElement('link');
link.id = cssId; link.id = cssId;
@ -25,12 +29,13 @@ var cssId = 'fontAwesome';
link.href = 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'; link.href = 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css';
link.media = 'all'; link.media = 'all';
head.appendChild(link); head.appendChild(link);
} }
$(document).on(_CONF_LISTENER_TYPE, function(e){ $(document).on(_CONF_LISTENER_TYPE, function(e) {
$('.issue .attributes .attribute .value').removeClass('edited'); $('.issue .attributes .attribute .value').removeClass('edited');
if($(e.target).closest('a').length){ return; }
if($(e.target).closest('.' + _CONF_LISTENER_TARGET).length) { if ($(e.target).closest('a').length) { return; }
if ($(e.target).closest('.' + _CONF_LISTENER_TARGET).length) {
// avoid text selection if dblclick // avoid text selection if dblclick
var sel = window.getSelection ? window.getSelection() : document.selection; var sel = window.getSelection ? window.getSelection() : document.selection;
var activeElement = document.activeElement; var activeElement = document.activeElement;
@ -43,6 +48,7 @@ $(document).on(_CONF_LISTENER_TYPE, function(e){
sel.empty(); sel.empty();
} }
} }
// we show the edit box // we show the edit box
$(e.target).closest('.value').addClass('edited'); $(e.target).closest('.value').addClass('edited');
} }
@ -52,26 +58,31 @@ function isExcluded(elmt_id) {
return _CONF_EXCLUDED_FIELD_ID.indexOf(elmt_id) > -1; return _CONF_EXCLUDED_FIELD_ID.indexOf(elmt_id) > -1;
} }
function initEditFields() function initEditFields() {
{
/* Put new dropdown lists in the detailed info block */ /* Put new dropdown lists in the detailed info block */
if($('#statusListDropdown').length > 0 && !isExcluded('statusListDropdown')) { if ($('#statusListDropdown').length > 0 && !isExcluded('statusListDropdown')) {
var htmlCopy = $('#statusListDropdown').get(0).outerHTML; var htmlCopy = $('#statusListDropdown').get(0).outerHTML;
$('#statusListDropdown').remove(); $('#statusListDropdown').remove();
$('.details .attributes .status.attribute .value').html( '<span class="showValue">' + $('.details .attributes .status.attribute .value').html(
$('.details .attributes .status.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
htmlCopy); $('.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')) { if ($('#prioritiesListDropdown').length > 0 && !isExcluded('prioritiesListDropdown')) {
var htmlCopy = $('#prioritiesListDropdown').get(0).outerHTML; var htmlCopy = $('#prioritiesListDropdown').get(0).outerHTML;
$('#prioritiesListDropdown').remove(); $('#prioritiesListDropdown').remove();
$('.details .attributes .priority.attribute .value').html( '<span class="showValue">' + $('.details .attributes .priority.attribute .value').html(
$('.details .attributes .priority.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
htmlCopy); $('.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')) { if ($('#doneRatioListDropdown').length > 0 && !isExcluded('doneRatioListDropdown')) {
var htmlCopy = $('#doneRatioListDropdown').get(0).outerHTML; var htmlCopy = $('#doneRatioListDropdown').get(0).outerHTML;
$('#doneRatioListDropdown').remove(); $('#doneRatioListDropdown').remove();
$('.details .attributes .progress.attribute .value').html('<span class="showValue">' + $('.details .attributes .progress.attribute .value').html('<span class="showValue">' +
@ -79,46 +90,57 @@ function initEditFields()
htmlCopy); htmlCopy);
} }
if($('#EstimatedTimeInput').length > 0 && !isExcluded('EstimatedTimeInput')) { if ($('#EstimatedTimeInput').length > 0 && !isExcluded('EstimatedTimeInput')) {
var htmlCopy = $('#EstimatedTimeInput').get(0).outerHTML; var htmlCopy = $('#EstimatedTimeInput').get(0).outerHTML;
$('#EstimatedTimeInput').remove(); $('#EstimatedTimeInput').remove();
$('.details .attributes .estimated-hours.attribute .value').html('<span class="showValue">' + $('.details .attributes .estimated-hours.attribute .value').html(
$('.details .attributes .estimated-hours.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
htmlCopy); $('.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')) { if ($('#StartDateInput').length > 0 && !isExcluded('StartDateInput')) {
var htmlCopy = $('#StartDateInput').get(0).outerHTML; var htmlCopy = $('#StartDateInput').get(0).outerHTML;
$('#StartDateInput').remove(); $('#StartDateInput').remove();
$('.details .attributes .start-date.attribute .value').html('<span class="showValue">' + $('.details .attributes .start-date.attribute .value').html(
$('.details .attributes .start-date.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
htmlCopy); $('.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')) { if ($('#DueDateInput').length > 0 && !isExcluded('DueDateInput')) {
var htmlCopy = $('#DueDateInput').get(0).outerHTML; var htmlCopy = $('#DueDateInput').get(0).outerHTML;
$('#DueDateInput').remove(); $('#DueDateInput').remove();
$('.details .attributes .due-date.attribute .value').html('<span class="showValue">' + $('.details .attributes .due-date.attribute .value').html(
$('.details .attributes .due-date.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
htmlCopy); $('.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')) { if ($('#TitleInput').length > 0 && !isExcluded('TitleInput')) {
var htmlCopy = $('#TitleInput').get(0).outerHTML; var htmlCopy = $('#TitleInput').get(0).outerHTML;
$('#TitleInput').remove(); $('#TitleInput').remove();
$('.subject h3').html('<span class="showValue">' + $('.subject h3').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + $('.subject h3').html('<span class="showValue">' + $('.subject h3').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' +
htmlCopy).addClass('value'); htmlCopy).addClass('value');
} }
if($('#DescriptionInput').length > 0 && !isExcluded('DescriptionInput')) { if ($('#DescriptionInput').length > 0 && !isExcluded('DescriptionInput')) {
var htmlCopy = $('#DescriptionInput').get(0).outerHTML; var htmlCopy = $('#DescriptionInput').get(0).outerHTML;
$('#DescriptionInput').remove(); $('#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>' + $('div.description .wiki').html(
htmlCopy).addClass('value'); ' <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; var htmlCopy = $('select#issue_assigned_to_id').get(0).outerHTML;
// 2 technics with simple or double quote (safety first) // 2 technics with simple or double quote (safety first)
htmlCopy = htmlCopy.replace(/id="/g, 'id="dynamic_').replace(/id='/g, "id='dynamic_"); 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 += " <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>"; editHTML += "</span>";
$('.details .attributes .assigned-to.attribute .value').html('<span class="showValue">' + $('.details .attributes .assigned-to.attribute .value').html(
$('.details .attributes .assigned-to.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
editHTML); $('.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; var htmlCopy = $('select#issue_fixed_version_id').get(0).outerHTML;
// 2 technics with simple or double quote (safety first) // 2 technics with simple or double quote (safety first)
htmlCopy = htmlCopy.replace(/id="/g, 'id="dynamic_').replace(/id='/g, "id='dynamic_"); htmlCopy = htmlCopy.replace(/id="/g, 'id="dynamic_').replace(/id='/g, "id='dynamic_");
@ -144,45 +168,52 @@ 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 += " <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>"; editHTML += "</span>";
$('.details .attributes .fixed-version.attribute .value').html('<span class="showValue">' + $('.details .attributes .fixed-version.attribute .value').html(
$('.details .attributes .fixed-version.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
editHTML); $('.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 info = CF_VALUE_JSON[i].custom_field;
var value = CF_VALUE_JSON[i].value; var value = CF_VALUE_JSON[i].value;
if(info.visible && info.editable && !isExcluded("issue_custom_field_values_" + info.id))
{ if (info.visible && info.editable && !isExcluded("issue_custom_field_values_" + info.id)) {
if($('.details .attributes .cf_' + info.id + '.attribute .value').length if (
&& $('#issue_custom_field_values_' + info.id).length ) $('.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; 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(); htmlCopy = $('#issue_custom_field_values_' + info.id).parents('span').html();
} }
// 2 technics with simple or double quote (safety first) // 2 technics with simple or double quote (safety first)
htmlCopy = htmlCopy.replace(/id="/g, 'id="dynamic_').replace(/id='/g, "id='dynamic_"); 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 + " "); 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 + "'>"; var editHTML = "<span class='dynamicEdit " + info.field_format + "' id='dynamic_edit_cf_" + info.id + "'>";
editHTML += htmlCopy; 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 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 += " <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>"; editHTML += "</span>";
$('.details .attributes .cf_' + info.id + '.attribute .value').html('<span class="showValue">' + $('.details .attributes .cf_' + info.id + '.attribute .value').html(
$('.details .attributes .cf_' + info.id + '.attribute .value').html() + '</span> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>' + '<span class="showValue">' +
editHTML); $('.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 (info.field_format == "date") {
{ if (
if( $('body').find('#dynamic_issue_custom_field_values_' + info.id).length $('body').find('#dynamic_issue_custom_field_values_' + info.id).length &&
&& $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback instanceof Function $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback instanceof Function &&
&& typeof datepickerOptions !== 'undefined') typeof datepickerOptions !== 'undefined'
{ ) {
$('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback(datepickerOptions); $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback(datepickerOptions);
} }
} }
@ -194,20 +225,22 @@ function initEditFields()
initEditFields(); initEditFields();
/* Add required style to attributes */ /* Add required style to attributes */
function updateRequiredFields(reqFieldsArray) function updateRequiredFields(reqFieldsArray) {
{
for (var i = 0; i < reqFieldsArray.length; i++) { for (var i = 0; i < reqFieldsArray.length; i++) {
var htmlLabel = reqFieldsArray[i].replace(/_/g, '-'); 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>'
);
} }
}
if($('#required_field_array').length) { if ($('#required_field_array').length) {
updateRequiredFields(JSON.parse($('#required_field_array').html())); updateRequiredFields(JSON.parse($('#required_field_array').html()));
} }
$('body.controller-issues.action-show').on('click', '.btn.close', function(e) {
$('body.controller-issues.action-show').on('click', '.btn.close', function(e){
e.preventDefault(); e.preventDefault();
$(e.target).closest('.value').removeClass('edited'); $(e.target).closest('.value').removeClass('edited');
return false; return false;
@ -216,6 +249,8 @@ $('body.controller-issues.action-show').on('click', '.btn.close', function(e){
function getLastLockVersion() { function getLastLockVersion() {
var token = $("meta[name=csrf-token]").attr('content'); var token = $("meta[name=csrf-token]").attr('content');
var lock_version = $('#issue_lock_version').val(); var lock_version = $('#issue_lock_version').val();
jQuery.ajax({ jQuery.ajax({
type: 'GET', type: 'GET',
url: LOCATION_HREF, url: LOCATION_HREF,
@ -233,8 +268,7 @@ function getLastLockVersion() {
return lock_version; return lock_version;
} }
function issueDynamicUpdate(field_name, field_value, type, cssClass){ function issueDynamicUpdate(field_name, field_value, type, cssClass) {
/* hide edit field */ /* hide edit field */
$('.details .' + cssClass + ' .value').removeClass('edited'); $('.details .' + cssClass + ' .value').removeClass('edited');
@ -242,25 +276,20 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
$('.details .' + cssClass + ' .value').append(' <i class="fa fa-refresh fa-spin fa-fw"></i>'); $('.details .' + cssClass + ' .value').append(' <i class="fa fa-refresh fa-spin fa-fw"></i>');
/* update value displayed */ /* update value displayed */
$('.details .' + cssClass + ' .showValue').html(function(){ $('.details .' + cssClass + ' .showValue').html(function() {
if(type == "select") if (type == "select") {
{
return $('.details .' + cssClass + ' .value select option:selected').html() return $('.details .' + cssClass + ' .value select option:selected').html()
} else if (type == "input") } else if (type == "input") {
{
return $('.details .' + cssClass + ' .value input').val() return $('.details .' + cssClass + ' .value input').val()
} else if(type == "textarea") } else if (type == "textarea") {
{
return $('.details .' + cssClass + ' .value textarea').val() return $('.details .' + cssClass + ' .value textarea').val()
} else if(type == "date") } else if (type == "date") {
{
return "XXXX/XX/XX"; return "XXXX/XX/XX";
} }
}); });
/* lost focus on element */ /* lost focus on element */
if( type != "select") if (type != "select") {
{
$('.details .' + cssClass + ' .value input').blur(); $('.details .' + cssClass + ' .value input').blur();
} }
@ -272,6 +301,7 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
$('#issue_lock_version').val(lastLockVersion); $('#issue_lock_version').val(lastLockVersion);
var formData = $('#issue-form').serialize(); var formData = $('#issue-form').serialize();
jQuery.ajax({ jQuery.ajax({
type: 'POST', type: 'POST',
url: LOCATION_HREF, url: LOCATION_HREF,
@ -286,23 +316,22 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
var error = $(parsed).find("#errorExplanation"); var error = $(parsed).find("#errorExplanation");
if(error.length) if (error.length) {
{ if ($('html').find("#errorExplanation").length == 0) {
if($('html').find("#errorExplanation").length == 0)
{
$('.issue.details').before("<div id='errorExplanation'>" + error.html() + "</div>"); $('.issue.details').before("<div id='errorExplanation'>" + error.html() + "</div>");
} else } else {
{
$('html').find("#errorExplanation").html(error.html()); $('html').find("#errorExplanation").html(error.html());
} }
/* data updated, remove spin and add success icon for 2sec */ /* data updated, remove spin and add success icon for 2sec */
setTimeout(function(){ setTimeout(function() {
$('.details .' + cssClass + ' i.fa-spin').removeClass('fa-refresh fa-spin').addClass('fa-times statusKo'); $('.details .' + cssClass + ' i.fa-spin').removeClass('fa-refresh fa-spin').addClass('fa-times statusKo');
setTimeout(function(){ setTimeout(function() {
$('.details .' + cssClass + ' i.fa-times.statusKo').remove(); $('.details .' + cssClass + ' i.fa-times.statusKo').remove();
}, 2000); }, 2000);
}, 500); }, 500);
jQuery.ajax({ jQuery.ajax({
type: 'GET', type: 'GET',
url: LOCATION_HREF, url: LOCATION_HREF,
@ -316,29 +345,26 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
parsed = $.parseHTML(msg); parsed = $.parseHTML(msg);
} }
}); });
} else { } else {
/* removing error div if exists */ /* removing error div if exists */
$('html').find("#errorExplanation").remove(); $('html').find("#errorExplanation").remove();
} }
/* we update the details block */ /* we update the details block */
$('div.issue.details').html($(parsed).find('div.issue.details').html()); $('div.issue.details').html( $(parsed).find('div.issue.details').html() );
$('body').find('.details .' + cssClass + ' .value').append(' <i class="fa fa-refresh fa-spin fa-fw"></i>'); $('body').find('.details .' + cssClass + ' .value').append(' <i class="fa fa-refresh fa-spin fa-fw"></i>');
/* we update form*/ /* we update form*/
$('form#issue-form').html($(parsed).find('form#issue-form').html()); $('form#issue-form').html( $(parsed).find('form#issue-form').html() );
/* we update issue properties edit block */ /* we update issue properties edit block */
$('#all_attributes').html($(parsed).find('#all_attributes').html()); $('#all_attributes').html( $(parsed).find('#all_attributes').html() );
/* we init edit fields */ /* we init edit fields */
initEditFields(); initEditFields();
initEditFieldListeners(); initEditFieldListeners();
if($(parsed).find('#required_field_array').length) { if ($(parsed).find('#required_field_array').length) {
updateRequiredFields(JSON.parse($(parsed).find('#required_field_array').html())); updateRequiredFields(JSON.parse($(parsed).find('#required_field_array').html()));
} }
@ -354,13 +380,13 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
}, 500); }, 500);
//set datepicker fallback for input type date //set datepicker fallback for input type date
if( $('body').find('input[type=date]').length if (
&& $('body').find('input[type=date]').datepickerFallback instanceof Function $('body').find('input[type=date]').length &&
&& typeof datepickerOptions !== 'undefined') $('body').find('input[type=date]').datepickerFallback instanceof Function &&
{ typeof datepickerOptions !== 'undefined'
) {
$('body').find('input[type=date]').datepickerFallback(datepickerOptions); $('body').find('input[type=date]').datepickerFallback(datepickerOptions);
} }
}, },
error: function(xhr, msg, error) { error: function(xhr, msg, error) {
/* error and no update, info logged into console */ /* error and no update, info logged into console */
@ -372,6 +398,7 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
console.log('%c error data: ', 'background: black; color: white;');; console.log('%c error data: ', 'background: black; color: white;');;
console.log(error); console.log(error);
console.log('%c ---------------------------------------------------------- ', 'background: #ff0000; color: white; font-weight:900'); 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); $('.details .' + cssClass + ' i.fa-spin').removeClass('fa-refresh fa-spin').addClass('fa-times').html(" " + _TXT_ERROR_AJAX_CALL);
setTimeout(function(){ setTimeout(function(){
$('.details .' + cssClass + ' i.fa-times').remove(); $('.details .' + cssClass + ' i.fa-times').remove();
@ -381,10 +408,9 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){
}; };
/* Listeners foreach attribute */ /* Listeners foreach attribute */
function initEditFieldListeners() function initEditFieldListeners() {
{
var domSelectStatus = $('body').find('#statusListDropdown select'); var domSelectStatus = $('body').find('#statusListDropdown select');
domSelectStatus.on('change', function(e){ domSelectStatus.on('change', function(e) {
issueDynamicUpdate('status_id', domSelectStatus.val(), 'select', 'status'); issueDynamicUpdate('status_id', domSelectStatus.val(), 'select', 'status');
/* update the classes status from */ /* update the classes status from */
@ -414,18 +440,18 @@ function initEditFieldListeners()
}); /* end on change domSelectRatio */ }); /* end on change domSelectRatio */
var domInputEstimatedTime = $('body').find('#EstimatedTimeInput input'); var domInputEstimatedTime = $('body').find('#EstimatedTimeInput input');
$('#EstimatedTimeInput a.btn.validate').on('click', function(e) $('#EstimatedTimeInput a.btn.validate').on('click', function(e) {
{
e.preventDefault(); e.preventDefault();
$('.estimated-hours .value .error').remove(); $('.estimated-hours .value .error').remove();
var estimatedTime = parseFloat(domInputEstimatedTime.val()); var estimatedTime = parseFloat(domInputEstimatedTime.val());
if(estimatedTime >= 0)
{ if (estimatedTime >= 0) {
issueDynamicUpdate('estimated_hours', estimatedTime, 'input', 'estimated-hours'); issueDynamicUpdate('estimated_hours', estimatedTime, 'input', 'estimated-hours');
} else { } else {
/* estimated time must be > 0 */ /* 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>'); $('.estimated-hours .value').append('<span class="error"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> ' + _TXT_ERROR_POSITIVE_NUMBER + '</span>');
} }
return false; return false;
}); });
@ -433,23 +459,24 @@ function initEditFieldListeners()
$('.details .attributes .estimated-hours.attribute .selectedValue span').html( $('.details .attributes .estimated-hours.attribute .selectedValue span').html(
$('.details .attributes .estimated-hours.attribute .value input').val() $('.details .attributes .estimated-hours.attribute .value input').val()
); );
if (e.keyCode == 13) { if (e.keyCode == 13) {
$('#EstimatedTimeInput a.btn.validate').click(); $('#EstimatedTimeInput a.btn.validate').click();
} }
});/* end EstimatedTime */ });/* end EstimatedTime */
var domInputStartDate = $('body').find('#StartDateInput input'); var domInputStartDate = $('body').find('#StartDateInput input');
$('#StartDateInput a.btn.validate').on('click', function(e) $('#StartDateInput a.btn.validate').on('click', function(e) {
{
e.preventDefault(); e.preventDefault();
$('.start-date .value .error').remove(); $('.start-date .value .error').remove();
if(new Date(domInputStartDate.val()).getTime() <= new Date($('body').find('#DueDateInput input').val()).getTime() || $('body').find('#DueDateInput input').val() == "") if (new Date(domInputStartDate.val()).getTime() <= new Date($('body').find('#DueDateInput input').val()).getTime() || $('body').find('#DueDateInput input').val() == "")
{ {
issueDynamicUpdate('start_date', domInputStartDate.val(), 'date', 'start-date'); issueDynamicUpdate('start_date', domInputStartDate.val(), 'date', 'start-date');
} else { } else {
/* start date must be < due date */ /* 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>'); $('.start-date .value').append('<span class="error"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> ' + _TXT_ERROR_START_DATE + '</span>');
} }
return false; return false;
}); });
@ -460,10 +487,10 @@ function initEditFieldListeners()
});/* end StartDate */ });/* end StartDate */
var domInputDueDate = $('body').find('#DueDateInput input'); var domInputDueDate = $('body').find('#DueDateInput input');
$('#DueDateInput a.btn.validate').on('click', function(e) $('#DueDateInput a.btn.validate').on('click', function(e) {
{
e.preventDefault(); e.preventDefault();
$('.due-date .value .error').remove(); $('.due-date .value .error').remove();
if(new Date($('body').find('#StartDateInput input').val()).getTime() <= new Date(domInputDueDate.val()).getTime() || $('body').find('#StartDateInput input').val() == "" ) 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'); issueDynamicUpdate('due_date', domInputDueDate.val(), 'date', 'due-date');
@ -481,8 +508,7 @@ function initEditFieldListeners()
});/* end StartDate */ });/* end StartDate */
var domInputTitle = $('body').find('#TitleInput input'); var domInputTitle = $('body').find('#TitleInput input');
$('#TitleInput a.btn.validate').on('click', function(e) $('#TitleInput a.btn.validate').on('click', function(e) {
{
e.preventDefault(); e.preventDefault();
issueDynamicUpdate('subject', domInputTitle.val(), 'input', 'subject'); issueDynamicUpdate('subject', domInputTitle.val(), 'input', 'subject');
@ -497,15 +523,15 @@ function initEditFieldListeners()
var domInputDescription = $('body').find('#DescriptionInput textarea'); var domInputDescription = $('body').find('#DescriptionInput textarea');
if(domInputDescription.length) if(domInputDescription.length) {
{ $('#DescriptionInput a.btn.validate').on('click', function(e) {
$('#DescriptionInput a.btn.validate').on('click', function(e)
{
e.preventDefault(); e.preventDefault();
var new_value = domInputDescription.val(); var new_value = domInputDescription.val();
if(typeof(CKEDITOR) === "object" if (
&& typeof(CKEDITOR.instances['description_textarea'].getData) === typeof(Function)){ typeof(CKEDITOR) === "object" &&
typeof(CKEDITOR.instances['description_textarea'].getData) === typeof(Function)
) {
new_value = CKEDITOR.instances['description_textarea'].getData(); new_value = CKEDITOR.instances['description_textarea'].getData();
} }
@ -514,18 +540,16 @@ function initEditFieldListeners()
return false; return false;
}); });
if(typeof(jsToolBar) === typeof(Function)) if (typeof(jsToolBar) === typeof(Function)) {
{
var wikiToolbar = new jsToolBar(document.getElementById('description_textarea')); wikiToolbar.draw(); var wikiToolbar = new jsToolBar(document.getElementById('description_textarea')); wikiToolbar.draw();
} else if(typeof(CKEDITOR) === "object" && typeof(CKEDITOR.replace) === typeof(Function)) { } else if (typeof(CKEDITOR) === "object" && typeof(CKEDITOR.replace) === typeof(Function)) {
CKEDITOR.replace('description_textarea', { height: 100 }); CKEDITOR.replace('description_textarea', { height: 100 });
} }
} }
var dynamic_edit_assigned_to_id = $('body').find('#dynamic_edit_assigned_to_id select'); 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){ dynamic_edit_assigned_to_id.on('change', function(e){
issueDynamicUpdate('assigned_to_id', dynamic_edit_assigned_to_id.val(), 'select', 'assigned-to'); issueDynamicUpdate('assigned_to_id', dynamic_edit_assigned_to_id.val(), 'select', 'assigned-to');
}); });
@ -533,8 +557,7 @@ function initEditFieldListeners()
var dynamic_edit_fixed_version = $('body').find('#dynamic_edit_fixed_version select'); 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){ dynamic_edit_fixed_version.on('change', function(e){
issueDynamicUpdate('fixed_version_id', dynamic_edit_fixed_version.val(), 'select', 'fixed-version'); issueDynamicUpdate('fixed_version_id', dynamic_edit_fixed_version.val(), 'select', 'fixed-version');
}); });
@ -543,16 +566,15 @@ function initEditFieldListeners()
/* end Description */ /* end Description */
/* Custom fields */ /* Custom fields */
for(var i = 0 ; i < CF_VALUE_JSON.length ; i++) for (var i = 0 ; i < CF_VALUE_JSON.length ; i++) {
{ (
(function() { function() {
var info = CF_VALUE_JSON[i].custom_field; var info = CF_VALUE_JSON[i].custom_field;
var value = CF_VALUE_JSON[i].value; var value = CF_VALUE_JSON[i].value;
if(info.visible && info.editable)
{ if (info.visible && info.editable) {
var inputType = "input"; var inputType = "input";
switch (info.field_format) switch (info.field_format) {
{
case "bool": case "bool":
case "user": case "user":
case "list": case "list":
@ -563,21 +585,18 @@ function initEditFieldListeners()
case "text": case "text":
inputType = "textarea"; inputType = "textarea";
break; break;
} }
// Specific case : version field with checkboxes // 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"; inputType = "version";
$('body').find('#dynamic_edit_cf_' + info.id + ' input').on('click', function(e){ $('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(); $('label[for=issue_custom_field_values_' + info.id + ']').next().find('input[value=' + $(this).val() + ']').click();
}); });
} }
var domInputField = $('body').find('#dynamic_issue_custom_field_values_' + info.id); 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(); var new_value = domInputField.val();
issueDynamicUpdate('custom_field_values_' + info.id , new_value, inputType, 'cf_' + info.id); issueDynamicUpdate('custom_field_values_' + info.id , new_value, inputType, 'cf_' + info.id);
@ -585,16 +604,15 @@ function initEditFieldListeners()
return false; return false;
}); });
domInputField.on('keyup', function(e){ domInputField.on('keyup', function(e) {
if (e.keyCode == 13 && inputType != "textarea") { if (e.keyCode == 13 && inputType != "textarea") {
$('body').find('#dynamic_edit_cf_' + info.id + ' a.btn.validate').click(); $('body').find('#dynamic_edit_cf_' + info.id + ' a.btn.validate').click();
} }
}); });
} }
}()); // closure FTW }()
); // closure FTW
} }
} }
initEditFieldListeners(); initEditFieldListeners();