not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
6.8 KiB

  1. // Copyright (c) 2014-17 Walter Bender
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the The GNU Affero General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 3 of the License, or (at your option) any later version.
  7. //
  8. // You should have received a copy of the GNU Affero General Public
  9. // License along with this library; if not, write to the Free Software
  10. // Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
  11. var CONFIRMBOX = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="180" height="180"> <rect width="180" height="180" x="0" y="-3.5762787e-06" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" /> <g transform="translate(124.943,-0.053)" style="fill:#000000;display:block"> <path d="m 27.557,5.053 c -12.43,0 -22.5,10.076 -22.5,22.497 0,12.432 10.07,22.503 22.5,22.503 12.431,0 22.5,-10.071 22.5,-22.503 0,-12.421 -10.07,-22.497 -22.5,-22.497 z m 10.199,28.159 c 1.254,1.256 1.257,3.291 0,4.545 -0.628,0.629 -1.451,0.943 -2.274,0.943 -0.822,0 -1.644,-0.314 -2.27,-0.94 l -5.76,-5.761 -5.76,5.761 c -0.627,0.626 -1.449,0.94 -2.271,0.94 -0.823,0 -1.647,-0.314 -2.275,-0.943 -1.254,-1.254 -1.254,-3.289 0.004,-4.545 l 5.758,-5.758 -5.758,-5.758 c -1.258,-1.254 -1.258,-3.292 -0.004,-4.546 1.255,-1.254 3.292,-1.259 4.546,0 l 5.76,5.759 5.76,-5.759 c 1.252,-1.259 3.288,-1.254 4.544,0 1.257,1.254 1.254,3.292 0,4.546 l -5.758,5.758 5.758,5.758 z" style="fill:#000000;display:inline" /> </g> <rect width="174" height="120" x="3" y="57" style="fill:#92b5c8;fill-opacity:1;stroke:none" /> <rect width="30.772253" height="29.05797" x="74.828156" y="79.274384" style="fill:none;stroke:#000000;stroke-width:3.89899993;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <rect width="38.669331" height="1.6693259" x="70.665337" y="77.540131" style="fill:none;stroke:#000000;stroke-width:1.75924551;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <rect width="24.428572" height="0.14285715" x="78.214279" y="71.517647" style="fill:none;stroke:#000000;stroke-width:3.59899998;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <rect width="0.14285715" height="5.1428571" x="78.214279" y="71.80336" style="fill:none;stroke:#000000;stroke-width:3.59899998;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <rect width="0.14285715" height="5.1428571" x="102.42857" y="71.660507" style="fill:none;stroke:#000000;stroke-width:3.59899998;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /> <g transform="translate(62.5,68.5)" style="fill:#000000;stroke:none;display:block"> <path d="m 13,12.033 0,26.934 29,0 0,-26.934 z M 37.575,35.1 c 0.684,0.683 0.684,1.793 0,2.476 -0.341,0.342 -0.789,0.513 -1.237,0.513 -0.448,0 -0.896,-0.171 -1.238,-0.513 l -7.601,-7.602 -7.602,7.602 c -0.342,0.342 -0.79,0.513 -1.237,0.513 -0.447,0 -0.895,-0.171 -1.237,-0.513 -0.684,-0.683 -0.684,-1.793 0,-2.476 l 7.601,-7.601 -7.601,-7.602 c -0.684,-0.684 -0.684,-1.791 0,-2.474 0.683,-0.684 1.791,-0.684 2.474,0 l 7.602,7.601 7.601,-7.601 c 0.683,-0.684 1.793,-0.684 2.476,0 0.684,0.683 0.684,1.791 0,2.474 l -7.602,7.602 z" style="fill:#000000;stroke:none" /> </g> <text style="font-size:16px;font-style:normal;font-weight:normal;text-align:end;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"><tspan x="90.272461" y="147.20338" style="font-size:18px;text-align:center;text-anchor:middle">confirm</tspan></text> </svg>'
  12. // A pop up for deleting projects
  13. function ClearBox () {
  14. this._canvas = null;
  15. this._stage = null;
  16. this._refreshCanvas = null;
  17. this._doClear = null;
  18. this._container = null;
  19. this.save = null;
  20. this.close = null;
  21. this._scale = 1;
  22. this.setCanvas = function (canvas) {
  23. this._canvas = canvas;
  24. return this;
  25. };
  26. this.setStage = function (stage) {
  27. this._stage = stage;
  28. return this;
  29. };
  30. this.setClear = function (clear) {
  31. this._doClear = clear;
  32. return this;
  33. };
  34. this.setRefreshCanvas = function (refreshCanvas) {
  35. this._refreshCanvas = refreshCanvas;
  36. return this;
  37. };
  38. this._hide = function () {
  39. if (this._container != null) {
  40. this._container.visible = false;
  41. this._refreshCanvas();
  42. }
  43. };
  44. this.show = function (scale) {
  45. this._scale = scale;
  46. if (this._container == null) {
  47. this._container = new createjs.Container();
  48. this._stage.addChild(this._container);
  49. this._container.x = Math.floor(((this._canvas.width / scale) - 180) / 2);
  50. this._container.y = 27;
  51. function __processBackground(that, name, bitmap, extras) {
  52. that._container.addChild(bitmap);
  53. that._loadClearContainerHandler();
  54. that._completeShow();
  55. }
  56. this._makeBoxBitmap(CONFIRMBOX.replace(/confirm/g, _('confirm')), 'box', __processBackground, null);
  57. } else {
  58. this._completeShow();
  59. }
  60. };
  61. this._completeShow = function () {
  62. this._container.visible = true;
  63. this._refreshCanvas();
  64. };
  65. this._loadClearContainerHandler = function () {
  66. var hitArea = new createjs.Shape();
  67. this.bounds = this._container.getBounds();
  68. hitArea.graphics.beginFill('#FFF').drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
  69. hitArea.x = 0;
  70. hitArea.y = 0;
  71. this._container.hitArea = hitArea;
  72. var locked = false;
  73. var that = this;
  74. this._container.on('click', function(event) {
  75. // We need a lock to "debouce" the click.
  76. if (locked) {
  77. console.log('debouncing click');
  78. return;
  79. }
  80. locked = true;
  81. setTimeout(function () {
  82. locked = false;
  83. }, 500);
  84. var x = (event.stageX / that._scale) - that._container.x;
  85. var y = (event.stageY / that._scale) - that._container.y;
  86. if (x > 125 && y < 55) {
  87. that._hide();
  88. } else if (y > 55) {
  89. // Clear
  90. that._doClear(true);
  91. that._hide();
  92. }
  93. });
  94. };
  95. this._makeBoxBitmap = function (data, name, callback, extras) {
  96. // Async creation of bitmap from SVG data
  97. // Works with Chrome, Safari, Firefox (untested on IE)
  98. var img = new Image();
  99. var that = this;
  100. img.onload = function() {
  101. var bitmap = new createjs.Bitmap(img);
  102. callback(that, name, bitmap, extras);
  103. };
  104. img.src = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(data)));
  105. };
  106. };