From 49d1c9c506b954b4dcc083c94e07bde23a82e73d Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 10 Apr 2015 20:17:36 +0300 Subject: [PATCH] Improved embed support --- app/js/controllers.js | 31 +++++++++++++++ app/js/directives.js | 8 +++- app/js/services.js | 30 +++++++++++---- app/less/desktop.less | 5 +++ app/partials/desktop/embed_modal.html | 38 +++++++++++++++++++ .../desktop/message_attach_webpage.html | 4 +- 6 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 app/partials/desktop/embed_modal.html diff --git a/app/js/controllers.js b/app/js/controllers.js index e52c78b5..e98967b0 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -2335,6 +2335,37 @@ angular.module('myApp.controllers', ['myApp.i18n']) }); }) + .controller('EmbedModalController', function ($q, $sce, $scope, $rootScope, $modalInstance, AppPhotosManager, AppMessagesManager, AppPeersManager, AppWebPagesManager, PeersSelectService, ErrorService) { + + $scope.webpage = AppWebPagesManager.wrapForHistory($scope.webpageID); + + $scope.iframeSrc = $sce.trustAsResourceUrl($scope.webpage.embed_url); + + $scope.nav = {}; + + $scope.forward = function () { + var messageID = $scope.messageID; + PeersSelectService.selectPeers({confirm_type: 'FORWARD_PEER'}).then(function (peerStrings) { + angular.forEach(peerStrings, function (peerString) { + var peerID = AppPeersManager.getPeerID(peerString); + AppMessagesManager.forwardMessages(peerID, [messageID]).then(function () { + if (peerStrings.length == 1) { + $rootScope.$broadcast('history_focus', {peerString: peerString}); + } + }); + }); + }); + }; + + $scope['delete'] = function () { + var messageID = $scope.messageID; + ErrorService.confirm({type: 'MESSAGE_DELETE'}).then(function () { + AppMessagesManager.deleteMessages([messageID]); + }); + }; + + }) + .controller('UserModalController', function ($scope, $location, $rootScope, $modal, AppUsersManager, MtpApiManager, NotificationsManager, AppPhotosManager, AppMessagesManager, AppPeersManager, PeersSelectService, ErrorService) { var peerString = AppUsersManager.getUserString($scope.userID); diff --git a/app/js/directives.js b/app/js/directives.js index d0c7054a..18ed4257 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -457,7 +457,7 @@ angular.module('myApp.directives', ['myApp.filters']) templateUrl: templateUrl('message_attach_contact') }; }) - .directive('myMessageWebpage', function(AppPhotosManager) { + .directive('myMessageWebpage', function(AppWebPagesManager, AppPhotosManager) { return { scope: { 'webpage': '=myMessageWebpage', @@ -466,6 +466,12 @@ angular.module('myApp.directives', ['myApp.filters']) templateUrl: templateUrl('message_attach_webpage'), link: function ($scope) { $scope.openPhoto = AppPhotosManager.openPhoto; + $scope.openEmbed = function ($event) { + if ($scope.webpage && $scope.webpage.embed_url) { + AppWebPagesManager.openEmbed($scope.webpage.id, $scope.messageId); + return cancelEvent($event); + } + }; $scope.$on('webpage_updated', function (e, eventData) { if ($scope.webpage && $scope.webpage.id == eventData.id) { diff --git a/app/js/services.js b/app/js/services.js index 8da21099..60cd67a1 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -2827,13 +2827,20 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } }; - $rootScope.$on('apiUpdate', function (e, update) { - switch (update._) { - case 'updateWebPage': - saveWebPage(update.webpage); - break; - } - }); + function openEmbed (webpageID, messageID) { + var scope = $rootScope.$new(true); + + scope.webpageID = webpageID; + scope.messageID = messageID; + + $modal.open({ + templateUrl: templateUrl('embed_modal'), + windowTemplateUrl: templateUrl('media_modal_layout'), + controller: 'EmbedModalController', + scope: scope, + windowClass: 'photo_modal_window' + }); + } function wrapForHistory (webPageID) { var webPage = angular.copy(webpages[webPageID]) || {_: 'webPageEmpty'}; @@ -2845,8 +2852,17 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) return webPage; } + $rootScope.$on('apiUpdate', function (e, update) { + switch (update._) { + case 'updateWebPage': + saveWebPage(update.webpage); + break; + } + }); + return { saveWebPage: saveWebPage, + openEmbed: openEmbed, wrapForHistory: wrapForHistory } }) diff --git a/app/less/desktop.less b/app/less/desktop.less index e1c31771..781b5807 100644 --- a/app/less/desktop.less +++ b/app/less/desktop.less @@ -2153,6 +2153,11 @@ a.im_panel_peer_photo .peer_initials { } } +.embed_modal_wrap .modal-body { + line-height: 0; + padding: 0; +} + .photo_modal_window, .video_modal_window, .document_modal_window { diff --git a/app/partials/desktop/embed_modal.html b/app/partials/desktop/embed_modal.html new file mode 100644 index 00000000..12c1c7bb --- /dev/null +++ b/app/partials/desktop/embed_modal.html @@ -0,0 +1,38 @@ + + +
+
+ + +
+
+ +
+
+
+ +
+
+
+ + \ No newline at end of file diff --git a/app/partials/desktop/message_attach_webpage.html b/app/partials/desktop/message_attach_webpage.html index 2e64a0ec..b5766a7b 100644 --- a/app/partials/desktop/message_attach_webpage.html +++ b/app/partials/desktop/message_attach_webpage.html @@ -19,7 +19,7 @@
- +
- +