gitlab-org--gitlab-foss/app/assets/javascripts/compare.js.coffee

68 lines
1.8 KiB
CoffeeScript
Raw Normal View History

class @Compare
constructor: (@opts) ->
@source_loading = $ ".js-source-loading"
@target_loading = $ ".js-target-loading"
2016-03-29 06:11:16 -04:00
$('.js-compare-dropdown').each (i, dropdown) =>
$dropdown = $(dropdown)
2016-03-29 06:11:16 -04:00
$dropdown.glDropdown(
selectable: true
fieldName: $dropdown.data 'field-name'
2016-03-29 06:51:13 -04:00
filterable: true
2016-03-29 06:11:16 -04:00
id: (obj, $el) ->
$el.data 'id'
toggleLabel: (obj, $el) ->
$el.text().trim()
clicked: (e, el) =>
if $dropdown.is '.js-target-branch'
@getTargetHtml()
else if $dropdown.is '.js-source-branch'
@getSourceHtml()
else if $dropdown.is '.js-target-project'
@getTargetProject()
)
2016-03-29 06:11:16 -04:00
@initialState()
initialState: ->
@getSourceHtml()
@getTargetHtml()
getTargetProject: ->
2016-03-29 07:43:33 -04:00
$.ajax(
url: @opts.targetProjectUrl
data:
target_project_id: $("input[name='merge_request[target_project_id]']").val()
beforeSend: ->
$('.mr_target_commit').empty()
success: (html) ->
$('.js-target-branch-dropdown .dropdown-content').html html
)
getSourceHtml: ->
2016-03-29 07:43:33 -04:00
@sendAjax(@opts.sourceBranchUrl, @source_loading, '.mr_source_commit',
ref: $("input[name='merge_request[source_branch]']").val()
)
getTargetHtml: ->
2016-03-29 07:43:33 -04:00
@sendAjax(@opts.targetBranchUrl, @target_loading, '.mr_target_commit',
target_project_id: $("input[name='merge_request[target_project_id]']").val()
ref: $("input[name='merge_request[target_branch]']").val()
)
sendAjax: (url, loading, target, data) ->
$target = $(target)
$.ajax(
2016-03-29 07:43:33 -04:00
url: url
data: data
beforeSend: ->
loading.show()
$target.empty()
success: (html) ->
loading.hide()
$target.html html
$('.js-timeago', $target).timeago()
)