Front-end work for duplicating components on the unit page.

STUD-1186
This commit is contained in:
cahrens
2014-01-16 16:09:46 -05:00
parent 58e6f60ebf
commit b5726a6889
13 changed files with 262 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
define ["backbone", "jquery", "underscore", "gettext", "xblock/runtime.v1",
"js/views/feedback_notification", "js/views/metadata", "js/collections/metadata"
"js/utils/modal", "jquery.inputnumber", "xmodule"],
"js/utils/modal", "jquery.inputnumber", "xmodule", "coffee/src/main"],
(Backbone, $, _, gettext, XBlock, NotificationView, MetadataView, MetadataCollection, ModalUtils) ->
class ModuleEdit extends Backbone.View
tagName: 'li'
@@ -62,7 +62,7 @@ define ["backbone", "jquery", "underscore", "gettext", "xblock/runtime.v1",
changedMetadata: ->
return _.extend(@metadataEditor.getModifiedMetadataValues(), @customMetadata())
createItem: (parent, payload) ->
createItem: (parent, payload, callback=->) ->
payload.parent_locator = parent
$.postJSON(
@model.urlRoot
@@ -71,7 +71,7 @@ define ["backbone", "jquery", "underscore", "gettext", "xblock/runtime.v1",
@model.set(id: data.locator)
@$el.data('locator', data.locator)
@render()
)
).success(callback)
render: ->
if @model.id

View File

@@ -13,6 +13,7 @@ define ["jquery", "jquery.ui", "gettext", "backbone",
'click .create-draft': 'createDraft'
'click .publish-draft': 'publishDraft'
'change .visibility-select': 'setVisibility'
"click .component-actions .duplicate-button": 'duplicateComponent'
initialize: =>
@visibilityView = new UnitEditView.Visibility(
@@ -86,7 +87,7 @@ define ["jquery", "jquery.ui", "gettext", "backbone",
@$newComponentItem.removeClass('adding')
@$newComponentItem.find('.rendered-component').remove()
saveNewComponent: (event) =>
createComponent: (event, data, message, success_callback) =>
event.preventDefault()
editor = new ModuleEditView(
@@ -94,20 +95,52 @@ define ["jquery", "jquery.ui", "gettext", "backbone",
model: new ModuleModel()
)
@$newComponentItem.before(editor.$el)
notification = new NotificationView.Mini
title: gettext(message) + '…'
notification.show()
callback = ->
notification.hide()
success_callback()
analytics.track message,
course: course_location_analytics
unit_id: unit_location_analytics
type: editor.$el.data('locator')
editor.createItem(
@$el.data('locator'),
$(event.currentTarget).data()
data,
callback
)
analytics.track "Added a Component",
course: course_location_analytics
unit_id: unit_location_analytics
type: $(event.currentTarget).data('location')
return editor
saveNewComponent: (event) =>
success_callback = =>
@$newComponentItem.before(editor.$el)
editor = @createComponent(
event, $(event.currentTarget).data(),
"Adding",
success_callback
)
@closeNewComponent(event)
duplicateComponent: (event) =>
$component = $(event.currentTarget).parents('.component')
source_locator = $component.data('locator')
success_callback = ->
$component.after(editor.$el)
$('html, body').animate({
scrollTop: editor.$el.offset().top
}, 500)
editor = @createComponent(
event,
{duplicate_source_locator: source_locator},
"Duplicating",
success_callback
)
components: => @$('.component').map((idx, el) -> $(el).data('locator')).get()
wait: (value) =>