diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-02-06 16:21:26 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-02-07 20:55:17 +0100 |
commit | 463d9f76e449849be15926a7df0564fbc9a35452 (patch) | |
tree | 001f28b827d8596d54061eed0d98f5a5864ed6b2 /app | |
parent | bc57ff0ef023db3d07f1adfa6a309fb4a24ed203 (diff) | |
download | gitlab-ce-463d9f76e449849be15926a7df0564fbc9a35452.tar.gz |
Autosave and autorestore unsaved comments.
Closes #1738.
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/application.js.coffee | 1 | ||||
-rw-r--r-- | app/assets/javascripts/autosave.js.coffee | 33 | ||||
-rw-r--r-- | app/assets/javascripts/notes.js.coffee | 17 |
3 files changed, 49 insertions, 2 deletions
diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 4912c534b0e..9c97582e6dd 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -17,6 +17,7 @@ #= require jquery.blockUI #= require jquery.turbolinks #= require turbolinks +#= require autosave #= require bootstrap #= require select2 #= require raphael diff --git a/app/assets/javascripts/autosave.js.coffee b/app/assets/javascripts/autosave.js.coffee new file mode 100644 index 00000000000..3450f4b55f7 --- /dev/null +++ b/app/assets/javascripts/autosave.js.coffee @@ -0,0 +1,33 @@ +class @Autosave + constructor: (field, key) -> + @field = field + + key = key.join("/") if key.join? + @key = "autosave/#{key}" + + @field.data "autosave", this + + @restore() + + @field.on "input", => @save() + + restore: -> + return unless window.localStorage? + + text = window.localStorage.getItem @key + @field.val text if text?.length > 0 + @field.trigger "input" + + save: -> + return unless window.localStorage? + + text = @field.val() + if text?.length > 0 + window.localStorage.setItem @key, text + else + @reset() + + reset: -> + return unless window.localStorage? + + window.localStorage.removeItem @key
\ No newline at end of file diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee index 15597060c6b..37a7b31d3c8 100644 --- a/app/assets/javascripts/notes.js.coffee +++ b/app/assets/javascripts/notes.js.coffee @@ -170,6 +170,8 @@ class @Notes form.find(".js-md-write-button").click() form.find(".js-note-text").val("").trigger "input" + form.find(".js-note-text").data("autosave").reset() + ### Called when clicking the "Choose File" button. @@ -220,12 +222,22 @@ class @Notes # setup preview buttons form.find(".js-md-write-button, .js-md-preview-button").tooltip placement: "left" previewButton = form.find(".js-md-preview-button") - form.find(".js-note-text").on "input", -> + + textarea = form.find(".js-note-text") + + textarea.on "input", -> if $(this).val().trim() isnt "" previewButton.removeClass("turn-off").addClass "turn-on" else previewButton.removeClass("turn-on").addClass "turn-off" + new Autosave textarea, [ + "Note" + form.find("#note_commit_id").val() + form.find("#note_line_code").val() + form.find("#note_noteable_type").val() + form.find("#note_noteable_id").val() + ] # remove notify commit author checkbox for non-commit notes form.find(".js-notify-commit-author").remove() if form.find("#note_noteable_type").val() isnt "Commit" @@ -233,7 +245,6 @@ class @Notes new DropzoneInput(form) form.show() - ### Called in response to the new note form being submitted @@ -407,6 +418,8 @@ class @Notes removeDiscussionNoteForm: (form)-> row = form.closest("tr") + form.find(".js-note-text").data("autosave").reset() + # show the reply button (will only work for replies) form.prev(".js-discussion-reply-button").show() if row.is(".js-temp-notes-holder") |