diff --git a/www/index.html b/www/index.html index fe43c3f752a3952427c05955b6d60f527ac2dd05..72084060e2784042c8039c94a010b43a03875032 100644 --- a/www/index.html +++ b/www/index.html @@ -249,6 +249,7 @@ <script src="dist/dist_js/plugins/map/js/services/wot-services.js"></script> <script src="dist/dist_js/plugins/map/js/services/registry-services.js"></script> <script src="dist/dist_js/plugins/map/js/services/utils-services.js"></script> + <script src="dist/dist_js/plugins/map/js/controllers/common-controllers.js"></script> <script src="dist/dist_js/plugins/map/js/controllers/wot-controllers.js"></script> <script src="dist/dist_js/plugins/map/js/controllers/registry-controllers.js"></script> <script src="dist/dist_js/plugins/map/js/controllers/network-controllers.js"></script> diff --git a/www/plugins/es/js/controllers/common-controllers.js b/www/plugins/es/js/controllers/common-controllers.js index 415602f8936985b7cc5fdee8a45431b3e9fd0fde..2952735a5d2a071673092f37412e367374acde26 100644 --- a/www/plugins/es/js/controllers/common-controllers.js +++ b/www/plugins/es/js/controllers/common-controllers.js @@ -495,6 +495,7 @@ function ESPositionEditController($scope, csConfig, esGeo, ModalUtils) { loading: false, enable: undefined }; + $scope.searchModalOpened = false; $scope.tryToLocalize = function() { if ($scope.formPosition.loading || loadingCurrentPosition) return; @@ -603,6 +604,9 @@ function ESPositionEditController($scope, csConfig, esGeo, ModalUtils) { $scope.openSearchLocationModal = function(options) { + if ($scope.searchModalOpened) return; // Skip + + $scope.searchModalOpened = true; options = options || {}; var parameters = { @@ -618,10 +622,16 @@ function ESPositionEditController($scope, csConfig, esGeo, ModalUtils) { parameters, { focusFirstInput: true - //,scope: $scope } ) - .then($scope.updateGeoPoint); + .then(function(res) { + $scope.searchModalOpened = false; + $scope.updateGeoPoint(res); + }) + .catch(function() { + console.error(err); + $scope.searchModalOpened = false; + }); }; } diff --git a/www/plugins/es/js/controllers/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js index 7d1cc4c221d9e7608200d6400eca545a4b0315eb..621387f58a54b74b52dacdf0c914bd7b9bff9a2a 100644 --- a/www/plugins/es/js/controllers/registry-controllers.js +++ b/www/plugins/es/js/controllers/registry-controllers.js @@ -1375,8 +1375,6 @@ function ESRegistryRecordEditController($scope, $timeout, $state, $q, $ionicHis if (!$scope.avatar) { $scope.avatarClass['cion-page-' + type] = true; } - $scope.doSearch(); - $scope.updateLocationHref(); } }); }; @@ -1392,8 +1390,6 @@ function ESRegistryRecordEditController($scope, $timeout, $state, $q, $ionicHis .then(function(cat){ if (cat && cat.parent) { $scope.formData.category = cat; - $scope.doSearch(); - $scope.updateLocationHref(); } }); }; diff --git a/www/plugins/es/templates/registry/edit_record.html b/www/plugins/es/templates/registry/edit_record.html index 204528e579189eea40f4caacfafb51e40c388e21..e001f7caa24d401967276ee33a621f22b6a02e95 100644 --- a/www/plugins/es/templates/registry/edit_record.html +++ b/www/plugins/es/templates/registry/edit_record.html @@ -115,7 +115,7 @@ </div> <!-- position --> - <ng-include src="'plugins/es/templates/common/edit_position.html'"></ng-include> + <ng-include src="'plugins/es/templates/common/edit_position.html'" ng-controller="ESPositionEditCtrl as ctrl"></ng-include> <!-- social networks --> <ng-include src="'plugins/es/templates/common/edit_socials.html'" ng-controller="ESSocialsEditCtrl"></ng-include> diff --git a/www/plugins/map/js/controllers/common-controllers.js b/www/plugins/map/js/controllers/common-controllers.js new file mode 100644 index 0000000000000000000000000000000000000000..cd36c8d1dcddb28cd85d457e7e824d7da4f315da --- /dev/null +++ b/www/plugins/map/js/controllers/common-controllers.js @@ -0,0 +1,109 @@ + +angular.module('cesium.map.common.controllers', ['cesium.services', 'cesium.map.services']) + + .controller('MapEditPositionAbstractCtrl', MapEditPositionAbstractController) + +; + +/** + * An abstract controller, that allow to edit psotion, using a map view (e.g. used by profile and page edition) + * @param $scope + * @param $timeout + * @param $q + * @param MapUtils + * @param $translate + * @constructor + */ +function MapEditPositionAbstractController($scope, $timeout, $q, MapUtils, $translate) { + 'ngInject'; + + var listeners = []; + $scope.mapId = 'map-user-profile-' + $scope.$id; + $scope.map = MapUtils.map({ + markers: {}, + center: { + zoom: 13 + } + }); + $scope.loading = true; + $scope.mapId = $scope.mapId ||Â 'map-abstract-' + $scope.$id; // Should have beed override by sub-controllers + + $scope.enter = function(e, state) { + + // Wait parent controller load the profile + if (!$scope.formData || (!$scope.formData.title && !$scope.formData.geoPoint)) { + return $timeout($scope.enter, 500); + } + + $scope.loading = true; + return $scope.load(); + }; + $scope.$on('$csExtension.enter', $scope.enter); + $scope.$on('$ionicParentView.enter', $scope.enter); + + $scope.load = function() { + + // no position define: remove existing listener + if (!$scope.formData.geoPoint || !$scope.formData.geoPoint.lat || !$scope.formData.geoPoint.lon) { + _.forEach(listeners, function(listener){ + listener(); // unlisten + }); + listeners = []; + delete $scope.map.markers.geoPoint; + $scope.loading = false; + return $q.when(); + } + + // If no marker exists on map: create it + if (!$scope.map.markers.geoPoint) { + + return $translate('MAP.PROFILE.MARKER_HELP') + .then(function(helpText) { + + $scope.map.markers.geoPoint = { + message: helpText, + lat: parseFloat($scope.formData.geoPoint.lat), + lng: parseFloat($scope.formData.geoPoint.lon), + draggable: true, + focus: true + }; + angular.extend($scope.map.center, { + lat: $scope.map.markers.geoPoint.lat, + lng: $scope.map.markers.geoPoint.lng + }); + + // Listening changes + var listener = $scope.$watch('map.markers.geoPoint', function() { + if ($scope.loading) return; + if ($scope.map.markers.geoPoint && $scope.map.markers.geoPoint.lat && $scope.map.markers.geoPoint.lng) { + $scope.formData.geoPoint = $scope.formData.geoPoint || {}; + $scope.formData.geoPoint.lat = $scope.map.markers.geoPoint.lat; + $scope.formData.geoPoint.lon = $scope.map.markers.geoPoint.lng; + } + }, true); + listeners.push(listener); + + + // Make sure map appear, if shown later + if (!$scope.ionItemClass) { + $scope.ionItemClass = 'done in'; + } + + $scope.loading = false; + }); + } + + // Marker exists: update lat/lon + else { + $scope.map.markers.geoPoint.lat = $scope.formData.geoPoint.lat; + $scope.map.markers.geoPoint.lng = $scope.formData.geoPoint.lon; + } + }; + + + $scope.$watch('formData.geoPoint', function() { + if ($scope.loading) return; + $scope.load(); + }, true); + +} diff --git a/www/plugins/map/js/controllers/registry-controllers.js b/www/plugins/map/js/controllers/registry-controllers.js index 562dfe96f344b4f383c0ac5a173d89203c0fb251..fc1954716376cfc12778ddf8bbd62df1431ba792 100644 --- a/www/plugins/map/js/controllers/registry-controllers.js +++ b/www/plugins/map/js/controllers/registry-controllers.js @@ -1,5 +1,5 @@ -angular.module('cesium.map.registry.controllers', ['cesium.services', 'cesium.map.services', 'cesium.map.help.controllers']) +angular.module('cesium.map.registry.controllers', ['cesium.services', 'cesium.map.services', 'cesium.map.help.controllers', 'cesium.map.common.controllers']) .config(function($stateProvider, PluginServiceProvider, csConfig) { 'ngInject'; @@ -23,6 +23,15 @@ angular.module('cesium.map.registry.controllers', ['cesium.services', 'cesium.ma templateUrl: "plugins/map/templates/registry/lookup_lg_extend.html" } } + }) + + .extendState('app.registry_edit_record', { + points: { + 'after-position': { + templateUrl: 'plugins/map/templates/common/edit_position_extend.html', + controller: 'MapPageEditCtrl' + } + } }); $stateProvider @@ -46,6 +55,7 @@ angular.module('cesium.map.registry.controllers', ['cesium.services', 'cesium.ma // Map view of the registry .controller('MapRegistryViewCtrl', MapRegistryViewController) + .controller('MapPageEditCtrl', MapPageEditController) ; @@ -423,3 +433,13 @@ function MapRegistryViewController($scope, $filter, $templateCache, $interpolate }); }; } + + +function MapPageEditController($scope, $controller) { + 'ngInject'; + + $scope.mapId = 'map-page-' + $scope.$id; + + // Initialize the super classes and extend it. + angular.extend(this, $controller('MapEditPositionAbstractCtrl', { $scope: $scope})); +} diff --git a/www/plugins/map/js/controllers/user-controllers.js b/www/plugins/map/js/controllers/user-controllers.js index 5b429c2e5ed9531fca8050bdfbaca42372a7a01d..15ab5730590c2cd7e372af62ce96097c76944a4c 100644 --- a/www/plugins/map/js/controllers/user-controllers.js +++ b/www/plugins/map/js/controllers/user-controllers.js @@ -1,5 +1,5 @@ -angular.module('cesium.map.user.controllers', ['cesium.services', 'cesium.map.services']) +angular.module('cesium.map.user.controllers', ['cesium.services', 'cesium.map.services', 'cesium.map.common.controllers']) .config(function(PluginServiceProvider, csConfig) { 'ngInject'; @@ -12,8 +12,8 @@ angular.module('cesium.map.user.controllers', ['cesium.services', 'cesium.map.se .extendState('app.edit_profile', { points: { 'after-position': { - templateUrl: 'plugins/map/templates/user/edit_profile_extend.html', - controller: 'MapEditProfileViewCtrl' + templateUrl: 'plugins/map/templates/common/edit_position_extend.html', + controller: 'MapProfileEditCtrl' } } }) @@ -21,105 +21,22 @@ angular.module('cesium.map.user.controllers', ['cesium.services', 'cesium.map.se .extendState('app.edit_profile_by_id', { points: { 'after-position': { - templateUrl: 'plugins/map/templates/user/edit_profile_extend.html', - controller: 'MapEditProfileViewCtrl' + templateUrl: 'plugins/map/templates/common/edit_position_extend.html', + controller: 'MapProfileEditCtrl' } } }); } }) - // [NEW] Manage events from the page #/app/wot/map - .controller('MapEditProfileViewCtrl', function($scope, $timeout, $q, MapUtils, $translate) { - 'ngInject'; - - var listeners = []; - $scope.mapId = 'map-user-profile-' + $scope.$id; - $scope.map = MapUtils.map({ - markers: {}, - center: { - zoom: 13 - } - }); - $scope.loading = true; - $scope.mapId = 'map-profile-' + $scope.$id; - - $scope.enter = function(e, state) { - - // Wait parent controller load the profile - if (!$scope.formData || (!$scope.formData.title && !$scope.formData.geoPoint)) { - return $timeout($scope.enter, 500); - } - - $scope.loading = true; - return $scope.load(); - }; - $scope.$on('$csExtension.enter', $scope.enter); - $scope.$on('$ionicParentView.enter', $scope.enter); - - $scope.load = function() { - - // no position define: remove existing listener - if (!$scope.formData.geoPoint || !$scope.formData.geoPoint.lat || !$scope.formData.geoPoint.lon) { - _.forEach(listeners, function(listener){ - listener(); // unlisten - }); - listeners = []; - delete $scope.map.markers.geoPoint; - $scope.loading = false; - return $q.when(); - } - - // If no marker exists on map: create it - if (!$scope.map.markers.geoPoint) { - - return $translate('MAP.PROFILE.MARKER_HELP') - .then(function(helpText) { - - $scope.map.markers.geoPoint = { - message: helpText, - lat: parseFloat($scope.formData.geoPoint.lat), - lng: parseFloat($scope.formData.geoPoint.lon), - draggable: true, - focus: true - }; - angular.extend($scope.map.center, { - lat: $scope.map.markers.geoPoint.lat, - lng: $scope.map.markers.geoPoint.lng - }); - - // Listening changes - var listener = $scope.$watch('map.markers.geoPoint', function() { - if ($scope.loading) return; - if ($scope.map.markers.geoPoint && $scope.map.markers.geoPoint.lat && $scope.map.markers.geoPoint.lng) { - $scope.formData.geoPoint = $scope.formData.geoPoint || {}; - $scope.formData.geoPoint.lat = $scope.map.markers.geoPoint.lat; - $scope.formData.geoPoint.lon = $scope.map.markers.geoPoint.lng; - } - }, true); - listeners.push(listener); - - - // Make sure map appear, if shown later - if (!$scope.ionItemClass) { - $scope.ionItemClass = 'done in'; - } - - $scope.loading = false; - }); - } + .controller('MapProfileEditCtrl', MapProfileEditController); - // Marker exists: update lat/lon - else { - $scope.map.markers.geoPoint.lat = $scope.formData.geoPoint.lat; - $scope.map.markers.geoPoint.lng = $scope.formData.geoPoint.lon; - } - }; +function MapProfileEditController($scope, $controller) { + 'ngInject'; - $scope.$watch('formData.geoPoint', function() { - if ($scope.loading) return; - $scope.load(); - }, true); + $scope.mapId = 'map-profile-' + $scope.$id; - }); + // Initialize the super classes and extend it. + angular.extend(this, $controller('MapEditPositionAbstractCtrl', { $scope: $scope})); +} diff --git a/www/plugins/map/js/plugin.js b/www/plugins/map/js/plugin.js index 9d00f86e9c407e4418e2745bf67dadb25813cd20..b4be381536f80725abfb30faedc209c3d9173645 100644 --- a/www/plugins/map/js/plugin.js +++ b/www/plugins/map/js/plugin.js @@ -4,6 +4,7 @@ angular.module('cesium.map.plugin', [ // Services 'cesium.map.services', // Controllers + 'cesium.map.common.controllers', 'cesium.map.wot.controllers', 'cesium.map.registry.controllers', 'cesium.map.network.controllers', diff --git a/www/plugins/map/templates/user/edit_profile_extend.html b/www/plugins/map/templates/common/edit_position_extend.html similarity index 100% rename from www/plugins/map/templates/user/edit_profile_extend.html rename to www/plugins/map/templates/common/edit_position_extend.html