[bugzilla-gnome-org-extensions] Handle deleting everything from a draft



commit f9923212398f6c0d2e5c4c4d28d7631924d1f498
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Oct 3 14:56:48 2009 -0400

    Handle deleting everything from a draft
    
    If you delete all text/comments from a draft, delete the draft, rather
    than saving an empty draft.

 js/reviewStorage.js |   15 +++++++++++++++
 js/splinter.js      |   28 +++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)
---
diff --git a/js/reviewStorage.js b/js/reviewStorage.js
index e4185f5..dc118a4 100644
--- a/js/reviewStorage.js
+++ b/js/reviewStorage.js
@@ -96,6 +96,14 @@ LocalReviewStorage.prototype = {
         localStorage.splinterReviews = JSON.stringify(this._reviewInfos);
     },
 
+    _deleteReviewInfo : function(bug, attachment) {
+        var reviewIndex = this._findReview(bug, attachment);
+        if (reviewIndex >= 0) {
+            this._reviewInfos.splice(reviewIndex, 1);
+            localStorage.splinterReviews = JSON.stringify(this._reviewInfos);
+        }
+    },
+
     saveDraft : function(bug, attachment, review) {
         var propertyName = this._reviewPropertyName(bug, attachment);
 
@@ -103,6 +111,13 @@ LocalReviewStorage.prototype = {
         localStorage[propertyName] = "" + review;
     },
 
+    deleteDraft : function(bug, attachment, review) {
+        var propertyName = this._reviewPropertyName(bug, attachment);
+
+        this._deleteReviewInfo(bug, attachment);
+        delete localStorage[propertyName];
+    },
+
     draftPublished : function(bug, attachment) {
         var propertyName = this._reviewPropertyName(bug, attachment);
 
diff --git a/js/splinter.js b/js/splinter.js
index d11a452..d9a5917 100644
--- a/js/splinter.js
+++ b/js/splinter.js
@@ -148,7 +148,20 @@ function publishReview() {
     }
 }
 
+function haveDraft() {
+    if ($("#myComment").val().search(/\S/) >= 0)
+        return true;
+
+    for (var i = 0; i  < theReview.files.length; i++) {
+        if (theReview.files[i].comments.length > 0)
+            return true;
+    }
+
+    return false;
+}
+
 function hideSaveDraftNotice() {
+    clearTimeout(saveDraftNoticeTimeoutId);
     saveDraftNoticeTimeoutId = null;
     $("#saveDraftNotice").hide();
 }
@@ -177,7 +190,13 @@ function saveDraft() {
 
     theReview.setIntro($("#myComment").val());
 
-    reviewStorage.saveDraft(theBug, theAttachment, theReview);
+    var draftSaved = false;
+    if (haveDraft()) {
+        reviewStorage.saveDraft(theBug, theAttachment, theReview);
+        draftSaved = true;
+    } else {
+        reviewStorage.deleteDraft(theBug, theAttachment, theReview);
+    }
 
     if (currentEditComment && !currentEditComment.comment) {
         currentEditComment = currentEditComment.file.addComment(currentEditComment.location,
@@ -186,8 +205,11 @@ function saveDraft() {
     }
 
     savingDraft = false;
-    $("#saveDraftNotice")
-        .text("Saved Draft");
+    if (draftSaved)
+        $("#saveDraftNotice")
+            .text("Saved Draft");
+    else
+        hideSaveDraftNotice();
 }
 
 function queueSaveDraft() {


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