Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # ROTATIONS
- #
- # EVENT HANLDERS
- $('.inline_rot_add').live 'click' , -> new_rotation()
- $('.remove_rot_btn').live 'click' , -> delete_rotation($(this).attr('id'))
- $('.rot_active' ).live 'change' , -> save_rotation($(this).attr('id'))
- # EDITORS
- init_rotation_editors = ->
- $('.rot_name').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
- type : 'text'
- onblur : 'submit'
- indicator : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
- event : 'click'
- cssclass : 'jeditable'
- placeholder : ''
- submitdata : {rot_id: $(this).attr('id'), property: 'name'}
- method : 'POST'
- callback : (value, settings) ->
- $(this).html(value)
- $('.rot_active').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
- type : 'select'
- data : {'true' : 'Yes', 'false' : 'No', 'selected' : 'true'}
- onblur : 'submit'
- indicator : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
- event : 'click'
- cssclass : 'jeditable'
- placeholder : ''
- submitdata : {rot_id: $(this).attr('id'), property: 'active'}
- method : 'POST'
- callback : (value, settings) ->
- $(this).html(value)
- $('.rot_sample').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
- type : 'text'
- onblur : 'submit'
- indicator : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
- event : 'click'
- cssclass : 'jeditable'
- placeholder : ''
- submitdata : {rot_id: $(this).attr('id'), property: 'sample'}
- method : 'POST'
- callback : (value, settings) ->
- $(this).html(value)
- $('.rot_setup').editable '{{url_for("inline_save_rot_property", study_id=study_id)}}',
- type : 'text'
- onblur : 'submit'
- indicator : '<img src="{{static("img/UI/ajax-loader.gif")}}" /'+'>'
- event : 'click'
- cssclass : 'jeditable'
- placeholder : ''
- submitdata : {rot_id: $(this).attr('id'), property: 'setup'}
- method : 'POST'
- callback : (value, settings) ->
- $(this).html(value)
- new_rotation = ->
- rot =
- id : -1
- name : 'New Rotation'
- active : false
- sample : 0
- rooms : []
- deletable : true
- add_rotation(rot, true)
- delete_rotation = (rot_id) ->
- $.ajax
- url : '{{url_for("inline_delete_rot", study_id=study_id)}}'
- dataType : 'json'
- type : 'POST'
- data : rot_id
- error : -> 'Error deleting rotation.'
- success : (json) ->
- if json.status == 'OK'
- populate_rotation_table()
- else
- alert 'Error deleting rotation: '+json.data
- get_rotation_data = (rot_id) ->
- id : id
- setup : $( '.rot_setup #' + rot_id).html()
- name : $( '.rot_name #' + rot_id).html()
- active : $( '.rot_active #' + rot_id).attr('checked')
- sample : $( '.rot_n #' + rot_id).html()
- deletable : $('.rot_deletable #' + rot_id).html() != ''
- set_rotation_data = (rot) ->
- $('.rot_name #' + rot.id).html(rot.name)
- $('.rot_active #' + rot.id).attr('checked', rot.active)
- $('.rot_n #' + rot.id).html(rot.sample)
- if rot.deletable
- $('.rot_deletable #' + rot.id).html(
- '<td><a href="javascript:void(0)"><img class="remove_rot_btn" id="' + rot.id + '"' +
- ' src="{{static("img/UI/button_cancel_16x16.png")}}" /'+'>'
- )
- else
- $('.rot_deletable #' + rot.id).html('')
- save_rotation = (rot_id) ->
- $.ajax
- url : '{{url_for("inline_save_rot", study_id=study_id)}}'
- dataType : 'json'
- type : 'POST'
- data : get_rotation_data(rot_id)
- error : -> 'Error saving rotation.'
- success : (json) ->
- if json.status == 'ERR'
- alert 'Error saving rotation: '+json.data
- populate_rotation_table = ->
- $.ajax
- url : '{{url_for("inline_rotations", study_id=study_id)}}'
- dataType : 'json'
- type : 'GET'
- error : -> 'Error loading rotations.'
- success : (json) ->
- if json.status == 'OK'
- build_rotation_table(json)
- init_rotation_editors()
- else
- alert 'Error loading rotations: '+json.data
- add_rotation = (rot, save) ->
- $(".rotation_table_body").append([
- '<tr>'
- '<td class="rot_name" id="' + rot.id + '"></td>'
- '<td class="rot_active" id="' + rot.id + '"></td>'
- '<td class="rot_sample" id="' + rot.id + '"></td>'
- '<td class="rot_setup" id="' + rot.id + '"></td>'
- '<td><a href="javascript:void(0)"><img class="remove_rot_btn" id="' + rot.id + '"'
- ' src="{{static("img/UI/button_cancel_16x16.png")}}" /'+'>'
- '</tr>'
- ].join(''))
- set_rotation_data(rot)
- if save then save_rotation(rot)
- build_rotation_table = (json) ->
- $('.rotation_table_body').html('')
- add_rotation(rot, false) for rot in json.data.rots
Add Comment
Please, Sign In to add comment