Changeset 32132


Ignore:
Timestamp:
2018-02-13T11:43:05+13:00 (4 years ago)
Author:
kjdon
Message:

added multivalued metadata input shortcut functionality. In documentedit_scripts you can specify which metadata fields are multivalued, and what the delimiter is. For these fields, the user can put a delimiter spearated list, and the values will get split and saved to the doc.xml file individually

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
2 edited

Legend:

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

    r31909 r32132  
    3232var dcSubject_values = ["Kings", "Queens", "others"];
    3333*/
     34
     35/* The metadata specified in multiValuedMetadata array will be treated as a delimited list, using mvm_delimiter. On saving, the values will be separated and saved individually */
     36
     37var multiValuedMetadata = new Array(); // eg ["xx.Person", "xx.Location"];
     38var mvm_delimiter = ";";
    3439
    3540/************************
  • main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js

    r32078 r32132  
    336336  var metadataChanges = new Array();
    337337  if (_deletedMetadata.length > 0) {
     338    //addCollectionToBuild(collection);
    338339
    339340    for(var i = 0; i < _deletedMetadata.length; i++) {
     
    348349      //Get metadata name
    349350      var cells = currentRow.getElementsByTagName("TD");
    350       var nameCell = cells[0];
    351       var name = nameCell.innerHTML;
     351    var nameCell = cells[0];
     352    // metadata name cell might have the multivalue indicator in it, so just want the first word
     353    var name = nameCell.innerHTML.split(" ")[0];
    352354      var valueCell = cells[1];
    353       var value = valueCell.getElementsByTagName("TEXTAREA")[0].value;
     355    var value = valueCell.getElementsByTagName("TEXTAREA")[0].value;
    354356    if (value.length) {
    355357        // check for non empty value, in case all they have done is add a field then deleted it.
     
    374376            while((currentElem = currentElem.parentNode).tagName != "TABLE");
    375377            var docID = currentElem.getAttribute("id").substring(4);
    376 
     378           
    377379            //Get metadata name
    378380            var row = changedElem.parentNode.parentNode;
    379381            var cells = row.getElementsByTagName("TD");
    380             var nameCell = cells[0];
    381             var name = nameCell.innerHTML;
     382            var nameCell = cells[0];
     383            // metadata name cell might have the multivalue indicator in it, so just want the first word
     384            var name = nameCell.innerHTML.split(" ")[0];
    382385            var value = changedElem.value;
    383386            value = value.replace(/&nbsp;/g, " ");
     
    387390              orig = orig.replace(/&nbsp;/g, " ");
    388391            }
     392            if (jQuery.inArray(name, multiValuedMetadata) != -1) {
     393
     394            // split the values
     395            var values_list = value.split(mvm_delimiter);
     396            var orig_list;
     397            var num_orig;
     398            if (orig) {
     399                orig_list = orig.split(mvm_delimiter);
     400                num_orig = orig_list.length;
     401            }
     402
     403            for(var i = 0; i < values_list.length; i++) {
     404                var val = values_list[i];
     405                var ori =null;
     406                if (orig && i<num_orig) {
     407                    ori = orig_list[i];
     408                }
     409                metadataChanges.push({collection:collection, docID:docID, name:name, value:val, orig:ori});
     410            }
     411            } else {
    389412            metadataChanges.push({collection:collection, docID:docID, name:name, value:value, orig:orig});
     413            }
    390414            changedElem.originalValue = changedElem.value;
    391415            addCollectionToBuild(collection);
     
    750774                else
    751775                {
    752                     var cells = rows[j].getElementsByTagName("TD");
    753                     var cellName = cells[0].innerHTML;
     776                    var cells = rows[j].getElementsByTagName("TD");
     777                    // metadata name cell might have the multivalue indicator in it, so just want the first word
     778                    var cellName = cells[0].innerHTML.split(" ")[0];
    754779                   
    755780                    if(cellName.indexOf(".") == -1)
     
    829854        var cells = $(this).find("td");
    830855        var metadataName = $(cells[0]).html();
    831        
     856
    832857        if(dynamic_metadata_set_list == true && metadataName.indexOf(".") != -1)
    833858        {
     
    852877           
    853878        asyncRegisterEditSection(cells[1].getElementsByTagName("textarea")[0]);
    854         addRemoveLinkToRow(this);
     879        addRemoveLinkToRow(this);
     880
     881        // add multivalued indicator if needed
     882         if (jQuery.inArray(metadataName, multiValuedMetadata) != -1) {
     883        //if (multiValuedMetadata.includes(metadataName)){
     884        $(cells[0]).html(metadataName + " <span title='"+gs.text.de.multi_valued_tooltip + "' style='float:right;'>"+mvm_delimiter+"</span>"); //Multi-valued metadata. Separate values with semi-colon ;
     885        }
     886       
    855887    });
    856888
     
    867899    }
    868900    }
     901
     902    // add metadata field selector
    869903        var metaNameField = createMetadataElementSelector();   
    870904    table.after(metaNameField);
Note: See TracChangeset for help on using the changeset viewer.