view gis_gui/blocks/home.js @ 273:d1b43624cc63

some hacks to make the european4D connection work
author dwinter
date Thu, 23 Feb 2012 11:44:38 +0100
parents 52b1247140b7
children
line wrap: on
line source

$(".block.home").livequery(function(){

    var homeblock = $(this);

    // OPEN
    homeblock.find(".open_button").live("click", function(){
    	clearAllTasks();
    	homeblock.find(".open_button").addClass("selected");	
		homeblock.find('.subscreen.open').fadeIn();
    });

    // OPEN TASKS
    homeblock.find(".open_table_button").live("click", function(){
    	//	homeblock.find(".task[id*=open_]").removeClass("selected");
    	homeblock.find(".open_table_button").addClass("selected");
    	// load list of tables 
    	homeblock.find(".open_table select").load("../db/RESTdb/db/public/?format=HTML&type=schema_usertables&layout=select&element_id=tables #tables *",
    	        function() {
    	            $(this).find("option").dblclick( 
    	                    function() {
    	                        console.debug("table option dblclick");
    	                        console.debug("this=",this);
    	                        clearAllTasks();
    	                        foldBlock($(this).parents().filter(".block"));
    	                        var tablename = $(this).val();
    	                        blocks.addTableBlock("blocks/table.html?table="+escape(tablename),"table", tablename);
    	                    });
    	        });
    	homeblock.find(".subscreen.open_table").fadeIn();
    });
    
    homeblock.find(".open_layer_button").live("click", function(){
    	homeblock.find(".open_layer_button").addClass("selected");
        // load list of layers 
    	var el = homeblock.find(".subscreen.open_layer select").get(0);
    	blocks.loadListOfItems("test1","layer",function(data) {
    	    console.debug("open layer list of items=",data);
    	    $(el).empty();
    	    for (var i=0; i < data.length; i++) {
    	        var key = data[i].key;
    	        var val = data[i].val;
    	        var name = val.name;
    	        console.debug("layer",i," key=",key," value=",name);
    	        $(el).append('<option value="'+key+'">'+name+'</option>');
    	    }
    	    // arm load layer button
    	    homeblock.find(".open_open_layer").unbind("click");
    	    homeblock.find(".open_open_layer").click(function() {
    	        clearAllTasks();
    	        foldBlock($(this).parents().filter(".block"));
    	        var layername = $(this).parent().find("select").val();
    	        var params = jQuery.grep(data, function(x){return (x.key == layername);})[0].val;
                console.debug("open layer=",layername," params=",params);
    	        var newblock = blocks.addLayerBlock("blocks/layer.html?table="+escape(params.table),"layer", params);
    	    });
    	});
    	homeblock.find(".subscreen.open_layer").fadeIn();
    });
    
    homeblock.find(".open_map_button").live("click", function(){
        homeblock.find(".open_map_button").addClass("selected");
        // load list of maps 
        var el = homeblock.find(".subscreen.open_map select").get(0);
        blocks.loadListOfItems("test1","map",function(data) {
            console.debug("open map list of items=",data);
            $(el).empty();
            for (var i=0; i < data.length; i++) {
                var key = data[i].key;
                var val = data[i].val;
                var name = val.name;
                console.debug("map",i," key=",key," value=",name);
                $(el).append('<option value="'+key+'">'+name+'</option>');
            }
            // arm load map button
            homeblock.find(".open_open_map").unbind("click");
            homeblock.find(".open_open_map").click(function() {
                clearAllTasks();
                foldBlock($(this).parents().filter(".block"));
                var mapname = $(this).parent().find("select").val();
                var params = jQuery.grep(data, function(x){return (x.key == mapname);})[0].val;
                console.debug("open map=",mapname," params=",params);
                var newblock = blocks.addMapBlock("blocks/map.html?table="+escape(params.table),"map", params);
            });
        });
        homeblock.find(".subscreen.open_map").fadeIn();
    });

    // open subtasks
    homeblock.find(".open_open_view").live('click', function(){
    	clearAllTasks();
    	foldBlock($(this).parents().filter(".block"));
    	addBlock("blocks/view?title=view","view");
    });
    homeblock.find(".open_workspace_button").live('click', function(){
        window.location.href="workspace";
    });
    // load table button
    homeblock.find(".open_open_table").live("click", function() {
    //  switchSubscreens(homeblock, 'open', 'main');
        clearAllTasks();
        foldBlock($(this).parents().filter(".block"));
        var tablename = $(this).parent().find("select").val();
        var newblock = blocks.addTableBlock("blocks/table.html?table="+escape(tablename),"table", tablename);
    });


    // CREATE
    homeblock.find(".create_button").live('click', function(){
        clearAllTasks();
        homeblock.find(".create_button").addClass("selected");
        homeblock.find(".subscreen.create").fadeIn();
    });
    // CREATE TASKS
    // create table menu
    homeblock.find(".create_table_button").live("click", function() {
        //  homeblock.find(".task[id*=open_]").removeClass("selected");
        homeblock.find(".create_table_button").addClass("selected");
        homeblock.find(".subscreen.create_table").fadeIn();
    });
    homeblock.find(".create_table_empty_button").live("click", function() {
        //  homeblock.find(".task[id*=open_]").removeClass("selected");
        clearTasks(".create_table",".create_table_task");
        homeblock.find(".create_table_empty_button").addClass("selected");
        homeblock.find(".subscreen.create_table_empty").fadeIn();
    });
    homeblock.find(".create_table_file_button").live("click", function() {
        //  homeblock.find(".task[id*=open_]").removeClass("selected");
        clearTasks(".create_table",".create_table_task");
        homeblock.find(".create_table_file_button").addClass("selected");
        homeblock.find(".subscreen.create_table_file").fadeIn();
        var segment = $(this).parents().filter(".block");
        var uploadForm = homeblock.find(".create_table_file_form").get();
        $(uploadForm).unbind("submit");
        $(uploadForm).iframePostForm({
        	post: blocks.checkTableSubmitFn(segment),
        	complete: blocks.checkTableCompleteFn(segment,uploadForm)
         });
    });
    homeblock.find(".create_table_empty_create_button").live("click", function() {
        //  switchSubscreens(homeblock, 'open', 'main');
            clearAllTasks();
            foldBlock($(this).parents().filter(".block"));
            var tablename = $(this).parent().find(".create_table_name").val();
            var tablefile = $(this).parent().find(".create_table_file").val();
            var newblock = blocks.addTableBlock("blocks/table.html?table="+escape(tablename),"table", tablename);
    });
    
    // create map menu
    homeblock.find(".create_map_button").live("click", function() {
            //  homeblock.find(".task[id*=open_]").removeClass("selected");
            homeblock.find(".create_map_button").addClass("selected");
            homeblock.find(".subscreen.create_map").fadeIn();
    });
    homeblock.find(".create_map_empty_button").live("click", function() {
            //  homeblock.find(".task[id*=open_]").removeClass("selected");
            clearTasks(".create_map",".create_map_task");
            homeblock.find(".create_map_empty_button").addClass("selected");
//            homeblock.find(".subscreen.create_map_empty").fadeIn();
            var params =  {"type": "layer", "color_field":"red","geometry_field":"point"};
            var mapblock = blocks.addMapBlock("blocks/map.html?","map",null,params);
    });
/*    homeblock.find(".create_map_empty_create_button").live("click", function() {
        //  switchSubscreens(homeblock, 'open', 'main');
            clearAllTasks();
            foldBlock($(this).parents().filter(".block"));
            var mapname = $(this).parent().find(".create_map_name").val();
            var mapfile = $(this).pa
            rent().find(".create_map_file").val();
            var newblock = blocks.addMapBlock("blocks/map.html?");
    });
*/
    
    // SEARCH
    homeblock.find(".search_button").live('click', function(){
        clearAllTasks();
        var segment = $(this).parents().filter(".block");
        foldBlock(segment);
        addBlock("blocks/search?title=search","search");
    });
    // NOTES
    homeblock.find(".notes_button").live('click', function(){
        clearAllTasks();
        var segment = $(this).parents().filter(".block");
        foldBlock(segment);
        addBlock("blocks/notes?title=notes","notes");
    });

});


function clearAllTasks(){
  $(".block.home").each(function(){
      $(this).find(".task").removeClass("selected");
      $(this).find(".subscreen:not(.main)").hide();
    });
}

function clearTasks(selectClass,taskClass) {
    $(".block.home").find(".subscreen"+selectClass).find(".task").removeClass("selected");
    $(".block.home").find(".subscreen"+taskClass).hide();
}