Skip to content

Commit

Permalink
Merge pull request #216 from dpaloucva/MOBILE-1218
Browse files Browse the repository at this point in the history
MOBILE-1218 keyboard: Close keyboard when submitting some forms
  • Loading branch information
jleyva committed Sep 10, 2015
2 parents 4d62590 + bb77588 commit c0e5e5a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 5 deletions.
5 changes: 4 additions & 1 deletion www/addons/messages/controllers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('mm.addons.messages')
* @ngdoc controller
* @name mmaMessagesContactsCtrl
*/
.controller('mmaMessagesContactsCtrl', function($scope, $mmaMessages, $mmSite, $mmUtil, mmUserProfileState) {
.controller('mmaMessagesContactsCtrl', function($scope, $mmaMessages, $mmSite, $mmUtil, $mmApp, mmUserProfileState) {

var currentUserId = $mmSite.getUserId();

Expand Down Expand Up @@ -52,6 +52,9 @@ angular.module('mm.addons.messages')
// too many users!
return;
}

$mmApp.closeKeyboard();

$scope.loaded = false;
return $mmaMessages.searchContacts(query).then(function(result) {
$scope.hasContacts = result.length > 0;
Expand Down
5 changes: 5 additions & 0 deletions www/addons/messages/controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ angular.module('mm.addons.messages')
message.sending = false;
notifyNewMessage();
}, function(error) {

// Only close the keyboard if an error happens, we want the user to be able to send multiple
// messages withoutthe keyboard being closed.
$mmApp.closeKeyboard();

if (typeof error === 'string') {
$mmUtil.showErrorModal(error);
} else {
Expand Down
4 changes: 4 additions & 0 deletions www/addons/mod_chat/controllers/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ angular.module('mm.addons.mod_chat')
$scope.newMessage.text = '';
}
}, function(error) {
// Only close the keyboard if an error happens, we want the user to be able to send multiple
// messages withoutthe keyboard being closed.
$mmApp.closeKeyboard();

showError(error);
});
};
Expand Down
5 changes: 4 additions & 1 deletion www/addons/notes/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('mm.addons.notes')
* @ngdoc service
* @name $mmaNotesHandlers
*/
.factory('$mmaNotesHandlers', function($mmaNotes, $mmSite, $translate, $ionicLoading, $ionicModal, $mmUtil) {
.factory('$mmaNotesHandlers', function($mmaNotes, $mmSite, $mmApp, $ionicModal, $mmUtil) {

var self = {};

Expand Down Expand Up @@ -92,6 +92,9 @@ angular.module('mm.addons.notes')
};

$scope.addNote = function(){

$mmApp.closeKeyboard();

var loadingModal = $mmUtil.showModalLoading('mm.core.sending', true);
// Freeze the add note button.
$scope.processing = true;
Expand Down
4 changes: 3 additions & 1 deletion www/core/components/login/controllers/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ angular.module('mm.core.login')
* @ngdoc controller
* @name mmLoginCredentialsCtrl
*/
.controller('mmLoginCredentialsCtrl', function($scope, $state, $stateParams, $mmSitesManager, $mmUtil, $ionicHistory) {
.controller('mmLoginCredentialsCtrl', function($scope, $state, $stateParams, $mmSitesManager, $mmUtil, $ionicHistory, $mmApp) {

$scope.siteurl = $stateParams.siteurl;
$scope.credentials = {};

$scope.login = function() {

$mmApp.closeKeyboard();

// Get input data.
var siteurl = $scope.siteurl,
username = $scope.credentials.username,
Expand Down
4 changes: 3 additions & 1 deletion www/core/components/login/controllers/reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('mm.core.login')
* @ngdoc controller
* @name mmLoginReconnectCtrl
*/
.controller('mmLoginReconnectCtrl', function($scope, $state, $stateParams, $mmSitesManager, $mmSite, $mmUtil, $ionicHistory) {
.controller('mmLoginReconnectCtrl', function($scope, $state, $stateParams, $mmSitesManager, $mmApp, $mmUtil, $ionicHistory) {

var infositeurl = $stateParams.infositeurl; // Siteurl in site info. It might be different than siteurl (http/https).
$scope.siteurl = $stateParams.siteurl;
Expand All @@ -42,6 +42,8 @@ angular.module('mm.core.login')

$scope.login = function() {

$mmApp.closeKeyboard();

// Get input data.
var siteurl = $scope.siteurl,
username = $scope.credentials.username,
Expand Down
4 changes: 3 additions & 1 deletion www/core/components/login/controllers/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ angular.module('mm.core.login')
* @ngdoc controller
* @name mmLoginSiteCtrl
*/
.controller('mmLoginSiteCtrl', function($scope, $state, $mmSitesManager, $mmUtil, $translate, $ionicHistory,
.controller('mmLoginSiteCtrl', function($scope, $state, $mmSitesManager, $mmUtil, $translate, $ionicHistory, $mmApp,
$ionicModal, $mmLoginHelper) {

$scope.siteurl = '';
Expand All @@ -45,6 +45,8 @@ angular.module('mm.core.login')

$scope.connect = function(url) {

$mmApp.closeKeyboard();

if (!url) {
$mmUtil.showErrorModal('mm.login.siteurlrequired', true);
return;
Expand Down
13 changes: 13 additions & 0 deletions www/core/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ angular.module('mm.core')
$stateProvider.state(name, config);
};

/**
* Closes the keyboard if plugin is available.
*
* @return {Boolean} True if plugin is available, false otherwise.
*/
self.closeKeyboard = function() {
if (cordova && cordova.plugins && cordova.plugins.Keyboard && cordova.plugins.Keyboard.close) {
cordova.plugins.Keyboard.close();
return true;
}
return false;
};

/**
* Get the application global database.
* @return {Object} App's DB.
Expand Down

0 comments on commit c0e5e5a

Please sign in to comment.