Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready ->
  2.   svg = undefined
  3.   if listBean.length > 0
  4.     nameOfImage = new String($('#departments option:selected').text()).replace(/\s/g, "")
  5.     nameOfImage = nameOfImage + '.svg'
  6.   else
  7.     nameOfImage = 'error.png'
  8.   height = 800
  9.   width = $('#mapa').innerWidth()
  10.   twidth = $('#mapa').innerWidth()  
  11.   map = d3.floorplan()
  12.   imagelayer = d3.floorplan.imagelayer()
  13.   mapdata = {}
  14.  
  15.   map.addLayer imagelayer
  16.  
  17.  
  18.   skalirajx = undefined
  19.   skalirajy = undefined
  20.   window.onload = ->
  21.     tmpimg = undefined
  22.     tmpimg = new Image();
  23.    
  24.     tmpimg.src = '/floorplan/' + nameOfImage;
  25.     tmpimg.onload = ->
  26.       width = tmpimg.width;
  27.       height = tmpimg.height * twidth / width;
  28.       i=0
  29.       while i<listBean.length
  30.         console.log listBean[i]
  31.         listBean[i].x=listBean[i].x * twidth / width
  32.         listBean[i].y=listBean[i].y * twidth / width
  33.         i++
  34.       mapdata[imagelayer.id()] = [ {
  35.         url: '/floorplan/' + nameOfImage
  36.         x: 0
  37.         y: 0
  38.         height: height
  39.         width: twidth
  40.       }]
  41.       xscale = d3.scale.linear().domain([0,twidth]).range([0,twidth])
  42.       yscale = d3.scale.linear().domain([0,height]).range([0,height])
  43.       map.xScale(xscale).yScale(yscale)
  44.       svg = d3.select('#mapaOvde').append('svg').attr('id', 'svgMapa').attr("width", twidth).attr("height", height).datum(mapdata).call(map)
  45.       crtajUredaje()
  46.       drag = d3.behavior.drag().origin((d) -> d).on('dragstart', dragstarted).on('drag', dragged)
  47.       d3.selectAll('.xpass').call(drag).data listBean
  48.     return
  49.  
  50.   d3.selectAll('.map-controls .layer-controls').remove()
  51.  
  52.   # ==================== Prikaz podataka o uredjaju ====================
  53.  
  54.   window.showInformation = (data) ->
  55.     i=0
  56.     while i<listBean.length
  57.       if Math.round(listBean[i].x * 10) / 10 == Math.round(data.x * 10) / 10 && Math.round(listBean[i].y * 10) / 10 == Math.round(data.y * 10) / 10
  58.         #console.log listBean[i]
  59.         break
  60.       i++
  61.     return
  62.  
  63.   # ==================== Postavljanje inicijalnih vrednosti ====================
  64.   window.crtajUredaje = () ->  
  65.     if !listBean.length
  66.       $("#saveDevices").hide()
  67.     i = 0
  68.     while i < listBean.length
  69.       d3.select('.imagelayer').append('image').attr(                # ====== Dodavanje slike uredjaju
  70.         'xlink:href': 'https://www.supremainc.com/sites/all/themes/suprema/images/products/XPass_D2/XPass_D2_Mullion_1.png'
  71.         x: listBean[i].x
  72.         y: listBean[i].y
  73.         height: 30).attr('class', 'xpass').attr('data-tooltip',true).attr('aria-haspopup','true').attr('data-toggle', 'tooltip').attr("title", listBean[i].device_name)
  74.       d3.selectAll('.xpass').classed('draggable', true)
  75.       $('.xpass').tooltip()
  76.       d3.select('.imagelayer').append('circle').attr("cx",(listBean[i].x + 15)).attr("cy", (listBean[i].y + 15)).attr("r", 5).attr("fill", "red")
  77.       i++
  78.     showInformation(listBean[0])
  79.    
  80.   # ==================== Popunjavanje dropdown-a sa update-ovanim vrednostima i slanje vrednosti kontroleru ====================
  81.    
  82.   window.saveDevices = () ->
  83.     uredjaji = listBean
  84.     $.ajax(
  85.       type: "POST"
  86.       url: "/advancedOptions/getDevices"
  87.       contentType: "application/json; charset=utf-8"
  88.       dataType: "text"
  89.       data: JSON.stringify uredjaji
  90.     )
  91.     return
  92.    
  93.   # ==================== DRAGGING DEVICES ====================
  94.  
  95.   window.dragstarted = (d) ->
  96.     d3.event.sourceEvent.stopPropagation()
  97.     return
  98.  
  99.   window.dragged = (d) ->
  100.     dx = d3.event.x
  101.     dy = d3.event.y
  102.     for obj in listBean
  103.       if obj.device_id == d.device_id
  104.         d3.select(this).attr('x', dx)
  105.         d3.select(this).attr('y', dy)
  106.         $(this).next().attr('cx', dx + 14)
  107.         $(this).next().attr('cy', dy + 15) #kruzici za status
  108.         obj.x =  dx# * width / width
  109.         obj.y =  dy# * width / width
  110.         console.log obj.x,obj.y
  111.         break
  112.     showInformation(d)
  113.     return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement