From f8b20ecb107589783dc32358e484dd3723d90b2f Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Wed, 19 Nov 2014 14:31:36 +0100 Subject: [PATCH] Refactored automatic settings opener to open only once after user settings were loaded by adding the userSettingsLoaded event to appData service. --- static/js/controllers/mediastreamcontroller.js | 1 + static/js/directives/settings.js | 16 +++++++++++++++- static/js/directives/usability.js | 2 -- static/js/services/appdata.js | 14 ++++++++++---- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/static/js/controllers/mediastreamcontroller.js b/static/js/controllers/mediastreamcontroller.js index ee5bb48b..0ada8db2 100644 --- a/static/js/controllers/mediastreamcontroller.js +++ b/static/js/controllers/mediastreamcontroller.js @@ -273,6 +273,7 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder } else { $scope.loadedUser = false; } + appData.e.triggerHandler("userSettingsLoaded", [$scope.loadedUser, $scope.user]); $scope.reset(); }; diff --git a/static/js/directives/settings.js b/static/js/directives/settings.js index a17cb8ac..6317cae4 100644 --- a/static/js/directives/settings.js +++ b/static/js/directives/settings.js @@ -45,10 +45,11 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t return ["$compile", "mediaStream", function($compile, mediaStream) { - var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', 'localStorage', 'userSettingsData', 'constraints', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation, localStorage, userSettingsData, constraints) { + var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', 'localStorage', 'userSettingsData', 'constraints', 'appData', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation, localStorage, userSettingsData, constraints, appData) { $scope.layout.settings = false; $scope.showAdvancedSettings = true; + $scope.autoshowSettings = true; $scope.rememberSettings = true; $scope.desktopNotify = desktopNotify; $scope.mediaSources = mediaSources; @@ -154,6 +155,19 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t } }); + appData.e.on("userSettingsLoaded", function(event, loaded) { + if ($scope.autoshowSettings) { + $scope.autoshowSettings = false; + if (!loaded) { + $scope.layout.settings = true; + } + } + }); + + appData.e.on("authenticationChanged", function() { + $scope.autoshowSettings = true; + }); + constraints.e.on("refresh", function(event, constraints) { var settings = $scope.master.settings; diff --git a/static/js/directives/usability.js b/static/js/directives/usability.js index d9a9194f..cd838173 100644 --- a/static/js/directives/usability.js +++ b/static/js/directives/usability.js @@ -88,14 +88,12 @@ define(['jquery', 'underscore', 'text!partials/usability.html'], function($, _, $scope.$on("room.joined", function(event) { if (complete) { - $scope.layout.settings = !$scope.loadedUser; ctrl.setInfo("ok"); } }); $scope.$on("room.left", function(event) { if (complete) { - $scope.layout.settings = false; ctrl.setInfo("ok"); } }); diff --git a/static/js/services/appdata.js b/static/js/services/appdata.js index 6cbcb735..cfd16e2d 100644 --- a/static/js/services/appdata.js +++ b/static/js/services/appdata.js @@ -21,7 +21,7 @@ define(["jquery"], function($) { // appData.e events: - // subscribe these events with appData.e.on(eventname, function() {}). + // Subscribe these events with appData.e.on(eventname, function() {}). // // - authenticationChanged(event, userid, suserid) // userid (string) : Public user id of the authenticated user. @@ -39,11 +39,17 @@ define(["jquery"], function($) { // status (string) : Status id (connected, waiting, ...) // // - authorizing(event, flag) - // flag (bool) : True if authorizing, else false. + // flag (bool) : True if authorizing phase, else false. // - // appData properties: + // - userSettingsLoaded(event, loaded, user_settings) + // loaded (bool) : True if something was loaded, else false. + // user_settings (map) : User map which was loaded. // - // - language (string): ISO language code of active language + // Other appData properties: + // + // - language (string) : ISO language code of active language. + // - id (string) : Random string generated on app startup. + // - flags (map) : Flag table. // appData return ["randomGen", "$window", function(randomGen, $window) {