From 365efe60379bcabb311e280dee9f89ab4505abf0 Mon Sep 17 00:00:00 2001 From: Haktrum Date: Sun, 23 Feb 2014 19:53:14 -0300 Subject: [PATCH 1/2] Fix to #75 - Added support for updating user photo --- app/css/app.css | 15 +++++++++++++++ app/js/controllers.js | 29 ++++++++++++++++++++++++++++- app/js/directives.js | 21 +++++++++++++++++++++ app/partials/settings_modal.html | 14 +++++++++++++- 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/app/css/app.css b/app/css/app.css index 48c621b8..8ed381a3 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -2067,4 +2067,19 @@ img.img_fullsize { .im_emoji_btn { display: none; } +} + +.user_photo_update { + cursor: pointer; + display: block; + overflow: hidden; + padding: 0; + + margin-top: 5px; + margin-left: 20px; + width: 120px; + height: 120px; + left: 0; + top: 15px; + position: absolute; } \ No newline at end of file diff --git a/app/js/controllers.js b/app/js/controllers.js index a3d614c1..661f82c8 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -833,7 +833,7 @@ angular.module('myApp.controllers', []) }) - .controller('SettingsModalController', function ($rootScope, $scope, $timeout, AppUsersManager, AppChatsManager, MtpApiManager, AppConfigManager, NotificationsManager) { + .controller('SettingsModalController', function ($rootScope, $scope, $timeout, AppUsersManager, AppChatsManager, MtpApiManager, AppConfigManager, NotificationsManager, MtpApiFileManager) { $scope.profile = {}; @@ -841,12 +841,39 @@ angular.module('myApp.controllers', []) var user = AppUsersManager.getUser(id); $scope.profile.first_name = user.first_name; $scope.profile.last_name = user.last_name; + $scope.profile.photo = AppUsersManager.getUserPhoto(id, 'User'); $scope.phone = user.phone; }); $scope.notify = {}; $scope.send = {}; + $scope.profile.userPhoto = {}; + $scope.updatingPhoto = false; + + $scope.$watch('profile.userPhoto', onPhotoSelected); + + function onPhotoSelected (photo) { + if (!photo.hasOwnProperty('name')) { + return; + } + $scope.updatingPhoto = true; + MtpApiFileManager.uploadFile(photo).then(function (inputFile) { + MtpApiManager.invokeApi('photos.uploadProfilePhoto', { + file: inputFile, + caption: '', + geo_point: {_: 'inputGeoPointEmpty'}, + crop: {_: 'inputPhotoCropAuto'} + }).then(function() { + MtpApiManager.getUserID().then(function (id) { + console.log($scope.profile.photo); + $scope.profile.photo = AppUsersManager.getUserPhoto(id, 'User'); + console.log($scope.profile.photo); + }); + $scope.updatingPhoto = false; + }); + }); + }; AppConfigManager.get('notify_nodesktop', 'notify_nosound', 'send_ctrlenter').then(function (settings) { $scope.notify.desktop = !settings[0]; diff --git a/app/js/directives.js b/app/js/directives.js index 7308be7a..fcec9124 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -749,4 +749,25 @@ angular.module('myApp.directives', ['myApp.filters']) }, 100); } }; + }) + + .directive('mySettingsForm', function(){ + return { + link: link + }; + + function link(scope, element, attrs) { + var photoSelect = $('input.im_attach_input', element); + photoSelect.on('change', function () { + var self = this; + scope.$apply(function () { + scope.profile.userPhoto = self.files[0]; + setTimeout(function () { + try { + self.value = ''; + } catch (e) {}; + }, 1000); + }); + }); + }; }); diff --git a/app/partials/settings_modal.html b/app/partials/settings_modal.html index 435720b6..0bddf812 100644 --- a/app/partials/settings_modal.html +++ b/app/partials/settings_modal.html @@ -7,7 +7,19 @@