Browse Source

Added settings, sound notifications

master
Igor Zhukov 11 years ago
parent
commit
64168144db
  1. 44
      app/css/app.css
  2. 8
      app/index.html
  3. 6
      app/js/app.js
  4. 81
      app/js/controllers.js
  5. 19
      app/js/services.js
  6. 2
      app/partials/head.html
  7. 4
      app/partials/im.html
  8. 2
      app/partials/login.html
  9. 55
      app/partials/settings_modal.html
  10. 2
      app/partials/welcome.html

44
app/css/app.css

@ -224,16 +224,21 @@ fieldset[disabled] .btn-tg.active {
line-height: 1.4; line-height: 1.4;
} }
.modal-close-link { .modal-close-link,
.modal-save-link {
font-size: 12px; font-size: 12px;
line-height: 1.4; line-height: 1.4;
float: right; float: right;
padding: 0 2px 0; padding: 0 2px 0;
margin: 6px 2px 0 0; margin: 6px 2px 0 0;
} }
.modal-close-link:hover { .modal-close-link:hover,
.modal-save-link:hover {
text-decoration: none; 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;
}

8
app/index.html

@ -7,7 +7,7 @@
<link rel="stylesheet" href="vendor/angular/angular-csp.css"/> <link rel="stylesheet" href="vendor/angular/angular-csp.css"/>
<link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.css"/> <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" href="vendor/jquery.nanoscroller/nanoscroller.css"/> <link rel="stylesheet" href="vendor/jquery.nanoscroller/nanoscroller.css"/>
<link rel="stylesheet" href="css/app.css?17"/> <link rel="stylesheet" href="css/app.css?18"/>
<link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="icon" href="favicon.ico" type="image/x-icon" />
<meta property="og:title" content="Webogram"> <meta property="og:title" content="Webogram">
@ -51,9 +51,9 @@
<script type="text/javascript" src="js/lib/mtproto.js?17"></script> <script type="text/javascript" src="js/lib/mtproto.js?17"></script>
<script type="text/javascript" src="js/util.js"></script> <script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/app.js?12"></script> <script type="text/javascript" src="js/app.js?13"></script>
<script type="text/javascript" src="js/services.js?13"></script> <script type="text/javascript" src="js/services.js?14"></script>
<script type="text/javascript" src="js/controllers.js?21"></script> <script type="text/javascript" src="js/controllers.js?22"></script>
<script type="text/javascript" src="js/filters.js?3"></script> <script type="text/javascript" src="js/filters.js?3"></script>
<script type="text/javascript" src="js/directives.js?15"></script> <script type="text/javascript" src="js/directives.js?15"></script>

6
app/js/app.js

@ -55,9 +55,9 @@ config(['$locationProvider', '$routeProvider', '$compileProvider', function($loc
// $locationProvider.html5Mode(true); // $locationProvider.html5Mode(true);
$routeProvider.when('/', {templateUrl: 'partials/welcome.html?2', controller: 'AppWelcomeController'}); $routeProvider.when('/', {templateUrl: 'partials/welcome.html?3', controller: 'AppWelcomeController'});
$routeProvider.when('/login', {templateUrl: 'partials/login.html?3', controller: 'AppLoginController'}); $routeProvider.when('/login', {templateUrl: 'partials/login.html?4', controller: 'AppLoginController'});
$routeProvider.when('/im', {templateUrl: 'partials/im.html?9', controller: 'AppIMController', reloadOnSearch: false}); $routeProvider.when('/im', {templateUrl: 'partials/im.html?10', controller: 'AppIMController', reloadOnSearch: false});
$routeProvider.otherwise({redirectTo: '/'}); $routeProvider.otherwise({redirectTo: '/'});
}]); }]);

81
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); $scope.$on('$routeUpdate', updateCurDialog);
@ -159,10 +159,12 @@ angular.module('myApp.controllers', [])
$scope.isLoggedIn = true; $scope.isLoggedIn = true;
$scope.logOut = function () { $scope.openSettings = function () {
MtpApiManager.logOut().then(function () { $modal.open({
location.hash = '/login'; templateUrl: 'partials/settings_modal.html?1',
location.reload(); 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();
});
}
})

19
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 notificationsUiSupport = 'Notification' in window;
var notificationsShown = {}; var notificationsShown = {};
@ -1983,6 +1983,7 @@ angular.module('myApp.services', [])
start: start, start: start,
notify: notify, notify: notify,
cancel: notificationCancel, cancel: notificationCancel,
clear: notificationsClear,
getPeerSettings: getPeerSettings getPeerSettings: getPeerSettings
}; };
@ -2036,6 +2037,16 @@ angular.module('myApp.services', [])
return false; return false;
} }
AppConfigManager.get('notify_nosound').then(function (noSound) {
if (!noSound) {
playSound();
}
})
AppConfigManager.get('notify_nodesktop').then(function (noShow) {
if (noShow) {
return;
}
var idx = ++notificationIndex, var idx = ++notificationIndex,
key = data.key || 'k' + idx; key = data.key || 'k' + idx;
@ -2060,8 +2071,14 @@ angular.module('myApp.services', [])
}; };
notificationsShown[key] = notification; notificationsShown[key] = notification;
});
}; };
function playSound () {
var filename = 'img/sound_a.wav';
$('#notify_sound').html('<audio autoplay="autoplay"><source src="' + filename + '" type="audio/mpeg" /><embed hidden="true" autostart="true" loop="false" src="' + filename +'" /></audio>');
}
function notificationCancel (key) { function notificationCancel (key) {
var notification = notificationsShown[key]; var notification = notificationsShown[key];
if (notification) { if (notification) {

2
app/partials/head.html

@ -7,7 +7,7 @@
<div class="navbar-collapse collapse"> <div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/zhukov/webogram" target="_blank">About</a></li> <li><a href="https://github.com/zhukov/webogram" target="_blank">About</a></li>
<li ng-if="isLoggedIn"><a href="" ng-click="logOut()">Log out</a></li> <li ng-if="isLoggedIn"><a href="" ng-click="openSettings()">Settings</a></li>
</ul> </ul>
</div> </div>
</div> </div>

4
app/partials/im.html

@ -1,4 +1,4 @@
<div ng-include="'partials/head.html?1'"></div> <div ng-include="'partials/head.html?2'"></div>
<div class="im_page_wrap"> <div class="im_page_wrap">
@ -147,3 +147,5 @@
<a class="im_page_footer_brand" target="_blank" href="https://github.com/zhukov/webogram">Telegram alpha</a> by izhukov &amp; toberg <a class="im_page_footer_brand" target="_blank" href="https://github.com/zhukov/webogram">Telegram alpha</a> by izhukov &amp; toberg
</div> </div>
<div id="notify_sound"></div>

2
app/partials/login.html

@ -1,4 +1,4 @@
<div ng-include="'partials/head.html?1'"></div> <div ng-include="'partials/head.html?2'"></div>
<div class="login_form_wrap"> <div class="login_form_wrap">

55
app/partials/settings_modal.html

@ -0,0 +1,55 @@
<div class="settings_modal_wrap">
<div class="modal-header">
<a class="modal-close-link" ng-click="$close()">Close</a>
<a class="modal-save-link" ng-click="save()">Save</a>
<h4 class="modal-title">Settings</h4>
</div>
<div class="modal-body">
<form class="settings_profile_edit_form clearfix">
<div class="form-group settings_profile_first_name" ng-class="{'has-error': error.field == 'first_name'}">
<label class="control-label" for="first_name">
<span ng-if="error.field == 'first_name'">Invalid First Name</span>
<span ng-if="error.field != 'first_name'">First Name</span>
</label>
<input type="text" class="form-control" name="first_name" ng-model="profile.first_name" required />
</div>
<div class="form-group settings_profile_last_name" ng-class="{'has-error': error.field == 'last_name'}">
<label class="control-label" for="last_name">
<span ng-if="error.field == 'last_name'">Invalid Last Name</span>
<span ng-if="error.field != 'last_name'">Last Name</span>
</label>
<input type="text" class="form-control" name="last_name" ng-model="profile.last_name" />
</div>
</form>
<p>
<strong>Sound: </strong>
<a ng-click="notify.sound = !notify.sound">{{notify.sound ? 'ON' : 'OFF'}}</a>
</p>
<p>
<strong>Desktop Notifications: </strong>
<a ng-click="notify.desktop = !notify.desktop">{{notify.desktop ? 'ON' : 'OFF'}}</a>
</p>
<p>
<strong>User: </strong>
<span class="settings_user_phone">{{phone | phoneNumber}}</span>
</p>
<p>
<strong>Version: </strong>
<span class="settings_version">alpha 0.0.12</span>
</p>
<hr/>
<div class="settings_logout_wrap">
<a href="" ng-click="logOut()">Log out</a>
</div>
</div>
</div>

2
app/partials/welcome.html

@ -1,4 +1,4 @@
<div ng-include="'partials/head.html?1'"></div> <div ng-include="'partials/head.html?2'"></div>
<div ng-show="showWelcome"> <div ng-show="showWelcome">

Loading…
Cancel
Save