Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
170
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.       console.log tmpimg.width,tmpimg.height
  29.       console.log twidth,height
  30.       mapdata[imagelayer.id()] = [ {
  31.         url: '/floorplan/' + nameOfImage
  32.         x: 0
  33.         y: 0
  34.         height: height
  35.         width: twidth
  36.       }]
  37.       xscale = d3.scale.linear().domain([0,twidth]).range([0,twidth])
  38.       yscale = d3.scale.linear().domain([0,height]).range([0,height])
  39.       map.xScale(xscale).yScale(yscale)
  40.       svg = d3.select('#mapaOvde').append('svg').attr('id', 'svgMapa').attr("width", twidth).attr("height", height).datum(mapdata).call(map)
  41.       crtajUredaje()
  42.       drag = d3.behavior.drag().origin((d) -> d).on('dragstart', dragstarted).on('drag', dragged)
  43.       d3.selectAll('.xpass').call(drag).data listBean
  44.     return
  45.  
  46.   d3.selectAll('.map-controls .layer-controls').remove()
  47.  
  48.   # ==================== Prikaz podataka o uredjaju ====================
  49.  
  50.   window.showInformation = (data) ->
  51.     i=0
  52.     while i<listBean.length
  53.       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
  54.         #console.log listBean[i]
  55.         break
  56.       i++
  57.     return
  58.  
  59.   # ==================== Postavljanje inicijalnih vrednosti ====================
  60.   window.crtajUredaje = () ->  
  61.     if !listBean.length
  62.       $("#saveDevices").hide()
  63.     i = 0
  64.     while i < listBean.length
  65.       d3.select('.imagelayer').append('image').attr(                # ====== Dodavanje slike uredjaju
  66.         'xlink:href': 'https://www.supremainc.com/sites/all/themes/suprema/images/products/XPass_D2/XPass_D2_Mullion_1.png'
  67.         x: listBean[i].x * twidth / width
  68.         y: listBean[i].y * twidth / width
  69.         height: 30).attr('class', 'xpass').attr('data-tooltip',true).attr('aria-haspopup','true').attr('data-toggle', 'tooltip').attr("title", listBean[i].device_name)
  70.       d3.selectAll('.xpass').classed('draggable', true)
  71.       $('.xpass').tooltip()
  72.       d3.select('.imagelayer').append('circle').attr("cx",(listBean[i].x * twidth / width + 15)).attr("cy", (listBean[i].y * twidth / width + 15)).attr("r", 5).attr("fill", "red")
  73.       i++
  74.     showInformation(listBean[0])
  75.    
  76.   # ==================== Popunjavanje dropdown-a sa update-ovanim vrednostima i slanje vrednosti kontroleru ====================
  77.    
  78.   window.saveDevices = () ->
  79.     uredjaji = listBean
  80.     $.ajax(
  81.       type: "POST"
  82.       url: "/advancedOptions/getDevices"
  83.       contentType: "application/json; charset=utf-8"
  84.       dataType: "text"
  85.       data: JSON.stringify uredjaji
  86.     )
  87.     return
  88.    
  89.   # ==================== DRAGGING DEVICES ====================
  90.  
  91.   window.dragstarted = (d) ->
  92.     d3.event.sourceEvent.stopPropagation()
  93.     return
  94.  
  95.   window.dragged = (d) ->
  96.     dx = d3.event.x
  97.     dy = d3.event.y
  98.     for obj in listBean
  99.       if obj.device_id == d.device_id
  100.         d3.select(this).attr('x', d3.event.x * twidth / twidth)
  101.         d3.select(this).attr('y', d3.event.y * twidth / twidth)
  102.         $(this).next().attr('cx', d3.event.x * twidth / twidth + 14)
  103.         $(this).next().attr('cy', d3.event.y * twidth / twidth + 15) #kruzici za status
  104.         #obj.x =  d3.event.x# * width / twidth
  105.         #obj.y =  d3.event.y# * width / twidth
  106.         break
  107.     showInformation(d)
  108.     return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement