Changeset 29085 for main


Ignore:
Timestamp:
05/29/14 14:30:09 (7 years ago)
Author:
kjdon
Message:

several changes. need to encodeURI the orig value too, before passing to metadataChanges. Have moved sendBuildRequest definition up so I can call it separately, not as the callback funciton in setMetadataLoop - if we have deleted some elements, but not made any other changes, then this wasn't being called, and the deletions weren't making their way into the index. Use row.hide to disappear the row when click remove. row.css didn't seem to work. need to set changedElem.original value after getting out the previous original.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/documentmaker_scripts_util.js

    r29077 r29085  
    211211    }
    212212
    213     var changes = de.Changes.getChangedEditableSections();
    214     var metadataChanges = new Array();
    215    
    216     for(var i = 0; i < changes.length; i++)
    217     {
    218         var changedElem = changes[i];
    219        
    220         //Save metadata
    221         if(gs.functions.hasClass(changedElem, "metaTableCell"))
    222         {
    223             //Get document ID
    224             var currentElem = changedElem;
    225             while((currentElem = currentElem.parentNode).tagName != "TABLE");
    226             var docID = currentElem.getAttribute("id").substring(4);
    227 
    228             //Get metadata name
    229             var row = changedElem.parentNode;
    230             var cells = row.getElementsByTagName("TD");
    231             var nameCell = cells[0];
    232             var name = nameCell.innerHTML;
    233             var value = changedElem.innerHTML;
    234             value = value.replace(/&nbsp;/g, " ");
    235             value = encodeURI(value);
    236 
    237             changedElem.originalValue = changedElem.innerHTML;
    238             metadataChanges.push({collection:collection, docID:docID, name:name, value:value, orig:changedElem.originalValue});
    239             addCollectionToBuild(collection);
    240         }
    241         //Save content
    242         else if(gs.functions.hasClass(changedElem, "renderedText"))
    243         {
    244             var section = changedElem.parentDiv.parentItem;
    245             saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + section.collection + '", "oid":"' + section.nodeID + '"}');
    246             addCollectionToBuild(section.collection);
    247         }
    248         else if(gs.functions.hasClass(changedElem, "sectionText"))
    249         {
    250             var id = changedElem.getAttribute("id");
    251             var sectionID = id.substring(4);
    252             saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + gs.cgiParams.c + '", "oid":"' + sectionID + '"}');
    253             addCollectionToBuild(gs.cgiParams.c);
    254         }
    255     }
    256    
    257213    var sendBuildRequest = function()
    258214    {
     
    314270        }
    315271    }
     272
     273    var changes = de.Changes.getChangedEditableSections();
     274    var metadataChanges = new Array();
     275    if (changes.length == 0) {
     276      sendBuildRequest();
     277      return;
     278    }
     279   
     280    for(var i = 0; i < changes.length; i++)
     281    {
     282        var changedElem = changes[i];
     283       
     284        //Save metadata     
     285        if(gs.functions.hasClass(changedElem, "metaTableCell"))
     286        {
     287            //Get document ID
     288            var currentElem = changedElem;
     289            while((currentElem = currentElem.parentNode).tagName != "TABLE");
     290            var docID = currentElem.getAttribute("id").substring(4);
     291
     292            //Get metadata name
     293            var row = changedElem.parentNode;
     294            var cells = row.getElementsByTagName("TD");
     295            var nameCell = cells[0];
     296            var name = nameCell.innerHTML;
     297            var value = changedElem.innerHTML;
     298            value = value.replace(/&nbsp;/g, " ");
     299            value = encodeURI(value);
     300
     301            var orig = changedElem.originalValue;
     302            if (orig) {
     303              orig = orig.replace(/&nbsp;/g, " ");
     304              orig = encodeURI(orig);
     305            }
     306            //changedElem.originalValue = changedElem.innerHTML;
     307            //metadataChanges.push({collection:collection, docID:docID, name:name, value:value, orig:changedElem.originalValue});
     308            metadataChanges.push({collection:collection, docID:docID, name:name, value:value, orig:orig});
     309            changedElem.originalValue = changedElem.innerHTML;
     310            //changedElem.originalValue = value;
     311            addCollectionToBuild(collection);
     312        }
     313        //Save content
     314        else if(gs.functions.hasClass(changedElem, "renderedText"))
     315        {
     316            var section = changedElem.parentDiv.parentItem;
     317            saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + section.collection + '", "oid":"' + section.nodeID + '"}');
     318            addCollectionToBuild(section.collection);
     319        }
     320        else if(gs.functions.hasClass(changedElem, "sectionText"))
     321        {
     322            var id = changedElem.getAttribute("id");
     323            var sectionID = id.substring(4);
     324            saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + gs.cgiParams.c + '", "oid":"' + sectionID + '"}');
     325            addCollectionToBuild(gs.cgiParams.c);
     326        }
     327    }
     328   
     329   
    316330   
    317331    var setMetadataLoop = function(index)
    318332    {
     333     
    319334        var change = metadataChanges[index];
    320335       
     
    764779        _undoOperations.push(undo);
    765780        _deletedMetadata.push(row);
    766         row.css("display", "none");
     781        //row.css("display", "none");
     782        $(row).hide();
    767783    });
    768784    newCell.append(removeLink);
Note: See TracChangeset for help on using the changeset viewer.