From 70a021d722d352fb6e3375322fb6f4179043a215 Mon Sep 17 00:00:00 2001 From: Kenneth Ho Date: Tue, 15 Mar 2016 02:27:57 +0800 Subject: [PATCH 1/3] Added if statement to check where is the current page before showing the create exploration modal or redirecting. --- .../ExplorationCreationButtonService.js | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/core/templates/dev/head/components/ExplorationCreationButtonService.js b/core/templates/dev/head/components/ExplorationCreationButtonService.js index 69e363e40ed2..1245f35f9be2 100644 --- a/core/templates/dev/head/components/ExplorationCreationButtonService.js +++ b/core/templates/dev/head/components/ExplorationCreationButtonService.js @@ -140,31 +140,37 @@ oppia.factory('ExplorationCreationButtonService', [ showCreateExplorationModal: function(categoryList) { alertsService.clearWarnings(); - siteAnalyticsService.registerOpenExplorationCreationModalEvent(); + var currentPage = window.location.pathname; - getModalInstance(categoryList, false).result.then(function(result) { - var category = $filter('normalizeWhitespace')(result.category); - if (!validatorsService.isValidEntityName(category, true)) { - return; - } + if (currentPage.indexOf('/my_explorations') === -1) { + window.location.replace('/my_explorations?mode=create'); + } else { + siteAnalyticsService.registerOpenExplorationCreationModalEvent(); - $rootScope.loadingMessage = 'Creating exploration'; - $http.post('/contributehandler/create_new', { - category: category, - language_code: result.languageCode, - objective: $filter('normalizeWhitespace')(result.objective), - title: result.title - }).success(function(data) { - siteAnalyticsService.registerCreateNewExplorationEvent( - data.explorationId); - $timeout(function() { - $window.location = '/create/' + data.explorationId; - }, 150); - return false; - }).error(function() { - $rootScope.loadingMessage = ''; + getModalInstance(categoryList, false).result.then(function(result) { + var category = $filter('normalizeWhitespace')(result.category); + if (!validatorsService.isValidEntityName(category, true)) { + return; + } + + $rootScope.loadingMessage = 'Creating exploration'; + $http.post('/contributehandler/create_new', { + category: category, + language_code: result.languageCode, + objective: $filter('normalizeWhitespace')(result.objective), + title: result.title + }).success(function(data) { + siteAnalyticsService.registerCreateNewExplorationEvent( + data.explorationId); + $timeout(function() { + $window.location = '/create/' + data.explorationId; + }, 150); + return false; + }).error(function() { + $rootScope.loadingMessage = ''; + }); }); - }); + } }, showUploadExplorationModal: function(categoryList) { alertsService.clearWarnings(); From 071a2354580888ce0bf7472bfbf4fad27bace9ba Mon Sep 17 00:00:00 2001 From: Kenneth Ho Date: Tue, 15 Mar 2016 09:38:11 +0800 Subject: [PATCH 2/3] Changed comparison to strict comparison --- .../dev/head/components/ExplorationCreationButtonService.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/templates/dev/head/components/ExplorationCreationButtonService.js b/core/templates/dev/head/components/ExplorationCreationButtonService.js index 1245f35f9be2..e4bfbbc2d756 100644 --- a/core/templates/dev/head/components/ExplorationCreationButtonService.js +++ b/core/templates/dev/head/components/ExplorationCreationButtonService.js @@ -142,7 +142,8 @@ oppia.factory('ExplorationCreationButtonService', [ var currentPage = window.location.pathname; - if (currentPage.indexOf('/my_explorations') === -1) { + if (currentPage !== '/my_explorations' && + currentPage !== '/my_explorations?mode=create') { window.location.replace('/my_explorations?mode=create'); } else { siteAnalyticsService.registerOpenExplorationCreationModalEvent(); From 02eecb4aaeeced0a9541131290f7c19a19eee359 Mon Sep 17 00:00:00 2001 From: Kenneth Ho Date: Tue, 15 Mar 2016 14:12:51 +0800 Subject: [PATCH 3/3] Added getPathname in urlService and updated as required. --- core/templates/dev/head/app.js | 3 +++ .../components/ExplorationCreationButtonService.js | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/templates/dev/head/app.js b/core/templates/dev/head/app.js index a2f8ce7414e0..5ecb2f73469e 100644 --- a/core/templates/dev/head/app.js +++ b/core/templates/dev/head/app.js @@ -358,6 +358,9 @@ oppia.factory('urlService', ['$window', function($window) { }, isIframed: function() { return !!(this.getUrlParams().iframed); + }, + getPathname: function() { + return window.location.pathname; } }; }]); diff --git a/core/templates/dev/head/components/ExplorationCreationButtonService.js b/core/templates/dev/head/components/ExplorationCreationButtonService.js index e4bfbbc2d756..7f96b33f8008 100644 --- a/core/templates/dev/head/components/ExplorationCreationButtonService.js +++ b/core/templates/dev/head/components/ExplorationCreationButtonService.js @@ -21,10 +21,12 @@ // Service for the create/upload exploration buttons and modals. oppia.factory('ExplorationCreationButtonService', [ '$filter', '$http', '$modal', '$timeout', '$rootScope', '$window', - 'validatorsService', 'alertsService', 'focusService', 'siteAnalyticsService', + 'validatorsService', 'alertsService', 'focusService', + 'siteAnalyticsService', 'urlService', function( $filter, $http, $modal, $timeout, $rootScope, $window, - validatorsService, alertsService, focusService, siteAnalyticsService) { + validatorsService, alertsService, focusService, + siteAnalyticsService, urlService) { var getModalInstance = function(categoryList, isUploadModal) { var modalInstance = $modal.open({ backdrop: true, @@ -140,10 +142,9 @@ oppia.factory('ExplorationCreationButtonService', [ showCreateExplorationModal: function(categoryList) { alertsService.clearWarnings(); - var currentPage = window.location.pathname; + var currentPathname = urlService.getPathname(); - if (currentPage !== '/my_explorations' && - currentPage !== '/my_explorations?mode=create') { + if (currentPathname !== '/my_explorations') { window.location.replace('/my_explorations?mode=create'); } else { siteAnalyticsService.registerOpenExplorationCreationModalEvent();