Mercurial > hg > ChinaGisRestApi
view gis_gui/lib/blocks.js @ 276:55bc9972fb1b
Merge with d1b43624cc63b829f64cc952540748e15272e389
author | casties |
---|---|
date | Thu, 23 Feb 2012 21:29:06 +0100 |
parents | d1b43624cc63 |
children |
line wrap: on
line source
/* * fallback for console.log calls */ if (typeof(console) == 'undefined') { console = { log : function(){}, debug : function(){}, error : function(){} }; } function defined(x) { // returns if x is defined return (typeof arguments[0] !== "undefined"); } function randomString() { var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; var string_length = 8; var randomstring = ''; for (var i=0; i<string_length; i++) { var rnum = Math.floor(Math.random() * chars.length); randomstring += chars.substring(rnum,rnum+1); } return randomstring; } /* * guiBlocks base */ function guiBlocks(container) { // list of blocks this.blocks = []; this.containerElement = container; return this; } //var guiBlocks = new Object(); /* * Block base class */ guiBlocks.Block = function(id, element) { this.id = id; // the blocks html id this.element = element; // the html dom element this.storeId = null; // the id in online storage this.params = {}; // parameters to store return this; }; // create a new block and add it to the current workspaces stack guiBlocks.prototype.addBlock = function(url, baseId, params, whenDone) { // add title to url var newblock = $("<div>Block loading...</div>"); var newid = baseId+"_"+randomString(); var container = this.containerElement; console.debug("addblock newid="+newid); newblock.hide(); newblock.load(url, function() { // after load function console.debug("addblock after load block"); console.debug(container); $(this).find(".block").attr("id",newid); $(this).appendTo(container); // chain done function if (typeof(whenDone) == "function") { // chain whenDone (should we add parameters?) whenDone.apply(this); } else { // default after load function $(this).fadeIn(); } }); // create new Block object var block = new guiBlocks.Block(newid, newblock); // add parameters if (params == null) { // create new params params = {"id": newid}; } block.params = params; // add to list of blocks this.blocks.push(block); return block; }; guiBlocks.prototype.getBlock = function(id) { for (b in this.blocks) { if (b.id == id) { return b; } } return null; }; /* guiBlocks.prototype.getStoreItem = function(tag,type,item) { // get item from online storage jQuery.get(); } */ guiBlocks.prototype.loadListOfItems = function(storeTag,storeType,callback) { // loads list of id and type objects and executes callback function var url = "../db/RESTjson/db/public/gui_objects/"+escape(storeTag)+"/"+storeType+"?recursive=true"; jQuery.getJSON(url,callback); }; guiBlocks.prototype.e4DOpen = function(titel,tablesParam,from_year_name,until_year_name){ var e4D_URL="http://mappit.mpiwg-berlin.mpg.de:8080/e4D?"; var paramstr; if (until_year_name!='') { paramstr = "format=KML&from_year_name="+from_year_name+"&until_year_name="+until_year_name; }else{ paramstr = "format=KML&from_year_name="+from_year_name } // var layer_URL = "http://chinagis-develop.mpiwg-berlin.mpg.de:9080/db/RESTdb/db/public/" + escape(table) + "?" + paramstr; var layer_URL = ""; var tables; if (tablesParam instanceof Array) { tables=tablesParam; } else { tables=new Array(tablesParam); } for (var i=0;i<tables.length;i++){ if (i!=0) {e4D_URL=e4D_URL+"&";} layer_URL= escape("http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/public/" + tables[i] + "?" + paramstr); //layer_URL= escape("http://dw.mpiwg-berlin.mpg.de:8080/db/RESTdb/db/public/" + tables[i] + "?" + paramstr); e4D_URL=e4D_URL+"kml"+[i+1]+"="+layer_URL+"&source"+[i+1]+"=1"; } console.debug(" e4D_URL=", e4D_URL ); var newwindow=window.open(e4D_URL,"Mappit@Europeana4D","height=800,width=900,resizable=1,scrollbars=1"); if (window.focus) {newwindow.focus();} return false; /* });*/ }; guiBlocks.Block.prototype.storeBlock = function(storeTag) { var storeType = this.params.type; var storeItem = this.params.id; var url = "../db/RESTjson/db/public/gui_objects/"+escape(storeTag)+"/"+storeType+"/"+storeItem; var ds = JSON.stringify(this.params); jQuery.ajax({ type: "PUT", url: url, data: ds, success: function(msg){ console.debug("PUT success msg=",msg); this.storeId = storeItem; } }); }; // collapse the block so that only its titlebar is visible function foldBlock(segment){ if (segment == null) { return; } if(segment.hasClass("folded")){ //if the segment is collapsed segment.removeClass("folded"); segment.find(".body").slideDown(); } else{ //if the segment is expanded segment.addClass("folded"); segment.find(".body").slideUp(); } } function switchSubscreens(container, id1, id2) { var oldScreen = container.find("#"+id1); var newScreen = container.find("#"+id2); oldScreen.fadeOut(); newScreen.fadeIn(); } function guiBlocks_init() { // initialize collapsed windows $("div.block.folded").each(function(e){ $(this).find(".body").slideUp(); }); // TitleBar Click $("div.block div.titlebar h1").live("click", function(e) { var segment = $(this).parents().filter("div.block"); foldBlock(segment); }); // TitleBar Close $("div.block div.titlebar div.close_button").live("click", function(e){ segment = $(this).parents().filter("div.block"); segment.fadeOut(function(){ segment.remove();}); }); // TitleBar Reload $("div.block div.titlebar div.reload_button").live("click", function(e){ segment = $(this).parents().filter("div.block"); console.debug("guiBlocks_init().live(reload) segment[0].id="+ segment[0].id); //FJK: funktioniert leider noch nicht! // var blockid=$(this).parents().firstElementChild.id; // var mapblock=getBlock(blockid); // var params=mapblock.readMapParams(); // var be = mapblock.element; //var mapblock = $(be).find(".map_box"); // console.debug("guiBlocks_init().live(reload) params="+ new String(params)); // mapblock.updateMap(be,params); }); } function getBlock(id){ for (b in this.blocks) { if (b.id == id) { return b; } } return null; }