[bugzilla-gnome-org-extensions] Improvements for draft handling



commit 74490834f9e91f3cfb02ac5adfdb7cab59ed909c
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sun Oct 4 19:08:27 2009 -0400

    Improvements for draft handling
    
    * Including changes to the attachment status in the "Draft" indicator
    
      (Changes to the attachment status aren't stored in the draft,
      however. This is probably the right thing since someone else might
      change the status before restoring the review.)
    
    * Disable 'Publish' and 'Cancel' buttons when there is no draft
    
    * Hook up the 'Cancel' button with a confirmation dialog.

 js/splinter.js |   43 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 3 deletions(-)
---
diff --git a/js/splinter.js b/js/splinter.js
index 5f211bb..577308f 100644
--- a/js/splinter.js
+++ b/js/splinter.js
@@ -1,5 +1,6 @@
 /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
 include('Bug');
+include('Dialog');
 include('Patch');
 include('Review');
 include('ReviewStorage');
@@ -151,7 +152,35 @@ function publishReview() {
     }
 }
 
+function doDiscardReview() {
+    if (theAttachment.status)
+        $("#attachmentStatus").val(theAttachment.status);
+
+    $("#myComment").val("");
+    $("#emptyCommentNotice").show();
+
+    for (var i = 0; i  < theReview.files.length; i++) {
+        while (theReview.files[i].comments.length > 0)
+            theReview.files[i].comments[0].remove();
+    }
+    updateMyPatchComments();
+
+    updateHaveDraft();
+    saveDraft();
+}
+
+function discardReview() {
+    var dialog = new Dialog.Dialog("Really discard your changes?",
+                                   'Continue', function() {},
+                                   'Discard', doDiscardReview);
+    dialog.show();
+    dialog.focus('Continue');
+}
+
 function haveDraft() {
+    if (theAttachment.status && $("#attachmentStatus").val() != theAttachment.status)
+        return true;
+
     if ($("#myComment").val().search(/\S/) >= 0)
         return true;
 
@@ -167,10 +196,15 @@ function updateHaveDraft() {
     clearTimeout(updateHaveDraftTimeoutId);
     updateHaveDraftTimeoutId = null;
 
-    if (haveDraft())
+    if (haveDraft()) {
+        $("#publishButton").removeAttr('disabled');
+        $("#cancelButton").removeAttr('disabled');
         $("#haveDraftNotice").show();
-    else
+    } else {
+        $("#publishButton").attr('disabled', 1);
+        $("#cancelButton").attr('disabled', 1);
         $("#haveDraftNotice").hide();
+    }
 }
 
 function queueUpdateHaveDraft() {
@@ -803,7 +837,9 @@ function start(xml) {
         .appendTo($("#attachmentStatus")); }
 
     if (theAttachment.status != null)
-        $("#attachmentStatus").val(theAttachment.status);
+        $("#attachmentStatus")
+            .val(theAttachment.status)
+            .change(queueUpdateHaveDraft);
     else
         $("#attachmentStatusSpan").hide();
 
@@ -896,6 +932,7 @@ function start(xml) {
     queueUpdateHaveDraft();
 
     $("#publishButton").click(publishReview);
+    $("#cancelButton").click(discardReview);
 }
 
 function gotBug(xml) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]