summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r--app/assets/javascripts/blob/blob_ci_yaml.js46
-rw-r--r--app/assets/javascripts/blob/blob_ci_yaml.js.coffee23
-rw-r--r--app/assets/javascripts/blob/blob_file_dropzone.js62
-rw-r--r--app/assets/javascripts/blob/blob_file_dropzone.js.coffee57
-rw-r--r--app/assets/javascripts/blob/blob_gitignore_selector.js23
-rw-r--r--app/assets/javascripts/blob/blob_gitignore_selector.js.coffee5
-rw-r--r--app/assets/javascripts/blob/blob_gitignore_selectors.js25
-rw-r--r--app/assets/javascripts/blob/blob_gitignore_selectors.js.coffee17
-rw-r--r--app/assets/javascripts/blob/blob_license_selector.js28
-rw-r--r--app/assets/javascripts/blob/blob_license_selector.js.coffee9
-rw-r--r--app/assets/javascripts/blob/blob_license_selectors.js25
-rw-r--r--app/assets/javascripts/blob/blob_license_selectors.js.coffee17
-rw-r--r--app/assets/javascripts/blob/edit_blob.js66
-rw-r--r--app/assets/javascripts/blob/edit_blob.js.coffee42
-rw-r--r--app/assets/javascripts/blob/template_selector.js74
-rw-r--r--app/assets/javascripts/blob/template_selector.js.coffee60
16 files changed, 349 insertions, 230 deletions
diff --git a/app/assets/javascripts/blob/blob_ci_yaml.js b/app/assets/javascripts/blob/blob_ci_yaml.js
new file mode 100644
index 00000000000..68758574967
--- /dev/null
+++ b/app/assets/javascripts/blob/blob_ci_yaml.js
@@ -0,0 +1,46 @@
+
+/*= require blob/template_selector */
+
+(function() {
+ var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
+ hasProp = {}.hasOwnProperty;
+
+ this.BlobCiYamlSelector = (function(superClass) {
+ extend(BlobCiYamlSelector, superClass);
+
+ function BlobCiYamlSelector() {
+ return BlobCiYamlSelector.__super__.constructor.apply(this, arguments);
+ }
+
+ BlobCiYamlSelector.prototype.requestFile = function(query) {
+ return Api.gitlabCiYml(query.name, this.requestFileSuccess.bind(this));
+ };
+
+ return BlobCiYamlSelector;
+
+ })(TemplateSelector);
+
+ this.BlobCiYamlSelectors = (function() {
+ function BlobCiYamlSelectors(opts) {
+ var ref;
+ this.$dropdowns = (ref = opts.$dropdowns) != null ? ref : $('.js-gitlab-ci-yml-selector'), this.editor = opts.editor;
+ this.$dropdowns.each((function(_this) {
+ return function(i, dropdown) {
+ var $dropdown;
+ $dropdown = $(dropdown);
+ return new BlobCiYamlSelector({
+ pattern: /(.gitlab-ci.yml)/,
+ data: $dropdown.data('data'),
+ wrapper: $dropdown.closest('.js-gitlab-ci-yml-selector-wrap'),
+ dropdown: $dropdown,
+ editor: _this.editor
+ });
+ };
+ })(this));
+ }
+
+ return BlobCiYamlSelectors;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/blob_ci_yaml.js.coffee b/app/assets/javascripts/blob/blob_ci_yaml.js.coffee
deleted file mode 100644
index d9a03d05529..00000000000
--- a/app/assets/javascripts/blob/blob_ci_yaml.js.coffee
+++ /dev/null
@@ -1,23 +0,0 @@
-#= require blob/template_selector
-
-class @BlobCiYamlSelector extends TemplateSelector
- requestFile: (query) ->
- Api.gitlabCiYml query.name, @requestFileSuccess.bind(@)
-
-class @BlobCiYamlSelectors
- constructor: (opts) ->
- {
- @$dropdowns = $('.js-gitlab-ci-yml-selector')
- @editor
- } = opts
-
- @$dropdowns.each (i, dropdown) =>
- $dropdown = $(dropdown)
-
- new BlobCiYamlSelector(
- pattern: /(.gitlab-ci.yml)/,
- data: $dropdown.data('data'),
- wrapper: $dropdown.closest('.js-gitlab-ci-yml-selector-wrap'),
- dropdown: $dropdown,
- editor: @editor
- )
diff --git a/app/assets/javascripts/blob/blob_file_dropzone.js b/app/assets/javascripts/blob/blob_file_dropzone.js
new file mode 100644
index 00000000000..f4044f22db2
--- /dev/null
+++ b/app/assets/javascripts/blob/blob_file_dropzone.js
@@ -0,0 +1,62 @@
+(function() {
+ this.BlobFileDropzone = (function() {
+ function BlobFileDropzone(form, method) {
+ var dropzone, form_dropzone, submitButton;
+ form_dropzone = form.find('.dropzone');
+ Dropzone.autoDiscover = false;
+ dropzone = form_dropzone.dropzone({
+ autoDiscover: false,
+ autoProcessQueue: false,
+ url: form.attr('action'),
+ method: method,
+ clickable: true,
+ uploadMultiple: false,
+ paramName: "file",
+ maxFilesize: gon.max_file_size || 10,
+ parallelUploads: 1,
+ maxFiles: 1,
+ addRemoveLinks: true,
+ previewsContainer: '.dropzone-previews',
+ headers: {
+ "X-CSRF-Token": $("meta[name=\"csrf-token\"]").attr("content")
+ },
+ init: function() {
+ this.on('addedfile', function(file) {
+ $('.dropzone-alerts').html('').hide();
+ });
+ this.on('success', function(header, response) {
+ window.location.href = response.filePath;
+ });
+ this.on('maxfilesexceeded', function(file) {
+ this.removeFile(file);
+ });
+ return this.on('sending', function(file, xhr, formData) {
+ formData.append('target_branch', form.find('.js-target-branch').val());
+ formData.append('create_merge_request', form.find('.js-create-merge-request').val());
+ formData.append('commit_message', form.find('.js-commit-message').val());
+ });
+ },
+ error: function(file, errorMessage) {
+ var stripped;
+ stripped = $("<div/>").html(errorMessage).text();
+ $('.dropzone-alerts').html('Error uploading file: \"' + stripped + '\"').show();
+ this.removeFile(file);
+ }
+ });
+ submitButton = form.find('#submit-all')[0];
+ submitButton.addEventListener('click', function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ if (dropzone[0].dropzone.getQueuedFiles().length === 0) {
+ alert("Please select a file");
+ }
+ dropzone[0].dropzone.processQueue();
+ return false;
+ });
+ }
+
+ return BlobFileDropzone;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/blob_file_dropzone.js.coffee b/app/assets/javascripts/blob/blob_file_dropzone.js.coffee
deleted file mode 100644
index 9df932817f6..00000000000
--- a/app/assets/javascripts/blob/blob_file_dropzone.js.coffee
+++ /dev/null
@@ -1,57 +0,0 @@
-class @BlobFileDropzone
- constructor: (form, method) ->
- form_dropzone = form.find('.dropzone')
- Dropzone.autoDiscover = false
- dropzone = form_dropzone.dropzone(
- autoDiscover: false
- autoProcessQueue: false
- url: form.attr('action')
- # Rails uses a hidden input field for PUT
- # http://stackoverflow.com/questions/21056482/how-to-set-method-put-in-form-tag-in-rails
- method: method
- clickable: true
- uploadMultiple: false
- paramName: "file"
- maxFilesize: gon.max_file_size or 10
- parallelUploads: 1
- maxFiles: 1
- addRemoveLinks: true
- previewsContainer: '.dropzone-previews'
- headers:
- "X-CSRF-Token": $("meta[name=\"csrf-token\"]").attr("content")
-
- init: ->
- this.on 'addedfile', (file) ->
- $('.dropzone-alerts').html('').hide()
-
- return
-
- this.on 'success', (header, response) ->
- window.location.href = response.filePath
- return
-
- this.on 'maxfilesexceeded', (file) ->
- @removeFile file
- return
-
- this.on 'sending', (file, xhr, formData) ->
- formData.append('target_branch', form.find('.js-target-branch').val())
- formData.append('create_merge_request', form.find('.js-create-merge-request').val())
- formData.append('commit_message', form.find('.js-commit-message').val())
- return
-
- # Override behavior of adding error underneath preview
- error: (file, errorMessage) ->
- stripped = $("<div/>").html(errorMessage).text();
- $('.dropzone-alerts').html('Error uploading file: \"' + stripped + '\"').show()
- @removeFile file
- return
- )
-
- submitButton = form.find('#submit-all')[0]
- submitButton.addEventListener 'click', (e) ->
- e.preventDefault()
- e.stopPropagation()
- alert "Please select a file" if dropzone[0].dropzone.getQueuedFiles().length == 0
- dropzone[0].dropzone.processQueue()
- return false
diff --git a/app/assets/javascripts/blob/blob_gitignore_selector.js b/app/assets/javascripts/blob/blob_gitignore_selector.js
new file mode 100644
index 00000000000..54a09e919f8
--- /dev/null
+++ b/app/assets/javascripts/blob/blob_gitignore_selector.js
@@ -0,0 +1,23 @@
+
+/*= require blob/template_selector */
+
+(function() {
+ var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
+ hasProp = {}.hasOwnProperty;
+
+ this.BlobGitignoreSelector = (function(superClass) {
+ extend(BlobGitignoreSelector, superClass);
+
+ function BlobGitignoreSelector() {
+ return BlobGitignoreSelector.__super__.constructor.apply(this, arguments);
+ }
+
+ BlobGitignoreSelector.prototype.requestFile = function(query) {
+ return Api.gitignoreText(query.name, this.requestFileSuccess.bind(this));
+ };
+
+ return BlobGitignoreSelector;
+
+ })(TemplateSelector);
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee b/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee
deleted file mode 100644
index 8d0e3f363d1..00000000000
--- a/app/assets/javascripts/blob/blob_gitignore_selector.js.coffee
+++ /dev/null
@@ -1,5 +0,0 @@
-#= require blob/template_selector
-
-class @BlobGitignoreSelector extends TemplateSelector
- requestFile: (query) ->
- Api.gitignoreText query.name, @requestFileSuccess.bind(@)
diff --git a/app/assets/javascripts/blob/blob_gitignore_selectors.js b/app/assets/javascripts/blob/blob_gitignore_selectors.js
new file mode 100644
index 00000000000..4e9500428b2
--- /dev/null
+++ b/app/assets/javascripts/blob/blob_gitignore_selectors.js
@@ -0,0 +1,25 @@
+(function() {
+ this.BlobGitignoreSelectors = (function() {
+ function BlobGitignoreSelectors(opts) {
+ var ref;
+ this.$dropdowns = (ref = opts.$dropdowns) != null ? ref : $('.js-gitignore-selector'), this.editor = opts.editor;
+ this.$dropdowns.each((function(_this) {
+ return function(i, dropdown) {
+ var $dropdown;
+ $dropdown = $(dropdown);
+ return new BlobGitignoreSelector({
+ pattern: /(.gitignore)/,
+ data: $dropdown.data('data'),
+ wrapper: $dropdown.closest('.js-gitignore-selector-wrap'),
+ dropdown: $dropdown,
+ editor: _this.editor
+ });
+ };
+ })(this));
+ }
+
+ return BlobGitignoreSelectors;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/blob_gitignore_selectors.js.coffee b/app/assets/javascripts/blob/blob_gitignore_selectors.js.coffee
deleted file mode 100644
index a719ba25122..00000000000
--- a/app/assets/javascripts/blob/blob_gitignore_selectors.js.coffee
+++ /dev/null
@@ -1,17 +0,0 @@
-class @BlobGitignoreSelectors
- constructor: (opts) ->
- {
- @$dropdowns = $('.js-gitignore-selector')
- @editor
- } = opts
-
- @$dropdowns.each (i, dropdown) =>
- $dropdown = $(dropdown)
-
- new BlobGitignoreSelector(
- pattern: /(.gitignore)/,
- data: $dropdown.data('data'),
- wrapper: $dropdown.closest('.js-gitignore-selector-wrap'),
- dropdown: $dropdown,
- editor: @editor
- )
diff --git a/app/assets/javascripts/blob/blob_license_selector.js b/app/assets/javascripts/blob/blob_license_selector.js
new file mode 100644
index 00000000000..9a8ef08f4e5
--- /dev/null
+++ b/app/assets/javascripts/blob/blob_license_selector.js
@@ -0,0 +1,28 @@
+
+/*= require blob/template_selector */
+
+(function() {
+ var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
+ hasProp = {}.hasOwnProperty;
+
+ this.BlobLicenseSelector = (function(superClass) {
+ extend(BlobLicenseSelector, superClass);
+
+ function BlobLicenseSelector() {
+ return BlobLicenseSelector.__super__.constructor.apply(this, arguments);
+ }
+
+ BlobLicenseSelector.prototype.requestFile = function(query) {
+ var data;
+ data = {
+ project: this.dropdown.data('project'),
+ fullname: this.dropdown.data('fullname')
+ };
+ return Api.licenseText(query.id, data, this.requestFileSuccess.bind(this));
+ };
+
+ return BlobLicenseSelector;
+
+ })(TemplateSelector);
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/blob_license_selector.js.coffee b/app/assets/javascripts/blob/blob_license_selector.js.coffee
deleted file mode 100644
index a3cc8dd844c..00000000000
--- a/app/assets/javascripts/blob/blob_license_selector.js.coffee
+++ /dev/null
@@ -1,9 +0,0 @@
-#= require blob/template_selector
-
-class @BlobLicenseSelector extends TemplateSelector
- requestFile: (query) ->
- data =
- project: @dropdown.data('project')
- fullname: @dropdown.data('fullname')
-
- Api.licenseText query.id, data, @requestFileSuccess.bind(@)
diff --git a/app/assets/javascripts/blob/blob_license_selectors.js b/app/assets/javascripts/blob/blob_license_selectors.js
new file mode 100644
index 00000000000..39237705e8d
--- /dev/null
+++ b/app/assets/javascripts/blob/blob_license_selectors.js
@@ -0,0 +1,25 @@
+(function() {
+ this.BlobLicenseSelectors = (function() {
+ function BlobLicenseSelectors(opts) {
+ var ref;
+ this.$dropdowns = (ref = opts.$dropdowns) != null ? ref : $('.js-license-selector'), this.editor = opts.editor;
+ this.$dropdowns.each((function(_this) {
+ return function(i, dropdown) {
+ var $dropdown;
+ $dropdown = $(dropdown);
+ return new BlobLicenseSelector({
+ pattern: /^(.+\/)?(licen[sc]e|copying)($|\.)/i,
+ data: $dropdown.data('data'),
+ wrapper: $dropdown.closest('.js-license-selector-wrap'),
+ dropdown: $dropdown,
+ editor: _this.editor
+ });
+ };
+ })(this));
+ }
+
+ return BlobLicenseSelectors;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/blob_license_selectors.js.coffee b/app/assets/javascripts/blob/blob_license_selectors.js.coffee
deleted file mode 100644
index 68438733108..00000000000
--- a/app/assets/javascripts/blob/blob_license_selectors.js.coffee
+++ /dev/null
@@ -1,17 +0,0 @@
-class @BlobLicenseSelectors
- constructor: (opts) ->
- {
- @$dropdowns = $('.js-license-selector')
- @editor
- } = opts
-
- @$dropdowns.each (i, dropdown) =>
- $dropdown = $(dropdown)
-
- new BlobLicenseSelector(
- pattern: /^(.+\/)?(licen[sc]e|copying)($|\.)/i,
- data: $dropdown.data('data'),
- wrapper: $dropdown.closest('.js-license-selector-wrap'),
- dropdown: $dropdown,
- editor: @editor
- )
diff --git a/app/assets/javascripts/blob/edit_blob.js b/app/assets/javascripts/blob/edit_blob.js
new file mode 100644
index 00000000000..649c79daee8
--- /dev/null
+++ b/app/assets/javascripts/blob/edit_blob.js
@@ -0,0 +1,66 @@
+(function() {
+ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ this.EditBlob = (function() {
+ function EditBlob(assets_path, ace_mode) {
+ if (ace_mode == null) {
+ ace_mode = null;
+ }
+ this.editModeLinkClickHandler = bind(this.editModeLinkClickHandler, this);
+ ace.config.set("modePath", assets_path + "/ace");
+ ace.config.loadModule("ace/ext/searchbox");
+ this.editor = ace.edit("editor");
+ this.editor.focus();
+ if (ace_mode) {
+ this.editor.getSession().setMode("ace/mode/" + ace_mode);
+ }
+ $('form').submit((function(_this) {
+ return function() {
+ return $("#file-content").val(_this.editor.getValue());
+ };
+ })(this));
+ this.initModePanesAndLinks();
+ new BlobLicenseSelectors({
+ editor: this.editor
+ });
+ new BlobGitignoreSelectors({
+ editor: this.editor
+ });
+ new BlobCiYamlSelectors({
+ editor: this.editor
+ });
+ }
+
+ EditBlob.prototype.initModePanesAndLinks = function() {
+ this.$editModePanes = $(".js-edit-mode-pane");
+ this.$editModeLinks = $(".js-edit-mode a");
+ return this.$editModeLinks.click(this.editModeLinkClickHandler);
+ };
+
+ EditBlob.prototype.editModeLinkClickHandler = function(event) {
+ var currentLink, currentPane, paneId;
+ event.preventDefault();
+ currentLink = $(event.target);
+ paneId = currentLink.attr("href");
+ currentPane = this.$editModePanes.filter(paneId);
+ this.$editModeLinks.parent().removeClass("active hover");
+ currentLink.parent().addClass("active hover");
+ this.$editModePanes.hide();
+ currentPane.fadeIn(200);
+ if (paneId === "#preview") {
+ return $.post(currentLink.data("preview-url"), {
+ content: this.editor.getValue()
+ }, function(response) {
+ currentPane.empty().append(response);
+ return currentPane.syntaxHighlight();
+ });
+ } else {
+ return this.editor.focus();
+ }
+ };
+
+ return EditBlob;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/edit_blob.js.coffee b/app/assets/javascripts/blob/edit_blob.js.coffee
deleted file mode 100644
index 19e584519d7..00000000000
--- a/app/assets/javascripts/blob/edit_blob.js.coffee
+++ /dev/null
@@ -1,42 +0,0 @@
-class @EditBlob
- constructor: (assets_path, ace_mode = null) ->
- ace.config.set "modePath", "#{assets_path}/ace"
- ace.config.loadModule "ace/ext/searchbox"
- @editor = ace.edit("editor")
- @editor.focus()
- @editor.getSession().setMode "ace/mode/#{ace_mode}" if ace_mode
-
- # Before a form submission, move the content from the Ace editor into the
- # submitted textarea
- $('form').submit =>
- $("#file-content").val(@editor.getValue())
-
- @initModePanesAndLinks()
-
- new BlobLicenseSelectors { @editor }
- new BlobGitignoreSelectors { @editor }
- new BlobCiYamlSelectors { @editor }
-
- initModePanesAndLinks: ->
- @$editModePanes = $(".js-edit-mode-pane")
- @$editModeLinks = $(".js-edit-mode a")
- @$editModeLinks.click @editModeLinkClickHandler
-
- editModeLinkClickHandler: (event) =>
- event.preventDefault()
- currentLink = $(event.target)
- paneId = currentLink.attr("href")
- currentPane = @$editModePanes.filter(paneId)
- @$editModeLinks.parent().removeClass "active hover"
- currentLink.parent().addClass "active hover"
- @$editModePanes.hide()
- currentPane.fadeIn 200
- if paneId is "#preview"
- $.post currentLink.data("preview-url"),
- content: @editor.getValue()
- , (response) ->
- currentPane.empty().append response
- currentPane.syntaxHighlight()
-
- else
- @editor.focus()
diff --git a/app/assets/javascripts/blob/template_selector.js b/app/assets/javascripts/blob/template_selector.js
new file mode 100644
index 00000000000..2cf0a6631b8
--- /dev/null
+++ b/app/assets/javascripts/blob/template_selector.js
@@ -0,0 +1,74 @@
+(function() {
+ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ this.TemplateSelector = (function() {
+ function TemplateSelector(opts) {
+ var ref;
+ if (opts == null) {
+ opts = {};
+ }
+ this.onClick = bind(this.onClick, this);
+ this.dropdown = opts.dropdown, this.data = opts.data, this.pattern = opts.pattern, this.wrapper = opts.wrapper, this.editor = opts.editor, this.fileEndpoint = opts.fileEndpoint, this.$input = (ref = opts.$input) != null ? ref : $('#file_name');
+ this.buildDropdown();
+ this.bindEvents();
+ this.onFilenameUpdate();
+ }
+
+ TemplateSelector.prototype.buildDropdown = function() {
+ return this.dropdown.glDropdown({
+ data: this.data,
+ filterable: true,
+ selectable: true,
+ toggleLabel: this.toggleLabel,
+ search: {
+ fields: ['name']
+ },
+ clicked: this.onClick,
+ text: function(item) {
+ return item.name;
+ }
+ });
+ };
+
+ TemplateSelector.prototype.bindEvents = function() {
+ return this.$input.on('keyup blur', (function(_this) {
+ return function(e) {
+ return _this.onFilenameUpdate();
+ };
+ })(this));
+ };
+
+ TemplateSelector.prototype.toggleLabel = function(item) {
+ return item.name;
+ };
+
+ TemplateSelector.prototype.onFilenameUpdate = function() {
+ var filenameMatches;
+ if (!this.$input.length) {
+ return;
+ }
+ filenameMatches = this.pattern.test(this.$input.val().trim());
+ if (!filenameMatches) {
+ this.wrapper.addClass('hidden');
+ return;
+ }
+ return this.wrapper.removeClass('hidden');
+ };
+
+ TemplateSelector.prototype.onClick = function(item, el, e) {
+ e.preventDefault();
+ return this.requestFile(item);
+ };
+
+ TemplateSelector.prototype.requestFile = function(item) {};
+
+ TemplateSelector.prototype.requestFileSuccess = function(file) {
+ this.editor.setValue(file.content, 1);
+ return this.editor.focus();
+ };
+
+ return TemplateSelector;
+
+ })();
+
+}).call(this);
diff --git a/app/assets/javascripts/blob/template_selector.js.coffee b/app/assets/javascripts/blob/template_selector.js.coffee
deleted file mode 100644
index 40c9169beac..00000000000
--- a/app/assets/javascripts/blob/template_selector.js.coffee
+++ /dev/null
@@ -1,60 +0,0 @@
-class @TemplateSelector
- constructor: (opts = {}) ->
- {
- @dropdown,
- @data,
- @pattern,
- @wrapper,
- @editor,
- @fileEndpoint,
- @$input = $('#file_name')
- } = opts
-
- @buildDropdown()
- @bindEvents()
- @onFilenameUpdate()
-
- buildDropdown: ->
- @dropdown.glDropdown(
- data: @data,
- filterable: true,
- selectable: true,
- toggleLabel: @toggleLabel,
- search:
- fields: ['name']
- clicked: @onClick
- text: (item) ->
- item.name
- )
-
- bindEvents: ->
- @$input.on('keyup blur', (e) =>
- @onFilenameUpdate()
- )
-
- toggleLabel: (item) ->
- item.name
-
- onFilenameUpdate: ->
- return unless @$input.length
-
- filenameMatches = @pattern.test(@$input.val().trim())
-
- if not filenameMatches
- @wrapper.addClass('hidden')
- return
-
- @wrapper.removeClass('hidden')
-
- onClick: (item, el, e) =>
- e.preventDefault()
- @requestFile(item)
-
- requestFile: (item) ->
- # To be implemented on the extending class
- # e.g.
- # Api.gitignoreText item.name, @requestFileSuccess.bind(@)
-
- requestFileSuccess: (file) ->
- @editor.setValue(file.content, 1)
- @editor.focus()