Mercurial > hg > ChinaGisRestApi
annotate gis_gui/lib/blocks.js @ 276:55bc9972fb1b
Merge with d1b43624cc63b829f64cc952540748e15272e389
author | casties |
---|---|
date | Thu, 23 Feb 2012 21:29:06 +0100 |
parents | d1b43624cc63 |
children |
rev | line source |
---|---|
63 | 1 /* |
2 * fallback for console.log calls | |
3 */ | |
4 if (typeof(console) == 'undefined') { | |
5 console = { | |
6 log : function(){}, | |
7 debug : function(){}, | |
65 | 8 error : function(){} |
9 }; | |
63 | 10 } |
11 | |
12 function defined(x) { | |
13 // returns if x is defined | |
68 | 14 return (typeof arguments[0] !== "undefined"); |
63 | 15 } |
16 | |
72 | 17 function randomString() { |
18 var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; | |
19 var string_length = 8; | |
20 var randomstring = ''; | |
21 for (var i=0; i<string_length; i++) { | |
22 var rnum = Math.floor(Math.random() * chars.length); | |
23 randomstring += chars.substring(rnum,rnum+1); | |
24 } | |
25 return randomstring; | |
26 } | |
27 | |
28 | |
263 | 29 |
63 | 30 /* |
31 * guiBlocks base | |
32 */ | |
33 function guiBlocks(container) { | |
34 // list of blocks | |
35 this.blocks = []; | |
36 this.containerElement = container; | |
37 return this; | |
38 } | |
39 //var guiBlocks = new Object(); | |
40 | |
41 /* | |
42 * Block base class | |
43 */ | |
44 guiBlocks.Block = function(id, element) { | |
45 this.id = id; // the blocks html id | |
46 this.element = element; // the html dom element | |
47 this.storeId = null; // the id in online storage | |
65 | 48 this.params = {}; // parameters to store |
63 | 49 return this; |
50 }; | |
51 | |
52 // create a new block and add it to the current workspaces stack | |
53 guiBlocks.prototype.addBlock = function(url, baseId, params, whenDone) { | |
54 // add title to url | |
55 var newblock = $("<div>Block loading...</div>"); | |
68 | 56 var newid = baseId+"_"+randomString(); |
63 | 57 var container = this.containerElement; |
58 console.debug("addblock newid="+newid); | |
59 newblock.hide(); | |
60 newblock.load(url, function() { | |
61 // after load function | |
62 console.debug("addblock after load block"); | |
63 console.debug(container); | |
64 $(this).find(".block").attr("id",newid); | |
65 $(this).appendTo(container); | |
253
d6c7bedf4370
New reload button active in upper right corner of block
fknauft
parents:
248
diff
changeset
|
66 |
63 | 67 // chain done function |
68 if (typeof(whenDone) == "function") { | |
72 | 69 // chain whenDone (should we add parameters?) |
70 whenDone.apply(this); | |
63 | 71 } else { |
72 // default after load function | |
73 $(this).fadeIn(); | |
65 | 74 } |
63 | 75 |
76 }); | |
77 // create new Block object | |
78 var block = new guiBlocks.Block(newid, newblock); | |
79 // add parameters | |
68 | 80 if (params == null) { |
63 | 81 // create new params |
82 params = {"id": newid}; | |
83 } | |
84 block.params = params; | |
85 // add to list of blocks | |
86 this.blocks.push(block); | |
87 return block; | |
65 | 88 }; |
63 | 89 |
90 guiBlocks.prototype.getBlock = function(id) { | |
91 for (b in this.blocks) { | |
92 if (b.id == id) { | |
93 return b; | |
94 } | |
95 } | |
96 return null; | |
65 | 97 }; |
63 | 98 |
99 /* | |
100 guiBlocks.prototype.getStoreItem = function(tag,type,item) { | |
101 // get item from online storage | |
102 jQuery.get(); | |
103 } | |
104 */ | |
105 | |
106 guiBlocks.prototype.loadListOfItems = function(storeTag,storeType,callback) { | |
107 // loads list of id and type objects and executes callback function | |
108 var url = "../db/RESTjson/db/public/gui_objects/"+escape(storeTag)+"/"+storeType+"?recursive=true"; | |
109 jQuery.getJSON(url,callback); | |
65 | 110 }; |
63 | 111 |
273 | 112 guiBlocks.prototype.e4DOpen = function(titel,tablesParam,from_year_name,until_year_name){ |
264 | 113 var e4D_URL="http://mappit.mpiwg-berlin.mpg.de:8080/e4D?"; |
273 | 114 var paramstr; |
115 if (until_year_name!='') { | |
116 paramstr = "format=KML&from_year_name="+from_year_name+"&until_year_name="+until_year_name; | |
117 }else{ | |
118 paramstr = "format=KML&from_year_name="+from_year_name | |
119 } | |
120 | |
263 | 121 // var layer_URL = "http://chinagis-develop.mpiwg-berlin.mpg.de:9080/db/RESTdb/db/public/" + escape(table) + "?" + paramstr; |
264 | 122 var layer_URL = ""; |
123 | |
273 | 124 var tables; |
125 | |
126 if (tablesParam instanceof Array) { | |
127 tables=tablesParam; | |
128 } else { | |
129 tables=new Array(tablesParam); | |
130 } | |
264 | 131 for (var i=0;i<tables.length;i++){ |
132 if (i!=0) {e4D_URL=e4D_URL+"&";} | |
273 | 133 layer_URL= escape("http://mappit.mpiwg-berlin.mpg.de/db/RESTdb/db/public/" + tables[i] + "?" + paramstr); |
134 //layer_URL= escape("http://dw.mpiwg-berlin.mpg.de:8080/db/RESTdb/db/public/" + tables[i] + "?" + paramstr); | |
265 | 135 e4D_URL=e4D_URL+"kml"+[i+1]+"="+layer_URL+"&source"+[i+1]+"=1"; |
264 | 136 } |
137 console.debug(" e4D_URL=", e4D_URL ); | |
267 | 138 var newwindow=window.open(e4D_URL,"Mappit@Europeana4D","height=800,width=900,resizable=1,scrollbars=1"); |
264 | 139 if (window.focus) {newwindow.focus();} |
263 | 140 return false; |
264 | 141 |
263 | 142 /* });*/ |
143 }; | |
63 | 144 |
145 guiBlocks.Block.prototype.storeBlock = function(storeTag) { | |
146 var storeType = this.params.type; | |
147 var storeItem = this.params.id; | |
148 var url = "../db/RESTjson/db/public/gui_objects/"+escape(storeTag)+"/"+storeType+"/"+storeItem; | |
149 var ds = JSON.stringify(this.params); | |
150 jQuery.ajax({ | |
151 type: "PUT", | |
152 url: url, | |
153 data: ds, | |
154 success: function(msg){ | |
264 | 155 console.debug("PUT success msg=",msg); |
63 | 156 this.storeId = storeItem; |
157 } | |
158 }); | |
159 }; | |
160 | |
161 | |
162 | |
163 // collapse the block so that only its titlebar is visible | |
164 function foldBlock(segment){ | |
72 | 165 if (segment == null) { |
63 | 166 return; |
167 } | |
168 if(segment.hasClass("folded")){ | |
169 //if the segment is collapsed | |
170 segment.removeClass("folded"); | |
171 segment.find(".body").slideDown(); | |
172 } else{ | |
173 //if the segment is expanded | |
174 segment.addClass("folded"); | |
175 segment.find(".body").slideUp(); | |
176 } | |
177 } | |
178 | |
179 function switchSubscreens(container, id1, id2) { | |
180 var oldScreen = container.find("#"+id1); | |
181 var newScreen = container.find("#"+id2); | |
182 | |
183 oldScreen.fadeOut(); | |
184 newScreen.fadeIn(); | |
185 } | |
186 | |
187 function guiBlocks_init() { | |
188 // initialize collapsed windows | |
189 $("div.block.folded").each(function(e){ | |
190 $(this).find(".body").slideUp(); | |
191 }); | |
192 | |
193 // TitleBar Click | |
194 $("div.block div.titlebar h1").live("click", function(e) { | |
195 var segment = $(this).parents().filter("div.block"); | |
196 foldBlock(segment); | |
197 }); | |
198 | |
199 // TitleBar Close | |
200 $("div.block div.titlebar div.close_button").live("click", function(e){ | |
201 segment = $(this).parents().filter("div.block"); | |
65 | 202 segment.fadeOut(function(){ segment.remove();}); |
63 | 203 }); |
204 | |
248 | 205 // TitleBar Reload |
206 $("div.block div.titlebar div.reload_button").live("click", function(e){ | |
207 segment = $(this).parents().filter("div.block"); | |
208 console.debug("guiBlocks_init().live(reload) segment[0].id="+ segment[0].id); | |
209 //FJK: funktioniert leider noch nicht! | |
210 // var blockid=$(this).parents().firstElementChild.id; | |
211 // var mapblock=getBlock(blockid); | |
212 // var params=mapblock.readMapParams(); | |
213 // var be = mapblock.element; | |
214 //var mapblock = $(be).find(".map_box"); | |
215 // console.debug("guiBlocks_init().live(reload) params="+ new String(params)); | |
216 // mapblock.updateMap(be,params); | |
217 }); | |
218 | |
65 | 219 } |
248 | 220 |
221 function getBlock(id){ | |
222 for (b in this.blocks) { | |
223 if (b.id == id) { | |
224 return b; | |
225 } | |
226 } | |
227 return null; | |
228 } |