Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
committerFatih Acet <acetfatih@gmail.com>2016-07-24 23:45:11 +0300
commitaaa9509d120524573085e94af9de5cdde83e3271 (patch)
tree3824cffd4cdd132ee9cf75a00a7624f5ccc0dabd /app/assets/javascripts/profile
parent56b79181adc0bd6e9abef97ea075c14be971a01a (diff)
ES6ify all the things!
Diffstat (limited to 'app/assets/javascripts/profile')
-rw-r--r--app/assets/javascripts/profile/gl_crop.js169
-rw-r--r--app/assets/javascripts/profile/gl_crop.js.coffee152
-rw-r--r--app/assets/javascripts/profile/profile.js102
-rw-r--r--app/assets/javascripts/profile/profile.js.coffee83
-rw-r--r--app/assets/javascripts/profile/profile_bundle.js7
-rw-r--r--app/assets/javascripts/profile/profile_bundle.js.coffee2
6 files changed, 278 insertions, 237 deletions
diff --git a/app/assets/javascripts/profile/gl_crop.js b/app/assets/javascripts/profile/gl_crop.js
new file mode 100644
index 00000000000..a3eea316f67
--- /dev/null
+++ b/app/assets/javascripts/profile/gl_crop.js
@@ -0,0 +1,169 @@
+(function() {
+ var GitLabCrop,
+ bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ GitLabCrop = (function() {
+ var FILENAMEREGEX;
+
+ FILENAMEREGEX = /^.*[\\\/]/;
+
+ function GitLabCrop(input, opts) {
+ var ref, ref1, ref2, ref3, ref4;
+ if (opts == null) {
+ opts = {};
+ }
+ this.onUploadImageBtnClick = bind(this.onUploadImageBtnClick, this);
+ this.onModalHide = bind(this.onModalHide, this);
+ this.onModalShow = bind(this.onModalShow, this);
+ this.onPickImageClick = bind(this.onPickImageClick, this);
+ this.fileInput = $(input);
+ this.fileInput.attr('name', (this.fileInput.attr('name')) + "-trigger").attr('id', (this.fileInput.attr('id')) + "-trigger");
+ this.exportWidth = (ref = opts.exportWidth) != null ? ref : 200, this.exportHeight = (ref1 = opts.exportHeight) != null ? ref1 : 200, this.cropBoxWidth = (ref2 = opts.cropBoxWidth) != null ? ref2 : 200, this.cropBoxHeight = (ref3 = opts.cropBoxHeight) != null ? ref3 : 200, this.form = (ref4 = opts.form) != null ? ref4 : this.fileInput.parents('form'), this.filename = opts.filename, this.previewImage = opts.previewImage, this.modalCrop = opts.modalCrop, this.pickImageEl = opts.pickImageEl, this.uploadImageBtn = opts.uploadImageBtn, this.modalCropImg = opts.modalCropImg;
+ this.filename = this.getElement(this.filename);
+ this.previewImage = this.getElement(this.previewImage);
+ this.pickImageEl = this.getElement(this.pickImageEl);
+ this.modalCrop = _.isString(this.modalCrop) ? $(this.modalCrop) : this.modalCrop;
+ this.uploadImageBtn = _.isString(this.uploadImageBtn) ? $(this.uploadImageBtn) : this.uploadImageBtn;
+ this.modalCropImg = _.isString(this.modalCropImg) ? $(this.modalCropImg) : this.modalCropImg;
+ this.cropActionsBtn = this.modalCrop.find('[data-method]');
+ this.bindEvents();
+ }
+
+ GitLabCrop.prototype.getElement = function(selector) {
+ return $(selector, this.form);
+ };
+
+ GitLabCrop.prototype.bindEvents = function() {
+ var _this;
+ _this = this;
+ this.fileInput.on('change', function(e) {
+ return _this.onFileInputChange(e, this);
+ });
+ this.pickImageEl.on('click', this.onPickImageClick);
+ this.modalCrop.on('shown.bs.modal', this.onModalShow);
+ this.modalCrop.on('hidden.bs.modal', this.onModalHide);
+ this.uploadImageBtn.on('click', this.onUploadImageBtnClick);
+ this.cropActionsBtn.on('click', function(e) {
+ var btn;
+ btn = this;
+ return _this.onActionBtnClick(btn);
+ });
+ return this.croppedImageBlob = null;
+ };
+
+ GitLabCrop.prototype.onPickImageClick = function() {
+ return this.fileInput.trigger('click');
+ };
+
+ GitLabCrop.prototype.onModalShow = function() {
+ var _this;
+ _this = this;
+ return this.modalCropImg.cropper({
+ viewMode: 1,
+ center: false,
+ aspectRatio: 1,
+ modal: true,
+ scalable: false,
+ rotatable: false,
+ zoomable: true,
+ dragMode: 'move',
+ guides: false,
+ zoomOnTouch: false,
+ zoomOnWheel: false,
+ cropBoxMovable: false,
+ cropBoxResizable: false,
+ toggleDragModeOnDblclick: false,
+ built: function() {
+ var $image, container, cropBoxHeight, cropBoxWidth;
+ $image = $(this);
+ container = $image.cropper('getContainerData');
+ cropBoxWidth = _this.cropBoxWidth;
+ cropBoxHeight = _this.cropBoxHeight;
+ return $image.cropper('setCropBoxData', {
+ width: cropBoxWidth,
+ height: cropBoxHeight,
+ left: (container.width - cropBoxWidth) / 2,
+ top: (container.height - cropBoxHeight) / 2
+ });
+ }
+ });
+ };
+
+ GitLabCrop.prototype.onModalHide = function() {
+ return this.modalCropImg.attr('src', '').cropper('destroy');
+ };
+
+ GitLabCrop.prototype.onUploadImageBtnClick = function(e) {
+ e.preventDefault();
+ this.setBlob();
+ this.setPreview();
+ this.modalCrop.modal('hide');
+ return this.fileInput.val('');
+ };
+
+ GitLabCrop.prototype.onActionBtnClick = function(btn) {
+ var data, result;
+ data = $(btn).data();
+ if (this.modalCropImg.data('cropper') && data.method) {
+ return result = this.modalCropImg.cropper(data.method, data.option);
+ }
+ };
+
+ GitLabCrop.prototype.onFileInputChange = function(e, input) {
+ return this.readFile(input);
+ };
+
+ GitLabCrop.prototype.readFile = function(input) {
+ var _this, reader;
+ _this = this;
+ reader = new FileReader;
+ reader.onload = function() {
+ _this.modalCropImg.attr('src', reader.result);
+ return _this.modalCrop.modal('show');
+ };
+ return reader.readAsDataURL(input.files[0]);
+ };
+
+ GitLabCrop.prototype.dataURLtoBlob = function(dataURL) {
+ var array, binary, i, k, len, v;
+ binary = atob(dataURL.split(',')[1]);
+ array = [];
+ for (k = i = 0, len = binary.length; i < len; k = ++i) {
+ v = binary[k];
+ array.push(binary.charCodeAt(k));
+ }
+ return new Blob([new Uint8Array(array)], {
+ type: 'image/png'
+ });
+ };
+
+ GitLabCrop.prototype.setPreview = function() {
+ var filename;
+ this.previewImage.attr('src', this.dataURL);
+ filename = this.fileInput.val().replace(FILENAMEREGEX, '');
+ return this.filename.text(filename);
+ };
+
+ GitLabCrop.prototype.setBlob = function() {
+ this.dataURL = this.modalCropImg.cropper('getCroppedCanvas', {
+ width: 200,
+ height: 200
+ }).toDataURL('image/png');
+ return this.croppedImageBlob = this.dataURLtoBlob(this.dataURL);
+ };
+
+ GitLabCrop.prototype.getBlob = function() {
+ return this.croppedImageBlob;
+ };
+
+ return GitLabCrop;
+
+ })();
+
+ $.fn.glCrop = function(opts) {
+ return this.each(function() {
+ return $(this).data('glcrop', new GitLabCrop(this, opts));
+ });
+ };
+
+}).call(this);
diff --git a/app/assets/javascripts/profile/gl_crop.js.coffee b/app/assets/javascripts/profile/gl_crop.js.coffee
deleted file mode 100644
index df9bfdfa6cc..00000000000
--- a/app/assets/javascripts/profile/gl_crop.js.coffee
+++ /dev/null
@@ -1,152 +0,0 @@
-class GitLabCrop
- # Matches everything but the file name
- FILENAMEREGEX = /^.*[\\\/]/
-
- constructor: (input, opts = {}) ->
- @fileInput = $(input)
-
- # We should rename to avoid spec to fail
- # Form will submit the proper input filed with a file using FormData
- @fileInput
- .attr('name', "#{@fileInput.attr('name')}-trigger")
- .attr('id', "#{@fileInput.attr('id')}-trigger")
-
- # Set defaults
- {
- @exportWidth = 200
- @exportHeight = 200
- @cropBoxWidth = 200
- @cropBoxHeight = 200
- @form = @fileInput.parents('form')
-
- # Required params
- @filename
- @previewImage
- @modalCrop
- @pickImageEl
- @uploadImageBtn
- @modalCropImg
- } = opts
-
- # Ensure needed elements are jquery objects
- # If selector is provided we will convert them to a jQuery Object
- @filename = @getElement(@filename)
- @previewImage = @getElement(@previewImage)
- @pickImageEl = @getElement(@pickImageEl)
-
- # Modal elements usually are outside the @form element
- @modalCrop = if _.isString(@modalCrop) then $(@modalCrop) else @modalCrop
- @uploadImageBtn = if _.isString(@uploadImageBtn) then $(@uploadImageBtn) else @uploadImageBtn
- @modalCropImg = if _.isString(@modalCropImg) then $(@modalCropImg) else @modalCropImg
-
- @cropActionsBtn = @modalCrop.find('[data-method]')
-
- @bindEvents()
-
- getElement: (selector) ->
- $(selector, @form)
-
- bindEvents: ->
- _this = @
- @fileInput.on 'change', (e) ->
- _this.onFileInputChange(e, @)
-
- @pickImageEl.on 'click', @onPickImageClick
- @modalCrop.on 'shown.bs.modal', @onModalShow
- @modalCrop.on 'hidden.bs.modal', @onModalHide
- @uploadImageBtn.on 'click', @onUploadImageBtnClick
- @cropActionsBtn.on 'click', (e) ->
- btn = @
- _this.onActionBtnClick(btn)
- @croppedImageBlob = null
-
- onPickImageClick: =>
- @fileInput.trigger('click')
-
- onModalShow: =>
- _this = @
- @modalCropImg.cropper(
- viewMode: 1
- center: false
- aspectRatio: 1
- modal: true
- scalable: false
- rotatable: false
- zoomable: true
- dragMode: 'move'
- guides: false
- zoomOnTouch: false
- zoomOnWheel: false
- cropBoxMovable: false
- cropBoxResizable: false
- toggleDragModeOnDblclick: false
- built: ->
- $image = $(@)
- container = $image.cropper 'getContainerData'
- cropBoxWidth = _this.cropBoxWidth;
- cropBoxHeight = _this.cropBoxHeight;
-
- $image.cropper('setCropBoxData',
- width: cropBoxWidth,
- height: cropBoxHeight,
- left: (container.width - cropBoxWidth) / 2,
- top: (container.height - cropBoxHeight) / 2
- )
- )
-
-
- onModalHide: =>
- @modalCropImg
- .attr('src', '') # Remove attached image
- .cropper('destroy') # Destroy cropper instance
-
- onUploadImageBtnClick: (e) =>
- e.preventDefault()
- @setBlob()
- @setPreview()
- @modalCrop.modal('hide')
- @fileInput.val('')
-
- onActionBtnClick: (btn) ->
- data = $(btn).data()
-
- if @modalCropImg.data('cropper') && data.method
- result = @modalCropImg.cropper data.method, data.option
-
- onFileInputChange: (e, input) ->
- @readFile(input)
-
- readFile: (input) ->
- _this = @
- reader = new FileReader
- reader.onload = ->
- _this.modalCropImg.attr('src', reader.result)
- _this.modalCrop.modal('show')
-
- reader.readAsDataURL(input.files[0])
-
- dataURLtoBlob: (dataURL) ->
- binary = atob(dataURL.split(',')[1])
- array = []
- for v, k in binary
- array.push(binary.charCodeAt(k))
- new Blob([new Uint8Array(array)], type: 'image/png')
-
- setPreview: ->
- @previewImage.attr('src', @dataURL)
- filename = @fileInput.val().replace(FILENAMEREGEX, '')
- @filename.text(filename)
-
- setBlob: ->
- @dataURL = @modalCropImg.cropper('getCroppedCanvas',
- width: 200
- height: 200
- ).toDataURL('image/png')
- @croppedImageBlob = @dataURLtoBlob(@dataURL)
-
- getBlob: ->
- @croppedImageBlob
-
-$.fn.glCrop = (opts) ->
- return @.each ->
- $(@).data('glcrop', new GitLabCrop(@, opts))
diff --git a/app/assets/javascripts/profile/profile.js b/app/assets/javascripts/profile/profile.js
new file mode 100644
index 00000000000..ed1d87abafe
--- /dev/null
+++ b/app/assets/javascripts/profile/profile.js
@@ -0,0 +1,102 @@
+(function() {
+ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ this.Profile = (function() {
+ function Profile(opts) {
+ var cropOpts, ref;
+ if (opts == null) {
+ opts = {};
+ }
+ this.onSubmitForm = bind(this.onSubmitForm, this);
+ this.form = (ref = opts.form) != null ? ref : $('.edit-user');
+ $('.js-preferences-form').on('change.preference', 'input[type=radio]', function() {
+ return $(this).parents('form').submit();
+ });
+ $('#user_notification_email').on('change', function() {
+ return $(this).parents('form').submit();
+ });
+ $('.update-username').on('ajax:before', function() {
+ $('.loading-username').show();
+ $(this).find('.update-success').hide();
+ return $(this).find('.update-failed').hide();
+ });
+ $('.update-username').on('ajax:complete', function() {
+ $('.loading-username').hide();
+ $(this).find('.btn-save').enable();
+ return $(this).find('.loading-gif').hide();
+ });
+ $('.update-notifications').on('ajax:success', function(e, data) {
+ if (data.saved) {
+ return new Flash("Notification settings saved", "notice");
+ } else {
+ return new Flash("Failed to save new settings", "alert");
+ }
+ });
+ this.bindEvents();
+ cropOpts = {
+ filename: '.js-avatar-filename',
+ previewImage: '.avatar-image .avatar',
+ modalCrop: '.modal-profile-crop',
+ pickImageEl: '.js-choose-user-avatar-button',
+ uploadImageBtn: '.js-upload-user-avatar',
+ modalCropImg: '.modal-profile-crop-image'
+ };
+ this.avatarGlCrop = $('.js-user-avatar-input').glCrop(cropOpts).data('glcrop');
+ }
+
+ Profile.prototype.bindEvents = function() {
+ return this.form.on('submit', this.onSubmitForm);
+ };
+
+ Profile.prototype.onSubmitForm = function(e) {
+ e.preventDefault();
+ return this.saveForm();
+ };
+
+ Profile.prototype.saveForm = function() {
+ var avatarBlob, formData, self;
+ self = this;
+ formData = new FormData(this.form[0]);
+ avatarBlob = this.avatarGlCrop.getBlob();
+ if (avatarBlob != null) {
+ formData.append('user[avatar]', avatarBlob, 'avatar.png');
+ }
+ return $.ajax({
+ url: this.form.attr('action'),
+ type: this.form.attr('method'),
+ data: formData,
+ dataType: "json",
+ processData: false,
+ contentType: false,
+ success: function(response) {
+ return new Flash(response.message, 'notice');
+ },
+ error: function(jqXHR) {
+ return new Flash(jqXHR.responseJSON.message, 'alert');
+ },
+ complete: function() {
+ window.scrollTo(0, 0);
+ return self.form.find(':input[disabled]').enable();
+ }
+ });
+ };
+
+ return Profile;
+
+ })();
+
+ $(function() {
+ $(document).on('focusout.ssh_key', '#key_key', function() {
+ var $title, comment;
+ $title = $('#key_title');
+ comment = $(this).val().match(/^\S+ \S+ (.+)\n?$/);
+ if (comment && comment.length > 1 && $title.val() === '') {
+ return $title.val(comment[1]).change();
+ }
+ });
+ if (gl.utils.getPagePath() === 'profiles') {
+ return new Profile();
+ }
+ });
+
+}).call(this);
diff --git a/app/assets/javascripts/profile/profile.js.coffee b/app/assets/javascripts/profile/profile.js.coffee
deleted file mode 100644
index f3b05f2c646..00000000000
--- a/app/assets/javascripts/profile/profile.js.coffee
+++ /dev/null
@@ -1,83 +0,0 @@
-class @Profile
- constructor: (opts = {}) ->
- {
- @form = $('.edit-user')
- } = opts
-
- # Automatically submit the Preferences form when any of its radio buttons change
- $('.js-preferences-form').on 'change.preference', 'input[type=radio]', ->
- $(this).parents('form').submit()
-
- # Automatically submit email form when it changes
- $('#user_notification_email').on 'change', ->
- $(this).parents('form').submit()
-
- $('.update-username').on 'ajax:before', ->
- $('.loading-username').show()
- $(this).find('.update-success').hide()
- $(this).find('.update-failed').hide()
-
- $('.update-username').on 'ajax:complete', ->
- $('.loading-username').hide()
- $(this).find('.btn-save').enable()
- $(this).find('.loading-gif').hide()
-
- $('.update-notifications').on 'ajax:success', (e, data) ->
- if data.saved
- new Flash("Notification settings saved", "notice")
- else
- new Flash("Failed to save new settings", "alert")
-
- @bindEvents()
-
- cropOpts =
- filename: '.js-avatar-filename'
- previewImage: '.avatar-image .avatar'
- modalCrop: '.modal-profile-crop'
- pickImageEl: '.js-choose-user-avatar-button'
- uploadImageBtn: '.js-upload-user-avatar'
- modalCropImg: '.modal-profile-crop-image'
-
- @avatarGlCrop = $('.js-user-avatar-input').glCrop(cropOpts).data 'glcrop'
-
- bindEvents: ->
- @form.on 'submit', @onSubmitForm
-
- onSubmitForm: (e) =>
- e.preventDefault()
- @saveForm()
-
- saveForm: ->
- self = @
- formData = new FormData(@form[0])
-
- avatarBlob = @avatarGlCrop.getBlob()
- formData.append('user[avatar]', avatarBlob, 'avatar.png') if avatarBlob?
-
- $.ajax
- url: @form.attr('action')
- type: @form.attr('method')
- data: formData
- dataType: "json"
- processData: false
- contentType: false
- success: (response) ->
- new Flash(response.message, 'notice')
- error: (jqXHR) ->
- new Flash(jqXHR.responseJSON.message, 'alert')
- complete: ->
- window.scrollTo 0, 0
- # Enable submit button after requests ends
- self.form.find(':input[disabled]').enable()
-
-$ ->
- # Extract the SSH Key title from its comment
- $(document).on 'focusout.ssh_key', '#key_key', ->
- $title = $('#key_title')
- comment = $(@).val().match(/^\S+ \S+ (.+)\n?$/)
-
- if comment && comment.length > 1 && $title.val() == ''
- $title.val(comment[1]).change()
-
- if gl.utils.getPagePath() == 'profiles'
- new Profile()
diff --git a/app/assets/javascripts/profile/profile_bundle.js b/app/assets/javascripts/profile/profile_bundle.js
new file mode 100644
index 00000000000..b95faadc8e7
--- /dev/null
+++ b/app/assets/javascripts/profile/profile_bundle.js
@@ -0,0 +1,7 @@
+
+/*= require_tree . */
+
+(function() {
+
+
+}).call(this);
diff --git a/app/assets/javascripts/profile/profile_bundle.js.coffee b/app/assets/javascripts/profile/profile_bundle.js.coffee
deleted file mode 100644
index 91cacfece46..00000000000
--- a/app/assets/javascripts/profile/profile_bundle.js.coffee
+++ /dev/null
@@ -1,2 +0,0 @@
-#
-#= require_tree .