Skip to content

Commit

Permalink
Display a warning when trying to transfer more than one file
Browse files Browse the repository at this point in the history
  • Loading branch information
szimek committed Mar 31, 2014
1 parent 3c54081 commit 5fece2f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
10 changes: 10 additions & 0 deletions app/scripts/app/models/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ ShareDrop.App.Peer = Ember.Object.extend({
// - declined_file_transfer
// - receiving_file_data
// - sending_file_data
// - error
internalState: "idle",

// Used to display error messages in popovers. Possible codes:
// - multiple_files
errorCode: null,

internalStateChanged: function () {
console.log('Peer:\t Internal state has changed: ', this.get('internalState'));

// Automatically clear error code if transitioning to a non-error state
if (this.get('internalState') !== 'error') {
this.set('errorCode', null);
}
}.observes('internalState').on('init')
});
1 change: 1 addition & 0 deletions app/scripts/app/templates/errors/multiple_files.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
You can only send one file at a time.
4 changes: 4 additions & 0 deletions app/scripts/app/templates/peer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<strong>"{{peer.label}}"</strong> has declined your request.
{{/popover-confirm}}

{{#popover-confirm confirm="cancelFileTransfer" isShowing=view.hasError partialName=view.errorTemplateName confirm-button-label="Ok"}}
{{partial view.partialName}}
{{/popover-confirm}}

<!-- Recipient related popups -->
{{#popover-confirm confirm="acceptFileTransfer" cancel="rejectFileTransfer" isShowing=view.hasReceivedFileInfo filename=filename confirm-button-label="Save" cancel-button-label="Decline"}}
<strong>"{{peer.label}}"</strong> wants to send you <strong>"{{filename}}"</strong>.
Expand Down
33 changes: 21 additions & 12 deletions app/scripts/app/views/peer_avatar_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ ShareDrop.App.PeerAvatarView = Ember.View.extend(Ember.ViewTargetActionSupport,
'data-sending-progress',
'data-receiving-progress'
],
src: Ember.computed.alias('controller.model.avatarUrl'),
alt: Ember.computed.alias('controller.model.label'),
title: Ember.computed.alias('controller.model.uuid'),
"data-sending-progress": Ember.computed.alias('controller.model.transfer.sendingProgress'),
"data-receiving-progress": Ember.computed.alias('controller.model.transfer.receivingProgress'),
peer: Ember.computed.alias('controller.model'),
src: Ember.computed.alias('peer.avatarUrl'),
alt: Ember.computed.alias('peer.label'),
title: Ember.computed.alias('peer.uuid'),
"data-sending-progress": Ember.computed.alias('peer.transfer.sendingProgress'),
"data-receiving-progress": Ember.computed.alias('peer.transfer.receivingProgress'),

// Delegate click to hidden file field in peer template
click: function (event) {
Expand All @@ -34,19 +35,27 @@ ShareDrop.App.PeerAvatarView = Ember.View.extend(Ember.ViewTargetActionSupport,
this.cancelEvent(event);

var self = this,
peer = this.get('peer'),
dt = event.originalEvent.dataTransfer,
files = dt.files,
file = files[0];

if (this.canSendFile()) {
this.isFile(file).then(function () {
self.triggerAction({
action: 'uploadFile',
actionContext: {
file: file
}
if (files.length > 1) {
peer.setProperties({
internalState: 'error',
errorCode: 'multiple_files'
});
});
} else {
this.isFile(file).then(function () {
self.triggerAction({
action: 'uploadFile',
actionContext: {
file: file
}
});
});
}
}
},

Expand Down
9 changes: 7 additions & 2 deletions app/scripts/app/views/peer_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ ShareDrop.App.PeerView = Ember.View.extend({
classNames: ['peer'],
classNameBindings: ['isConnected:connected:disconnected'],

// TODO: figure out a shorter way to define these
isIdle: Ember.computed.equal('peer.internalState', 'idle'),
isAwaitingFileInfo: Ember.computed.equal('peer.internalState', 'awaiting_file_info'),
isAwaitingResponse: Ember.computed.equal('peer.internalState', 'awaiting_response'),
hasReceivedFileInfo: Ember.computed.equal('peer.internalState', 'received_file_info'),
hasDeclinedFileTransfer: Ember.computed.equal('peer.internalState', 'declined_file_transfer')
hasDeclinedFileTransfer: Ember.computed.equal('peer.internalState', 'declined_file_transfer'),
hasError: Ember.computed.equal('peer.internalState', 'error'),
errorTemplateName: function () {
var errorCode = this.get('peer.errorCode');

return errorCode ? 'errors/' + errorCode : null;
}.property('peer.errorCode')
});

0 comments on commit 5fece2f

Please sign in to comment.