Mercurial > hg > ChinaGisRestApi
view gis_gui/lib/blocks.js @ 256:cb953cc153a6
GIS-Links from MPDL-Documents now served by Mappit-Server
author | fknauft |
---|---|
date | Wed, 28 Sep 2011 18:46:00 +0200 |
parents | d6c7bedf4370 |
children | 3a10287447b1 |
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.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; }