More fixes/ES6

This commit is contained in:
Szymon Nowak 2015-09-13 21:04:52 +02:00
parent c8c5d0b021
commit 6773ac5a20
8 changed files with 62 additions and 68 deletions

View File

@ -4,23 +4,23 @@ export default Ember.TextField.extend({
type: 'file',
classNames: ['invisible'],
click(event) {
click: function (event) {
event.stopPropagation();
},
change(event) {
change: function (event) {
const input = event.target;
const files = input.files;
const file = files[0];
this.sendAction('action', { file: file });
this.reset()
this.reset();
},
// Hackish way to reset file input when sender cancels file transfer,
// so if sender wants later to send the same file again,
// the 'change' event is triggered correctly.
reset() {
reset: function () {
const field = this.$();
field.wrap('<form>').closest('form').get(0).reset();
field.unwrap();

View File

@ -4,9 +4,9 @@ export default Ember.Component.extend({
content: null,
selectedValue: null,
didInitAttrs() {
didInitAttrs: function () {
this._super(...arguments);
var content = this.get("content");
const content = this.get("content");
if (!content) {
this.set("content", []);
@ -14,7 +14,7 @@ export default Ember.Component.extend({
},
actions: {
change() {
change: function () {
const changeAction = this.get("action");
const selectedEl = this.$("select")[0];
const selectedIndex = selectedEl.selectedIndex;

View File

@ -2,11 +2,10 @@ import Ember from 'ember';
export default Ember.Component.extend({
actions: {
close() {
console.log("nop");
close: function () {
return this.sendAction();
},
nop() {}
nop: function () {}
}
});

View File

@ -19,29 +19,28 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, {
"data-receiving-progress": alias('peer.transfer.receivingProgress'),
didInsertElement: function () {
var self = this,
peer = this.get('peer'),
toggleTransferCompletedClass = function () {
var klass = 'transfer-completed';
this._super(...arguments);
const peer = this.get('peer');
const toggleTransferCompletedClass = () => {
const klass = 'transfer-completed';
Ember.run.later(self, function () {
this.$().parent('.avatar')
.addClass(klass)
.delay(2000)
.queue(function () {
Ember.$(this).removeClass(klass).dequeue();
});
}, 250);
};
Ember.run.later(this, function () {
this.$().parent('.avatar')
.addClass(klass)
.delay(2000)
.queue(function () {
Ember.$(this).removeClass(klass).dequeue();
});
}, 250);
};
peer.on('didReceiveFile', toggleTransferCompletedClass);
peer.on('didSendFile', toggleTransferCompletedClass);
this._super();
},
willDestroyElement: function () {
var peer = this.get('peer');
this._super(...arguments);
const peer = this.get('peer');
peer.off('didReceiveFile');
peer.off('didSendFile');
@ -71,14 +70,12 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, {
drop: function (event) {
this.cancelEvent(event);
this.$().parent('.avatar').removeClass('hover');
var self = this,
peer = this.get('peer'),
dt = event.originalEvent.dataTransfer,
files = dt.files,
file = files[0];
const peer = this.get('peer');
const dt = event.originalEvent.dataTransfer;
const files = dt.files;
const file = files[0];
if (this.canSendFile()) {
if (files.length > 1) {
@ -87,8 +84,8 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, {
errorCode: 'multiple_files'
});
} else {
this.isFile(file).then(function () {
self.triggerAction({
this.isFile(file).then(() => {
this.triggerAction({
action: 'uploadFile',
actionContext: {
file: file
@ -105,14 +102,10 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, {
},
canSendFile: function () {
var peer = this.get('peer');
const peer = this.get('peer');
// Can't send files if another file transfer is already in progress
if (peer.get('transfer.file') || peer.get('transfer.info')) {
return false;
}
return true;
return !(peer.get('transfer.file') || peer.get('transfer.info'));
},
isFile: function (file) {
@ -124,7 +117,7 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, {
} else {
// Try to read it using FileReader - if it's not a file,
// it should trigger onerror handler
var reader = new FileReader();
const reader = new FileReader();
reader.onload = function () { resolve(); };
reader.onerror = function () { reject(); };
reader.readAsArrayBuffer(file);

View File

@ -18,19 +18,20 @@ export default Ember.Component.extend({
hasError: equal('peer.state', 'error'),
filename: function () {
var file = this.get('peer.transfer.file'),
info = this.get('peer.transfer.info');
const file = this.get('peer.transfer.file');
const info = this.get('peer.transfer.info');
if (file) { return file.name; }
if (info) { return info.name; }
return null;
}.property('peer.transfer.file', 'peer.transfer.info'),
actions: {
// TODO: rename to something more meaningful (e.g. askIfWantToSendFile)
uploadFile: function (data) {
var peer = this.get('peer'),
file = data.file;
const peer = this.get('peer');
const file = data.file;
// Cache the file, so that it's available
// when the response from the recipient comes in
@ -39,8 +40,8 @@ export default Ember.Component.extend({
},
sendFileTransferInquiry: function () {
var webrtc = this.get('webrtc'),
peer = this.get('peer');
const webrtc = this.get('webrtc');
const peer = this.get('peer');
webrtc.connect(peer.get('peer.id'));
},
@ -52,14 +53,14 @@ export default Ember.Component.extend({
abortFileTransfer: function () {
this._cancelFileTransfer();
var webrtc = this.get('webrtc'),
connection = this.get('peer.peer.connection');
const webrtc = this.get('webrtc');
const connection = this.get('peer.peer.connection');
webrtc.sendCancelRequest(connection);
},
acceptFileTransfer: function () {
var peer = this.get('peer');
const peer = this.get('peer');
this._sendFileTransferResponse(true);
@ -70,7 +71,7 @@ export default Ember.Component.extend({
},
rejectFileTransfer: function () {
var peer = this.get('peer');
const peer = this.get('peer');
this._sendFileTransferResponse(false);
peer.set('transfer.info', null);
@ -79,7 +80,7 @@ export default Ember.Component.extend({
},
_cancelFileTransfer: function () {
var peer = this.get('peer');
const peer = this.get('peer');
peer.setProperties({
'transfer.file': null,
@ -88,15 +89,16 @@ export default Ember.Component.extend({
},
_sendFileTransferResponse: function (response) {
var webrtc = this.get('webrtc'),
peer = this.get('peer'),
connection = peer.get('peer.connection');
const webrtc = this.get('webrtc');
const peer = this.get('peer');
const connection = peer.get('peer.connection');
webrtc.sendFileResponse(connection, response);
},
errorTemplateName: function () {
var errorCode = this.get('peer.errorCode');
const errorCode = this.get('peer.errorCode');
return errorCode ? 'errors/popovers/' + errorCode : null;
}.property('peer.errorCode'),

View File

@ -4,8 +4,8 @@ export default Ember.Component.extend({
classNames: ['popover-confirm'],
iconClass: function () {
var filename = this.get('filename'),
regex, match, extension;
const filename = this.get('filename');
let regex, match, extension;
if (filename) {
regex = /\.([0-9a-z]+)$/i;

View File

@ -15,7 +15,7 @@ export default Ember.Component.extend({
},
sendingProgressDidChange: function () {
var progress = this.get('transfer.sendingProgress');
const progress = this.get('transfer.sendingProgress');
if (this.get('path')) {
this._calculateSVGAnim(progress);
@ -23,7 +23,7 @@ export default Ember.Component.extend({
}.observes('transfer.sendingProgress'),
receivingProgressDidChange: function () {
var progress = this.get('transfer.receivingProgress');
const progress = this.get('transfer.receivingProgress');
if (this.get('path')) {
this._calculateSVGAnim(progress);
@ -34,13 +34,13 @@ export default Ember.Component.extend({
const path = this.get('path');
if (!path) { return; }
var π = Math.PI,
α = progress * 360,
r = ( α * π / 180 ),
mid = ( α > 180 ) ? 1 : 0,
x = Math.sin( r ) * 38,
y = Math.cos( r ) * - 38,
anim = 'M 0 0 v -38 A 38 38 1 ' + mid + ' 1 ' + x + ' ' + y + ' z';
const π = Math.PI;
const α = progress * 360;
const r = ( α * π / 180 );
const mid = ( α > 180 ) ? 1 : 0;
const x = Math.sin( r ) * 38;
const y = Math.cos( r ) * - 38;
const anim = 'M 0 0 v -38 A 38 38 1 ' + mid + ' 1 ' + x + ' ' + y + ' z';
path.attr('d', anim);
}

View File

@ -9,7 +9,7 @@ export default Ember.TextField.extend({
copyValueToClipboard: function () {
if (window.ClipboardEvent) {
var pasteEvent = new window.ClipboardEvent('paste', {
const pasteEvent = new window.ClipboardEvent('paste', {
dataType: 'text/plain',
data: this.$().val()
});