diff --git a/dreditor.user.js b/dreditor.user.js index 2df266e..30d9926 100644 --- a/dreditor.user.js +++ b/dreditor.user.js @@ -1553,58 +1553,11 @@ Drupal.behaviors.dreditorIssueSummary = function (context) { /** * Adds a button to insert the issue summary template. */ -Drupal.behaviors.dreditorIssueSummaryTemplate = function (context) { +Drupal.behaviors.dreditorIssueSummaryTemplate = function() { + "use strict"; - // Show a warning on the bare issue summary template edit page. - if (!(location.href.search('node/1326662/edit') === -1)) { - $('body.logged-in.page-node #content').once('dreditorIssueTemplate', function () { - var $content = $(this).hide(); - var $warning = $('
') - .html('WARNING: editing this page affects the Dreditor project. A new window will appear before actually saving this page so you can automatically file an issue to notify the project of this change.') - .css({ - color: '#ff0000', - fontSize: '20px', - lineHeight: '1.25em', - marginBottom: '1em' - }) - .appendTo($content.parent()); - $('') - .addClass('dreditor-button') - .text('Continue') - .click(function(){ - $(this).remove(); - $warning.remove(); - $content.show(); - }) - .appendTo($content.parent()); - var issueOpened = false; - $('#node-form').submit(function(){ - var $form = $(this); - if (!issueOpened) { - var w = window.open('//drupal.org/node/add/project-issue/dreditor#edit-rid-wrapper', '_blank'); - w.onload = function() { - $(w).ready(function() { - setTimeout(function() { - var $doc = $(w.document); - $doc.find('#edit-component').val('Miscellaneous'); - $doc.find('#edit-category').val('task'); - $doc.find('#edit-priority').val('1'); - $doc.find('#edit-assigned').val('501638'); - $doc.find('#edit-sid').val('8'); - $doc.find('#edit-title').val('Updated bare issue summary template').focus(); - $doc.find('#edit-body').val('Log message: ' + $form.find('#edit-log').val()); - issueOpened = true; - $form.trigger('submit'); - }, 10); - }); - } - return false; - } - }); - }); - } - // Add the template button above the issue summary field. - $('body.logged-in.page-node div.project-issue #edit-body').once('dreditorIssueTemplate', function () { + // Add the template button above the issue summary field. + $('body.logged-in.page-node div.project-issue #edit-body').once('dreditorIssueTemplate', function() { var $body = $(this); // Append this button to the label area. @@ -1619,20 +1572,25 @@ Drupal.behaviors.dreditorIssueSummaryTemplate = function (context) { }) .text('Insert template') .appendTo($label) - .click(function () { + .click(function() { // Load the issue summary instructions. - $.get('//drupal.org/node/1326662', function (data) { + $.get('//drupal.org/node/1326662', function(data) { // Retrieve the template. var $template = $('').html($(data).find('#node-1326662 code').text()); // On node add, remove the "Original report by" section. - if (!(location.href.search('node/add') === -1)) { + if (location.href.search('node/add') !== -1) { $template.find('#summary-original-report').remove(); } // On quick edit, we can go ahead and replace the @username with the // existing link to the original author. else if (!location.href.match(/^.*node\/[^\/]*\/edit/)) { var $profileLink = $('div.node > div.submitted a').clone(); - $profileLink.text('@' + $profileLink.text()); + if ($profileLink.length) { + $profileLink.text('@' + $profileLink.text()); + } + else { + $profileLink = $('').text('Anonymous').attr('href', '#'); + } $template.find('#summary-original-report a').replaceWith($('').html($profileLink).html()); } // On actual node edit pages, we need to do an AJAX callback to get @@ -1642,9 +1600,13 @@ Drupal.behaviors.dreditorIssueSummaryTemplate = function (context) { var nodePath = location.href.match(/^.*node\/[0-9]*/); if (nodePath) { $.getJSON(nodePath[0] + '/project-issue/json', function(json){ - // Find the link to the original poster's profile. - var $profileLink = $('').text('@' + json.authorName).attr('href', json.authorUrl); - var $bodyVal = $('').html($body.val()); + var $profileLink, $bodyVal = $('').html($body.val()); + if (json.assignedUrl) { + $profileLink = $('').text('@' + json.authorName).attr('href', json.authorUrl); + } + else { + $profileLink = $('').text('Anonymous').attr('href', '#'); + } $bodyVal.find('#summary-original-report a').replaceWith($('').html($profileLink).html()); $body.val($bodyVal.html()); }); @@ -1655,15 +1617,63 @@ Drupal.behaviors.dreditorIssueSummaryTemplate = function (context) { }); // Take no action other than executing the .click() behavior. return false; - } - ); + }); // Add a link to view the issue summary instructions. - $('Issue summary standards') + $('Issue summary instructions') .appendTo($label) .before('(') .after(')'); }); + + // Show a warning on the bare issue summary template edit page. + if (location.href.search('node/1326662/edit') !== -1) { + $('body.logged-in.page-node #content').once('dreditorIssueTemplate', function () { + var $content = $(this).hide(); + var $warning = $('') + .html('WARNING: editing this page affects the Dreditor project. A new window will appear before actually saving this page so you can automatically file an issue to notify the project of this change.') + .css({ + color: '#ff0000', + fontSize: '20px', + lineHeight: '1.25em', + marginBottom: '0.5em' + }) + .appendTo($content.parent()); + $('') + .addClass('dreditor-button') + .text('Continue') + .appendTo($content.parent()) + .click(function() { + $(this).remove(); + $warning.remove(); + $content.show(); + }); + var issueOpened = false; + $('#node-form').submit(function(e) { + var $form = $(this); + if (!issueOpened) { + var w = window.open('//drupal.org/node/add/project-issue/dreditor#edit-rid-wrapper', '_blank'); + w.onload = function() { + $(w).ready(function() { + setTimeout(function() { + var $doc = $(w.document); + $doc.find('#edit-component').val('Miscellaneous'); + $doc.find('#edit-category').val('task'); + $doc.find('#edit-priority').val('1'); + $doc.find('#edit-sid').val('8'); + $doc.find('#edit-title').val('Updated bare issue summary template').focus(); + $doc.find('#edit-body').val('Log message: ' + $form.find('#edit-log').val()); + issueOpened = true; + $form.trigger('submit'); + }, 10); + }); + } + e.preventDefault(); + } + }); + }); + } + }; /**