63
|
1
|
70
|
2 guiBlocks.prototype.addTableBlock = function (url, baseId, params) {
|
|
3 if (typeof(params) === "string") {
|
|
4 // then its the table name
|
|
5 params = {"type": "table", "table": params};
|
|
6 }
|
|
7 var block = this.addBlock(url, baseId, params, function () {
|
63
|
8 // function after add block finished
|
|
9 var id = block.id;
|
70
|
10 var tablename = params.table;
|
|
11 var $tbl = $(block.element).find(".datatable");
|
63
|
12 console.debug("in tableblock after block load!");
|
|
13 console.debug("this=", this);
|
|
14 console.debug("block=",block);
|
70
|
15 console.debug($tbl);
|
|
16 $tbl.load(
|
63
|
17 "../db/RESTdb/db/public/" + tablename + "?format=HTML&layout=table&element_id=newtable #newtable>*",
|
70
|
18 function () {
|
63
|
19 // function after load table finished
|
|
20 console.debug("In table load! this=");
|
|
21 console.debug(this);
|
70
|
22 $tbl.find("td").addClass('compacted');
|
63
|
23 // Add DataTables functionality
|
70
|
24 $tbl.dataTable( {
|
63
|
25 'bPaginate' : true,
|
|
26 'sPaginationType' : 'full_numbers'
|
|
27 });
|
|
28 // show block
|
|
29 $(block.element).fadeIn();
|
|
30 });
|
|
31 });
|
|
32 };
|
|
33
|
|
34
|
70
|
35 guiBlocks.prototype.checkTableSubmitFn = function (oldsegment) {
|
63
|
36 // we need oldsegment in the returned function
|
70
|
37 return function () {
|
63
|
38 var tablename = $(this).find(".create_table_name").val();
|
|
39 console.debug("check table="+tablename," this=",this);
|
|
40 var uploadUrl = "../db/RESTdb/db/public/" + tablename;
|
|
41 // Firefox has a problem with changing the action attribute...
|
|
42 $(this).get(0).setAttribute("action",uploadUrl);
|
|
43 $(this).find("input[type=hidden][name=format]").remove();
|
|
44 $(this).prepend('<input type="hidden" name="format" value="JSONHTML"/>');
|
|
45 //foldBlock(oldsegment);
|
70
|
46 };
|
|
47 };
|
63
|
48
|
70
|
49 guiBlocks.prototype.checkTableCompleteFn = function (oldsegment,uploadForm) {
|
63
|
50 // we need the blocks object in the returned function
|
|
51 var gui_blocks = this;
|
70
|
52 return function (result) {
|
63
|
53 console.debug("check complete. this=", this, " result=",result);
|
|
54 // json inside pre tag
|
|
55 var txtres = $(result).text();
|
|
56 var res = jQuery.parseJSON(txtres);
|
|
57 console.debug("check complete. res=",res);
|
|
58 var tablename = res.tablename;
|
|
59 var tableExists = res.table_exists;
|
|
60 if (tableExists) {
|
|
61 var dlg = $(oldsegment).find(".dialog.create_table_exists");
|
|
62 $(dlg).find(".tablename").text(tablename);
|
|
63 console.debug("dlg=",dlg);
|
|
64 $(dlg).dialog({
|
|
65 buttons: {
|
|
66 "Yes": function() {
|
|
67 $(this).dialog("close");
|
|
68 clearAllTasks();
|
|
69 foldBlock(oldsegment);
|
|
70 gui_blocks.addTableStructureBlock("blocks/tablestructure.html?table="+escape(tablename),"tablestruct", tablename, res.fields, uploadForm);
|
|
71 },
|
|
72 "No": function() {
|
|
73 $(this).dialog("close");
|
|
74 }
|
|
75 }
|
|
76 });
|
|
77 } else {
|
|
78 clearAllTasks();
|
|
79 foldBlock(oldsegment);
|
|
80 gui_blocks.addTableStructureBlock("blocks/tablestructure.html?table="+escape(tablename),"tablestruct", tablename, res.fields, uploadForm);
|
|
81 }
|
70
|
82 };
|
|
83 };
|
63
|
84
|
|
85 guiBlocks.prototype.uploadTableSubmitFn = function(oldsegment,fields) {
|
|
86 // we need oldsegment in the returned function
|
|
87 return function() {
|
|
88 var tablename = $(this).find(".create_table_name").val();
|
|
89 console.debug("upload table="+tablename);
|
|
90 var uploadUrl = "../db/RESTdb/db/public/" + tablename;
|
|
91 // Firefox has problems with changing the action attribute by jQuery
|
|
92 $(this).get(0).setAttribute("action",uploadUrl);
|
|
93 $(this).find("input[type=hidden][name=action]").remove();
|
|
94 $(this).prepend('<input type="hidden" name="action" value="PUT"/>');
|
|
95 $(this).find("input[type=hidden][name=format]").remove();
|
|
96 $(this).prepend('<input type="hidden" name="format" value="JSONHTML"/>');
|
|
97 $(this).find("input[type=hidden][name=create_table_fields]").remove();
|
|
98 var fieldsStr = "";
|
|
99 for (var i = 0; i < fields.length; i++) {
|
70
|
100 if (i > 0) { fieldsStr += ",";}
|
63
|
101 fieldsStr += fields[i].name + ":" + fields[i].type;
|
|
102 }
|
|
103 $(this).prepend('<input type="hidden" name="create_table_fields" value="'+fieldsStr+'"/>');
|
|
104 foldBlock(oldsegment);
|
70
|
105 };
|
|
106 };
|
63
|
107
|
|
108 /* function that returns an upload complete function.
|
|
109 */
|
|
110 guiBlocks.prototype.uploadTableCompleteFn = function() {
|
|
111 // we need the blocks object in the returned function
|
|
112 var gui_blocks = this;
|
|
113 return function(result) {
|
|
114 console.debug("upload complete. this=", this, " result=",result);
|
|
115 // json inside pre tag
|
|
116 var txtres = $(result).text();
|
|
117 var res = jQuery.parseJSON(txtres);
|
|
118 console.debug("upload complete. res=",res);
|
|
119 var tablename = res.tablename;
|
|
120 // open new table block
|
|
121 var newblock = gui_blocks.addTableBlock("blocks/table.html?table="+escape(tablename),"table", tablename);
|
70
|
122 };
|
|
123 };
|
63
|
124
|
|
125 // Show Tooltip
|
|
126 $("td.compacted").livequery(function() {
|
|
127 $(this).attr('title', $(this).html());
|
|
128 $(this).tooltip( {
|
|
129 track : false,
|
|
130 delay : 750,
|
|
131 showURL : false,
|
|
132 opacity : 0.85,
|
|
133 top : -15,
|
|
134 left : 5
|
|
135 });
|
|
136 });
|