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