Commit 44fc8e15 authored by Benoit Lavenier's avatar Benoit Lavenier

[enh] Page edit: add the map preview

[enh] Position edit: avoid to open modal twice
parent 2207d8e8
......@@ -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>
......
......@@ -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;
});
};
}
......
......@@ -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();
}
});
};
......
......@@ -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>
......
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);
}
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}));
}
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}));
}
......@@ -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',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment