Skip to content

Commit

Permalink
Merge pull request #2557 from camptocamp/on-init
Browse files Browse the repository at this point in the history
Add new on-init callback to gmf.searchDirective
  • Loading branch information
fredj authored May 1, 2017
2 parents 764201f + d295731 commit 2f98a74
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
7 changes: 6 additions & 1 deletion contribs/gmf/examples/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<link rel="stylesheet" href="../../../node_modules/bootstrap/dist/css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="../../../third-party/jquery-ui/jquery-ui.min.css">
<style>
#message {
width: 300px;
}
.ngeo-colorpicker-palette {
border-collapse: separate;
border-spacing: 0;
Expand Down Expand Up @@ -159,11 +162,13 @@
gmf-search-input-value="ctrl.inputValue"
gmf-search-colorchooser="true"
gmf-search-placeholder="Search for « Laus » for example…"
gmf-search-clearbutton="true">
gmf-search-clearbutton="true"
gmf-search-on-init="ctrl.searchIsReady()">
</gmf-search>
<p id="desc">This example shows how to use the <code>gmf-search</code> directive, which
is based on Twitter's <code>typeahead</code> component.</p>
<p>You typed: {{ctrl.inputValue}}</p>
<div id="message"></div>
</div>
<script src="../../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../../third-party/jquery-ui/jquery-ui.min.js"></script>
Expand Down
21 changes: 20 additions & 1 deletion contribs/gmf/examples/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ goog.provide('gmfapp.search');
/** @suppress {extraRequire} */
goog.require('gmf.mapDirective');
goog.require('ngeo.FeatureOverlayMgr');
goog.require('ngeo.Notification');
/** @suppress {extraRequire} */
goog.require('ngeo.proj.EPSG21781');
/** @suppress {extraRequire} */
Expand All @@ -28,10 +29,11 @@ gmfapp.module.value('gmfTreeUrl',
/**
* @param {gmf.Themes} gmfThemes Themes service.
* @param {ngeo.FeatureOverlayMgr} ngeoFeatureOverlayMgr The ngeo feature overlay manager service.
* @param {ngeo.Notification} ngeoNotification Ngeo notification service.
* @constructor
* @ngInject
*/
gmfapp.MainController = function(gmfThemes, ngeoFeatureOverlayMgr) {
gmfapp.MainController = function(gmfThemes, ngeoFeatureOverlayMgr, ngeoNotification) {

gmfThemes.loadThemes();

Expand Down Expand Up @@ -98,6 +100,23 @@ gmfapp.MainController = function(gmfThemes, ngeoFeatureOverlayMgr) {
})
});

/**
* @type {ngeo.Notification}
* @private
*/
this.notification_ = ngeoNotification;
};


/**
* @export
*/
gmfapp.MainController.prototype.searchIsReady = function() {
this.notification_.notify({
msg: 'gmf-search initialized',
target: angular.element('#message'),
type: ngeo.MessageType.SUCCESS
});
};


Expand Down
9 changes: 8 additions & 1 deletion contribs/gmf/src/directives/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ gmf.module.value('gmfSearchTemplateUrl',
* @htmlAttribute {ngeox.SearchDirectiveListeners} gmf-search-listeners
* The listeners.
* @htmlAttribute {number} gmf-search-maxzoom The maximum zoom we will zoom on result, default is 16.
* @htmlAttribute {function} gmf-search-on-init Optional function called when the directive is initialized.
* @return {angular.Directive} The Directive Definition Object.
* @ngInject
* @ngdoc directive
Expand All @@ -137,7 +138,8 @@ gmf.searchDirective = function(gmfSearchTemplateUrl) {
'colorchooser': '=gmfSearchColorchooser',
'coordinatesProjections': '=?gmfSearchCoordinatesprojections',
'additionalListeners': '=gmfSearchListeners',
'maxZoom': '<gmfSearchMaxzoom'
'maxZoom': '<gmfSearchMaxzoom',
'onInitCallback': '&?gmfSearchOnInit'
},
controller: 'GmfSearchController',
controllerAs: 'ctrl',
Expand All @@ -156,6 +158,11 @@ gmf.searchDirective = function(gmfSearchTemplateUrl) {
ctrl.clear();
});
}

var callback = scope['onInitCallback'];
if (callback) {
callback();
}
}
};
};
Expand Down

0 comments on commit 2f98a74

Please sign in to comment.