[Mapbender-commits] r5949 - trunk/mapbender/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Apr 13 11:14:54 EDT 2010
Author: christoph
Date: 2010-04-13 11:14:53 -0400 (Tue, 13 Apr 2010)
New Revision: 5949
Added:
trunk/mapbender/http/plugins/mb_metadata_controller.js
trunk/mapbender/http/plugins/mb_metadata_edit.js
trunk/mapbender/http/plugins/mb_metadata_select.js
trunk/mapbender/http/plugins/mb_metadata_server.php
Log:
Added: trunk/mapbender/http/plugins/mb_metadata_controller.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_controller.js (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_controller.js 2010-04-13 15:14:53 UTC (rev 5949)
@@ -0,0 +1,23 @@
+Mapbender.events.init.register(function () {
+
+ if (options.$target.length < 3) {
+ return;
+ }
+ var tabsIndex = 0;
+ var selectIndex = 1;
+ var editIndex = 2;
+
+ var $tabs = options.$target.eq(tabsIndex);
+ var $select = options.$target.eq(selectIndex);
+ var $edit = options.$target.eq(editIndex);
+ var select = $select.mapbender();
+ var edit = $edit.mapbender();
+
+ select.events.selected.register(function (obj) {
+ $select.fadeOut(function () {
+ $tabs.tabs("select", editIndex-1);
+ edit.edit(obj);
+ $select.show();
+ });
+ });
+});
Added: trunk/mapbender/http/plugins/mb_metadata_edit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_edit.js (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_edit.js 2010-04-13 15:14:53 UTC (rev 5949)
@@ -0,0 +1,47 @@
+/**
+ * Package: mb_metadata_edit
+ *
+ * Description:
+ *
+ * Files:
+ *
+ * SQL:
+ *
+ * Help:
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * License:
+ * Copyright (c) 2009, Open Source Geospatial Foundation
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
+var $metadataEdit = $(this);
+
+var MetadataEditApi = function (o) {
+ this.edit = function (obj) {
+ // empty form
+
+ // get metadata from server
+ var req = new Mapbender.Ajax.Request({
+ url: "../plugins/mb_metadata_server.php",
+ method: "getWms",
+ parameters: {
+ },
+ callback: function (obj, result, message) {
+ if (!result) {
+ return;
+ }
+ console.log(obj);
+ }
+ });
+ req.send();
+ // fill form
+
+ };
+};
+
+$metadataEdit.mapbender(new MetadataEditApi(options));
Added: trunk/mapbender/http/plugins/mb_metadata_select.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_select.js (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_select.js 2010-04-13 15:14:53 UTC (rev 5949)
@@ -0,0 +1,98 @@
+/**
+ * Package: mb_metadata_select
+ *
+ * Description:
+ *
+ * Files:
+ *
+ * SQL:
+ *
+ * Help:
+ *
+ * Maintainer:
+ * http://www.mapbender.org/User:Christoph_Baudson
+ *
+ * License:
+ * Copyright (c) 2009, Open Source Geospatial Foundation
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+
+var $metadataSelect = $(this);
+
+var MetadataSelectApi = function (o) {
+ var table = null;
+ var that = this;
+
+ var fnGetSelected = function (oTableLocal){
+ var aReturn = [];
+ var aTrs = oTableLocal.fnGetNodes();
+
+ for ( var i=0 ; i<aTrs.length ; i++ ){
+ if ( $(aTrs[i]).hasClass('row_selected') ){
+ aReturn.push( aTrs[i] );
+ }
+ }
+ return aReturn;
+ };
+
+ this.getData = function () {
+ var req = new Mapbender.Ajax.Request({
+ url: "../plugins/mb_metadata_server.php",
+ method: "getWms",
+ parameters: {
+ },
+ callback: function (obj, result, message) {
+ if (!result) {
+ return;
+ }
+ var aoColumns = [];
+ for (var i in obj.header) {
+ if (obj.header[i] === "WMS ID") {
+ continue;
+ }
+ aoColumns.push({"sTitle": obj.header[i]});
+ }
+
+ // initialize datatables
+ table = $metadataSelect.find("table").dataTable({
+ "aoColumns": aoColumns,
+ "bJQueryUI": true,
+ "bAutoWidth": false
+ });
+
+ // add rows
+ for (var j in obj.data) {
+ var data = obj.data[j];
+ var wmsId = data[0];
+ data.shift();
+ var index = table.fnAddData(data);
+ var rowNode = table.fnGetNodes(index[0]);
+ $(rowNode).data("wmsId", wmsId);
+ }
+
+ // make rows selectable
+ $metadataSelect.find("tbody").click(function (e) {
+ $(table.fnSettings().aoData).each(function (){
+ $(this.nTr).removeClass('row_selected');
+ });
+ $(e.target.parentNode).addClass('row_selected');
+ var selectedRow = fnGetSelected(table);
+ that.events.selected.trigger({
+ wmsId: $(selectedRow).data("wmsId")
+ });
+ });
+ }
+ });
+ req.send();
+ };
+
+ this.events = {
+ "selected": new Mapbender.Event()
+ };
+};
+
+$metadataSelect.mapbender(new MetadataSelectApi(options));
+
+$metadataSelect.mapbender("getData");
\ No newline at end of file
Added: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php 2010-04-13 15:14:53 UTC (rev 5949)
@@ -0,0 +1,87 @@
+<?php
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/../classes/class_user.php";
+
+$ajaxResponse = new AjaxResponse($_POST);
+
+function abort ($message) {
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage($message);
+ $ajaxResponse->send();
+ die;
+};
+
+function getWms ($wmsId = null) {
+ $user = new User(Mapbender::session()->get("mb_user_id"));
+ $wmsIdArray = $user->getOwnedWms();
+ if (!is_array($wmsIdArray) || count($wmsIdArray) === 0) {
+ abort(_mb("No metadata sets available."));
+ }
+ if (!is_null($wmsId) && !in_array($wmsId, $wmsIdArray)) {
+ abort(_mb("You are not allowed to access this WMS."));
+ }
+ return $wmsIdArray;
+}
+
+switch ($ajaxResponse->getMethod()) {
+ case "getWms" :
+ $wmsIdArray = getWms();
+
+ $wmsList = implode(",", $wmsIdArray);
+ $sql = <<<SQL
+
+SELECT wms.wms_id, wms.wms_title, wms.wms_timestamp, wms_version, m.status_comment
+FROM wms LEFT JOIN mb_monitor AS m
+ON wms.wms_id = m.fkey_wms_id
+WHERE wms_id IN ($wmsList);
+
+SQL;
+ $res = db_query($sql);
+ $resultObj = array(
+ "header" => array(
+ "WMS ID",
+ "Titel",
+ "Timestamp",
+ "Version",
+ "Status"
+ ),
+ "data" => array()
+ );
+
+ while ($row = db_fetch_row($res)) {
+ // convert NULL to '', NULL values cause datatables to crash
+ $walk = array_walk($row, create_function('&$s', '$s=strval($s);'));
+ $resultObj["data"][]= $row;
+ }
+ $ajaxResponse->setResult($resultObj);
+ $ajaxResponse->setSuccess(true);
+ break;
+
+ case "getWms" :
+ $wmsId = $ajaxResponse->getParameter("id");
+ getWms($wmsId);
+
+ $sql = <<<SQL
+
+SELECT * FROM wms WHERE wms_id = $wmsId;
+
+SQL;
+ $res = db_query($sql);
+
+ $resultObj = array();
+ while ($row = db_fetch_row($res)) {
+ $resultObj[]= $row;
+ }
+ $ajaxResponse->setResult($resultObj);
+ $ajaxResponse->setSuccess(true);
+
+
+ break;
+ default:
+ $ajaxResponse->setSuccess(false);
+ $ajaxResponse->setMessage(_mb("An unknown error occured."));
+ break;
+}
+
+$ajaxResponse->send();
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list