diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-05-06 18:13:16 +0300 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-05-20 23:58:36 +0300 |
commit | fab9dbb3eba55151c34fc8bc171e3670e6c7c422 (patch) | |
tree | c08e23dde57ed18176ea3d7b408c877b81c0fec0 /app/assets/javascripts/blob | |
parent | e166a8022a3f239938a1449a0a8ce3485f309766 (diff) |
First import of gitignores
Add .gitignore dropdown when creating a new .gitignore file
Signed-off-by: Alfredo Sumaran <alfredo@gitlab.com>
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r-- | app/assets/javascripts/blob/blob_gitignore_selector.js.coffee | 62 | ||||
-rw-r--r-- | app/assets/javascripts/blob/edit_blob.js.coffee | 1 |
2 files changed, 63 insertions, 0 deletions
diff --git a/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee b/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee new file mode 100644 index 00000000000..b413f31da00 --- /dev/null +++ b/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee @@ -0,0 +1,62 @@ +class @BlobGitIgnoreSelector + constructor: (opts) -> + { + @dropdown + @editor + @wrapper = @dropdown.parents('.gitignore-selector') + @fileNameInput = $('#file_name') + @data = @dropdown.data('filenames') + } = opts + + @dropdown.glDropdown( + data: @data, + filterable: true, + selectable: true, + search: + fields: ['text'] + clicked: @onClick.bind(@) + ) + + @toggleGitIgnoreSelector() + @bindEvents() + + bindEvents: -> + @fileNameInput + .on 'keyup blur', (e) => + @toggleGitIgnoreSelector() + + toggleGitIgnoreSelector: -> + filename = @fileNameInput.val() or $('.editor-file-name').text().trim() + @wrapper.toggleClass 'hidden', filename isnt '.gitignore' + + onClick: (item) -> + @requestIgnoreFile(item.text) + + requestIgnoreFile: (name) -> + Api.gitIgnoreText name, @requestIgnoreFileSuccess.bind(@) + + requestIgnoreFileSuccess: (gitignore) -> + @editor.setValue(gitignore.content, -1) + + # Move cursor position to end of file + row = @editor.session.getLength() - 1 + column = @editor.session.getLine(row).length + @editor.gotoLine(row + 1, column) + @editor.focus() + +class @BlobGitIgnoreSelectors + constructor: (opts) -> + _this = @ + + { + @dropdowns = $('.js-gitignore-selector') + @editor + } = opts + + @dropdowns.each -> + $dropdown = $(@) + + new BlobGitIgnoreSelector( + dropdown: $dropdown, + editor: _this.editor + ) diff --git a/app/assets/javascripts/blob/edit_blob.js.coffee b/app/assets/javascripts/blob/edit_blob.js.coffee index eea9aa972ee..f2efeb3960a 100644 --- a/app/assets/javascripts/blob/edit_blob.js.coffee +++ b/app/assets/javascripts/blob/edit_blob.js.coffee @@ -13,6 +13,7 @@ class @EditBlob @initModePanesAndLinks() new BlobLicenseSelector(@editor) + new BlobGitIgnoreSelectors(editor: @editor) initModePanesAndLinks: -> @$editModePanes = $(".js-edit-mode-pane") |