Blame view

backend/web/js/main.js 2.05 KB
5e673d8b   Administrator   Adding deletion c...
1
2
3
4
5
6
7
  var canvas = $('canvas')
      .attr({'width' : 1200, 'height' : 500})
      .css('border', '1px solid black')
      .get(0);
  
  if(canvas)
      var context = canvas.getContext('2d');
01ebf78c   Administrator   Initial commit
8
9
10
11
12
13
14
15
16
17
18
  
  var model = {
      width : 0,
      height : 0,
      point : {
          x : 0,
          y : 0
      }
  };
  
  var select = $('#ukr_seeds');
5e673d8b   Administrator   Adding deletion c...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  select.change(getModel);
  
  getModel();
  
  $('#delete').click(function() {
      var inputs = $('.single-checkbox:checked');
      var n = inputs.length;
      if(n) {
          var files = [];
          $.each(inputs, function() {
              files.push($(this).val());
          });
          deleteImages(files);
      }
  });
  
  $('#select-all').click(function() {
      $('.single-checkbox').prop('checked', true);
  });
  
  function deleteImages(images) {
      var href = decodeURIComponent(location.href);
      var url = href.substring(0, href.lastIndexOf('/'));
      $.ajax({
          url: url + '/delete-images',
          type: 'POST',
          dataType: 'json',
          data: {
              images: images
          },
          success: function(data) {
              var images = data['images'];
              for(var i = 0; i < images.length; i++) {
                  $('div[data-url="' + images[i] + '"]').remove();
              }
          }
      });
  }
01ebf78c   Administrator   Initial commit
57
  
01ebf78c   Administrator   Initial commit
58
  
5e673d8b   Administrator   Adding deletion c...
59
  function getModel()
01ebf78c   Administrator   Initial commit
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  {
      $.ajax({
          url: location.href + '/get-params',
          data: {
              'crop_id': select.val()
          },
          type: 'GET',
          dataType: 'json',
          success: function(data) {
              model.width = data.body.WIDTH;
              model.height = data.body.HEIGHT;
              model.point.x = data.body.X;
              model.point.y = data.body.Y;
              canvas.attr({'width' : model.width + 20, 'height' : model.height + 20});
              context.clearRect(0, 0, canvas.width, canvas.height);
              console.log(model);
          }
      });
  }
  
  function draw()
  {
      var image = $('img').get(0);
      context.clearRect(0, 0, canvas.width, canvas.height);
      context.drawImage(image, model.point.x, model.point.y, model.width, model.height, 10, 10, model.width, model.height);
      console.log( image.width, image.height );
5e673d8b   Administrator   Adding deletion c...
86
  }