Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 81 additions & 2 deletions assets/javascripts/issue_dynamic_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,38 @@ const SVG_EDIT = '<svg style="width: 1em; height: 1em;" version="1.1" viewBox="0
const SVG_VALID = '<svg style="width: 1em; height: 1em; fill:white;" version="1.1" viewBox="0 0 24 24" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="info"/><g id="icons"><path d="M10,18c-0.5,0-1-0.2-1.4-0.6l-4-4c-0.8-0.8-0.8-2,0-2.8c0.8-0.8,2.1-0.8,2.8,0l2.6,2.6l6.6-6.6 c0.8-0.8,2-0.8,2.8,0c0.8,0.8,0.8,2,0,2.8l-8,8C11,17.8,10.5,18,10,18z" class="svg_check"/></g></svg>';
const SVG_CANCEL = '<svg style="width: 1em; height: 1em;" version="1.1" viewBox="0 0 24 24" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="info"/><g id="icons"><path d="M14.8,12l3.6-3.6c0.8-0.8,0.8-2,0-2.8c-0.8-0.8-2-0.8-2.8,0L12,9.2L8.4,5.6c-0.8-0.8-2-0.8-2.8,0 c-0.8,0.8-0.8,2,0,2.8L9.2,12l-3.6,3.6c-0.8,0.8-0.8,2,0,2.8C6,18.8,6.5,19,7,19s1-0.2,1.4-0.6l3.6-3.6l3.6,3.6 C16,18.8,16.5,19,17,19s1-0.2,1.4-0.6c0.8-0.8,0.8-2,0-2.8L14.8,12z" class="svg_cancel"/></g></svg>';

/*
* History DIV
*/

const HISTORY_DIV = `
<div id="history">
<div class="tabs">
<ul>
<li><a id="tab-history" class="selected" onclick="showIssueHistory(&quot;history&quot;, this.href); return false;" href="/issues/38?tab=history">History</a></li>
<li><a id="tab-notes" onclick="showIssueHistory(&quot;notes&quot;, this.href); return false;" href="/issues/38?tab=notes">Notes</a></li>
<li><a id="tab-properties" onclick="showIssueHistory(&quot;properties&quot;, this.href); return false;" href="/issues/38?tab=properties">Property changes</a></li>
</ul>
<div class="tabs-buttons" style="display: none;">
<button class="tab-left" type="button" onclick="moveTabLeft(this);"></button>
<button class="tab-right" type="button" onclick="moveTabRight(this);"></button>
</div>
</div>
<div id="tab-content-history" class="tab-content" style=""></div>
</div>`


/*
* Allow inclusion from other page
* See https://github.com/Ilogeek/redmine_issue_dynamic_edit/commit/26684a2dd9b12dcc7377afd79e9fe5c142d26ebd for more info
*/
let LOCATION_HREF = typeof custom_location_href !== 'undefined' ? custom_location_href : window.location.href;

let clean_url = (url) => {
let nu = new URL(url);
return `${nu.protocol}//${nu.host}${nu.pathname}`;
}

let LOCATION_HREF = typeof custom_location_href !== 'undefined' ? custom_location_href : clean_url(window.location.href);

if (_CONF_FORCE_HTTPS) {
LOCATION_HREF = LOCATION_HREF.replace(/^http:\/\//i, 'https://');
Expand Down Expand Up @@ -118,6 +145,26 @@ const getEditFormHTML = function(attribute){
return null;
}

const item_is_visible = function (selectedTabId, item) {
//item is an array of dom elements. We need to reach the div.journal
var div = $(item).filter('div.journal').first();
if(selectedTabId == "tab-notes") {
if($(div).hasClass("has-notes")) {
return true;
} else {
return false;
}
} else if(selectedTabId == "tab-properties") {
if($(div).hasClass("has-details")) {
return true;
} else {
return false;
}
} else {
return true;
}
}

/* Loop over all form attribute and clone them into details part */
const cloneEditForm = function(){
const btn_refresh = document.createElement('button');
Expand Down Expand Up @@ -409,7 +456,39 @@ let sendData = function(serialized_data){
document.querySelector('form#issue-form').innerHTML = doc.querySelector('form#issue-form').innerHTML;
document.querySelector('#all_attributes').innerHTML = doc.querySelector('#all_attributes').innerHTML;
document.querySelector('div.issue.details').innerHTML = doc.querySelector('div.issue.details').innerHTML;
document.querySelector('#tab-content-history').appendChild(doc.querySelector('#history .journal.has-details:last-child'));

let tch = document.querySelector('#tab-content-history');
// sometimes, there will be no tab-content-history yet (like when the issue was just created).
if(!tch) {
let parser = new DOMParser();
let dom = parser.parseFromString(HISTORY_DIV, 'text/html');
let newHistory = dom.querySelector('div');
let oldHistory = document.querySelector('div#history');
oldHistory.parentNode.replaceChild(newHistory, oldHistory);
tch = document.querySelector('#tab-content-history');
}

let query
if(_COMMENTS_IN_REVERSE_ORDER_) {
query = '#history .journal.has-details:first-child';
} else {
query = '#history .journal.has-details:last-child';
}

let journal = doc.querySelector(query);
if(journal) {
let selectedTabId = $("#history .tabs ul li a.selected").attr("id");
if(!item_is_visible(selectedTabId, journal)) {
$(journal).css('display', 'none');
}

if(_COMMENTS_IN_REVERSE_ORDER_) {
tch.insertBefore(journal, tch.firstChild);
} else {
tch.appendChild(journal);
}
}

document.querySelector('#issue_lock_version').value = doc.querySelector("#issue_lock_version").value;

cloneEditForm();
Expand Down
1 change: 1 addition & 0 deletions lib/details_issue_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def view_issues_show_details_bottom(context)
content << " const _TXT_CONFLICT_TITLE = \"" + l(:ide_txt_notice_conflict_title) + "\";\n"
content << " const _TXT_CONFLICT_TXT = \"" + l(:ide_txt_notice_conflict_text) + "\";\n"
content << " const _TXT_CONFLICT_LINK = \"" + l(:ide_txt_notice_conflict_link) + "\";\n"
content << " const _COMMENTS_IN_REVERSE_ORDER_ = #{User.current.wants_comments_in_reverse_order? ? 'true' : 'false'};\n"
content << "</script>\n"
content << "<style>/* PRINT MEDIAQUERY */\n"
content << "@media print {\n"
Expand Down