source: main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js@ 32850

Last change on this file since 32850 was 32850, checked in by ak19, 5 years ago
  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.
File size: 6.5 KB
Line 
1
2function MapEditorHistory(mapEditor) {
3 this.prevOverlays = [];
4 this.presentOverlays = [];
5 this.undoneOverlays = [];
6 this.cycleCompvare = true;
7 this.mapEditor = mapEditor;
8}
9
10MapEditorHistory.prototype.undo = function () {
11
12
13 if (this.prevOverlays.length != 0) {
14 for (var i = 0; i < this.mapEditor.overlays.length; i++) {
15 this.mapEditor.overlays[i].setMap(null);
16 }
17
18 this.mapEditor.selectedShapes = [];
19 this.mapEditor.overlays = [];
20 this.undoneOverlaysPush();
21 var prev_overlay = this.prevOverlays.pop();
22 var draggableCB = document.getElementById("draggableCB" + "-" + this.mapEditor.id).checked = false;
23
24 if (prev_overlay.length > 0) {
25 for (var i = 0; i < prev_overlay.length; i++) {
26 this.mapEditor.overlays[i] = prev_overlay[i];
27 this.mapEditor.overlays[i].setMap(this.mapEditor.map);
28 this.mapEditor.overlays[i].draggable = true;
29 }
30 }
31 }
32};
33
34MapEditorHistory.prototype.redo = function () {
35
36 if (this.undoneOverlays.length != 0) {
37 if (this.undoneOverlays[this.undoneOverlays.length -1].length != 0) {
38 this.mapEditor.selectedShapes = [];
39 var draggableCB = document.getElementById("draggableCB" + "-" + this.mapEditor.id).checked = false;
40
41 for (var i = 0; i < this.mapEditor.overlays.length; i++) {
42 this.mapEditor.overlays[i].setMap(null);
43 }
44
45 this.mapEditor.overlays = [];
46 var lastEntry = this.undoneOverlays[this.undoneOverlays.length - 1];
47 for (var i = 0; i < lastEntry.length; i++) {
48 this.mapEditor.overlays[i] = lastEntry[i];
49 this.mapEditor.overlays[i].setMap(this.mapEditor.map);
50 this.mapEditor.overlays[i].draggable = true;
51 }
52
53 var conditionPrevious = this.presentOverlays[0];
54 if (conditionPrevious !== undefined) {
55 if (conditionPrevious.length == 0) {
56 this.prevOverlays.push(this.presentOverlays[0]);
57 } else {
58 var overlays_copy = [];
59 for (var i = 0; i < this.presentOverlays[0].length; i++) {
60 var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
61 if (ShapesUtil.overlayItemIsShape(clone_shape)) {
62 this.mapEditor.addShapeListeners(clone_shape, null);
63 } else {
64 this.mapEditor.addMarkerListeners(clone_shape, null);
65 }
66 overlays_copy[i] = clone_shape;
67 }
68 this.prevOverlays.push(overlays_copy);
69 }
70 }
71 this.presentOverlays = [];
72 this.presentOverlays.push(this.undoneOverlays[this.undoneOverlays.length - 1]);
73 this.undoneOverlays.pop();
74 }
75 }
76}
77
78MapEditorHistory.prototype.historyOverlayPush = function () {
79
80
81 if (this.cycleCompvare) {
82
83 var overlays_copy = [];
84 for (var i = 0; i < this.mapEditor.overlays.length; i++) {
85 var clone_shape = ShapesUtil.cloneShape(this.mapEditor.overlays[i]);
86 if (ShapesUtil.overlayItemIsShape(clone_shape)) {
87 this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
88 } else {
89 this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
90 }
91 overlays_copy[i] = clone_shape;
92 }
93 this.undoneOverlays = [];
94 this.prevOverlays.push(overlays_copy);
95 }
96
97 this.cycleCompvare = false;
98}
99
100MapEditorHistory.prototype.presentOverlayPush = function () {
101// console.log("presentOverlayPush");
102
103 this.presentOverlays = [];
104 var overlays_copy = [];
105 for (var i = 0; i < this.mapEditor.overlays.length; i++) {
106 var clone_shape = ShapesUtil.cloneShape(this.mapEditor.overlays[i]);
107 if (ShapesUtil.overlayItemIsShape(clone_shape)) {
108 this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
109 } else {
110 this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
111 }
112 overlays_copy[i] = clone_shape;
113 }
114 this.presentOverlays.push(overlays_copy);
115 this.cycleCompvare = true;
116
117
118}
119
120MapEditorHistory.prototype.undoneOverlaysPush = function () {
121
122 var conditionUndone = this.presentOverlays[this.presentOverlays.length - 1] !== undefined;
123
124 if (conditionUndone) {
125 var overlays_copy = [];
126 for (var i = 0; i < this.presentOverlays[0].length; i++) {
127 var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
128 if (ShapesUtil.overlayItemIsShape(clone_shape)) {
129 this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
130 } else {
131 this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
132 }
133 overlays_copy[i] = clone_shape;
134 }
135 this.undoneOverlays.push(overlays_copy);
136 }
137
138 var conditionPresent = this.prevOverlays[this.prevOverlays.length - 1] !== undefined;
139
140 if (conditionPresent) {
141 this.presentOverlays = [];
142 var overlays_copy = [];
143 for (var i = 0; i < this.prevOverlays[this.prevOverlays.length - 1].length; i++) {
144 var clone_shape = cloneShape(this.prevOverlays[this.prevOverlays.length - 1][i]);
145 if (ShapesUtil.overlayItemIsShape(clone_shape)) {
146 this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
147 } else {
148 this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
149 }
150 overlays_copy[i] = clone_shape;
151 }
152 this.presentOverlays.push(overlays_copy);
153 }
154}
155
156MapEditorHistory.prototype.undoneOverlaysPush = function () {
157
158 var conditionUndone = this.presentOverlays[this.presentOverlays.length - 1] !== undefined;
159
160 if (conditionUndone) {
161 var overlays_copy = [];
162 for (var i = 0; i < this.presentOverlays[0].length; i++) {
163 var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
164 if (ShapesUtil.overlayItemIsShape(clone_shape)) {
165 this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
166 } else {
167 this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
168 }
169 overlays_copy[i] = clone_shape;
170 }
171 this.undoneOverlays.push(overlays_copy);
172 }
173
174 var conditionPresent = this.prevOverlays[this.prevOverlays.length - 1] !== undefined;
175
176 if (conditionPresent) {
177 this.presentOverlays = [];
178 var overlays_copy = [];
179 for (var i = 0; i < this.prevOverlays[this.prevOverlays.length - 1].length; i++) {
180 var clone_shape = ShapesUtil.cloneShape(this.prevOverlays[this.prevOverlays.length - 1][i]);
181 if (ShapesUtil.overlayItemIsShape(clone_shape)) {
182 this.mapEditor.addShapeListeners(clone_shape, null); // don't have an overlay event!
183 } else {
184 this.mapEditor.addMarkerListeners(clone_shape, null); // don't have an overlay event!
185 }
186 overlays_copy[i] = clone_shape;
187 }
188 this.presentOverlays.push(overlays_copy);
189 }
190}
Note: See TracBrowser for help on using the repository browser.