From 22a533377b6fa834ec40a7f4289bfa1ba7cd1eaa Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 3 Jan 2015 19:41:01 -0300 Subject: [PATCH] send form --- index.html | 9 +- js/controllers/createProfile.js | 398 ++++++++++++++++---------------- js/controllers/send.js | 38 ++- views/send.html | 22 +- 4 files changed, 249 insertions(+), 218 deletions(-) diff --git a/index.html b/index.html index 6cd9f1a6d..cfc7024d9 100644 --- a/index.html +++ b/index.html @@ -77,7 +77,7 @@ Network Error.
Attempting to reconnect..
-
+
- @@ -116,10 +115,10 @@ class="head show-for-large-up" ng-include="'views/includes/head.html'" ng-if="$root.iden" - ng-class="{'dni':$root.hideNavigation}" + ng-class="{'dni':$root.hideNavigation || $root.wpInputFocused}" >
-
+
diff --git a/js/controllers/createProfile.js b/js/controllers/createProfile.js index 167e80698..7bdf36a53 100644 --- a/js/controllers/createProfile.js +++ b/js/controllers/createProfile.js @@ -1,222 +1,224 @@ 'use strict'; -angular.module('copayApp.controllers').controller('CreateProfileController', function ($scope, $rootScope, $location, $timeout, $window, notification, pluginManager, identityService, pinService, isMobile, isCordova, configService, go) { +angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, $timeout, $window, notification, pluginManager, identityService, pinService, isMobile, isCordova, configService, go) { - var _credentials, _firstpin; + var _credentials, _firstpin; - $scope.init = function () { + $scope.init = function() { - if ($rootScope.wallet) - go.walletHome(); + if ($rootScope.wallet) + go.walletHome(); - $scope.isMobile = isMobile.any(); - $scope.isWindowsPhoneApp = isMobile.Windows() && isCordova; + $scope.isMobile = isMobile.any(); + $scope.isWindowsPhoneApp = isMobile.Windows() && isCordova; + $scope.hideForWP = 0; + + + $scope.createStep = 'storage'; + $scope.useLocalstorage = false; + $scope.minPasswordStrength = _.isUndefined(config.minPasswordStrength) ? + 4 : config.minPasswordStrength; + + //TODO + $scope.minPasswordStrength = 1; + + pinService.makePinInput($scope, 'newpin', function(newValue) { + _firstpin = newValue; + $scope.hideForWP = 0; + $scope.askForPin = 2; + $timeout(function() { + $scope.$digest(); + }, 1); + + + }); + + pinService.makePinInput($scope, 'repeatpin', function(newValue) { + if (newValue === _firstpin) { + _firstpin = null; + $scope.createPin(newValue); + } else { + $scope.askForPin = 1; $scope.hideForWP = 0; + $scope.passwordStrength = null; + + _firstpin = null; + + $scope.setPinForm.newpin.$setViewValue(''); + $scope.setPinForm.newpin.$render(); + $scope.setPinForm.repeatpin.$setViewValue(''); + $scope.setPinForm.repeatpin.$render(); + $scope.setPinForm.$setPristine(); + + $scope.error = 'Entered PINs were not equal. Try again'; + $timeout(function() { + $scope.$digest(); + }, 1); + } + }); + }; + + $scope.formFocus = function() { + if (!$scope.isWindowsPhoneApp) return + $scope.hideForWP = true; + $timeout(function() { + $scope.$digest(); + }, 1); + }; + + $scope.createPin = function(pin) { + preconditions.checkArgument(pin); + preconditions.checkState($rootScope.iden); + preconditions.checkState(_credentials && _credentials.email); + $rootScope.starting = true; + + // hide Keyboard after submit form + $window.document.querySelector('#repeatpin').blur(); + + $timeout(function() { + pinService.save(pin, _credentials.email, _credentials.password, function(err) { + _credentials.password = ''; + _credentials = null; + $scope.askForPin = 0; + $rootScope.hasPin = true; + $rootScope.starting = null; + $scope.createDefaultWallet(); + }); + }, 100); + }; - $scope.createStep = 'storage'; - $scope.useLocalstorage = false; - $scope.minPasswordStrength = _.isUndefined(config.minPasswordStrength) ? - 4 : config.minPasswordStrength; + $scope.setStep = function(step) { + $scope.error = null; + $scope.createStep = step; + $scope.hideForWP = false; + $timeout(function() { + $scope.$digest(); + }, 1); + }; - pinService.makePinInput($scope, 'newpin', function (newValue) { - _firstpin = newValue; - $scope.hideForWP = 0; - $scope.askForPin = 2; - $timeout(function () { - $scope.$digest(); - }, 1); + $scope.selectStorage = function(storage) { + $scope.useLocalstorage = storage == 'local'; + $scope.hideForWP = false; + $timeout(function() { + $scope.$digest(); + }, 1); + }; + $scope.goToEmail = function() { + $scope.createStep = 'email'; + $scope.useEmail = !$scope.useLocalstorage; + }; - }); + $scope.setEmailOrUsername = function(form) { + $scope.userOrEmail = $scope.useLocalstorage ? form.username.$modelValue : form.email.$modelValue; + preconditions.checkState($scope.userOrEmail); - pinService.makePinInput($scope, 'repeatpin', function (newValue) { - if (newValue === _firstpin) { - _firstpin = null; - $scope.createPin(newValue); - } else { - $scope.askForPin = 1; - $scope.hideForWP = 0; - $scope.passwordStrength = null; + $scope.error = null; + $scope.hideForWP = false; + $scope.createStep = 'pass'; + $timeout(function() { + $scope.$digest(); + }, 1); + }; - _firstpin = null; + /* Last step. Will emit after creation so the UX gets updated */ + $scope.createDefaultWallet = function() { + $rootScope.hideNavigation = false; + identityService.createDefaultWallet(function(err) { + $scope.askForPin = 0; - $scope.setPinForm.newpin.$setViewValue(''); - $scope.setPinForm.newpin.$render(); - $scope.setPinForm.repeatpin.$setViewValue(''); - $scope.setPinForm.repeatpin.$render(); - $scope.setPinForm.$setPristine(); - - $scope.error = 'Entered PINs were not equal. Try again'; - $timeout(function () { - $scope.$digest(); - }, 1); - } - }); - }; - - - $scope.formFocus = function () { - if ($scope.isWindowsPhoneApp) { - $scope.hideForWP = true; - $timeout(function () { - $scope.$digest(); - }, 1); + if (err) { + var msg = err.toString(); + $scope.error = msg; + } else { + if (!$scope.useLocalstorage) { + $rootScope.pleaseConfirmEmail = true; } - }; - $scope.createPin = function (pin) { - preconditions.checkArgument(pin); - preconditions.checkState($rootScope.iden); - preconditions.checkState(_credentials && _credentials.email); - $rootScope.starting = true; + } - // hide Keyboard after submit form - $window.document.querySelector('#repeatpin').blur(); + }); + }; - $timeout(function () { - pinService.save(pin, _credentials.email, _credentials.password, function (err) { - _credentials.password = ''; - _credentials = null; - $scope.askForPin = 0; - $rootScope.hasPin = true; - $rootScope.starting = null; - $scope.createDefaultWallet(); - }); - }, 100); - }; + $scope._doCreateProfile = function(emailOrUsername, password, cb) { + preconditions.checkArgument(_.isString(emailOrUsername)); + preconditions.checkArgument(_.isString(password)); + $rootScope.hideNavigation = false; + $rootScope.starting = true; - $scope.setStep = function (step) { - $scope.error = null; - $scope.createStep = step; - $scope.hideForWP = false; - $timeout(function () { - $scope.$digest(); - }, 1); - }; - - $scope.selectStorage = function (storage) { - $scope.useLocalstorage = storage == 'local'; - $scope.hideForWP = false; - $timeout(function () { - $scope.$digest(); - }, 1); - }; - - $scope.goToEmail = function () { - $scope.createStep = 'email'; - $scope.useEmail = !$scope.useLocalstorage; - }; - - $scope.setEmailOrUsername = function (form) { - $scope.userOrEmail = $scope.useLocalstorage ? form.username.$modelValue : form.email.$modelValue; - preconditions.checkState($scope.userOrEmail); - - $scope.error = null; - $scope.hideForWP = false; - $scope.createStep = 'pass'; - $timeout(function () { - $scope.$digest(); - }, 1); - }; - - /* Last step. Will emit after creation so the UX gets updated */ - $scope.createDefaultWallet = function () { - $rootScope.hideNavigation = false; - identityService.createDefaultWallet(function (err) { - $scope.askForPin = 0; - - if (err) { - var msg = err.toString(); - $scope.error = msg; - } else { - if (!$scope.useLocalstorage) { - $rootScope.pleaseConfirmEmail = true; - } - } - - }); - }; - - $scope._doCreateProfile = function (emailOrUsername, password, cb) { - preconditions.checkArgument(_.isString(emailOrUsername)); - preconditions.checkArgument(_.isString(password)); - - $rootScope.hideNavigation = false; - $rootScope.starting = true; - - identityService.create(emailOrUsername, password, function (err) { - $rootScope.starting = null; - $scope.error = null; - if (err) { - var msg = err.toString(); - if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) { - msg = 'This profile already exists' - $scope.createStep = 'email'; - } - if (msg.indexOf('EMAILERROR') >= 0) { - msg = 'Could not send verification email. Please check your email address.'; - $scope.createStep = 'email'; - } - $scope.error = msg; - $scope.passwordStrength = null; - } else { - // mobile - if ($scope.isMobile) { - _credentials = { - email: emailOrUsername, - password: password, - }; - $scope.askForPin = 1; - $scope.hideForWP = 0; - - $rootScope.hideNavigation = true; - $timeout(function () { - $rootScope.$digest(); - }, 1); - return; - } else { - $scope.createDefaultWallet(); - } - } - return cb(); - }); - }; - - - $scope.saveSettings = function (cb) { - var plugins = config.plugins; - - plugins.EncryptedLocalStorage = false; - plugins.EncryptedInsightStorage = false; - - var pluginName = $scope.useLocalstorage ? 'EncryptedLocalStorage' : 'EncryptedInsightStorage'; - plugins[pluginName] = true; - - configService.set({ - plugins: plugins - }, cb); - }; - - - $scope.createProfile = function (form) { - if (form && form.$invalid) { - $scope.error = 'Please enter the required fields'; - return; + identityService.create(emailOrUsername, password, function(err) { + $rootScope.starting = null; + $scope.error = null; + if (err) { + var msg = err.toString(); + if (msg.indexOf('EEXIST') >= 0 || msg.indexOf('BADC') >= 0) { + msg = 'This profile already exists' + $scope.createStep = 'email'; } + if (msg.indexOf('EMAILERROR') >= 0) { + msg = 'Could not send verification email. Please check your email address.'; + $scope.createStep = 'email'; + } + $scope.error = msg; + $scope.passwordStrength = null; + } else { + // mobile + if ($scope.isMobile) { + _credentials = { + email: emailOrUsername, + password: password, + }; + $scope.askForPin = 1; + $scope.hideForWP = 0; - $scope.saveSettings(function (err) { - preconditions.checkState(!err, err); + $rootScope.hideNavigation = true; + $timeout(function() { + $rootScope.$digest(); + }, 1); + return; + } else { + $scope.createDefaultWallet(); + } + } + return cb(); + }); + }; - $scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue, function (err) { - $timeout(function () { - form.password.$setViewValue(''); - form.password.$render(); - form.repeatpassword.$setViewValue(''); - form.repeatpassword.$render(); - form.$setPristine(); - }, 1); - }); - }); - }; + + $scope.saveSettings = function(cb) { + var plugins = config.plugins; + + plugins.EncryptedLocalStorage = false; + plugins.EncryptedInsightStorage = false; + + var pluginName = $scope.useLocalstorage ? 'EncryptedLocalStorage' : 'EncryptedInsightStorage'; + plugins[pluginName] = true; + + configService.set({ + plugins: plugins + }, cb); + }; + + + $scope.createProfile = function(form) { + if (form && form.$invalid) { + $scope.error = 'Please enter the required fields'; + return; + } + + $scope.saveSettings(function(err) { + preconditions.checkState(!err, err); + + $scope._doCreateProfile($scope.userOrEmail, form.password.$modelValue, function(err) { + $timeout(function() { + form.password.$setViewValue(''); + form.password.$render(); + form.repeatpassword.$setViewValue(''); + form.repeatpassword.$render(); + form.$setPristine(); + }, 1); + }); + }); + }; }); diff --git a/js/controllers/send.js b/js/controllers/send.js index 428e38536..53f84f207 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -13,9 +13,16 @@ angular.module('copayApp.controllers').controller('SendController', preconditions.checkState(w.settings.unitToSatoshi); + $scope.isMobile = isMobile.any(); + $scope.isWindowsPhoneApp = isMobile.Windows() && isCordova; + + // TODO + $scope.isWindowsPhoneApp = 1; + $rootScope.wpInputFocused = false; + $scope.isShared = w.isShared(); $scope.requiresMultipleSignatures = w.requiresMultipleSignatures(); - $rootScope.title =$scope.requiresMultipleSignatures ? 'Send Proposal' : 'Send'; + $rootScope.title = $scope.requiresMultipleSignatures ? 'Send Proposal' : 'Send'; $scope.loading = false; $scope.error = $scope.success = null; @@ -44,7 +51,30 @@ angular.module('copayApp.controllers').controller('SendController', $scope.isRateAvailable = true; $scope.$digest(); }); - } + }; + + $scope.formFocus = function(what) { + if (!$scope.isWindowsPhoneApp) return + + if (!what) { + $rootScope.wpInputFocused = false; + $scope.hideAddress = false; + $scope.hideAmount = false; + + } else { + $rootScope.wpInputFocused = true; + if (what == 'amount') { + $scope.hideAddress = true; + } else if (what == 'msg') { + $scope.hideAddress = true; + $scope.hideAmount = true; + } + + } + $timeout(function() { + $rootScope.$digest(); + }, 1); + }; $scope.setInputs = function() { var w = $rootScope.wallet; @@ -291,7 +321,7 @@ angular.module('copayApp.controllers').controller('SendController', window.ignoreMobilePause = true; cordova.plugins.barcodeScanner.scan( function onSuccess(result) { - $timeout(function(){ + $timeout(function() { window.ignoreMobilePause = false; }, 100); if (result.cancelled) return; @@ -305,7 +335,7 @@ angular.module('copayApp.controllers').controller('SendController', }, 1000); }, function onError(error) { - $timeout(function(){ + $timeout(function() { window.ignoreMobilePause = false; }, 100); alert('Scanning error'); diff --git a/views/send.html b/views/send.html index 15475b0aa..7e226e47d 100644 --- a/views/send.html +++ b/views/send.html @@ -1,6 +1,6 @@
-
+

{{$root.title}}

@@ -33,7 +33,7 @@
-
+
@@ -52,10 +52,10 @@ ×
-
+
-
- +
-
+
-
+
@@ -110,7 +110,7 @@
@@ -118,7 +118,7 @@
@@ -131,8 +131,8 @@ too long!
- - + +