Ignore:
Timestamp:
2011-08-18T12:55:30+12:00 (13 years ago)
Author:
sjm84
Message:

More fixes to the format manager

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js

    r24417 r24420  
    398398    }
    399399
     400    //Retrieve the collection metadataset using ajax
    400401    $.ajax
    401402    ({
     
    404405        success: function(data)
    405406        {
    406             var selectorArea = document.getElementById("metadataSelector");
    407             var newSelectBox = document.createElement("SELECT");
    408             selectorArea.appendChild(newSelectBox);
     407            var str = "<select name=\"meta_select\" onChange=\"onSelectChange(this)\">";
     408           
     409            var selectorArea = document.getElementById("metadataSelector");     
    409410            var metadataSets = data.getElementsByTagName("metadataSet");
    410411            for(var i = 0; i < metadataSets.length; i++)
     
    413414                for(var j = 0; j < metadata.length; j++)
    414415                {
    415                     var option = document.createElement("OPTION");
    416                     option.setAttribute("value", metadataSets[i].getAttribute("name") + "." + metadata[j].getAttribute("name"));
    417                     option.innerHTML = metadataSets[i].getAttribute("name") + "." + metadata[j].getAttribute("name");
    418                     newSelectBox.appendChild(option);
     416                    var metaValue = metadataSets[i].getAttribute("name") + "." + metadata[j].getAttribute("name");
     417                    str += "<option value=\"" + metaValue + "\">" + metaValue + "</option>";
    419418                }
    420419            }
     420           
     421            str += "</select>";
     422
     423            selectorArea.innerHTML = str;
     424            gsf_metadata_element = str;
    421425        }
    422426    });
     427   
     428    $.ui.plugin.add("draggable", "connectToSortable", {
     429    start: function(event, ui) {
     430        //console.log("FUNCTION start draggable connectToSortable");
     431        var inst = $(this).data("draggable"), o = inst.options,
     432            uiSortable = $.extend({}, ui, { item: inst.element });
     433        inst.sortables = [];
     434        $(o.connectToSortable).each(function() {
     435            var sortable = $.data(this, 'sortable');
     436            if (sortable && !sortable.options.disabled) {
     437                inst.sortables.push({
     438                    instance: sortable,
     439                    shouldRevert: sortable.options.revert
     440                });
     441                sortable._refreshItems();   //Do a one-time refresh at start to refresh the containerCache
     442                sortable._trigger("activate", event, uiSortable);
     443            }
     444        });
     445
     446    },
     447    stop: function(event, ui) {
     448
     449        //console.log("FUNCTION stop draggable connectToSortable");
     450        //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
     451        var inst = $(this).data("draggable"),
     452            uiSortable = $.extend({}, ui, { item: inst.element });
     453
     454        $.each(inst.sortables, function() {
     455            if(this.instance.isOver) {
     456
     457                this.instance.isOver = 0;
     458
     459                inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
     460                this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
     461
     462                //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
     463                if(this.shouldRevert) this.instance.options.revert = true;
     464
     465                //Trigger the stop of the sortable
     466                //console.log("Draggable tells sortable to stop");
     467                this.instance._mouseStop(event);
     468
     469                this.instance.options.helper = this.instance.options._helper;
     470
     471                //If the helper has been the original item, restore properties in the sortable
     472                if(inst.options.helper == 'original')
     473                    this.instance.currentItem.css({ top: 'auto', left: 'auto' });
     474
     475            } else {
     476                this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
     477                this.instance._trigger("deactivate", event, uiSortable);
     478            }
     479
     480        });
     481
     482    },
     483    drag: function(event, ui) {
     484        //console.log("FUNCTION drag draggable connectToSortable");
     485
     486        var inst = $(this).data("draggable"), self = this;
     487
     488        var checkPos = function(o) {
     489            var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
     490            var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
     491            var itemHeight = o.height, itemWidth = o.width;
     492            var itemTop = o.top, itemLeft = o.left;
     493
     494            return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
     495        };
     496
     497        var intersecting_items = new Array();
     498
     499        $.each(inst.sortables, function(i) {
     500           
     501            //Copy over some variables to allow calling the sortable's native _intersectsWith
     502            this.instance.positionAbs = inst.positionAbs;
     503            this.instance.helperProportions = inst.helperProportions;
     504            this.instance.offset.click = inst.offset.click;
     505           
     506            if(this.instance._intersectsWith(this.instance.containerCache)) {
     507
     508                //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
     509                //if(!this.instance.isOver) {
     510
     511                    //console.log('Line 1113');
     512
     513                //  this.instance.isOver = 1;
     514
     515                    intersecting_items.push(this.instance); // sam
     516                //} //sam
     517
     518                    //Now we fake the start of dragging for the sortable instance,
     519                    //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
     520                    //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
     521                    //sam this.instance.currentItem = $(self).clone().appendTo(this.instance.element).data("sortable-item", true);
     522                    //sam this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
     523                    //sam this.instance.options.helper = function() { return ui.helper[0]; };
     524
     525                    //sam event.target = this.instance.currentItem[0];
     526                    //sam this.instance._mouseCapture(event, true);
     527                    //sam this.instance._mouseStart(event, true, true);
     528
     529                    //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
     530                    //sam this.instance.offset.click.top = inst.offset.click.top;
     531                    //sam this.instance.offset.click.left = inst.offset.click.left;
     532                    //sam this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
     533                    //sam this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
     534
     535                    //sam inst._trigger("toSortable", event);
     536                    //sam inst.dropped = this.instance.element; //draggable revert needs that
     537                    //hack so receive/update callbacks work (mostly)
     538                    //sam inst.currentItem = inst.element;
     539                    //sam this.instance.fromOutside = inst;
     540
     541                //sam brace
     542
     543                //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
     544                //sam if(this.instance.currentItem) this.instance._mouseDrag(event);
     545
     546            } else {
     547
     548                //If it doesn't intersect with the sortable, and it intersected before,
     549                //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
     550                if(this.instance.isOver) {
     551
     552                    console.log("UNSETTING ISOVER");
     553                    console.log("ON ITEM="+this.instance.currentItem[0].getAttribute('class'))
     554                    this.instance.isOver = 0;
     555                    this.instance.cancelHelperRemoval = true;
     556                   
     557                    //Prevent reverting on this forced stop
     558                    this.instance.options.revert = false;
     559                   
     560                    // The out event needs to be triggered independently
     561                    this.instance._trigger('out', event, this.instance._uiHash(this.instance));
     562                   
     563                    this.instance._mouseStop(event, true);
     564                    this.instance.options.helper = this.instance.options._helper;
     565
     566                    //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
     567                    //console.log("DO WE GET HERE?");
     568                    this.instance.currentItem.remove();
     569                    if(this.instance.placeholder) this.instance.placeholder.remove();
     570
     571                    inst._trigger("fromSortable", event);
     572                    inst.dropped = false; //draggable revert needs that
     573               
     574                }
     575       
     576            }
     577        });
     578
     579        //sam
     580        //console.log("Contents of intersecting_items");
     581        var innermostContainer = null, innermostIndex = null;       
     582        for (i=0;i<intersecting_items.length;i++)
     583        {
     584            //console.log('ITEM: '+intersecting_items[i].element[0].getAttribute('class'));
     585   
     586            if(innermostContainer && $.ui.contains(intersecting_items[i].element[0], innermostContainer.element[0]))
     587                continue;
     588                       
     589            innermostContainer = intersecting_items[i];
     590            innermostIndex = i;
     591                   
     592        }
     593
     594        for (i=0;i<intersecting_items.length;i++)
     595        {
     596            if(intersecting_items[i] != innermostContainer)
     597                if(intersecting_items[i].isOver) {
     598
     599                    console.log("UNSETTING ISOVER");
     600                    console.log("ON ITEM="+intersecting_items[i].currentItem[0].getAttribute('class'))
     601                    intersecting_items[i].isOver = 0;
     602                    intersecting_items[i].cancelHelperRemoval = true;
     603
     604                    //Prevent reverting on this forced stop
     605                    intersecting_items[i].options.revert = false;
     606
     607                    // The out event needs to be triggered independently
     608                    intersecting_items[i]._trigger('out', event, intersecting_items[i]._uiHash(intersecting_items[i]));
     609
     610                    intersecting_items[i]._mouseStop(event, true);
     611                    intersecting_items[i].options.helper = intersecting_items[i].options._helper;
     612
     613                    //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
     614                    //console.log("DO WE GET HERE?");
     615                    if(intersecting_items[i].currentItem) intersecting_items[i].currentItem.remove();
     616                    if(intersecting_items[i].placeholder) intersecting_items[i].placeholder.remove();
     617
     618                    inst._trigger("fromSortable", event);
     619                    inst.dropped = false; //draggable revert needs that
     620                }
     621
     622                intersecting_items[i].isOver = 0;
     623           
     624        }
     625
     626        if(innermostContainer && !innermostContainer.isOver)
     627        {
     628            console.log("INNER="+innermostContainer.element[0].getAttribute('class'));
     629            console.log("SETTING ISOVER");
     630            innermostContainer.isOver = 1;
     631
     632            //Now we fake the start of dragging for the sortable instance,
     633            //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
     634            //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
     635
     636            if(innermostContainer.currentItem) innermostContainer.currentItem.remove();
     637            if(innermostContainer.placeholder) innermostContainer.placeholder.remove();
     638
     639            innermostContainer.currentItem = $(self).clone().appendTo(innermostContainer.element).data("sortable-item", true);
     640           
     641            innermostContainer.options._helper = innermostContainer.options.helper; //Store helper option to later restore it
     642            innermostContainer.options.helper = function() { return ui.helper[0]; };
     643
     644            console.log("EVENT TARGET="+innermostContainer.currentItem[0].getAttribute('class'));
     645            event.target = innermostContainer.currentItem[0];
     646            innermostContainer._mouseCapture(event, true);
     647            innermostContainer._mouseStart(event, true, true);
     648
     649            //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
     650            innermostContainer.offset.click.top = inst.offset.click.top;
     651            innermostContainer.offset.click.left = inst.offset.click.left;
     652            innermostContainer.offset.parent.left -= inst.offset.parent.left - innermostContainer.offset.parent.left;
     653            innermostContainer.offset.parent.top -= inst.offset.parent.top - innermostContainer.offset.parent.top;
     654
     655            inst._trigger("toSortable", event);
     656            inst.dropped = innermostContainer.element; //draggable revert needs that
     657            //hack so receive/update callbacks work (mostly)
     658            inst.currentItem = inst.element;
     659            innermostContainer.fromOutside = inst;
     660
     661            //sam brace
     662        }
     663
     664        if(innermostContainer)
     665        {
     666            //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
     667            if(innermostContainer.currentItem) innermostContainer._mouseDrag(event);
     668        }
     669
     670    }
     671});
    423672
    424673    /*
Note: See TracChangeset for help on using the changeset viewer.