From 64168144dbb4321ff96fc39dad6d4b00e422b17f Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 4 Feb 2014 20:04:32 +0400 Subject: [PATCH] Added settings, sound notifications --- app/css/app.css | 44 ++++++++++++++++- app/index.html | 8 ++-- app/js/app.js | 6 +-- app/js/controllers.js | 81 ++++++++++++++++++++++++++++++-- app/js/services.js | 59 ++++++++++++++--------- app/partials/head.html | 2 +- app/partials/im.html | 4 +- app/partials/login.html | 2 +- app/partials/settings_modal.html | 55 ++++++++++++++++++++++ app/partials/welcome.html | 2 +- 10 files changed, 224 insertions(+), 39 deletions(-) create mode 100644 app/partials/settings_modal.html diff --git a/app/css/app.css b/app/css/app.css index 392036f3..4a066aa7 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -224,16 +224,21 @@ fieldset[disabled] .btn-tg.active { line-height: 1.4; } -.modal-close-link { +.modal-close-link, +.modal-save-link { font-size: 12px; line-height: 1.4; float: right; padding: 0 2px 0; margin: 6px 2px 0 0; } -.modal-close-link:hover { +.modal-close-link:hover, +.modal-save-link:hover { text-decoration: none; } +.modal-save-link { + margin-right: 15px; +} @@ -1427,3 +1432,38 @@ img.img_fullsize { } } + +.settings_modal_window .modal-dialog { + max-width: 502px; +} +.settings_profile_edit_form { + margin-bottom: 15px; +} +.settings_profile_first_name, +.settings_profile_last_name { + width: 210px; + float: left; +} +.settings_profile_first_name { + margin-right: 22px; +} + +.settings_profile_edit_form input { + font-size: 12px; + line-height: normal; + background: #F2F2F2; + border: 1px solid #F2F2F2; + border-radius: 0; + padding: 6px 6px 6px 6px; + margin-bottom: 0; + margin: 0; +} +.settings_profile_edit_form input:focus, +.settings_profile_edit_form input:active { + background-color: #FFF; +} + +.settings_user_phone, +.settings_version { + color: #999; +} \ No newline at end of file diff --git a/app/index.html b/app/index.html index abbbc437..7746eb45 100644 --- a/app/index.html +++ b/app/index.html @@ -7,7 +7,7 @@ - + @@ -51,9 +51,9 @@ - - - + + + diff --git a/app/js/app.js b/app/js/app.js index 3b60c652..6e0acc8a 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -55,9 +55,9 @@ config(['$locationProvider', '$routeProvider', '$compileProvider', function($loc // $locationProvider.html5Mode(true); - $routeProvider.when('/', {templateUrl: 'partials/welcome.html?2', controller: 'AppWelcomeController'}); - $routeProvider.when('/login', {templateUrl: 'partials/login.html?3', controller: 'AppLoginController'}); - $routeProvider.when('/im', {templateUrl: 'partials/im.html?9', controller: 'AppIMController', reloadOnSearch: false}); + $routeProvider.when('/', {templateUrl: 'partials/welcome.html?3', controller: 'AppWelcomeController'}); + $routeProvider.when('/login', {templateUrl: 'partials/login.html?4', controller: 'AppLoginController'}); + $routeProvider.when('/im', {templateUrl: 'partials/im.html?10', controller: 'AppIMController', reloadOnSearch: false}); $routeProvider.otherwise({redirectTo: '/'}); }]); diff --git a/app/js/controllers.js b/app/js/controllers.js index 7dcbbf4a..89fa6b36 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -145,7 +145,7 @@ angular.module('myApp.controllers', []) }; }) - .controller('AppIMController', function ($scope, $location, $routeParams, MtpApiManager) { + .controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, MtpApiManager) { $scope.$on('$routeUpdate', updateCurDialog); @@ -159,10 +159,12 @@ angular.module('myApp.controllers', []) $scope.isLoggedIn = true; - $scope.logOut = function () { - MtpApiManager.logOut().then(function () { - location.hash = '/login'; - location.reload(); + $scope.openSettings = function () { + $modal.open({ + templateUrl: 'partials/settings_modal.html?1', + controller: 'SettingsModalController', + scope: $rootScope.$new(), + windowClass: 'settings_modal_window' }); } @@ -569,5 +571,74 @@ angular.module('myApp.controllers', []) }); }) + .controller('SettingsModalController', function ($scope, $timeout, AppUsersManager, AppChatsManager, MtpApiManager, AppConfigManager, NotificationsManager) { + + $scope.profile = {}; + + MtpApiManager.getUserID().then(function (id) { + var user = AppUsersManager.getUser(id); + $scope.profile.first_name = user.first_name; + $scope.profile.last_name = user.last_name; + + $scope.phone = user.phone; + }); + + $scope.notify = {}; + + AppConfigManager.get(['notify_nodesktop', 'notify_nosound']).then(function (settings) { + $scope.notify.sound = !settings.notify_nosound; + $scope.notify.desktop = !settings.notify_nodesktop; + }); + + $scope.$watch('notify.sound', function(newValue) { + if (newValue) { + AppConfigManager.remove('notify_nosound'); + } else { + AppConfigManager.set({notify_nosound: true}); + NotificationsManager.clear(); + } + }); + + $scope.$watch('notify.desktop', function(newValue) { + if (newValue) { + AppConfigManager.remove('notify_nodesktop'); + } else { + AppConfigManager.set({notify_nodesktop: true}); + } + }); + + $scope.error = {}; + $scope.save = function () { + MtpApiManager.invokeApi('account.updateProfile', { + first_name: $scope.profile.first_name || '', + last_name: $scope.profile.last_name || '' + }).then(function (user) { + $scope.error = {}; + AppUsersManager.saveApiUser(user); + }, function (error) { + switch (error.type) { + case 'FIRSTNAME_INVALID': + $scope.error = {field: 'first_name'}; + break; + + case 'LASTNAME_INVALID': + $scope.error = {field: 'last_name'}; + break; + + case 'NAME_NOT_MODIFIED': + $scope.error = {}; + break; + } + }); + } + + $scope.logOut = function () { + MtpApiManager.logOut().then(function () { + location.hash = '/login'; + location.reload(); + }); + } + }) + diff --git a/app/js/services.js b/app/js/services.js index e345daea..57da48e0 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -1937,7 +1937,7 @@ angular.module('myApp.services', []) }) -.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, MtpApiManager, AppPeersManager, IdleManager) { +.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, MtpApiManager, AppPeersManager, IdleManager, AppConfigManager) { var notificationsUiSupport = 'Notification' in window; var notificationsShown = {}; @@ -1983,6 +1983,7 @@ angular.module('myApp.services', []) start: start, notify: notify, cancel: notificationCancel, + clear: notificationsClear, getPeerSettings: getPeerSettings }; @@ -2036,32 +2037,48 @@ angular.module('myApp.services', []) return false; } - var idx = ++notificationIndex, - key = data.key || 'k' + idx; - - var notification = new Notification(data.title, { - icon: data.image || '', - body: data.message || '' - }); + AppConfigManager.get('notify_nosound').then(function (noSound) { + if (!noSound) { + playSound(); + } + }) - notification.onclick = function () { - notification.close(); - window.focus(); - notificationsClear(); - if (data.onclick) { - data.onclick(); + AppConfigManager.get('notify_nodesktop').then(function (noShow) { + if (noShow) { + return; } - }; + var idx = ++notificationIndex, + key = data.key || 'k' + idx; - notification.onclose = function () { - delete notificationsShown[key]; - // lastClosed.push(+new Date()); - notificationsClear(); - }; + var notification = new Notification(data.title, { + icon: data.image || '', + body: data.message || '' + }); - notificationsShown[key] = notification; + notification.onclick = function () { + notification.close(); + window.focus(); + notificationsClear(); + if (data.onclick) { + data.onclick(); + } + }; + + notification.onclose = function () { + delete notificationsShown[key]; + // lastClosed.push(+new Date()); + notificationsClear(); + }; + + notificationsShown[key] = notification; + }); }; + function playSound () { + var filename = 'img/sound_a.wav'; + $('#notify_sound').html(''); + } + function notificationCancel (key) { var notification = notificationsShown[key]; if (notification) { diff --git a/app/partials/head.html b/app/partials/head.html index c88bdb9a..ecf994a8 100644 --- a/app/partials/head.html +++ b/app/partials/head.html @@ -7,7 +7,7 @@ diff --git a/app/partials/im.html b/app/partials/im.html index e6362b1b..4698ab46 100644 --- a/app/partials/im.html +++ b/app/partials/im.html @@ -1,4 +1,4 @@ -
+
@@ -147,3 +147,5 @@ Telegram alpha by izhukov & toberg
+
+ diff --git a/app/partials/login.html b/app/partials/login.html index 1aaa6ba5..0699c6db 100644 --- a/app/partials/login.html +++ b/app/partials/login.html @@ -1,4 +1,4 @@ -
+
diff --git a/app/partials/settings_modal.html b/app/partials/settings_modal.html new file mode 100644 index 00000000..bc8e4d92 --- /dev/null +++ b/app/partials/settings_modal.html @@ -0,0 +1,55 @@ +
+ + + + +
\ No newline at end of file diff --git a/app/partials/welcome.html b/app/partials/welcome.html index a8172abc..ddbac02d 100644 --- a/app/partials/welcome.html +++ b/app/partials/welcome.html @@ -1,4 +1,4 @@ -
+