Added literallycanvas and react libraries.
[openemr.git] / library / js / literallycanvas / js / core / actions.js
blob01a3801d0ac635252c21111e239e53315ee4fd15
1 var AddShapeAction, ClearAction;
3 ClearAction = (function() {
4   function ClearAction(lc1, oldShapes, newShapes1) {
5     this.lc = lc1;
6     this.oldShapes = oldShapes;
7     this.newShapes = newShapes1;
8   }
10   ClearAction.prototype["do"] = function() {
11     this.lc.shapes = this.newShapes;
12     return this.lc.repaintLayer('main');
13   };
15   ClearAction.prototype.undo = function() {
16     this.lc.shapes = this.oldShapes;
17     return this.lc.repaintLayer('main');
18   };
20   return ClearAction;
22 })();
24 AddShapeAction = (function() {
25   function AddShapeAction(lc1, shape1, previousShapeId) {
26     this.lc = lc1;
27     this.shape = shape1;
28     this.previousShapeId = previousShapeId != null ? previousShapeId : null;
29   }
31   AddShapeAction.prototype["do"] = function() {
32     var found, i, len, newShapes, ref, shape;
33     if (!this.lc.shapes.length || this.lc.shapes[this.lc.shapes.length - 1].id === this.previousShapeId || this.previousShapeId === null) {
34       this.lc.shapes.push(this.shape);
35     } else {
36       newShapes = [];
37       found = false;
38       ref = this.lc.shapes;
39       for (i = 0, len = ref.length; i < len; i++) {
40         shape = ref[i];
41         newShapes.push(shape);
42         if (shape.id === this.previousShapeId) {
43           newShapes.push(this.shape);
44           found = true;
45         }
46       }
47       if (!found) {
48         newShapes.push(this.shape);
49       }
50       this.lc.shapes = newShapes;
51     }
52     return this.lc.repaintLayer('main');
53   };
55   AddShapeAction.prototype.undo = function() {
56     var i, len, newShapes, ref, shape;
57     if (this.lc.shapes[this.lc.shapes.length - 1].id === this.shape.id) {
58       this.lc.shapes.pop();
59     } else {
60       newShapes = [];
61       ref = this.lc.shapes;
62       for (i = 0, len = ref.length; i < len; i++) {
63         shape = ref[i];
64         if (shape.id !== this.shape.id) {
65           newShapes.push(shape);
66         }
67       }
68       lc.shapes = newShapes;
69     }
70     return this.lc.repaintLayer('main');
71   };
73   return AddShapeAction;
75 })();
77 module.exports = {
78   ClearAction: ClearAction,
79   AddShapeAction: AddShapeAction