Index: main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js	(revision 22676)
+++ main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js	(revision 22768)
@@ -1,9 +1,2 @@
-//jQuery( function($) {
-//$('div.blockWrapper').iNestedSortable(
-//  {
-//    accept: 'block',
-//  }
-//);
-//});
 
 console.log("Loading gui_div.js\n");
@@ -109,50 +102,11 @@
  
     $('div.gsf_template').children(".block,.table").slideUp(300); 
-    //$('div.gsf_template .table').hide();  
-    //$('div.block').click(function() {    
-        //alert("I was clicked!");
-    //    $(this).children(".block").slideToggle('fast');
-    //    return false;
-    //});
-
- 
-    //hide the all of the element with class msg_body
-  //$(".gsf_template > table").hide();
-  //toggle the componenet with class msg_body
-  //$(".gsf_template").click(function()
-  //{
-    //alert("You clicked? " + $("this > .table"));
-    //$(this).getElementsByTagName("table")[0].slideToggle(600);
-  //});
-
-    //$(".resizable").resizable({containment: 'parent', alsoResize:'parent'});
-
-    //$('.tr').equalHeights();
-
-    //$(".td").resizable({
-    //            alsoResize: 'parent',
-                //containment: 'parent',
-    //            handles: 'e,s',
-    //            stop: function(event, ui) {
-    //                    $(this).parent().parent().equalHeights();
-    //            }, });
-
 }); 
 
 /*******************************************************************************/
 
-function minimize_templates()
-{
-    //$(".msg_body").hide();
-    //var targetContent = $('.table');
-    //targetContent.hide();
-    //targetContent.parent().css('display','none');
-    //targetContent.slideUp(300);
-    //targetContent.parent().html('[+]');
-
-}
-
 function bind_all_sortables()
 {
+    console.log('function bind_all_sortables()');
     bind_template_sortable();
     //bind_table_sortable();
@@ -173,5 +127,12 @@
 function bind_tables()
 {
-    $('.tr').equalHeights();
+    console.log('function bind_tables()');
+    //$('.tr').resize_tables($(this)); //equalHeights();
+
+    
+    $('td').click(function () {
+         console.log('td click');
+         return false;
+    });
 
     $(".td").resizable({
@@ -180,5 +141,7 @@
                 handles: 'w,e',
                 stop: function(event, ui) {
-                        $(this).parent().parent().equalHeights();
+                        console.log('Resize table on stop');
+                        resize_tables($(this));
+                        //$(this).parent().parent().equalHeights();
                 }, });
 
@@ -186,16 +149,19 @@
             accept: '.element_type_td',
             tolerance: 'pointer', 
-            activate: function(event, ui) { $(this).addClass("droppable_hl"); console.log("droppable activated")},
-            deactivate: function(event, ui) { $(this).removeClass("droppable_hl"); console.log("droppable deactivated")},
+            activate: function(event, ui) { $(this).addClass("droppable_hl");}, // console.log("droppable activated")},
+            deactivate: function(event, ui) { $(this).removeClass("droppable_hl"); }, // console.log("droppable deactivated")},
             drop: function(event, ui) {
-                //alert("Something has been dropped on me!!");
-                //$(this).addClass('ui-state-highlight').find('p').html('Dropped!');
-                 //var tr = this.parentNode.parentNode; //$(this).getElementsByTagName("tr")[0];
+                 var span = document.createElement("div");
+                 span.setAttribute("class","td");
+                 span.setAttribute("style","height:50px");
+                 span.setAttribute("style","display:block");
                  var td = document.createElement("td");
                  var div = document.createElement("div"); // class=\"td block\" title=\"td-div\"");
                  div.setAttribute("title","td-div");
                  div.setAttribute("class","td block");
+                 div.setAttribute("style","margin-left:0px");
                  div.setAttribute("width","25px");
                  td.appendChild(div);
+                 div.appendChild(span);
                  var sep = document.createElement("td");
                  sep.setAttribute("class","droppable");
@@ -204,5 +170,6 @@
                  $(this).after(td);                
                  bind_tables();
-                 //bind_td_sortable();
+                 resize_tables($(this));
+                 bind_td_sortable();
                  //bind_all_sortables();
             }
@@ -213,54 +180,37 @@
 function replace_with(item, me)
 {
-/*
-    (item.parents('.table')).each(function(index) { 
-        $(this).children().children().children('td').each(function() {
-            var sum = 0;
-            $(this).children('.block').each(function() { sum = sum + $(this).height(); } );
-            console.log("My height is " + $(this).height() + ", sum height is " + sum);
-        });
-    });
-*/
-    /*
-    alert(item.parents('.td').length);
-
-    (item.parents('.td')).each(function(index) { 
-        $(this).children.each(function()
-        alert(index + " height is " + $(this).height()); // + $(this).style('height') + $(this).offsetHeight); 
-        var h = $(this).height(); 
-        var a = 0;
-        // if we are now the maximum then set to h otherwise ignore?
-        $(this).parents('.table').each(function() {$(this).children().children().children().each(function() { if($(this).height() > a) a = $(this).height(); } ) } );
-        alert("A is " + a);
-        if( h > a)
-        {
-            h = h + 25; 
-            alert("Increasing height to " + h);
-            $(this).height(h);
-            alert("height is now " + $(this).height());
-        }
-        else
-            alert("height did not need increasing (h=" + h + ",a=" + a + ")");
-    }); //forEach().css('height'));
-    */
-    
+    console.log('function replace_with(item, me)');
     item.replaceWith(me); //'<div class="element element-txt">This text box has been added!</div>');
 
+    resize_tables(item);
+
+    bind_all_sortables();
+}
+
+function resize_tables(item)
+{
+    console.log('function resize_tables(item)');
+    var max_height = 0;
     (item.parents('.table')).each(function(index) {
         $(this).children().children().children().each(function() {
-            var sum = 0;
-            $(this).children('.block').each(function() { sum = sum + $(this).height(); } );
-            console.log("My height is " + $(this).height() + ", sum height is " + sum);
+            var sum_one = 0;
+            var sum_two = 0;
+            $(this).children('.block').each(function() { sum_one = sum_one + $(this).height();  
+                $(this).children('.block').each(function() { sum_two = sum_two + $(this).height(); } );
+                console.log("My height is " + $(this).height() + ", sum height 2 is " + sum_two);
+            });
+            console.log("My height is " + $(this).height() + ", sum height 1 is " + sum_one);
+            if (sum_two > max_height)
+                max_height = sum_two;
         });
     });
-
-    bind_all_sortables();
+    equalHeights(item,max_height);
 }
 
 function bind_template_sortable()
 {
+    console.log('function bind_template_sortable()');
     $('.gsf_template').sortable({
             'cursor':'pointer',
-            'tolerance': 'fit',
             'items':'.table, .gsf_choose_metadata, .gsf_metadata',
             'placeholder':'placeholder',
@@ -276,46 +226,18 @@
     });
 
-}
-
-/*
-function bind_table_sortable()
-{
-    $('.table').sortable({
+    $('.gsf_template').click(function () {
+         console.log('gsf_template class click');
+         return false;
+    });
+
+}
+
+function bind_td_sortable()
+{
+    console.log('function bind_td_sortable()');
+    $('.td').sortable({
             'cursor':'pointer',
             'tolerance': 'pointer',
-            'items':'.tr',
-            'placeholder':'placeholder',
-            //'nested':'.gsf:metadata'
-            stop: function(event, ui) {
-                if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_tr')) { replace_with(ui.item, "<tr class=\"tr\"></tr>"); }
-            }
-
-    });
-}
-
-function bind_tr_sortable()
-{
-    $('.tr').sortable({
-            'cursor':'pointer',
-            'tolerance': 'pointer',
-            'items':'.td',
-            'placeholder':'placeholder',
-            //'nested':'.gsf:metadata'
-            stop: function(event, ui) {
-                if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_td')) { replace_with(ui.item, "<td class=\"td\"></td>"); }
-            }
-
-    });
-}
-
-*/
-
-function bind_td_sortable()
-{
-    $('.td').sortable({
-            'cursor':'pointer',
-            'containment':'parent',
-            'tolerance': 'pointer',
-            'items':'.gsf_metadata, .gsf_choose_metadata, .gsf_link, .gsf_switch, .td',
+            'items':'.gsf_metadata, .gsf_choose_metadata, .gsf_link, .gsf_switch',
             'placeholder':'placeholder',
             //'nested':'.gsf:metadata'
@@ -323,30 +245,21 @@
             stop: function(event, ui) {
                 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
-                /*if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_td')) { 
-                    alert("Inserting td " + this.parentNode.parentNode + " " + $('.td').sortable( "widget" )); 
-                    var tr = this.parentNode.parentNode; //$(this).getElementsByTagName("tr")[0];
-                    var td = document.createElement("td"); 
-                    var div = document.createElement("div"); // class=\"td block\" title=\"td-div\"");
-                    //var cls = document.createAttribute("class");
-                    div.setAttribute("title","td-div");
-                    div.setAttribute("class","td block");
-                    var span = document.createElement("div");
-                    span.setAttribute("class", "block gsf_metadata");
-                    span.setAttribute("style","height:50px");
-                    //div.setAttribute(cls,"block");
-                    div.appendChild(span);
-                    td.appendChild(div);
-                    tr.appendChild(td); 
-                    ui.item.remove(); 
-                    bind_all_sortables();
-                }*/
                 
             }
 
     });
+
+    $('.td').click(function () {    
+         console.log('td class click');
+         return false;
+    });
+
+
+
 }
 
 function bind_choose_metadata_sortable()
 {
+    console.log('function bind_choose_metadata_sortable()');
     $('.gsf_choose_metadata').sortable({
             'cursor':'pointer',
@@ -364,4 +277,5 @@
 function bind_link_sortable()
 {
+    console.log('function bind_link_sortable()');
     $('.gsf_link').sortable({
             'cursor':'pointer',
@@ -378,4 +292,5 @@
 function bind_switch_sortable()
 {
+    console.log('function bind_switch_sortable()');
     $('.gsf_switch').sortable({
             'cursor':'pointer',
@@ -393,4 +308,5 @@
 function bind_when_sortable()
 {
+    console.log('function bind_when_sortable()');
     $('.gsf_when').sortable({
             'cursor':'pointer',
@@ -407,4 +323,5 @@
 function bind_otherwise_sortable()
 {
+    console.log('function bind_otherwise_sortable()');
     $('.gsf_otherwise').sortable({
             'cursor':'pointer',
@@ -422,7 +339,7 @@
 function bind_block_mouseover()
 {
+    console.log('function bind_block_mouseover()');
     $(".block").mouseover(function()
     {
-        //alert("Mouse over event");
         $(this).parents().css("border", "");
         $(this).css("border", "1px solid blue");
@@ -436,4 +353,5 @@
 function bind_minmax_remove()
 {
+    console.log('function bind_minmax_remove()');
     $('a.minmax').bind('click', toggleContent);
     $('a.remove').bind('click', removeContent);
@@ -441,7 +359,7 @@
 
 var removeContent = (function () {
-        //var parentTag = $(this).parent().get(0).titleName;
-        //alert("Removing div " + parentTag);
-        $(this).parent().remove();
+    console.log('var removeContent = (function ()');
+        // this -> a -> td -> tr -> tbody -> table -> div
+        $(this).parent().parent().parent().parent().parent().remove();
     });
 
@@ -449,26 +367,17 @@
 var toggleContent = function(e)
 {
-    //var targetContent = $('div.block', this.parentNode);
-    //$(".msg_head").click(function()
-  //{
-    //$(this).next(".block").slideToggle(600);
-  //});
-    //alert($(this).html() + " " + $(this).css('display') + " " + targetContent.css('display'));
+    console.log('var toggleContent = function(e)');
+    console.log('parent: ' + $(this).html());
     if ($(this).html() == '[+]'){ //targetContent.css('display') == 'none') {
-    //if ($(this).css('display') == 'none') {
-   //     var targetContent2 = $('.table');
-   //     targetContent2.show();
-
-   //     targetContent.show();
-   //     targetContent.slideDown(300);
-   //     alert("I should be sliding down! " + $(this).parent());
-        $(this).parent().children(".block,.table").slideDown(300);
+        $(this).parent().parent().parent().parent().parent().children(".block,.table").slideDown(300);
         $(this).html('[-]');
+        $(this).removeClass("ui-icon-plusthick");
+        $(this).addClass("ui-icon-minusthick");
     } else {
-    //    targetContent.slideUp(300);
-        $(this).parent().children(".block,.table").slideUp(300);
+        $(this).parent().parent().parent().parent().parent().children(".block,.table").slideUp(300);
         $(this).html('[+]');
+        $(this).removeClass("ui-icon-minusthick");
+        $(this).addClass("ui-icon-plusthick");
     }
-    //$(this).children(".block, .table").slideToggle('fast');
     return false;
 };
@@ -480,41 +389,12 @@
 };
 
-/*-------------------------------------------------------------------- 
- * JQuery Plugin: "EqualHeights"
- * by:  Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
- *
- * Copyright (c) 2008 Filament Group
- * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
- *
- * Description: Compares the heights or widths of the top-level children of a provided element 
-        and sets their min-height to the tallest height (or width to widest width). Sets in em units 
-        by default if pxToEm() method is available.
- * Dependencies: jQuery library, pxToEm method  (article: 
-        http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)                              
- * Usage Example: $(element).equalHeights();
-        Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
- * Version: 2.0, 08.01.2008
---------------------------------------------------------------------*/
-
-// Modified to get children of children ie. tr -> td -> div
-
-$.fn.equalHeights = function(px) {
-    //console.log("EQUAL HEIGHTS");
-    $(this).each(function(){
-        var currentTallest = 0;
-        //console.log($(this).children());
-        //console.log($(this).children().children());
-        //$(this).children().children().each(function(i){
-        //    console.log($(this));
-        //    console.log("THIS HEIGHT="+$(this).height()+ " CURRENT TALLEST="+ currentTallest);
-            //if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
-            //if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
-        //});
-        //if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
-        // for ie6, set height since min-height isn't supported
-        //if ($.browser.msie && $.browser.version == 6.0) { $(this).children().children().css({'height': $(this).currentTallest}); }
-        $(this).children().children().css({'height': $(this).height()}); //currentTallest}); 
-    });
-    return this;
+function equalHeights(item, height) {
+    console.log('function equalHeights(item, height)');
+    (item.parents('.table')).each(function(index) {
+        $(this).children().children().children().each(function() {
+            $(this).height(height);
+            $(this).children().height(height);
+        });
+    });
 };
 
