view gis_gui/blocks/table.js @ 244:57f0dfaf5949

show line and polygon-layer
author fknauft
date Tue, 06 Sep 2011 12:53:17 +0200
parents 9ec7e32e8ad3
children
line wrap: on
line source


guiBlocks.prototype.addTableBlock = function (url, baseId, params) {
    if (typeof(params) === "string") {
        // then its the table name
        params = {"type": "table", "table": params};
    }
    var block = this.addBlock(url, baseId, params, function () {
        // function after add block finished
        var id = block.id;
        var tablename = params.table;
        var $tbl = $(block.element).find(".datatable");
        console.debug("in tableblock after block load!");
        console.debug("this=", this);
        console.debug("block=",block);
        console.debug($tbl);
        $tbl.load(
            "../db/RESTdb/db/public/" + tablename + "?format=HTML&layout=table&element_id=newtable #newtable>*",
            function () {
                // function after load table finished
                console.debug("In table load! this=");
                console.debug(this);
                $tbl.find("td").addClass('compacted');
                // Add DataTables functionality
                $tbl.dataTable( {
                    'bPaginate' : true,
                    'sPaginationType' : 'full_numbers'
                });
                // show block
                $(block.element).fadeIn();
            });
    });
};

    
guiBlocks.prototype.checkTableSubmitFn = function (oldsegment) {
    // we need oldsegment in the returned function
    return function () {
        var tablename = $(this).find(".create_table_name").val();
        console.debug("check table="+tablename," this=",this);
        var uploadUrl = "../db/RESTdb/db/public/" + tablename;
        // Firefox has a problem with changing the action attribute...
        $(this).get(0).setAttribute("action",uploadUrl);
        $(this).find("input[type=hidden][name=format]").remove();
        $(this).prepend('<input type="hidden" name="format" value="JSONHTML"/>');
        //foldBlock(oldsegment);
    };
};

guiBlocks.prototype.checkTableCompleteFn = function (oldsegment,uploadForm) {
    // we need the blocks object in the returned function
    var gui_blocks = this;
    return function (result) {
        console.debug("check complete. this=", this, " result=",result);
        // json inside pre tag
        var txtres = $(result).text(); 
        var res = jQuery.parseJSON(txtres);
        console.debug("check complete. res=",res);
        var tablename = res.tablename;
        var tableExists = res.table_exists;
        if (tableExists) {
            var dlg = $(oldsegment).find(".dialog.create_table_exists");
            $(dlg).find(".tablename").text(tablename);
            console.debug("dlg=",dlg);
            $(dlg).dialog({
                buttons: {
                    "Yes": function() { 
                        $(this).dialog("close");
                        clearAllTasks();
                        foldBlock(oldsegment);
                        gui_blocks.addTableStructureBlock("blocks/tablestructure.html?table="+escape(tablename),"tablestruct", tablename, res.fields, uploadForm);
                    }, 
                    "No": function() { 
                        $(this).dialog("close"); 
                    } 
                }
            });
        } else {
            clearAllTasks();
            foldBlock(oldsegment);
            gui_blocks.addTableStructureBlock("blocks/tablestructure.html?table="+escape(tablename),"tablestruct", tablename, res.fields, uploadForm);
        }
    };
};

guiBlocks.prototype.uploadTableSubmitFn = function(oldsegment,fields) {
    // we need oldsegment in the returned function
    return function() {
        var tablename = $(this).find(".create_table_name").val();
        console.debug("upload table="+tablename);
        var uploadUrl = "../db/RESTdb/db/public/" + tablename;
        // Firefox has problems with changing the action attribute by jQuery
        $(this).get(0).setAttribute("action",uploadUrl);
        $(this).find("input[type=hidden][name=action]").remove();
        $(this).prepend('<input type="hidden" name="action" value="PUT"/>');
        $(this).find("input[type=hidden][name=format]").remove();
        $(this).prepend('<input type="hidden" name="format" value="JSONHTML"/>');
        $(this).find("input[type=hidden][name=create_table_fields]").remove();
        var fieldsStr = "";
        for (var i = 0; i < fields.length; i++) {
            if (i > 0) { fieldsStr += ",";}
            fieldsStr += fields[i].name + ":" + fields[i].type;
        }
        $(this).prepend('<input type="hidden" name="create_table_fields" value="'+fieldsStr+'"/>');
        foldBlock(oldsegment);
    };
};

/* function that returns an upload complete function.
 */
guiBlocks.prototype.uploadTableCompleteFn = function() {
    // we need the blocks object in the returned function
    var gui_blocks = this;
    return function(result) {
        console.debug("upload complete. this=", this, " result=",result);
        // json inside pre tag
        var txtres = $(result).text(); 
        var res = jQuery.parseJSON(txtres);
        console.debug("upload complete. res=",res);
        var tablename = res.tablename;
        // open new table block
        var newblock = gui_blocks.addTableBlock("blocks/table.html?table="+escape(tablename),"table", tablename);
    };
};

// Show Tooltip
$("td.compacted").livequery(function() {
    $(this).attr('title', $(this).html());
    $(this).tooltip( {
        track : false,
        delay : 750,
        showURL : false,
        opacity : 0.85,
        top : -15,
        left : 5
    });
});