Skip to content

Commit

Permalink
Merge pull request #250 from lewisl9029/feature-invite-modal-qr-reader
Browse files Browse the repository at this point in the history
Feature invite modal qr reader. Closes #235. Closes #236. Closes #246. Closes #251
  • Loading branch information
lewisl9029 committed Aug 26, 2015
2 parents 87f22e2 + f4482b5 commit 83f1ea5
Show file tree
Hide file tree
Showing 31 changed files with 496 additions and 155 deletions.
23 changes: 23 additions & 0 deletions app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,24 @@ $bar-subheader-height: 75px !default;
border-radius: 0;
}

.modal {
max-width: 680px;
}

.menu-content {
box-shadow: -1px 0px 3px rgba(0, 0, 0, 0.2), 1px 0px 3px rgba(0, 0, 0, 0.2);
}

.bar-footer {
box-shadow: 0px -1px 3px rgba(0, 0, 0, 0.2);
border-top-color: $light;
.col {
display: flex;
justify-content: center;
}
.button {
max-width: 325px;
width: 100%;
margin-top: 0;
height: 42px;
line-height: 40px;
Expand All @@ -63,9 +73,13 @@ $bar-subheader-height: 75px !default;
box-shadow: 0px -1px 3px rgba(0, 0, 0, 0.2);
padding-bottom: 0;
.col {
display: flex;
justify-content: center;
padding-bottom: 0;
}
.button {
max-width: 325px;
width: 100%;
margin-top: 0;
margin-bottom: 0;
height: 42px;
Expand All @@ -82,6 +96,15 @@ $bar-subheader-height: 75px !default;
}
}

.item-radio.item-icon-left {
.item-content {
padding-left: 54px;
}
.radio-icon {
left: unset;
}
}

.button {
opacity: 1;
transition: opacity 0.75s ease-in;
Expand Down
12 changes: 12 additions & 0 deletions app/components/auto-select/auto-select-directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export let directiveName = 'tocAutoSelect';
export default /*@ngInject*/ function tocAutoSelect(
) {
return {
restrict: 'A',
link: function linkAutoSelect(scope, element) {
element.bind('click', function() {
element[0].select();
});
}
};
}
6 changes: 6 additions & 0 deletions app/components/auto-select/auto-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import angular from 'angular';

import directive, { directiveName } from './auto-select-directive';

export default angular.module('toc.components.auto-select', [])
.directive(directiveName, directive);
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import template from './begin-conversation-modal.html!text';

export let directiveName = 'tocBeginConversationModal';
export default /*@ngInject*/ function tocBeginConversationModal() {
return {
restrict: 'E',
template: template,
scope: {
hideModal: '&'
},
controllerAs: 'beginConversationModal',
controller: /*@ngInject*/ function BeginConversationModalController(
$cordovaBarcodeScanner,
$ionicPopup,
$log,
$q,
$window,
$scope,
contacts,
devices,
identity,
state
) {
this.hideModal = $scope.hideModal;
this.userInfo = state.cloud.identity.get().userInfo;
this.userId = this.userInfo.id;
this.isCordovaApp = devices.isCordovaApp();

this.contactId = '';

let initializeSentInvite = (contactChannel) => {
return state.save(
state.cloud.channels,
[contactChannel.id, 'sentInvite'],
true
)
.then(() => state.save(
state.cloud.contacts,
[this.contactId, 'statusId'],
0
))
.then(() => {
this.hideModal();
return $q.when();
});
};

this.inviteMethod = 'enter';

this.inviteMethods = {
'enter': {
icon: 'ion-ios-compose',
text: 'Enter someone\'s ID',
isEnabled: true,
doInvite: () => {
let invitePopup = $ionicPopup.show({
template: `
<input type="text" placeholder="Your contact's user ID."
ng-model="beginConversationModal.contactId" toc-auto-focus>
`,
title: 'Enter ID',
scope: $scope,
buttons: [
{
text: 'Cancel',
type: 'button-outline button-calm'
},
{
text: 'Invite',
type: 'button-outline button-balanced',
onTap: (event) => {
if (!identity.validateId(this.contactId)) {
event.preventDefault();
$log.error('This is not a valid Toc ID.');
return;
}

return contacts.invite(this.contactId)
.then(initializeSentInvite)
.then(() => {
this.contactId = '';
});
}
}
]
});
}
},
'scan': {
icon: 'ion-camera',
text: 'Scan a picture ID',
isEnabled: this.isCordovaApp,
doInvite: () => {
if (this.isCordovaApp) {
return $cordovaBarcodeScanner.scan()
.then((barcodeData) => {
let contactId = barcodeData.text;
if (!identity.validateId(contactId)) {
return $q.reject('This is not a valid Toc picture ID.');
}

return contacts.invite(contactId);
})
.then(initializeSentInvite)
.catch((error) => $log.error(error));
}

}
},
'mail': {
icon: 'ion-email',
text: 'Send an invite email',
isEnabled: true,
doInvite: () => {
let mailSubject = encodeURIComponent(
`An invite for Toc Messenger`
);

let mailBody = encodeURIComponent(
'Please invite me as a contact on Toc Messenger:\n' +
'http://lewisl9029.github.io/toc\n\n' +

'It\'s pretty great. ^^\n\n' +

`My Toc ID is ${this.userId}.`
);

$window.open(
`mailto:?to=&body=${mailBody}&subject=${mailSubject}`,
'_system'
);
}
}
};

this.doInvite = () => {
this.inviteMethods[this.inviteMethod].doInvite();
};

this.showIdPopup = () => {
$ionicPopup.show({
title: 'Your ID',
cssClass: 'toc-id-popup',
scope: $scope,
buttons: [{
text: 'Ok',
type: 'button-balanced button-outline'
}],
template: `
<div class="list">
<label class="toc-id-input item item-input">
<input type="text" ng-model="::beginConversationModal.userId"
readonly toc-auto-select>
</label>
<div class="item item-image">
<toc-qr-image data="{{::beginConversationModal.userId}}">
</toc-qr-image>
</div>
</div>
`
});
};
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<ion-modal-view>
<ion-header-bar class="bar-royal">
<h1 class="title">Start a Conversation</h1>
</ion-header-bar>
<ion-content class="has-subfooter">
<div class="list">
<div class="item item-divider item-calm item-clear">
How would you like to start?
</div>
<ion-radio class="item-icon-left"
ng-repeat="(id, inviteMethod) in ::beginConversationModal.inviteMethods
track by id"
ng-model="beginConversationModal.inviteMethod"
ng-value="::id" ng-if="::inviteMethod.isEnabled">
<i class="icon" ng-class="::inviteMethod.icon"></i>
{{::inviteMethod.text}}
</ion-radio>
</div>
</ion-content>
<div class="bar bar-subfooter">
<div class="col">
<button type="button" ng-click="::beginConversationModal.showIdPopup()"
class="button button-outline button-block button-royal">
Show your own ID
</button>
</div>
</div>
<ion-footer-bar>
<div class="col">
<button class="button button-block button-outline button-calm"
ng-click="::beginConversationModal.hideModal()">
Cancel
</button>
</div>
<div class="col">
<button class="button button-block button-outline button-balanced"
ng-click="::beginConversationModal.doInvite()">
Start
</button>
</div>
</ion-footer-bar>
</ion-modal-view>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import angular from 'angular';

import directive, { directiveName } from './begin-conversation-modal-directive';

export default angular.module('toc.components.begin-conversation-modal', [])
.directive(directiveName, directive);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.toc-id-popup {
.popup {
width: 350px;
max-width: 90%;
}

.toc-id-input {
border-color: transparent;
input {
cursor: pointer;
background-color: transparent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ export default /*@ngInject*/ function tocCloudConnectForm() {
}
};

this.serviceList = [
this.services['remotestorage'],
this.services['dropbox'],
this.services['googledrive']
];
this.connect = () => {
this.services[this.selectedService].connect();
}
}
};
}
17 changes: 8 additions & 9 deletions app/components/cloud-connect-form/cloud-connect-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
Select a cloud storage service
</div>
<ion-radio class="item item-avatar toc-square-avatar"
ng-repeat="service in cloudConnectForm.serviceList track by service.id"
ng-model="cloudConnectForm.selectedService" ng-value="'{{service.id}}'"
icon="ion-checkmark">
<img ng-src="assets/images/{{service.img}}"
alt="Avatar for {{service.name}}" />
<h2>{{service.name}}</h2>
<p>{{service.description}}</p>
ng-repeat="(id, service) in ::cloudConnectForm.services track by id"
ng-model="cloudConnectForm.selectedService" ng-value="::id">
<img ng-src="assets/images/{{::service.img}}"
alt="Avatar for {{::service.name}}" />
<h2>{{::service.name}}</h2>
<p>{{::service.description}}</p>
</ion-radio>
<!-- <label class="item item-input item-stacked-label">
<span class="input-label">Email</span>
Expand All @@ -30,13 +29,13 @@ <h2>{{service.name}}</h2>
<ion-footer-bar>
<div class="col">
<button class="button button-block button-outline button-calm"
ng-click="cloudConnectForm.goBack()">
ng-click="::cloudConnectForm.goBack()">
Back
</button>
</div>
<div class="col">
<button class="button button-block button-outline button-balanced"
ng-click="cloudConnectForm.services[cloudConnectForm.selectedService].connect()">
ng-click="::cloudConnectForm.connect()">
Connect
</button>
</div>
Expand Down
5 changes: 5 additions & 0 deletions app/components/components.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import angular from 'angular';

import autoFocus from './auto-focus/auto-focus';
import autoSelect from './auto-select/auto-select';
import beginConversationModal from
'./begin-conversation-modal/begin-conversation-modal';
import channelCard from './channel-card/channel-card';
import channelList from './channel-list/channel-list';
import cloudConnectForm from './cloud-connect-form/cloud-connect-form';
Expand All @@ -18,6 +21,8 @@ import userCard from './user-card/user-card';

export default angular.module('toc.components', [
autoFocus.name,
autoSelect.name,
beginConversationModal.name,
channelCard.name,
channelList.name,
cloudConnectForm.name,
Expand Down
1 change: 1 addition & 0 deletions app/components/components.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import 'channel-card/channel-card';
@import 'begin-conversation-modal/begin-conversation-modal';
@import 'channel-list/channel-list';
@import 'message-list/message-list';
@import 'notification-overlay/notification-overlay';
Expand Down
Loading

0 comments on commit 83f1ea5

Please sign in to comment.