/* Turn the web toolkit to "Apollo" mode (this introduces minor modifications to the behaviour of the toolkit, such as appending the session id to ECWP layers URLs */ var IASClient = { init : function () { // Force create the main notebook/tabview this.getMainTabView (); // The ECWP layer computes bounding boxes that can be quite different from those // generated by COTS IONIC.api.maps.ECWPSSLayer.setFindEpsgIdTolerance (0.01); }, resize : function () { }, getServerRef : (function () { var sr; return function () { var serverIds; if (! sr) { serverIds = IONIC.misc.getLocationSearchParameter(window.location, "secure", true); if (serverIds && serverIds.length !== 0 && serverIds[0].toLowerCase() === "true") { sr = new IONIC.api.imagearchive.SessionScopeServerRef ("ArchiveServer"); } else { sr = new IONIC.api.imagearchive.ApplicationScopeServerRef ("ArchiveServer"); } } return sr; } }) (), getDomHelper : (function () { var dh; return function () { if (! dh) { dh = new IONIC.api.ui.DomHelper (document); } return dh; } }) (), getMainTabView : (function () { var tabView; return function () { if (! tabView) { tabView = new YAHOO.widget.TabView ("mainNotebook"); } return tabView; }; }) (), getLogger : (function () { var logger; return function () { if (! logger) { logger = IONIC.misc.createDedicatedLogger ("IASClient"); } return logger; } }) () }; if (true) { var SearchModule = { init : function () { // Force creating this.getSearchPanel (); /* this.getTimeLine(); */ this.getBrowsePanel (); // Force creating search map, and wire it to the search panel; create a footprint layer this.getSearchMap (); this.footprintLayer = new IONIC.geom.edit.GEditLayerDescriptor ("GELD" + gensym(), "SearchFootprints"); this.getSearchMap ().addUtilityLayerDescriptor (this.footprintLayer); // Force create navigation bar this.getSearchNavigationBar (); // Force creating this.getResultsTable (); this.makeTabView (); }, makeTabView : function () { var tabView = new YAHOO.widget.TabView(); var searchResults = document.getElementById("resultsTableHolder"); var browseResults = document.getElementById("browseResultsTableHolder"); // Initially hide browse results browseResults.style.display = "none"; // Hide/Show results panel when active tab change tabView.addListener ('activeTabChange', function (ev) { if (ev.newValue.get ("label") === "Search") { browseResults.style.display = "none"; searchResults.style.display = "block"; } else { browseResults.style.display = "block"; searchResults.style.display = "none"; } }); tabView.addTab (new YAHOO.widget.Tab({ label: 'Search', contentEl: document.getElementById("searchTab"), active: true })); tabView.addTab (new YAHOO.widget.Tab({ label: 'Browse', contentEl: document.getElementById("browseTab") })); tabView.appendTo ("search-yui-content"); }, getSearchPanel : (function () { var searchPanel; return function () { if (! searchPanel) { searchPanel = new IONIC.api.imagearchive.ImageArchiveSearchPanel ( "searchPanelHolder", IASClient.getServerRef ()); searchPanel.setAssociatedMap (this.getSearchMap ()); } return searchPanel; }; }) (), getBrowsePanel : (function () { var panel; return function () { if (! panel) { panel = new IONIC.api.imagearchive.ImageArchiveBrowsePanel ( "browserTreeHolder", "browseResultsTableContent", IASClient.getServerRef (), null, null); var aggregateMenu = new ContextualMenu (null, function () { return panel.getImageArchiveTool (); }, function () { return panel.getPreferredEpsgId (); }); var granuleMenu = new ContextualMenu (null, function () { return panel.getImageArchiveTool (); }, function () { return panel.getPreferredEpsgId (); }); panel.setAggregateHtmlDecorator (aggregateMenu); panel.setGranuleHtmlDecorator (granuleMenu); panel.setAssociatedMap (this.getSearchMap ()); } return panel; }; }) (), getTimeLine : (function () { var tl; return function () { if (! tl) { var evtSource = new Timeline.DefaultEventSource(); var bandInfos = [ Timeline.createBandInfo({ eventSource: evtSource, width: "70%", trackGap: 0.1, intervalUnit: Timeline.DateTime.MONTH, intervalPixels: 100 }), Timeline.createBandInfo({ showEventText: false, trackHeight: 0.3, trackGap: 0.1, eventSource: evtSource, width: "30%", intervalUnit: Timeline.DateTime.YEAR, intervalPixels: 200 }) ]; bandInfos[1].syncWith = 0; bandInfos[1].highlight = true; tl = new IONIC.api.imagearchive.CoverageTimeLine ( Timeline.create(IASClient.getDomHelper ().get ("coverageTimeline"), bandInfos)); tl.customizePainter(bandInfos[0].eventPainter); tl.init (); } return tl; }; }) (), getResultsTable : (function () { var resultsTable; var resultsPerPage = "12" || 10; var iaTool = new IONIC.imagearchive.ImageArchiveTool (IASClient.getServerRef ()); return function () { if (! resultsTable) { resultsTable = {}; var contextualMenu = new ContextualMenu (null, iaTool, function () { return SearchModule.getSearchPanel ().getPreferredEpsgId (); }); var renderer = new IONIC.api.imagearchive.DefaultTableRowRenderer (); renderer.setHtmlDecorator (contextualMenu); renderer.setFootprintLayer (this.getFootprintLayer ()); var resultsHandler = new SearchModuleTableResultsHandler ("resultsTableHolder", IASClient.getDomHelper (), renderer, resultsPerPage, contextualMenu); resultsHandler.setAssociatedMap (this.getSearchMap ()); var contextualMenuWfs = new ContextualMenuWfs (null, iaTool); var rendererWfs = new IONIC.api.imagearchive.WfsTableRowRenderer (); rendererWfs.setHtmlDecorator (contextualMenuWfs); var wfsResultsHandler = new SearchModuleTableResultsHandler ("resultsTableHolder", IASClient.getDomHelper (), rendererWfs, resultsPerPage, contextualMenuWfs); wfsResultsHandler.setAssociatedMap (this.getSearchMap ()); resultsTable.setAssociatedDisplayMap = function(map) { resultsHandler.setAssociatedDisplayMap (map); wfsResultsHandler.setAssociatedDisplayMap (map); } resultsTable.getResultHandler = function() { return resultsHandler; }; resultsTable.getWfsResultHandler = function() { return wfsResultsHandler; }; resultsTable.show = function () { IASClient.getDomHelper ().get ("resultsTableHolder").style.display = ""; } resultsTable.hide = function () { IASClient.getDomHelper ().get ("resultsTableHolder").style.display = "none"; } } return resultsTable; } }) (), /* The layer returned by this method allows to display the footprint of all the results found by a search */ getFootprintLayer : function () { return this.footprintLayer; }, getDetailPanel : (function () { var detailPanel, detailPanelHolder; return function () { if (! detailPanel) { detailPanelHolder = IASClient.getDomHelper ().get ("resultDetailsHolder"); detailPanelHolder.style.display = "none"; detailPanel = new IONIC.api.imagearchive.ImageArchiveDetailPanel ( IASClient.getDomHelper ().get ("resultDetailTableHolder"), IASClient.getServerRef ()); detailPanel.onRendered.subscribe (function () { detailPanel.show (); }); detailPanel.show = function () { detailPanelHolder.style.display = "block"; } detailPanel.hide = function () { detailPanelHolder.style.display = "none"; } } return detailPanel; } }) (), getSearchMap : (function () { var searchMap; return function () { if (! searchMap) { searchMap = new IONIC.api.maps.Map ("searchMapHolder"); searchMap.getHTMLView ().style.backgroundColor = "#f3f3ff"; searchMap.loadWMCFromWebapp ("/WEB-INF/contexts/search-map.xml"); } return searchMap; }; }) (), getSearchNavigationBar : (function () { var searchNavbar; return function () { if (! searchNavbar) { searchNavbar = new IONIC.api.ui.navigation.NavBar ("searchNavBarHolder", this.getSearchMap ()); searchNavbar.createDefaultButtons (); new IONIC.api.ui.navigation.SelectBoxButton (searchNavbar); new PolygonSelectionButton (searchNavbar); new IONIC.api.ui.navigation.SetExtentButton (searchNavbar); // Add navigation info var navInfo = new IONIC.api.ui.navigation.NavInfo ("searchNavInfoHolder", this.getSearchMap ()); navInfo.createDefaultFields (); } return searchNavbar; }; }) (), search : function () { var resultsTable = this.getResultsTable (); var type = this.getSearchPanel ().getEditor (IONIC.api.imagearchive.ImageArchiveSearchPanel.ED_AVAILABILITY).getValue (); var handler = (type !== "WFS") ? resultsTable.getResultHandler () : resultsTable.getWfsResultHandler (); this.getFootprintLayer ().clearCanvas (); this.getSearchPanel ().performSearchWithHandler (handler); // Hide previous detail panel when a new search is performed this.getDetailPanel ().hide (); } }; // Add an onload handler YAHOO.util.Event.on ( window, "load", function () { SearchModule.init (); }); } /** * A TableResultsHandler that calls "suspend" and "resume" on the underlying contextualMenu. */ SearchModuleTableResultsHandler = function (elt, dh, renderer, resultsPerPage, contextualMenu) { IONIC.api.imagearchive.TableResultsHandler.call (this, elt, dh, renderer, resultsPerPage); this.contextualMenu = contextualMenu; }; IONIC.misc.extendType (SearchModuleTableResultsHandler, IONIC.api.imagearchive.TableResultsHandler); SearchModuleTableResultsHandler.prototype.onBegin = function () { IONIC.api.imagearchive.TableResultsHandler.prototype.onBegin.call (this); this.contextualMenu.suspend (); }; SearchModuleTableResultsHandler.prototype.onEnd = function () { IONIC.api.imagearchive.TableResultsHandler.prototype.onEnd.call (this); this.contextualMenu.resume (); }; /** * Allows to select a polygon on the search map and to use it as a search criterion. */ function PolygonSelectionButton (navigationBar) { var self = this; IONIC.ui.navigation.AbstractNavBarButton.call ( this, navigationBar, { type: "push", label: "Select a polygon on the map", value: "selectpolygon", mapAction: "selectpolygon", groupName: "main" }); var map = this.getToolbar ().getMap (); var layer = new IONIC.geom.edit.GEditLayerDescriptor ("GELD" + gensym(), "PolygonSelector"); map.addUtilityLayerDescriptor (layer); var vmp = map.getViewMouseProcessor (); var self = this; this.action = vmp.registerAction ("selectpolygon", ["mouseup"], PolygonSelectionButton.SELECT_POLYGON_CODE, undefined, // onselect function () { // ondeselect self.setCurrentGeometry (null); }); this.action.button = this; this.layer = layer; this.currentGeometry = null; this.drawingOptions = PolygonSelectionButton.DRAWING_OPTIONS; // Bind to changes in the search panel's current geometry SearchModule.getSearchPanel (). getEditor (IONIC.api.imagearchive.ImageArchiveSearchPanel.ED_BBOX). onValueManuallyChanged.subscribe (function (type, args) { var geom = args [0]; self.setCurrentGeometry (geom); }); }; IONIC.misc.extendType (PolygonSelectionButton, IONIC.ui.navigation.AbstractNavBarButton); PolygonSelectionButton.DRAWING_OPTIONS = new IONIC.api.maps.Map.DrawingOptions ( 1, "#FF0000", null); PolygonSelectionButton.SELECT_POLYGON_CODE = function (processor, eventType, downInfo, currentInfo, buttons, lastResult) { var map = processor.getView (); var geom = this.button.currentGeometry; var ring; // As the user frenetically clicks the map, this will upgrade // the selected geometry from // // nothing -> point // point -> linestring // linestring -> polygon // switch (eventType) { case IONIC.api.maps.ViewMouseProcessor.Action.EVENT_MOUSE_UP: if (! geom) { geom = new IONIC.api.geom.Point ( currentInfo.point.x, currentInfo.point.y, map.getSrs ()); } else if (geom instanceof IONIC.api.geom.Point) { geom = new IONIC.api.geom.LineString ( [geom.x, geom.y, currentInfo.point.x, currentInfo.point.y ], map.getSrs ()); } else if (geom instanceof IONIC.api.geom.LineString) { ring = new IONIC.api.geom.LinearRing ( geom.points.concat ([currentInfo.point.x, currentInfo.point.y]), map.getSrs ()); geom = new IONIC.api.geom.Polygon (map.getSrs ()); geom.pushChild (ring); } else { geom.getChild (0).pushPoints ( new IONIC.api.geom.Point (currentInfo.point.x, currentInfo.point.y, map.getSrs ())); } break; default: throw "Polygon selection action should not receive this event: " + eventType; break; } this.button.setCurrentGeometry (geom); // Force this geometry into the panel SearchModule.getSearchPanel ().getEditor ( IONIC.api.imagearchive.ImageArchiveSearchPanel.ED_BBOX).setValue ( geom); }; PolygonSelectionButton.prototype.setCurrentGeometry = function (geom) { if (geom instanceof IONIC.api.geom.Box) { geom = geom.toPolygon (); } this.currentGeometry = geom; var layer = this.layer; layer.clearCanvas (); if (geom) { layer.addGeometry (geom, this.drawingOptions, false); } }; if (true) { var MapModule = { init : function () { var map = new IONIC.api.imagearchive.ImageArchiveMap ( "http://webservices.ionicsoft.com:8082/ioniciasv3/ias/IAS", "", "mapMapHolder"); MapModule._map = map; map.setBoxValues (-180, -90, 180, 90, 4326); map.loadWMCFromWebapp ("/WEB-INF/contexts/map.xml"); map.getHTMLView ().style.backgroundColor = "#f3f3ff"; MapModule._navigationBar = new IONIC.api.ui.navigation.NavBar ("mapNavBarHolder", map); MapModule._navigationBar.createDefaultButtons (); var loadButton = new IONIC.api.ui.navigation.LoadContextButton (MapModule._navigationBar); var saveButton = new IONIC.api.ui.navigation.SaveContextButton (MapModule._navigationBar); IASClient.getMainTabView ().addListener ("activeTabChange", function () { MapModule._navigationBar.doDeselectButton (loadButton); MapModule._navigationBar.doDeselectButton (saveButton); }); MapModule._navigationInfo = new IONIC.api.ui.navigation.NavInfo ("mapNavInfoHolder", map); MapModule._navigationInfo.createDefaultFields (); var srsLister = new IONIC.api.ui.navigation.SRSSelector (MapModule._navigationInfo); // EPSG:4326 should always be displayed srsLister.setAdditionalSRSes ([ 4326 ]); MapModule._layerList = new IONIC.api.ui.LayerList (map, "mapLayerListHolder", IONIC.api.ui.LayerList.VISIBILITY | IONIC.api.ui.LayerList.FIT | IONIC.api.ui.LayerList.OPACITY | IONIC.api.ui.LayerList.SELECTSTYLE | IONIC.api.ui.LayerList.REMOVE); MapModule._layerList.setLegendIconThumbnailing (true); /* Annotation panel */ MapModule.setupAnnotations(map); }, setupAnnotations : function (map) { var self = this; map.getViewMouseProcessor ().setGeometryEditingToolbarHolder ("mapGeometryToolbar"); var setFolder = function (feature, owner, folderName) { if (!feature) { return; } var folderNameProp = feature.getProperty ("folderName", "http://www.ionicsoft.com/wfs"); var folderOwnerProp = feature.getProperty ("folderOwner", "http://www.ionicsoft.com/wfs"); var ownerProp = feature.getProperty ("owner", "http://www.ionicsoft.com/wfs"); feature.setValue (folderNameProp.name, folderNameProp.namespace, folderName); feature.setValue (folderOwnerProp.name, folderOwnerProp.namespace, owner); feature.setValue (ownerProp.name, ownerProp.namespace, owner); }; var featurePanel = new IONIC.api.feature.SimpleFeaturePanel ("mapAnnotations", "http://webservices.ionicsoft.com/annotation/wfs/ANNOTATIONV2", "BaseAnnotation", "http://www.ionicsoft.com/wfs"); featurePanel.setEditingCapable (true); featurePanel.setView (map); featurePanel.createFeatureSetManager (); featurePanel.initialize (); featurePanel.onAccepted.subscribe (function () { setFolder(featurePanel.getFeature (), "training", "POLLUX"); }); // Refresh annotation layer var updatedLayer = false; var onAnnotationChangedHandler = function () { map.forEachMapLayer (function (ld) { ld.forEachServerSideLayer (function (ssLayer, ssLayerIdx) { if (ssLayer.getName ().toUpperCase () === "ANNOTATION") { map.refreshLayer (ld); updatedLayer = true; } }); }); // Add the annotation layer as soon as an annotation has been changed/created if (!updatedLayer) { self.addAnnotationLayer (map); } }; featurePanel.onReleased.subscribe (onAnnotationChangedHandler); featurePanel.onFeatureClean.subscribe (onAnnotationChangedHandler); map.onWMCLoaded.subscribe (function () { self.addAnnotationLayer (map); }); }, addAnnotationLayer : function (map) { var ssld = new IONIC.api.maps.WFSSSLayer ("Annotation"); var ld = new IONIC.api.maps.LayerDescriptor ("http://webservices.ionicsoft.com/annotation/wfs/ANNOTATIONV2", [ ssld ], "WFS"); var filter = this.getAnnotationFilter (); var filterUtils = new IONIC.api.feature.FilterUtils (); filterUtils.withFilterInPool (filter, function (id) { ssld.setFilterId (id); map.addLayerDescriptor (ld); }); }, getAnnotationFilter : function () { var ns = "http://www.ionicsoft.com/wfs"; var folderFilter = IONIC.api.feature.FilterBuilder.equalFilterBuilder ("folderName", ns, "POLLUX"); var ownerFilter = IONIC.api.feature.FilterBuilder.equalFilterBuilder ("folderOwner", ns, "training"); return folderFilter.and (ownerFilter).create (); }, getMap : function () { return MapModule._map; }, getLayerList : function () { return MapModule._layerList; }, getAnnotationPanel : function () { return MapModule._annotationPanel; }, discover : function () { var dh = IASClient.getDomHelper (); var url = dh.get ("mapDiscoverUrl").value; var serviceTypes = dh.get ("mapDiscoverServiceType").getElementsByTagName("input"); var serviceType; IONIC.misc.forEach (function (input) { if (input.checked) { serviceType = input.value; } }, serviceTypes); var providerDiscovery = new IONIC.api.maps.ProviderDiscoveryTool (MapModule.getMap ()); dh.get("mapDiscoveredLayers").style.display = "block"; providerDiscovery.withBuiltTree (url, serviceType, "mapDiscoverTree"); }, sendContextByMail : function () { var dh = IASClient.getDomHelper (); var fromName = "No reply"; var fromEmail = "noreply@ionicsoft.com"; var toEmail = dh.get("mapContextAddress").value; var message = "Context file generated at " + new Date(); var subject = message; if (toEmail.length == 0) { alert("Please enter a valid destination email address."); } else { ContextSender.send (MapModule.getMap (), fromName, fromEmail, toEmail, subject, message); } }, setStreamedRasterAccessCredentials : function (login, password) { this.getMap ().setStreamedRasterAccessCredentials (login, password); } }; ContextSender = { send : function (map, fromName, fromEmail, toEmail, subject, message) { var mapJsonContext = IONIC.api.maps.Map.toTransportFormat (map); var url = ContextSender.getUrl (fromName, fromEmail, toEmail, subject, message); function callback (success) { if (success) { // If not successful, the error handler will be called alert ("Context has been sent to the mail server."); } } var rt = IONIC.misc.RequestTool.newInstance (); rt.withUrl (url, "POST", callback, JSON.stringify(mapJsonContext)); }, getUrl : function (fromName, fromEmail, toEmail, subject, message) { var url = ContextSender.getActionUrl () + "?getToEmail=" + escape (toEmail) + "&fromEmail=" + escape (fromEmail) + "&toEmail=" + escape (toEmail) + "&subject=" + escape (subject) + "&message=" + escape (message) + "&mailServerUrl=" + escape ("mail.ionicsoft.com"); var port = "mail.smtp.port" || "25"; if (!isNaN (parseInt (port)) && parseInt (port) !== 0) { url += "&mailServerPort=" + parseInt(port); } return url; }, getActionUrl : function () { return IONIC.misc.getWebappBaseUrl () + "/sendContext.do"; } }; // Add an onload handler YAHOO.util.Event.on ( window, "load", function () { MapModule.init (); }); } /** * Redefine this so that annotations are filtered using the owner name. */ IONIC.api.feature.SimpleFeaturePanel._CREATE_BOX_AROUND_PIXEL = function (pxl, map, geomprop, tol) { var pbox = new IONIC.api.geom.Box (pxl [0] - tol, pxl [1] - tol, pxl [0] + tol, pxl [1] + tol); var lbox = IONIC.maps.NavHelper.pixelBoxToSRSBox (pbox, map); var fd = IONIC.feature.FilterDef; var filter = IONIC.api.feature.FilterBuilder.boxFilterBuilder (lbox, geomprop.name, geomprop.namespace); var folderFilterBuilder; if (MapModule && map === MapModule.getMap ()) { folderFilterBuilder = MapModule.getAnnotationFilter (); filter = filter.and (new IONIC.api.feature.FilterBuilder (folderFilterBuilder)); } return filter.create (); }; IONIC.api.maps.LayerDescriptor.toTransportFormat = function (ld) { // Do not put annotation layer in context if (ld.getServiceUrl () === "http://webservices.ionicsoft.com/annotation/wfs/ANNOTATIONV2") { return []; } var serviceType = ld.getServiceType ().toUpperCase (); var serializer = IONIC.api.maps.LayerDescriptor.getLayerSerializer (serviceType); if (serializer) { return serializer (ld); } else { throw "Cannot serialize layer of type: " + ld; } }; if (true) { var SecurityModule = { init : function() { SecurityModule.authenticationServletUrl = IONIC.misc.getWebappBaseUrl() + "/authentication"; SecurityModule.authenticationInfoServletUrl = IONIC.misc.getWebappBaseUrl() + "/authenticationInfo"; SecurityModule.displayAuthentication(); }, login : function() { var requestTool = new IONIC.misc.RequestTool(); var urlArgs = "?type=" + escape (SecurityModule.AUTHENTICATION_TYPE_BASIC); var callback = function(success, response) { if (!success) { // Query the authentication servlet to know the authentication status SecurityModule.displayAuthentication(); return; } SecurityModule.displayAuthentication(response); if (response.message) { alert(response.message); } if (response.status === "authenticated") { alert("Authentication succeeded. You are now redirected to a secured instance of the " + "web client."); window.location = IONIC.misc.getWebappBaseUrl() + "?secure=true"; } } requestTool.withUrl(SecurityModule.authenticationServletUrl + urlArgs, "GET", callback); }, logout : function() { var requestTool = new IONIC.misc.RequestTool(); var callback = function(success, response) { if (!success) { // Query the authentication servlet to know the authentication status SecurityModule.displayAuthentication(); return; } SecurityModule.displayAuthentication(response); if (response.status === "notAuthenticated") { alert("Logged out. You are now redirected to the public instance of the " + "web client."); window.location = IONIC.misc.getWebappBaseUrl(); } } requestTool.withUrl(SecurityModule.authenticationInfoServletUrl + "?request=logout", "GET", callback); }, /* * Displays information related to the authentication status. Asks the server about * the current authentication status if it is not passed as an argument. Displays * login/userpassword/logout fields/button. * @param {object} authenticationInfo (Optional.) The information about the authentication * status of the user, as returned by the 'authenticationInfo' servlet. */ displayAuthentication: function(authenticationInfo) { var display = function(success, info) { var dh = IASClient.getDomHelper(); var elt = dh.get("authenticationInfo"), infoElt; dh.clr(elt); // Cannot access authentication servlet if (!success) { infoElt = dh.elt("div"); infoElt.innerHTML = "Authentication servlet unreachable; authentication is not possible."; dh.append(elt, infoElt); return; } var isAuthenticated = (info.status === "authenticated") && (IASClient.getServerRef () instanceof IONIC.api.imagearchive.SessionScopeServerRef); var userHtml, userElt, buttonElt; infoElt = dh.elt("div"); infoElt.innerHTML = "

The access to the server is " + (isAuthenticated ? "authenticated." : "not authenticated.

");; dh.append(elt, infoElt); if (isAuthenticated) { userHtml = "

The authenticated user name is: " + info.userName + ".

"; userElt = dh.elt("div"); userElt.innerHTML = userHtml; dh.append(elt, userElt); addLogoutButton (); // We do not set the password in clear text, but use the session ID to authentify the user // MapModule.setStreamedRasterAccessCredentials (info.userName, info.password); } else { displayBasic(info); } } // Displays the information necessary to login using "basic" authentication (a login" button) var displayBasic = function(info) { addLoginButton(); }; /* Displays the information necessary to login using "userPasswor" authentication method (user/password fields and a login button). */ var displayUserPassword = function(info) { var dh = IASClient.getDomHelper(); var elt = dh.get("authenticationInfo"); dh.append(elt, SecurityModule.getUserPasswordPanel().getComponent()); addLoginButton(); }; // Displays a "login" button var addLoginButton = function() { var buttonElt = addButton("Login"); buttonElt.onclick = SecurityModule.login; return buttonElt; }; // Displays a "login" button var addLogoutButton = function() { var buttonElt = addButton("Logout"); buttonElt.onclick = SecurityModule.logout; return buttonElt; }; var addButton = function(name) { var dh = IASClient.getDomHelper(); var elt = dh.get("authenticationInfo"); var buttonElt = dh.elt("input"); buttonElt.type = "button"; buttonElt.value = name; dh.append(elt, buttonElt); return buttonElt; }; if (authenticationInfo) { display(true, authenticationInfo); } else { var requestTool = new IONIC.misc.RequestTool(); requestTool.withUrl(SecurityModule.authenticationInfoServletUrl, "GET", display); } }, /** * A panel that allows the user to input its username/password. */ getUserPasswordPanel: function() { if (!SecurityModule.userPasswordPanel) SecurityModule.userPasswordPanel = new UserPasswordPanel(); return SecurityModule.userPasswordPanel; }, AUTHENTICATION_TYPE_BASIC : "basic", AUTHENTICATION_TYPE_USERPASSWORD : "userPassword", AUTHENTICATION_TYPE_INFO : "info" }; // Add an onload handler YAHOO.util.Event.on(window, "load", function() { SecurityModule.init(); }); // Set a new Ionic error handler so as to refresh the 'login' panel when an authentication error occurs (function () { var oldIonicErrorHandler = IONIC.misc.RequestTool.DEFAULT_IONIC_ERROR_HANDLER_FUN; IONIC.misc.RequestTool.DEFAULT_IONIC_ERROR_HANDLER_FUN = function(status, respText, request, callback, quiet) { var errorMsg = eval ("(" + respText + ")"); if (errorMsg.type && errorMsg.type.indexOf("authentication") !== -1) SecurityModule.displayAuthentication(); oldIonicErrorHandler.apply (this, arguments); } })(); } else { // No security is required; remove the "login" tab (function() { function removeTab() { var loginTab = IASClient.getMainTabView().getTab(3); IASClient.getMainTabView().removeTab(loginTab); } YAHOO.util.Event.on(window, "load", removeTab); })(); } /** * @constructor * * @class * This class allows to display a "username/password" panel and send the input credentials to * the server-side authentication action. * * @param {htmlElt} htmlElt The HTML element to add the panel to. */ UserPasswordPanel = function() { var dh = IASClient.getDomHelper(); this.usernameInput = IONIC.ui.InputEditor.newInstance (dh); this.passwordInput = IONIC.ui.InputEditor.newInstance (dh); this.passwordInput.getComponent ().type = "password"; }; /* * Builds the HTML representation of this object. */ UserPasswordPanel.prototype.getComponent = function () { var dh = IASClient.getDomHelper(); var elt = dh.elt("div.UserPasswordPanel"); var tbody = dh.elt("tbody"); dh.append(elt, dh.elt("table", tbody)); dh.append(tbody, dh.elt ("tr", dh.elt ("td.InputLabel", dh.txt ("User name:")), dh.elt ("td", this.usernameInput.getComponent ()))); dh.append(tbody, dh.elt ("tr", dh.elt ("td.InputLabel", dh.txt ("Password:")), dh.elt ("td", this.passwordInput.getComponent ()))); return elt; }; /* * Returns the input username. */ UserPasswordPanel.prototype.getUsername = function () { return this.usernameInput.getValue(); }; /* * Returns the input password. */ UserPasswordPanel.prototype.getPassword = function () { return this.passwordInput.getValue(); }; if (true) { var GetCoverageModule; GetCoverageModule = { init : function () { var dh = IASClient.getDomHelper(); // Force creating var panel = this.getGetCoveragePanel(); var map = this.getGetCoverageMap(); var navbar = this.getGetCoverageNavigationBar(); var srsSwitcher = new IONIC.api.ui.SRSSwitcher("getCoverageSrsSwitcher", map); panel.onCoverageDescriptionLoaded.subscribe(function (type, args) { var iaObj = args [0]; srsSwitcher.setEPSGIDs(iaObj.getGetCoverageRequestSRSes()); }); panel.onCoverageAdded.subscribe(function () { dh.get("coverageHolder").style.display = ""; dh.get("noCoverageYet").style.display = "none"; navbar.deselectAllButtons (); }); dh.get("coverageHolder").style.display = "none"; }, getGetCoveragePanel : (function () { var panel; return function () { if (! panel) { panel = new MyImageArchiveGetCoveragePanel ("getCoverageHolder", IASClient.getServerRef(), "http://webservices.ionicsoft.com:8082/ioniciasv3/ias/IAS"); var resultsTable; /* Uncomment to add a "get coverage" button to the search result table resultsTable = SearchModule.getResultsTable(); resultsTable.getResultHandler().setAssociatedGetCoveragePanel(panel); */ panel.setAssociatedMap(GetCoverageModule.getGetCoverageMap()); } return panel; }; })(), getGetCoverageMap : (function () { var covMap; return function () { if (! covMap) { covMap = new IONIC.api.maps.Map("getCoverageMapHolder"); covMap.setDimensions(536, 400); } return covMap; }; })(), getGetCoverageNavigationBar : (function () { var covNavbar; return function () { if (! covNavbar) { covNavbar = new IONIC.api.ui.navigation.NavBar("getCoverageNavbarHolder", this.getGetCoverageMap()); covNavbar.createDefaultButtons(); new IONIC.api.ui.navigation.SelectBoxButton(covNavbar); } return covNavbar; }; })() }; // Add "loading..." visual feedback when the coverage is being fetched var MyImageArchiveGetCoveragePanel = function (htmlElt, serverRef, serverWmsUrl, win) { IONIC.api.imagearchive.ImageArchiveGetCoveragePanel.call (this, htmlElt, serverRef, serverWmsUrl, win); }; IONIC.misc.extendType (MyImageArchiveGetCoveragePanel, IONIC.api.imagearchive.ImageArchiveGetCoveragePanel); MyImageArchiveGetCoveragePanel.prototype.loadCoverageDescriptionByName = function (name) { var dh = IASClient.getDomHelper(); dh.get("coverageHolder").style.display = "none"; dh.get("noCoverageYet").style.display = ""; IONIC.api.imagearchive.ImageArchiveGetCoveragePanel.prototype.loadCoverageDescriptionByName.call( this, name); }; // Add an onload handler YAHOO.util.Event.on( window, "load", function () { GetCoverageModule.init(); }); } if (false) { var LoggerModule = { init : function () { var dh = IASClient.getDomHelper (); var logger = new QueryLogger ("logPage", dh); var iaTools = [ SearchModule.getBrowsePanel ().getImageArchiveTool (), SearchModule.getSearchPanel ().getImageArchiveTool (), SearchModule.getResultsTable ().getResultHandler ().getAssociatedIATool () ]; if (GetCoverageModule) { iaTools.push (GetCoverageModule.getGetCoveragePanel ().getImageArchiveTool ()); } for (var i = 0; i < iaTools.length; i++) { var iaTool = iaTools[i]; if (!iaTool) { continue; } iaTool.onQueryStart.subscribe (function (event, args) { logger.write ( dh.elt("div", dh.txt ("Query: " + args[0] + " (id: " + args[2] + ")"), dh.elt ("br"))); }); iaTool.onQuery.subscribe (function (event, args) { logger.logQuery (args[0], args[1], args[2], args[3], args[4]); }); } var clearButton = dh.elt ("input"); clearButton.value = "clear"; clearButton.type = "button"; clearButton.onclick = function () { logger.clear (); logger.write (clearButton); }; logger.write (clearButton); } }; QueryLogger = function (eltName, dh) { this.dh = dh; this.logElt = dh.get(eltName); }; QueryLogger.prototype = { logQuery: function (queryName, query, result, time, queryId) { var self = this; var elt = this.dh.elt ("div.logQuery"); var id = gensym ("log_elt"); var html = "" + queryName + " (" + time + "s, id: " + queryId + ")
" + ""; elt.innerHTML = html; var anchor = this.dh.elt ("a", this.dh.txt ("Show/hide")); anchor.href = "#"; anchor.onclick = function () { if (self.dh.get (id).style.display !== "none") { self.dh.get (id).style.display = "none"; } else { self.dh.get (id).style.display = "block"; } }; this.dh.append (elt, anchor); this.write (elt); }, write: function (elt) { this.dh.append (this.logElt, elt); }, clear: function () { this.dh.clr (this.logElt); } }; // Add an onload handler YAHOO.util.Event.on ( window, "load", function () { LoggerModule.init (); }); } else { // No logging is required; remove the "log" tab (function() { function removeTab() { var tabs = IASClient.getMainTabView().get("tabs"); var lastIndex = tabs.length - 1; var loginTab = IASClient.getMainTabView().getTab(lastIndex); IASClient.getMainTabView().removeTab(loginTab); } YAHOO.util.Event.on(window, "load", removeTab); })(); } /* * Copyright 2005- by IONIC Software S.A., * 18 Av Wallonie, 4460 Grace-Hollogne, Belgium. * All rights reserved. * * This software is the confidential and proprietary information * of IONIC Software S.A.("Confidential Information"). * You shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with IONIC Software. * * * IMPORTANT * * This file is internal to RedSpider Enterprise Tilapia toolkit * add-ons. It is subject to changes and CANNOT BE DIRECTLY ACCESSED * BY APPLICATIONS. Only the objects contained in the IONIC.api * package may be used. */ /** * @constructor * * @class * The {@link ContextualMenu} produces contextual menu that allow to get * information about a granule (detail, iso19115, map representation, coverage...). * * @param {[HTMLElements]} elements (Optional). The elements the menu is associated with. * @param {IONIC.imagearchive.ImageArchiveTool} iaTool The object used to retrieve ImageArchive * objects (or a function that returns this object). * @param {string} srs The srs to use to retrieve ImageArchive objects (or a function that returns * this object). */ var ContextualMenu = function (elements, iaTool, srs) { var self = this; var menu = new YAHOO.widget.ContextMenu (gensym ("contextmenu"), { trigger: elements, itemdata: ContextualMenu.menuItems, lazyload: true }); this.menu = menu; /* Holds the list of HTML elements that will trigger the menu */ this.elementsToAdd = undefined; this.getIaTool = (typeof (iaTool) == "function") ? iaTool : function () { return iaTool; }; this.getSrs = (typeof (srs) == "function") ? srs : function () { return srs; }; function onContextMenuClick(p_sType, p_aArgs, p_oMenu) { var oItem = p_aArgs[1]; // If the menu item is disabled, cancel menu event if (oItem.cfg.getProperty("disabled")) { return; } var sourceElt = this.contextEventTarget; var objectHolder = sourceElt.displayedObjectHolder; var iaObjectName = (objectHolder.data && objectHolder.data.iasObjectName) || (objectHolder.iaObject && objectHolder.iaObject.getName ()); if (!iaObjectName) { throw "Cannot find object name"; } if (oItem) { switch (ContextualMenu.menuGroupIndexToIndex(oItem.groupIndex, oItem.index)) { case ContextualMenu.menuIndexes.iso19115: objectHolder.getIAObject(function (iaObj) { ContextualMenu.retrieveISO19115 (iaObj, self.getIaTool ()); }, false); break; case ContextualMenu.menuIndexes.details: SearchModule.getDetailPanel ().renderDetailsByName (iaObjectName); break; case ContextualMenu.menuIndexes.extendedDetails: SearchModule.getDetailPanel ().renderExtendedDetailsByName (iaObjectName); break; case ContextualMenu.menuIndexes.map: sourceElt.className = "addedToMap"; objectHolder.getIAObject (function (iaObj) { MapModule.getMap ().addCoverage (iaObj); }, true); break; case ContextualMenu.menuIndexes.fit: objectHolder.getIAObject (function (iaObj) { var extent = iaObj.getSpatialExtent (); var map = SearchModule.getSearchMap (); if (extent) { ContextualMenu.transformBox (extent.getEnvelope (), map.getSrs (), function (box) { map.setBox (box); }); } }, true); break; case ContextualMenu.menuIndexes.coverage: GetCoverageModule.getGetCoveragePanel ().loadCoverageDescriptionByName (iaObjectName); IASClient.getMainTabView ().set ("activeTab", IASClient.getMainTabView ().getTab (2)); break; } } } function onContextMenuRender(p_sType, p_aArgs, p_oMenu) { this.clickEvent.subscribe(onContextMenuClick, menu, true); } // Disable irrelevant menu items before showing the menu function onBeforeShowEvent(p_sType, p_aArgs, p_oMenu) { // Before showing the menu, disable/enable the right entries var allEntries = [0, 1, 2, 3, 4, 5]; var disabledEntries = []; if (typeof MapModule == undefined) { disabledEntries.push (ContextualMenu.menuIndexes.map); } if (typeof GetCoverageModule == undefined) { disabledEntries.push (ContextualMenu.menuIndexes.coverage); } var sourceElt = this.contextEventTarget; var objectHolder = sourceElt.displayedObjectHolder; var iaObject = sourceElt.iaObject || (objectHolder && objectHolder.iaObject); if (iaObject) { if (iaObject.isAggregate ()) { disabledEntries.push (ContextualMenu.menuIndexes.extendedDetails); } if (!iaObject.isAvailableAsWCS ()) { disabledEntries.push (ContextualMenu.menuIndexes.coverage); disabledEntries.push (ContextualMenu.menuIndexes.iso19115); } if (!iaObject.isAvailableAsWMS ()) { disabledEntries.push (ContextualMenu.menuIndexes.map); } if (!iaObject.getSpatialExtent () && iaObject.isFull) { disabledEntries.push (ContextualMenu.menuIndexes.fit); } } IONIC.misc.forEach (function (e) { var index = ContextualMenu.menuIndexToGroupIndex (e); var item = menu.getItem(index[1], index[0]); item.cfg.setProperty("disabled", false); }, allEntries); IONIC.misc.forEach (function (e) { var index = ContextualMenu.menuIndexToGroupIndex (e); var item = menu.getItem(index[1], index[0]); item.cfg.setProperty("disabled", true); }, disabledEntries); } menu.renderEvent.subscribe(onContextMenuRender, menu, true); menu.beforeShowEvent.subscribe(onBeforeShowEvent, menu, true); }; /** * Runs this menu in "suspend" mode. In this mode, this actions are queued and executed * in one time when {@link #resume} is called. */ ContextualMenu.prototype.suspend = function () { this.elementsToAdd = []; }; /** * Stops the "suspend" mode. Executes the queued actions. */ ContextualMenu.prototype.resume = function () { var elements = this.elementsToAdd; this.elementsToAdd = undefined; if (elements.length) this.addElements (elements); }; /** * Add elements associated with the context menu. * * @param {[HTMLElement]} elements Elements associated with the context menu. */ ContextualMenu.prototype.addElements = function (elements) { var thisRef = this; // Check if 'suspend' mode active if (this.elementsToAdd) { this.elementsToAdd = this.elementsToAdd.concat (elements); return; } var menuElements = this.menu.cfg.getProperty("trigger"); if (menuElements) { menuElements = menuElements.concat (elements); } else { menuElements = elements; } this.menu.cfg.setProperty("trigger", menuElements); }; /** * Delete elements associated with the context menu. * * @param {[HTMLElement]} elements Elements not associated with the context menu anymore. * Setting to null remove all the elements. */ ContextualMenu.prototype.deleteElements = function (elements) { if (elements) { //TODO } else { // Delete all elements this.menu.cfg.setProperty("trigger", null); } }; ContextualMenu.menuIndexes = { "fit" : 0, "details" : 1, "extendedDetails" : 2, "iso19115" : 3, "map" : 4, "coverage" : 5 }; ContextualMenu.menuItems = [ [ { text: "Fit to layer" } ], [ { text: "Details" }, { text: "Extended details" }, { text: "ISO19115" } ], [ { text: "Add to navigator" }, { text: "Download data" } ] ]; // Retrieves the menu index given a groupIndex,index pair ContextualMenu.menuGroupIndexToIndex = function (groupIndex, index) { var i = 0, val = 0; for (; i < ContextualMenu.menuItems.length; i++) { if (i === groupIndex) return val + index; else val += ContextualMenu.menuItems[i].length; } }; // As menuGroupIndexToIndex, but the other way round ContextualMenu.menuIndexToGroupIndex = function (index) { var i = 0, j, val = 0; for (; i < ContextualMenu.menuItems.length; i++) { for (j = 0; j < ContextualMenu.menuItems[i].length; val++,j++) { if (val === index) return [i, j]; } } }; ContextualMenu.retrieveISO19115 = function (iaObject, iaTool) { var isoWin = window.open ("about:blank", "_blank", "toolbar=yes, location=yes, status=no, menubar=yes, scrollbars=yes, resizable=yes, width=800, height=600"); var dh = new IONIC.api.ui.DomHelper (isoWin.document); var loadingElt = dh.elt ("div", dh.txt ("Loading metadata...")); loadingElt.id = "loading"; var loadingImg = dh.elt ("img"); loadingImg.src = window.location.protocol + "//" + window.location.host + "/" + IONIC.misc.getWebappBaseUrl () + "/css/third-party/yui-assets/yui/build/tabview/assets/loading.gif"; dh.append (isoWin.document.body, loadingElt, loadingImg); var url = iaTool.getUrlForAction ("iaGetIso") + "&objectName=" + escape (iaObject.getName ()); isoWin.location = url; }; ContextualMenu.transformBox = function (bbox, epsgId, callback) { if (bbox.epsgId === epsgId) callback(bbox); IONIC.geom.TransformTool.withTransforms ( [ IONIC.geom.TransformTool.Transform.newInstance (bbox, bbox.epsgId, epsgId) ], function (transforms) { var transform = transforms ? transforms [0] : null; if (transform) { callback (transform); } else { throw "Cannot transform box."; } }); } /* * Copyright 2005- by IONIC Software S.A., * 18 Av Wallonie, 4460 Grace-Hollogne, Belgium. * All rights reserved. * * This software is the confidential and proprietary information * of IONIC Software S.A.("Confidential Information"). * You shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with IONIC Software. */ /** * @constructor * * @class * The {@link ContextualMenuWfs} produces contextual menu that allow to get * information about WFS (iso19115 or map representation). * * @param {[HTMLElements]} elements (Optional). The elements the menu is associated with. * @param {IONIC.imagearchive.ImageArchiveTool} iaTool The object used to retrieve ImageArchive * objects (or a function that returns this object). * @param {string} srs The srs to use to retrieve ImageArchive objects (or a function that returns * this object). */ var ContextualMenuWfs = function (elements, iaTool, srs) { var self = this; var menu = new YAHOO.widget.ContextMenu (gensym ("contextmenuwfs"), { trigger: elements, itemdata: ContextualMenuWfs.menuItems, lazyload: true}); this.menu = menu; var getDisplayMap = (typeof MapModule !== "undefined") ? MapModule.getMap : null; if (!getDisplayMap) { menu.getItem(1).cfg.setProperty("disabled", true); menu.getItem(2).cfg.setProperty("disabled", true); } this.getIaTool = (typeof (iaTool) == "function") ? iaTool : function () { return iaTool; }; this.getSrs = (typeof (srs) == "function") ? srs : function () { return srs; }; function onContextMenuClick(p_sType, p_aArgs, p_oMenu) { var oItem = p_aArgs[1]; var sourceElt = this.contextEventTarget; var wfsObject = sourceElt.wfsObject; if (oItem) { switch(oItem.index) { case 0: // ISO 19115 ContextualMenuWfs.retrieveISO19115 (self.getIaTool (), wfsObject); break; case 1: // Add to map var providerDiscovery = new IONIC.api.maps.ProviderDiscoveryTool (getDisplayMap ()); providerDiscovery.withAddedWFSLayers (wfsObject.wfsUrl, [ wfsObject.layerName ]); break; case 2: // Add to map (WMS) getDisplayMap ().addWMSLayers (wfsObject.wmsUrl, wfsObject.layerName); break; } } } function onContextMenuRender(p_sType, p_aArgs, p_oMenu) { this.clickEvent.subscribe(onContextMenuClick, menu, true); } menu.renderEvent.subscribe(onContextMenuRender, menu, true); }; /** * Add elements associated with the context menu. * * @param {[HTMLElement]} elements Elements associated with the context menu. */ ContextualMenuWfs.prototype.addElements = function (elements) { var thisRef = this; // Check if 'suspend' mode active if (this.elementsToAdd) { this.elementsToAdd = this.elementsToAdd.concat (elements); return; } var menuElements = this.menu.cfg.getProperty("trigger"); if (menuElements) { menuElements = menuElements.concat (elements); } else { menuElements = elements; } this.menu.cfg.setProperty("trigger", menuElements); }; /** * Delete elements associated with the context menu. * * @param {[HTMLElement]} elements Elements not associated with the context menu anymore. * Setting to null remove all the elements. */ ContextualMenuWfs.prototype.deleteElements = function (elements) { if (elements) { //TODO } else { // Delete all elements this.menu.cfg.setProperty("trigger", null); } }; ContextualMenuWfs.menuItems = [ { text: "ISO19115" }, { text: "Add to map (as a WFS)" }, { text: "Add to map (as a WMS)" } ]; ContextualMenuWfs.retrieveISO19115 = function (iaTool, wfsObject) { open (iaTool.getWfsISO19115SearchUrl(wfsObject.id), "ISO19115", "width=600,height=400,scrollbars=1,resizable=1"); }; /** * Runs this menu in "suspend" mode. In this mode, this actions are queued and executed * in one time when {@link #resume} is called. */ ContextualMenuWfs.prototype.suspend = function () { this.elementsToAdd = []; }; /** * Stops the "suspend" mode. Executes the queued actions. */ ContextualMenuWfs.prototype.resume = function () { var elements = this.elementsToAdd; this.elementsToAdd = undefined; if (elements.length) this.addElements (elements); };