Guest User

Untitled

a guest
Apr 23rd, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2.   #   ROTATIONS
  3.   #
  4.  
  5.   # EVENT HANLDERS
  6.   $('.inline_rot_add').live 'click'  , ->    new_rotation()
  7.   $('.remove_rot_btn').live 'click'  , -> delete_rotation($(this).attr('id'))
  8.   $('.rot_active'    ).live 'change' , ->   save_rotation($(this).attr('id'))
  9.  
  10.   # EDITORS
  11.   init_rotation_editors = ->
  12.     $('.rot_name').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
  13.       type        : 'text'
  14.       onblur      : 'submit'
  15.       indicator   : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
  16.       event       : 'click'
  17.       cssclass    : 'jeditable'
  18.       placeholder : ''
  19.       submitdata  : {rot_id: $(this).attr('id'), property: 'name'}
  20.       method      : 'POST'
  21.       callback    : (value, settings) ->
  22.         $(this).html(value)
  23.        
  24.     $('.rot_active').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
  25.       type        : 'select'
  26.       data        : {'true' : 'Yes', 'false' : 'No', 'selected' : 'true'}
  27.       onblur      : 'submit'
  28.       indicator   : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
  29.       event       : 'click'
  30.       cssclass    : 'jeditable'
  31.       placeholder : ''
  32.       submitdata  : {rot_id: $(this).attr('id'), property: 'active'}
  33.       method      : 'POST'
  34.       callback    : (value, settings) ->
  35.         $(this).html(value)
  36.        
  37.     $('.rot_sample').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
  38.       type        : 'text'
  39.       onblur      : 'submit'
  40.       indicator   : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
  41.       event       : 'click'
  42.       cssclass    : 'jeditable'
  43.       placeholder : ''
  44.       submitdata  : {rot_id: $(this).attr('id'), property: 'sample'}
  45.       method      : 'POST'
  46.       callback    : (value, settings) ->
  47.         $(this).html(value)
  48.        
  49.     $('.rot_setup').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
  50.       type        : 'text'
  51.       onblur      : 'submit'
  52.       indicator   : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
  53.       event       : 'click'
  54.       cssclass    : 'jeditable'
  55.       placeholder : ''
  56.       submitdata  : {rot_id: $(this).attr('id'), property: 'setup'}
  57.       method      : 'POST'
  58.       callback    : (value, settings) ->
  59.         $(this).html(value)
  60.  
  61.   new_rotation = ->
  62.     rot =
  63.       id        : -1
  64.       name      : 'New Rotation'
  65.       active    : false
  66.       sample    : 0
  67.       rooms     : []
  68.       deletable : true
  69.        
  70.     add_rotation(rot, true)
  71.  
  72.   delete_rotation = (rot_id) ->
  73.     $.ajax
  74.       url      : '{{url_for("inline_delete_rot", study_id=study_id)}}'
  75.       dataType : 'json'
  76.       type     : 'POST'
  77.       data     : rot_id
  78.       error    : -> 'Error deleting rotation.'
  79.       success  : (json) ->
  80.         if json.status == 'OK'
  81.           populate_rotation_table()
  82.         else
  83.           alert 'Error deleting rotation: '+json.data
  84.  
  85.   get_rotation_data = (rot_id) ->
  86.     id        : id
  87.     setup     : $(    '.rot_setup #' + rot_id).html()
  88.     name      : $(     '.rot_name #' + rot_id).html()
  89.     active    : $(   '.rot_active #' + rot_id).attr('checked')
  90.     sample    : $(        '.rot_n #' + rot_id).html()
  91.     deletable : $('.rot_deletable #' + rot_id).html() != ''
  92.          
  93.   set_rotation_data = (rot) ->
  94.     $('.rot_name #'   + rot.id).html(rot.name)
  95.     $('.rot_active #' + rot.id).attr('checked', rot.active)
  96.     $('.rot_n #'      + rot.id).html(rot.sample)
  97.    
  98.     if rot.deletable
  99.       $('.rot_deletable #' + rot.id).html(
  100.         '<td><a href="javascript:void(0)"><img class="remove_rot_btn" id="' + rot.id + '"' +
  101.         ' src="{{static("img/UI/button_cancel_16x16.png")}}" /'+'>'
  102.       )
  103.     else
  104.       $('.rot_deletable #' + rot.id).html('')
  105.  
  106.   save_rotation = (rot_id) ->
  107.     $.ajax
  108.       url      : '{{url_for("inline_save_rot", study_id=study_id)}}'
  109.       dataType : 'json'
  110.       type     : 'POST'
  111.       data     : get_rotation_data(rot_id)
  112.       error    : -> 'Error saving rotation.'
  113.       success  : (json) ->
  114.         if json.status == 'ERR'
  115.           alert 'Error saving rotation: '+json.data
  116.  
  117.   populate_rotation_table = ->
  118.     $.ajax
  119.       url      : '{{url_for("inline_rotations", study_id=study_id)}}'
  120.       dataType : 'json'
  121.       type     : 'GET'
  122.       error    : -> 'Error loading rotations.'
  123.       success  : (json) ->
  124.         if json.status == 'OK'
  125.           build_rotation_table(json)
  126.           init_rotation_editors()
  127.         else
  128.           alert 'Error loading rotations: '+json.data
  129.  
  130.   add_rotation = (rot, save) ->
  131.     $(".rotation_table_body").append([
  132.       '<tr>'
  133.       '<td class="rot_name" id="' + rot.id + '"></td>'
  134.       '<td class="rot_active" id="' + rot.id + '"></td>'
  135.       '<td class="rot_sample" id="' + rot.id + '"></td>'
  136.       '<td class="rot_setup" id="' + rot.id + '"></td>'
  137.       '<td><a href="javascript:void(0)"><img class="remove_rot_btn" id="' + rot.id + '"'
  138.       ' src="{{static("img/UI/button_cancel_16x16.png")}}" /'+'>'
  139.       '</tr>'
  140.     ].join(''))
  141.    
  142.     set_rotation_data(rot)
  143.    
  144.     if save then save_rotation(rot)
  145.  
  146.   build_rotation_table = (json) ->
  147.     $('.rotation_table_body').html('')
  148.    
  149.     add_rotation(rot, false) for rot in json.data.rots
Add Comment
Please, Sign In to add comment