[Mapbender-commits] r6043 - trunk/mapbender/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Apr 29 10:38:55 EDT 2010
Author: christoph
Date: 2010-04-29 10:38:54 -0400 (Thu, 29 Apr 2010)
New Revision: 6043
Added:
trunk/mapbender/http/plugins/mb_metadata_layerTree.js
Modified:
trunk/mapbender/http/plugins/mb_metadata_edit.js
trunk/mapbender/http/plugins/mb_metadata_layer.js
trunk/mapbender/http/plugins/mb_metadata_select.js
trunk/mapbender/http/plugins/mb_metadata_server.php
trunk/mapbender/http/plugins/mb_tabs_horizontal.js
Log:
Modified: trunk/mapbender/http/plugins/mb_metadata_edit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_edit.js 2010-04-29 14:27:35 UTC (rev 6042)
+++ trunk/mapbender/http/plugins/mb_metadata_edit.js 2010-04-29 14:38:54 UTC (rev 6043)
@@ -32,28 +32,38 @@
}
};
- this.edit = function (obj) {
- $metadataForm.load("../plugins/mb_metadata_edit.html", function () {
- validator = $metadataForm.validate();
+ var formReady = false;
- // get metadata from server
- var req = new Mapbender.Ajax.Request({
- url: "../plugins/mb_metadata_server.php",
- method: "getWmsMetadata",
- parameters: {
- "id": obj.wmsId
- },
- callback: function (obj, result, message) {
- if (!result) {
- return;
- }
- $metadataForm.easyform("reset");
- $metadataForm.easyform("fill", obj);
+ var fillForm = function (obj) {
+ // get metadata from server
+ var req = new Mapbender.Ajax.Request({
+ url: "../plugins/mb_metadata_server.php",
+ method: "getWmsMetadata",
+ parameters: {
+ "id": obj
+ },
+ callback: function (obj, result, message) {
+ if (!result) {
+ return;
}
- });
- req.send();
+ $metadataForm.easyform("reset");
+ $metadataForm.easyform("fill", obj);
+ }
});
+ req.send();
};
+
+ this.init = function (obj) {
+ if (!formReady) {
+ $metadataForm.load("../plugins/mb_metadata_edit.html", function () {
+ validator = $metadataForm.validate();
+ fillForm(obj);
+ formReady = true;
+ });
+ return;
+ }
+ fillForm(obj);
+ };
Mapbender.events.localize.register(function () {
that.valid();
Modified: trunk/mapbender/http/plugins/mb_metadata_layer.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layer.js 2010-04-29 14:27:35 UTC (rev 6042)
+++ trunk/mapbender/http/plugins/mb_metadata_layer.js 2010-04-29 14:38:54 UTC (rev 6043)
@@ -25,32 +25,30 @@
var MetadataLayerApi = function (o) {
var that = this;
var validator;
-
+
this.valid = function () {
if (validator && validator.numberOfInvalids() > 0) {
$metadataForm.valid();
}
};
-
- this.edit = function (obj) {
- $metadataForm.load("../plugins/mb_metadata_layer.html", function () {
- validator = $metadataForm.validate();
- // get layer from server
- var req = new Mapbender.Ajax.Request({
- url: "../plugins/mb_metadata_server.php",
- method: "getLayerByWms",
- parameters: {
- "id": obj.wmsId
- },
- callback: function (obj, result, message) {
- if (!result) {
- return;
- }
- console.log(obj);
- }
+ this.events = {
+ initialized: new Mapbender.Event()
+ };
+
+ this.init = function (obj) {
+ if (!that.events.initialized.done) {
+ $metadataForm.load("../plugins/mb_metadata_layer.html", function () {
+ validator = $metadataForm.validate();
+ that.events.initialized.trigger({
+ wmsId: obj
+ });
+ that.events.initialized.done = true;
});
-// req.send();
+ return;
+ }
+ that.events.initialized.trigger({
+ wmsId: obj
});
};
Added: trunk/mapbender/http/plugins/mb_metadata_layerTree.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layerTree.js (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_layerTree.js 2010-04-29 14:38:54 UTC (rev 6043)
@@ -0,0 +1,149 @@
+/**
+ * Package: mb_metadata_layerTree
+ *
+ * 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 $metadataLayerTree = $(this);
+
+var MetadataLayerTreeApi = function (o) {
+ var that = this;
+
+ var instanceId = "choose";
+
+ var createFolder = function (set) {
+ return {
+ attributes: {
+ data: $.toJSON(set.attr)
+ },
+ data: set.attr.title,
+ state: "closed",
+ children: []
+ };
+ };
+
+ var createLeaf = function (set) {
+ return {
+ attributes: {
+ data: $.toJSON(set.attr)
+ },
+ data: {
+ title: set.attr.title
+ }
+ };
+ };
+
+ var toJsTreeJson = function (nestedSets) {
+ if (!nestedSets.length && nestedSets.length !== 0) {
+ new Mapbender.Exception("Nested sets not an array.");
+ return [];
+ }
+ var right = null;
+ if (arguments.length === 2) {
+ right = arguments[1];
+ }
+ var children = [];
+ while (nestedSets.length > 0) {
+ set = nestedSets.shift();
+ if (typeof set.left != "number" || typeof set.right != "number") {
+ new Mapbender.Exception("Left or right not set.");
+ return [];
+ }
+
+ // is a different subtree, go back
+ if (right !== null && right < set.right) {
+ nestedSets.unshift(set);
+ return children;
+ }
+ // is a leaf
+ else if (set.right - set.left === 1) {
+ children.push(createLeaf(set));
+ }
+ // is a folder
+ else {
+ var node = createFolder(set);
+ var nodeChildren = toJsTreeJson(nestedSets, set.right);
+ children.push($.extend(node, {
+ children: nodeChildren
+ }));
+ }
+ }
+ return children;
+ };
+
+ var initTree = function (nestedSets) {
+ var jsTreeData = toJsTreeJson(nestedSets);
+ jsTreeData[0].state = "open";
+
+ var jsTree = $.tree.reference(instanceId);
+ if (jsTree !== null) {
+ jsTree.destroy();
+ }
+
+ $("#" + instanceId).tree({
+ ui: {
+ theme_path: "../extensions/jsTree.v.0.9.9a2/themes/checkbox/style.css",
+ theme_name: "checkbox"
+ },
+ plugins: {
+ checkbox: {
+ }
+ },
+ data : {
+ type : "json",
+ opts : {
+ static : jsTreeData
+ }
+ },
+ callback: {
+ onselect: function (node, treeObj) {
+ var data = $(node).metadata({
+ type: "attr",
+ name: "data"
+ });
+ that.events.selected.trigger(data);
+ }
+ }
+ });
+ };
+
+
+ this.events = {
+ selected: new Mapbender.Event()
+ };
+
+ this.init = function (obj) {
+ // get layer from server
+ var req = new Mapbender.Ajax.Request({
+ url: "../plugins/mb_metadata_server.php",
+ method: "getLayerByWms",
+ parameters: {
+ "id": obj
+ },
+ callback: function (obj, result, message) {
+ if (!result) {
+ return;
+ }
+ initTree(obj.nestedSets);
+ }
+ });
+ req.send();
+ };
+};
+
+$metadataLayerTree.mapbender(new MetadataLayerTreeApi(options));
Modified: trunk/mapbender/http/plugins/mb_metadata_select.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_select.js 2010-04-29 14:27:35 UTC (rev 6042)
+++ trunk/mapbender/http/plugins/mb_metadata_select.js 2010-04-29 14:38:54 UTC (rev 6043)
@@ -79,8 +79,11 @@
});
$(e.target.parentNode).addClass('row_selected');
var selectedRow = fnGetSelected(table);
- that.events.selected.trigger({
- wmsId: $(selectedRow).data("wmsId")
+ $metadataSelect.fadeOut(function () {
+ that.events.selected.trigger({
+ wmsId: $(selectedRow).data("wmsId")
+ });
+ $metadataSelect.show();
});
});
}
@@ -89,7 +92,7 @@
};
this.events = {
- "selected": new Mapbender.Event()
+ selected: new Mapbender.Event()
};
};
Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php 2010-04-29 14:27:35 UTC (rev 6042)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php 2010-04-29 14:38:54 UTC (rev 6043)
@@ -5,6 +5,7 @@
$ajaxResponse = new AjaxResponse($_POST);
function abort ($message) {
+ global $ajaxResponse;
$ajaxResponse->setSuccess(false);
$ajaxResponse->setMessage($message);
$ajaxResponse->send();
@@ -80,7 +81,7 @@
break;
case "getLayerByWms" :
$wmsId = $ajaxResponse->getParameter("id");
- getWms($wmsId);
+// getWms($wmsId);
$sql = <<<SQL
@@ -94,49 +95,69 @@
while ($row = db_fetch_assoc($res)) {
$rows[] = $row;
}
- $resultObj = array();
- $previousParent = null;
$left = 1;
- $resultObj[]= array(
- "left" => $left,
- "right" => 2*(count($rows) + 1),
- "wms" => ""
- );
- function addSubTree ($rows, $i, $left) {
- $currentRow = $rows[$i];
- $layer_parent = $currentRow["layer_parent"];
- $layer_pos = $currentRow["layer_pos"];
-
- $node = array(
+ function createNode ($left, $right, $row) {
+ return array(
"left" => $left,
- "right" => null,
- "wms" => $rows["layer_id"]
+ "right" => $right,
+ "parent" => $row["layer_parent"] !== "" ? intval($row["layer_parent"]) : null,
+ "pos" => intval($row["layer_pos"]),
+ "attr" => array (
+ "id" => intval($row["layer_id"]),
+ "name" => $row["layer_name"],
+ "title" => $row["layer_title"]
+ )
);
+ }
- $previousParent = is_numeric($layer_parent) ? $layer_parent : null;
- for ($j = $i+1; $j < count($rows); $j++) {
+ function addSubTree ($rows, $i, $left) {
+ $nodeArray = array();
+ $addNewNode = true;
+ for ($j = $i; $j < count($rows); $j++) {
$row = $rows[$j];
- $parent = $row["layer_parent"];
- $pos = $row["layer_pos"];
- if (!is_null($previousParent) && $previousParent > $parent) {
- break;
+ $pos = intval($row["layer_pos"]);
+ $parent = $row["layer_parent"] !== "" ? intval($row["layer_parent"]) : null;
+
+ // first node of subtree
+ if ($addNewNode) {
+ $nodeArray[]= createNode($left, null, $row);
+ $addNewNode = false;
}
- if (is_null($previousParent)) {
-
+ else {
+ // new sub tree
+ if ($parent === $nodeArray[count($nodeArray)-1]["pos"]) {
+ $addedNodeArray = addSubTree($rows, $j, ++$left);
+
+ $nodeArray[count($nodeArray)-1]["right"] =
+ $nodeArray[count($nodeArray)-1]["left"] +
+ 2 * count($addedNodeArray) + 1;
+
+ $left = $nodeArray[count($nodeArray)-1]["right"] + 1;
+
+ $nodeArray = array_merge($nodeArray, $addedNodeArray);
+ $j += count($addedNodeArray) - 1;
+ $addNewNode = true;
+
+ }
+ // siblings
+ elseif ($parent === $nodeArray[count($nodeArray)-1]["parent"]) {
+ $nodeArray[count($nodeArray)-1]["right"] = ++$left;
+ $nodeArray[]= createNode(++$left, null, $row);
+ }
}
- if ($previousParent < $parent) {
-
- }
- if ($previousParent < $parent) {
-
- }
}
-
- return $subTree;
+ if (is_null($nodeArray[count($nodeArray)-1]["right"])) {
+ $nodeArray[count($nodeArray)-1]["right"] = ++$left;
+ }
+ return $nodeArray;
}
+
- addSubTree($rows, 0, 0, $left);
+ $nodeArray = addSubTree($rows, 0, 1);
+ $resultObj = array(
+ "nestedSets" => $nodeArray
+ );
$ajaxResponse->setResult($resultObj);
$ajaxResponse->setSuccess(true);
Modified: trunk/mapbender/http/plugins/mb_tabs_horizontal.js
===================================================================
--- trunk/mapbender/http/plugins/mb_tabs_horizontal.js 2010-04-29 14:27:35 UTC (rev 6042)
+++ trunk/mapbender/http/plugins/mb_tabs_horizontal.js 2010-04-29 14:38:54 UTC (rev 6043)
@@ -33,21 +33,38 @@
*/
var $tabs = $(this);
-options.$target.each(function () {
- var $currentTabEntry = $(this);
- var tabId = $tabs.attr("id") + "_" + this.id;
+
+var HorizontalTabsApi = function (o) {
+ this.create = function () {
+ o.$target.each(function () {
+ var $currentTabEntry = $(this);
+ var tabId = $tabs.attr("id") + "_" + this.id;
+
+ $tabs.find("ul").append(
+ "<li><a href='#" + tabId + "'>" +
+ $currentTabEntry.mapbender("currentTitle") +
+ "</a></li>"
+ )
+ .end()
+ .append("<div id='" + tabId + "'/>")
+ .find("#" + tabId)
+ .append($currentTabEntry);
+ });
- $tabs.find("ul").append(
- "<li><a href='#" + tabId + "'>" +
- $currentTabEntry.mapbender("currentTitle") +
- "</a></li>"
- )
- .end()
- .append("<div id='" + tabId + "'/>")
- .find("#" + tabId)
- .append($currentTabEntry);
-});
+ if (o.$target.size() > 0) {
+ $tabs.tabs();
+ }
+ };
+
+ this.select = function (id) {
+ var index = $.inArray(id, o.target);
+ if (index === -1) {
+ return;
+ }
+ $tabs.tabs("select", index);
+ };
+
+ this.create();
+};
-if (options.$target.size() > 0) {
- $tabs.tabs();
-}
+$tabs.mapbender(new HorizontalTabsApi(options));
More information about the Mapbender_commits
mailing list