comparison gis_gui/blocks/tablestructure.js @ 63:7f008e782563

add gui files to product via FileSystemSite
author casties
date Fri, 05 Nov 2010 18:52:55 +0100
parents
children c84536a4993a
comparison
equal deleted inserted replaced
62:3905385c8854 63:7f008e782563
1
2 guiBlocks.prototype.addTableStructureBlock = function(url, baseId, tablename, fields, uploadForm) {
3
4 function getHtmlSelectFromList(optionlist, selected, attrs) {
5 var html = "<select " + attrs + ">";
6 for (var i = 0; i < optionlist.length; i++) {
7 var txt = optionlist[i];
8 if (txt == selected) {
9 html += '<option selected="true">' + txt + '</option>';
10 } else {
11 html += '<option>' + txt + '</option>';
12 }
13 }
14 html += "</select>";
15 return html;
16 }
17 var block = this.addBlock(url, baseId, function() {
18 // function after add block finished
19 var id = block.id;
20 var tbl = $(block.element).find(".datatable");
21 $(block.element).find(".msg.create_table_upload").show();
22 console.debug("in tablestructureblock after block load!");
23 console.debug("this=", this);
24 console.debug("block=",block);
25 console.debug(tbl);
26 var colheads = [];
27 var row = [];
28 for (var i = 0; i < fields.length; i++) {
29 colheads.push({'sTitle': fields[i].name});
30 row.push(getHtmlSelectFromList(['text','number','gis_id','coord_lat','coord_lon','id'],fields[i].type,'class="type_'+fields[i].name+'"'));
31 }
32 // Add DataTables functionality
33 $(tbl).dataTable({
34 'aoColumns': colheads,
35 'aaData': [row],
36 'bPaginate': false,
37 "bFilter": false,
38 "bSort": false,
39 "bInfo": false
40 });
41 // connect create button
42 $(block.element).find(".create_table_button").click(function() {
43 console.debug("create table button click form=",uploadForm);
44 // read table form
45 $(tbl).find("select").each(function(i,el) {
46 // we assume form and array have same ordering
47 fields[i].type = $(this).val();
48 });
49 console.debug("table struct=",fields);
50 // change upload file form
51 $(uploadForm).unbind("submit");
52 $(uploadForm).iframePostForm({
53 post: blocks.uploadTableSubmitFn(null,fields),
54 complete: blocks.uploadTableCompleteFn()
55 });
56 // hide structure block
57 $(block.element).hide();
58 $(uploadForm).submit();
59 });
60 $(block.element).find(".dont_create_table_button").click(function() {
61 console.debug("dont create table button click");
62 $(block.element).hide();
63 });
64 // show block
65 $(block.element).fadeIn();
66 });
67 };