Show
Ignore:
Timestamp:
04.03.2019 16:30:56 (9 months ago)
Author:
ak19
Message:

1. Zeddy introduces suppressUndo and cleaned up lots of CloneShape? sectionst that were commented out. 2. Zeddy and Dr Bainbridge solved the issue whereby shapes loaded from archives_metadata were not selectable and needed a deleteAllShapes followed by Undo to make them selectable. These steps are no longer needed now, as it's solved more efficiently.

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
5 modified

Legend:

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

    r32840 r32850  
    8181        }); 
    8282    newLink.click(function () { 
    83         console.log(metaTable.metaNameField); 
    8483        if (metaTable.css("display") == "none") { 
    8584            linkLabel.html(gs.text.de.hide_metadata); 
     
    137136        if(!oldMapData && newMapData !== "[]" || oldMapData && oldMapData !== newMapData) { 
    138137            var nodeID = map_editors_array[i].id; 
    139             console.log("old vs new mapdata for nodeID " + nodeID); 
    140             console.log(oldMapData); 
    141             console.log(newMapData); 
     138            //console.log("old vs new mapdata for nodeID " + nodeID); 
     139            //console.log("OLD: " + oldMapData); 
     140            //console.log("NEW: " + newMapData); 
    142141             
    143142            modifiedMaps.push({ 
     
    149148            }); 
    150149             
     150            // Save the new overlay values as the old ones for the state after saving and rebuilding is done. 
     151            // Ideally this should be do after saveAndRebuild has completed successfully, since if saveAndRebuild goes wrong 
     152            // we'd not have saved newMapData AND because savedOverlays will contain the newMapData, we won't detect these unsaved 
     153            // values in future attempts to save. 
     154            // But for now, we're doing this here *because* this is the procedure with regular metadata (works out changes, 
     155            // then saves those changes as initStates BEFORE saveAndRebuild is called)           
    151156            map_editor.savedOverlays = newMapData; 
    152157        } 
  • main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js

    r32838 r32850  
    3434    // else the following pop up always ends up appearing when attempting 
    3535    // to leave a doc view page in Doc Editing Mode (when not yet actually Doc Editing) 
     36     
     37     
    3638    var changes = changesToUpdate(); 
     39     
     40    //console.log("#### CHANGES before page reload: ", changes); 
    3741     
    3842    if(changes.length > 0) { 
     
    548552                // collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction                
    549553                //console.log("@@@ metapos! change: ", change); 
    550                 gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, change.metapos, change.value /*TODO: encodeDelimiters(change.value)*/, null, "override", function(){callbackFunction();}); 
     554                gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, change.metapos, encodeDelimiters(change.value), null, "override", function(){callbackFunction();}); 
    551555            } 
    552556          else if(change.orig) 
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js

    r32832 r32850  
    2020        this.undoneOverlaysPush(); 
    2121        var prev_overlay = this.prevOverlays.pop(); 
    22         var draggableCB = document.querySelector("input[name=draggableCB]").checked = false; 
    23          
    24          
     22        var draggableCB = document.getElementById("draggableCB" + "-" + this.mapEditor.id).checked = false; 
     23 
    2524        if (prev_overlay.length > 0) { 
    2625            for (var i = 0; i < prev_overlay.length; i++) { 
     
    3736    if (this.undoneOverlays.length != 0) { 
    3837        if (this.undoneOverlays[this.undoneOverlays.length -1].length != 0) { 
    39             var draggableCB = document.querySelector("input[name=draggableCB]").checked = false; 
    4038            this.mapEditor.selectedShapes = []; 
     39            var draggableCB = document.getElementById("draggableCB" + "-" + this.mapEditor.id).checked = false; 
     40             
    4141            for (var i = 0; i < this.mapEditor.overlays.length; i++) { 
    4242                this.mapEditor.overlays[i].setMap(null); 
     
    7575    } 
    7676} 
    77  
    78 /* 
    79 MapEditorHistory.prototype.clonePath = function (path) { 
    80     var clone_path = []; 
    81  
    82     for (var i = 0; i < path.length; i++) { 
    83         var lati = path.getAt(i).lat(); 
    84         var lngi = path.getAt(i).lng(); 
    85         clone_lat_lng = { 
    86             lat: lati, 
    87             lng: lngi 
    88         }; 
    89         clone_path.push(clone_lat_lng); 
    90     } 
    91  
    92     return clone_path; 
    93 } 
    94  
    95 MapEditorHistory.prototype.clonePolyline = function (polyline) { 
    96     var geodesic = polyline.geodesic; 
    97     var strokeColor = polyline.strokeColor; 
    98     var strokeOpacity = polyline.strokeOpacity; 
    99     var strokeWeight = polyline.strokeWeight; 
    100     //var clone_path = clonePath(path); 
    101      
    102     var clone_path = null; 
    103      
    104     var JSONSave = typeof polyline.getPath !== "function"; 
    105     //console.log(JSONSave) 
    106     if(JSONSave){ 
    107         var path = polyline.latLngs.j[0].j; 
    108         clone_path = path; 
    109          
    110     } else{ 
    111         var path = polyline.getPath(); 
    112         clone_path = this.clonePath(path);   
    113     } 
    114     var clone_polyline = new google.maps.Polyline({ 
    115             geodesic: geodesic, 
    116             strokeColor: strokeColor, 
    117             strokeOpacity: strokeOpacity, 
    118             strokeWeight: strokeWeight, 
    119             path: clone_path, 
    120             draggable: true, 
    121             editable: false 
    122         }); 
    123  
    124     clone_polyline.type = google.maps.drawing.OverlayType.POLYLINE; 
    125  
    126     return clone_polyline; 
    127 } 
    128  
    129 MapEditorHistory.prototype.clonePolygon = function (polygon) { 
    130     var geodesic = polygon.geodesic; 
    131     var strokeColor = polygon.strokeColor; 
    132     var strokeOpacity = polygon.strokeOpacity; 
    133     var strokeWeight = polygon.strokeWeight; 
    134     var fillColor = polygon.fillColor; 
    135     var fillOpacity = polygon.fillOpacity; 
    136  
    137     var clone_path = null; 
    138     var JSONSave = typeof polygon.getPath !== "function"; 
    139     //console.log(JSONSave) 
    140     if(JSONSave){ 
    141         var path = polygon.latLngs.j[0].j; 
    142         clone_path = path; 
    143          
    144     } else{ 
    145         var path = polygon.getPath(); 
    146         clone_path = this.clonePath(path); 
    147         console.log(path);   
    148     }    
    149     var clone_polygon = new google.maps.Polygon({ 
    150             geodesic: geodesic, 
    151             strokeColor: strokeColor, 
    152             strokeOpacity: strokeOpacity, 
    153             strokeWeight: strokeWeight, 
    154             fillColor: fillColor, 
    155             fillOpacity: fillOpacity, 
    156             path: clone_path, 
    157             draggable: true, 
    158             editable: false 
    159         }); 
    160     clone_polygon.type = google.maps.drawing.OverlayType.POLYGON; 
    161     return clone_polygon; 
    162 } 
    163  
    164 MapEditorHistory.prototype.cloneRectangle = function (rect) { 
    165     var strokeColor = rect.strokeColor; 
    166     var strokeOpacity = rect.strokeOpacity; 
    167     var strokeWeight = rect.strokeWeight; 
    168     var fillColor = rect.fillColor; 
    169     var fillOpacity = rect.fillOpacity; 
    170     //var bounds = rect.getBounds(); 
    171     var type = rect.type; 
    172      
    173     var bounds = null; 
    174      
    175     var JSONSave = typeof rect.getBounds !== "function"; 
    176      
    177     if(JSONSave){ 
    178         var north = rect.bounds.north; 
    179         var south = rect.bounds.south; 
    180         var east = rect.bounds.east; 
    181         var west = rect.bounds.west; 
    182         if (!isNaN(north) && !isNaN(south) && !isNaN(west) && !isNaN(east)) { 
    183             var NE = new google.maps.LatLng(north, east); 
    184             var SW = new google.maps.LatLng(south, west); 
    185             bounds = new google.maps.LatLngBounds(SW, NE); 
    186         }        
    187     } else { 
    188         bounds = rect.getBounds(); 
    189     } 
    190     var clone_rect = new google.maps.Rectangle({ 
    191             strokeColor: strokeColor, 
    192             strokeOpacity: strokeOpacity, 
    193             strokeWeight: strokeWeight, 
    194             fillColor: fillColor, 
    195             fillOpacity: fillOpacity, 
    196             bounds: bounds, 
    197             draggable: true, 
    198             editable: false, 
    199             type: type 
    200         }); 
    201  
    202     clone_rect.type = google.maps.drawing.OverlayType.RECTANGLE; 
    203     return clone_rect; 
    204 } 
    205  
    206 MapEditorHistory.prototype.cloneCircle = function (circ) { 
    207     var strokeColor = circ.strokeColor; 
    208     var strokeOpacity = circ.strokeOpacity; 
    209     var strokeWeight = circ.strokeWeight; 
    210     var fillColor = circ.fillColor; 
    211     var fillOpacity = circ.fillOpacity; 
    212     var center = circ.center; 
    213     var radius = circ.radius; 
    214      
    215     var clone_circ = new google.maps.Circle({ 
    216             strokeColor: strokeColor, 
    217             strokeOpacity: strokeOpacity, 
    218             strokeWeight: strokeWeight, 
    219             fillColor: fillColor, 
    220             fillOpacity: fillOpacity, 
    221             center: center, 
    222             radius: radius, 
    223             draggable: true, 
    224             editable: false 
    225         }); 
    226  
    227     clone_circ.type = google.maps.drawing.OverlayType.CIRCLE; 
    228  
    229     return clone_circ; 
    230 } 
    231  
    232 MapEditorHistory.prototype.cloneMarker = function (marker) { 
    233     var anchorPoint = marker.anchorPoint; 
    234     var JSONSave = typeof marker.getPosition !== "function"; 
    235     if(JSONSave){ 
    236         var position = marker.position; 
    237     } else{ 
    238         var position = marker.getPosition(); 
    239     } 
    240     var clone_marker = new google.maps.Marker({ 
    241             anchorPoint: anchorPoint, 
    242             position: position, 
    243             clickable: true, 
    244             draggable: true, 
    245             editable: false 
    246         }) 
    247         clone_marker.type = google.maps.drawing.OverlayType.MARKER; 
    248  
    249     return clone_marker; 
    250 } 
    251  
    252 MapEditorHistory.prototype.cloneShape = function (shape) { 
    253     if (shape.type === google.maps.drawing.OverlayType.POLYLINE) { 
    254         var clone_polyline = this.clonePolyline(shape); 
    255         return clone_polyline; 
    256     } else if (shape.type === google.maps.drawing.OverlayType.POLYGON) { 
    257         var clone_polygon = this.clonePolygon(shape); 
    258         return clone_polygon; 
    259     } else if (shape.type === google.maps.drawing.OverlayType.RECTANGLE) { 
    260         var clone_rect = this.cloneRectangle(shape); 
    261         return clone_rect; 
    262  
    263     } else if (shape.type === google.maps.drawing.OverlayType.CIRCLE) { 
    264         var clone_circ = this.cloneCircle(shape); 
    265         return clone_circ; 
    266  
    267     } else { 
    268         var clone_marker = this.cloneMarker(shape); 
    269         return clone_marker; 
    270     } 
    271 } 
    272  
    273 MapEditorHistory.prototype.overlayItemIsShape = function (overlay_item) { 
    274     var type = overlay_item.type; 
    275  
    276     is_shape = (type === google.maps.drawing.OverlayType.POLYLINE) 
    277      || (type === google.maps.drawing.OverlayType.POLYGON) 
    278      || (type === google.maps.drawing.OverlayType.RECTANGLE) 
    279      || (type === google.maps.drawing.OverlayType.CIRCLE); 
    280  
    281     return is_shape; 
    282 } 
    283  
    284 */ 
    28577 
    28678MapEditorHistory.prototype.historyOverlayPush = function () { 
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js

    r32840 r32850  
    2525    this.resizable = false; 
    2626    this.dontResize = false; 
    27     this.polyOptions = { 
     27    this.shapeOptions = { 
     28        suppressUndo: true, 
    2829        fillColor: '#CA4A2F', 
    2930        strokeWeight: this.thicknessValue, 
     
    3637} 
    3738 
     39//draggable checkbox control 
    3840MapEditor.prototype.initMapEditorControls = function () { 
    3941    var that = this; 
    4042 
    41  
    42     var draggableCB = document.querySelector("input[name=draggableCB]"); 
     43    var draggableCB = document.getElementById("draggableCB-"+ this.id); 
    4344    draggableCB.addEventListener('change', function () { 
    4445        if (this.checked) { 
    4546            for (var i = 0; i < that.overlays.length; i++) { 
    46                 console.log("checked"); 
    4747                that.overlays[i].draggable = false; 
    48                 that.polyOptions.draggable = false; 
     48                that.shapeOptions.draggable = false; 
    4949            } 
    5050        } else { 
    5151            for (var i = 0; i < that.overlays.length; i++) { 
    52                 console.log("not checked"); 
    5352                that.overlays[i].draggable = true; 
    54                 that.polyOptions.draggable = true; 
     53                that.shapeOptions.draggable = true; 
    5554            } 
    5655        } 
     
    6766        thicknessSliderOutput.innerHTML = ((this.value / 20) * 100) / 100; 
    6867        that.thicknessValue = this.value / 20; 
    69         that.polyOptions.strokeWeight = that.thicknessValue; 
     68        that.shapeOptions.strokeWeight = that.thicknessValue; 
    7069        that.setSelectedThickness(that.thicknessValue); 
    7170 
     
    8079        opacitySliderOutput.innerHTML = "% " + Math.round(this.value * 100) / 100; 
    8180        that.opacityValue = this.value / 100; 
    82         that.polyOptions.fillOpacity = that.opacityValue; 
     81        that.shapeOptions.fillOpacity = that.opacityValue; 
    8382        that.setSelectedOpacity(that.opacityValue); 
    8483    } 
     
    106105        var enableMessage = currentOverlays !== that.savedOverlays; 
    107106        var message = "Changes are not saved. Are you sure you want to leave?"; 
    108          
    109         console.log("@@@ onbeforeunload. currentOverlays: " + currentOverlays); 
    110         console.log(that.savedOverlays); 
    111         console.log(enableMessage); 
     107 
    112108         
    113109        // Comment out following section in entirety -- from "e = e || window.event" to end of "if(e)" -- if 
     
    150146                        that.resizable = true; 
    151147                        that.shapeResize(); 
     148                         
    152149                    } 
    153150                }); 
     
    277274                draggable: true 
    278275            }, 
    279             circleOptions: this.polyOptions, 
    280             polylineOptions: this.polyOptions, 
    281             polygonOptions: this.polyOptions, 
    282             rectangleOptions: this.polyOptions, 
     276            circleOptions: this.shapeOptions, 
     277            polylineOptions: this.shapeOptions, 
     278            polygonOptions: this.shapeOptions, 
     279            rectangleOptions: this.shapeOptions, 
    283280        }); 
    284281 
     
    333330 
    334331    //Keyboard shortcuts             
    335     var mapAndControls = document.getElementById("map-and-controls-" + this.id);  
    336     console.log("@@@@ initMapEditor. mapAndControls: ", mapAndControls); 
     332    var mapAndControls = document.getElementById("map-and-controls-" + this.id); 
    337333     
    338334    //Sets shift as unpressed 
     
    361357            }    
    362358        } 
    363          
    364359        else if (keyCode == 'A' && (event.ctrlKey || event.metaKey)) { 
    365360            event.preventDefault(); 
     
    371366            that.deselectAll(); 
    372367        } 
    373         else if (keyCode == '0' || keyCode == 'À' || keyCode == 'G') { 
    374  
     368        else if (keyCode == '0' || keyCode == 'À' || (keyCode == 'G'&& (event.ctrlKey || event.metaKey))) { 
     369            event.preventDefault();  
    375370            that.drawingManager.setDrawingMode(null); 
    376371        } else if (keyCode == '1') { 
     
    384379        } else if (keyCode == '5') { 
    385380            that.drawingManager.setDrawingMode('rectangle'); 
    386         } else if (keyCode == 'S') { 
    387             that.saveToArchives();   
    388         } else if (keyCode == 'Q') {             
     381        }  
     382        //else if (keyCode == 'S') { 
     383        //  that.saveToArchives();   
     384        //}  
     385        else if (keyCode == 'Q') { // for debugging information, press Q (easy to hit key) 
    389386            that.printHistory(); 
     387        } 
     388        else if (keyCode == '.') { 
     389            that.deleteSelectedShapes(); 
    390390        } 
    391391//                                  console.log(keyCode); 
     
    471471    // mouses down on it. 
    472472    google.maps.event.addListener(newShape, 'click', function (e) { 
    473  
    474473        that.vertexAndPolyDel(e, newShape); 
    475  
    476474    }); 
    477475 
     
    689687    console.log("present ", this.mapEditorHistory.presentOverlays); 
    690688    console.log("undone ", this.mapEditorHistory.undoneOverlays); 
    691     console.log("@@@@ selectedShapes: " + this.selectedShapes); 
     689    console.log("@@@@ allShapes: ", this.overlays); 
     690    console.log("@@@@ selectedShapes: ", this.selectedShapes); 
    692691} 
    693692 
     
    711710     
    712711    for (var i=0; i<map_editor.overlays.length; i++) { 
    713         map_editor.overlays[i].setMap(map_editor.map); 
    714     } 
    715      
    716     this.mapEditorHistory.presentOverlayPush(); 
    717      
    718      
    719     //When the overlays are loaded from the metadate, they cannot be selected when clicked on them.  
    720     //One fix for this issue is to delete all the sapes present then bring them back by 'undo', then they can be normally selected 
    721     this.deleteAllShapes(); 
    722     this.mapEditorHistory.undo(); 
    723     this.mapEditorHistory.prevOverlays = [];         
     712        var shape = map_editor.overlays[i]; 
     713        if (ShapesUtil.overlayItemIsShape(shape)) { 
     714            map_editor.addShapeListeners(shape, null); // don't have an overlay event! 
     715        } else { 
     716            map_editor.addMarkerListeners(shape, null); // don't have an overlay event! 
     717        } 
     718        shape.setMap(map_editor.map); 
     719    } 
     720 
     721    this.mapEditorHistory.presentOverlayPush();  
    724722} 
    725723 
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts-shapes-util.js

    r32832 r32850  
    6464         
    6565        clone_poly = new google.maps.Polyline({ 
     66            suppressUndo: true, 
    6667            geodesic:      geodesic, 
    6768            strokeColor:   strokeColor, 
     
    8081     
    8182        clone_poly = new google.maps.Polygon({ 
     83            suppressUndo: true, 
    8284            geodesic:      geodesic, 
    8385            strokeColor:   strokeColor, 
     
    186188     
    187189    var clone_rect = new google.maps.Rectangle({ 
    188             strokeColor: strokeColor, 
    189             strokeOpacity: strokeOpacity, 
    190             strokeWeight: strokeWeight, 
    191             fillColor: fillColor, 
    192             fillOpacity: fillOpacity, 
    193             bounds: bounds, 
    194             draggable: true, 
    195             editable: false, 
    196             type: type 
    197         }); 
     190        suppressUndo: true, 
     191        strokeColor: strokeColor, 
     192        strokeOpacity: strokeOpacity, 
     193        strokeWeight: strokeWeight, 
     194        fillColor: fillColor, 
     195        fillOpacity: fillOpacity, 
     196        bounds: bounds, 
     197        draggable: true, 
     198        editable: false, 
     199        type: type 
     200    }); 
    198201    return clone_rect; 
    199202} 
     
    267270     
    268271    var clone_circ = new google.maps.Circle({ 
    269             strokeColor: strokeColor, 
    270             strokeOpacity: strokeOpacity, 
    271             strokeWeight: strokeWeight, 
    272             fillColor: fillColor, 
    273             fillOpacity: fillOpacity, 
    274             center: center, 
    275             radius: radius, 
    276             draggable: true, 
    277             editable: false, 
    278             type: type 
    279         }); 
     272        suppressUndo: true, 
     273        strokeColor: strokeColor, 
     274        strokeOpacity: strokeOpacity, 
     275        strokeWeight: strokeWeight, 
     276        fillColor: fillColor, 
     277        fillOpacity: fillOpacity, 
     278        center: center, 
     279        radius: radius, 
     280        draggable: true, 
     281        editable: false, 
     282        type: type 
     283    }); 
    280284    return clone_circ; 
    281285} 
     
    320324     
    321325    var clone_marker = new google.maps.Marker({ 
    322             position: position, 
    323             clickable: true, 
    324             draggable: true, 
    325             editable: true, 
    326             type: google.maps.drawing.OverlayType.MARKER 
    327         }) 
     326        suppressUndo: true, 
     327        position: position, 
     328        clickable: true, 
     329        draggable: true, 
     330        editable: true, 
     331        type: google.maps.drawing.OverlayType.MARKER 
     332    }) 
    328333    return clone_marker; 
    329334}