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
|
63
|
29 /*
|
|
30 * guiBlocks base
|
|
31 */
|
|
32 function guiBlocks(container) {
|
|
33 // list of blocks
|
|
34 this.blocks = [];
|
|
35 this.containerElement = container;
|
|
36 return this;
|
|
37 }
|
|
38 //var guiBlocks = new Object();
|
|
39
|
|
40 /*
|
|
41 * Block base class
|
|
42 */
|
|
43 guiBlocks.Block = function(id, element) {
|
|
44 this.id = id; // the blocks html id
|
|
45 this.element = element; // the html dom element
|
|
46 this.storeId = null; // the id in online storage
|
65
|
47 this.params = {}; // parameters to store
|
63
|
48 return this;
|
|
49 };
|
|
50
|
|
51 // create a new block and add it to the current workspaces stack
|
|
52 guiBlocks.prototype.addBlock = function(url, baseId, params, whenDone) {
|
|
53 // add title to url
|
|
54 var newblock = $("<div>Block loading...</div>");
|
68
|
55 var newid = baseId+"_"+randomString();
|
63
|
56 var container = this.containerElement;
|
|
57 console.debug("addblock newid="+newid);
|
|
58 newblock.hide();
|
|
59 newblock.load(url, function() {
|
|
60 // after load function
|
|
61 console.debug("addblock after load block");
|
|
62 console.debug(container);
|
|
63 $(this).find(".block").attr("id",newid);
|
|
64 $(this).appendTo(container);
|
|
65 // chain done function
|
|
66 if (typeof(whenDone) == "function") {
|
72
|
67 // chain whenDone (should we add parameters?)
|
|
68 whenDone.apply(this);
|
63
|
69 } else {
|
|
70 // default after load function
|
|
71 $(this).fadeIn();
|
65
|
72 }
|
63
|
73
|
|
74 });
|
|
75 // create new Block object
|
|
76 var block = new guiBlocks.Block(newid, newblock);
|
|
77 // add parameters
|
68
|
78 if (params == null) {
|
63
|
79 // create new params
|
|
80 params = {"id": newid};
|
|
81 }
|
|
82 block.params = params;
|
|
83 // add to list of blocks
|
|
84 this.blocks.push(block);
|
|
85 return block;
|
65
|
86 };
|
63
|
87
|
|
88 guiBlocks.prototype.getBlock = function(id) {
|
|
89 for (b in this.blocks) {
|
|
90 if (b.id == id) {
|
|
91 return b;
|
|
92 }
|
|
93 }
|
|
94 return null;
|
65
|
95 };
|
63
|
96
|
|
97 /*
|
|
98 guiBlocks.prototype.getStoreItem = function(tag,type,item) {
|
|
99 // get item from online storage
|
|
100 jQuery.get();
|
|
101 }
|
|
102 */
|
|
103
|
|
104 guiBlocks.prototype.loadListOfItems = function(storeTag,storeType,callback) {
|
|
105 // loads list of id and type objects and executes callback function
|
|
106 var url = "../db/RESTjson/db/public/gui_objects/"+escape(storeTag)+"/"+storeType+"?recursive=true";
|
|
107 jQuery.getJSON(url,callback);
|
65
|
108 };
|
63
|
109
|
|
110
|
|
111 guiBlocks.Block.prototype.storeBlock = function(storeTag) {
|
|
112 var storeType = this.params.type;
|
|
113 var storeItem = this.params.id;
|
|
114 var url = "../db/RESTjson/db/public/gui_objects/"+escape(storeTag)+"/"+storeType+"/"+storeItem;
|
|
115 var ds = JSON.stringify(this.params);
|
|
116 jQuery.ajax({
|
|
117 type: "PUT",
|
|
118 url: url,
|
|
119 data: ds,
|
|
120 success: function(msg){
|
|
121 console.debug("PUT success msg=",msg);
|
|
122 this.storeId = storeItem;
|
|
123 }
|
|
124 });
|
|
125 };
|
|
126
|
|
127
|
|
128
|
|
129 // collapse the block so that only its titlebar is visible
|
|
130 function foldBlock(segment){
|
72
|
131 if (segment == null) {
|
63
|
132 return;
|
|
133 }
|
|
134 if(segment.hasClass("folded")){
|
|
135 //if the segment is collapsed
|
|
136 segment.removeClass("folded");
|
|
137 segment.find(".body").slideDown();
|
|
138 } else{
|
|
139 //if the segment is expanded
|
|
140 segment.addClass("folded");
|
|
141 segment.find(".body").slideUp();
|
|
142 }
|
|
143 }
|
|
144
|
|
145 function switchSubscreens(container, id1, id2) {
|
|
146 var oldScreen = container.find("#"+id1);
|
|
147 var newScreen = container.find("#"+id2);
|
|
148
|
|
149 oldScreen.fadeOut();
|
|
150 newScreen.fadeIn();
|
|
151 }
|
|
152
|
|
153 function guiBlocks_init() {
|
|
154 // initialize collapsed windows
|
|
155 $("div.block.folded").each(function(e){
|
|
156 $(this).find(".body").slideUp();
|
|
157 });
|
|
158
|
|
159 // TitleBar Click
|
|
160 $("div.block div.titlebar h1").live("click", function(e) {
|
|
161 var segment = $(this).parents().filter("div.block");
|
|
162 foldBlock(segment);
|
|
163 });
|
|
164
|
|
165 // TitleBar Close
|
|
166 $("div.block div.titlebar div.close_button").live("click", function(e){
|
|
167 segment = $(this).parents().filter("div.block");
|
65
|
168 segment.fadeOut(function(){ segment.remove();});
|
63
|
169 });
|
|
170
|
248
|
171 // TitleBar Reload
|
|
172 $("div.block div.titlebar div.reload_button").live("click", function(e){
|
|
173 segment = $(this).parents().filter("div.block");
|
|
174 console.debug("guiBlocks_init().live(reload) segment[0].id="+ segment[0].id);
|
|
175 //FJK: funktioniert leider noch nicht!
|
|
176 // var blockid=$(this).parents().firstElementChild.id;
|
|
177 // var mapblock=getBlock(blockid);
|
|
178 // var params=mapblock.readMapParams();
|
|
179 // var be = mapblock.element;
|
|
180 //var mapblock = $(be).find(".map_box");
|
|
181 // console.debug("guiBlocks_init().live(reload) params="+ new String(params));
|
|
182 // mapblock.updateMap(be,params);
|
|
183 });
|
|
184
|
65
|
185 }
|
248
|
186
|
|
187 function getBlock(id){
|
|
188 for (b in this.blocks) {
|
|
189 if (b.id == id) {
|
|
190 return b;
|
|
191 }
|
|
192 }
|
|
193 return null;
|
|
194 } |