view gis_gui/blocks/tablestructure.js @ 252:efd2469d1722

geometry-column of tables will be displayed as string
author fknauft
date Tue, 20 Sep 2011 11:19:35 +0200
parents c84536a4993a
children 3a10287447b1
line wrap: on
line source


guiBlocks.prototype.addTableStructureBlock = function(url, baseId, tablename, fields, uploadForm) {
    
    function getHtmlSelectFromList(optionlist, selected, attrs) {
        var html = "<select " + attrs + ">";
        for (var i = 0; i < optionlist.length; i++) {
            var txt = optionlist[i];
            if (txt == selected) {
                html += '<option selected="true">' + txt + '</option>';
            } else {
                html += '<option>' + txt + '</option>';
            }
        }
        html += "</select>";
        return html;
    }
    var block = this.addBlock(url, baseId, null, function() {
        // function after add block finished
        var id = block.id;
        var tbl = $(block.element).find(".datatable");
        $(block.element).find(".msg.create_table_upload").show();
        console.debug("in tablestructureblock after block load!");
        console.debug("this=", this);
        console.debug("block=",block);
        console.debug(tbl);
        var colheads = [];
        var row = [];
        for (var i = 0; i < fields.length; i++) {
            colheads.push({'sTitle': fields[i].name});
            row.push(getHtmlSelectFromList(['text','number','gis_id','coord_lat','coord_lon','the_geom','id'],fields[i].type,'class="type_'+fields[i].name+'"'));
        }
        // Add DataTables functionality
        $(tbl).dataTable({
            'aoColumns': colheads,
            'aaData': [row],
            'bPaginate': false,
            "bFilter": false,
            "bSort": false,
            "bInfo": false
            });
        // connect create button
        $(block.element).find(".create_table_button").click(function() {
            console.debug("create table button click form=",uploadForm);
            // read table form
            $(tbl).find("select").each(function(i,el) {
                // we assume form and array have same ordering
                fields[i].type = $(this).val();
            });
            console.debug("table struct=",fields);
            // change upload file form
            $(uploadForm).unbind("submit");
            $(uploadForm).iframePostForm({
                post: blocks.uploadTableSubmitFn(null,fields),
                complete: blocks.uploadTableCompleteFn()
            });
            // hide structure block
            $(block.element).hide();
            $(uploadForm).submit();
        });
        $(block.element).find(".dont_create_table_button").click(function() {
            console.debug("dont create table button click");
            $(block.element).hide();
        });
        // show block
        $(block.element).fadeIn();
    });
};