Add duplicate functionality for unit, sub-section and section - TNL-5797, TNL-5798

This commit is contained in:
Mushtaq Ali
2016-11-04 17:46:38 +05:00
parent dc8d020e30
commit a31a728a95
10 changed files with 263 additions and 68 deletions

View File

@@ -1,10 +1,12 @@
/**
* Provides utilities for views to work with xblocks.
*/
define(['jquery', 'underscore', 'gettext', 'common/js/components/utils/view_utils', 'js/utils/module'],
function($, _, gettext, ViewUtils, ModuleUtils) {
var addXBlock, deleteXBlock, createUpdateRequestData, updateXBlockField, VisibilityState,
getXBlockVisibilityClass, getXBlockListTypeClass, updateXBlockFields;
define(['jquery', 'underscore', 'gettext', 'common/js/components/utils/view_utils', 'js/utils/module',
'edx-ui-toolkit/js/utils/string-utils'],
function($, _, gettext, ViewUtils, ModuleUtils, StringUtils) {
'use strict';
var addXBlock, duplicateXBlock, deleteXBlock, createUpdateRequestData, updateXBlockField, VisibilityState,
getXBlockVisibilityClass, getXBlockListTypeClass, updateXBlockFields, getXBlockType;
/**
* Represents the possible visibility states for an xblock:
@@ -65,6 +67,30 @@ define(['jquery', 'underscore', 'gettext', 'common/js/components/utils/view_util
});
};
/**
* Duplicates the specified xblock element in its parent xblock.
* @param {jquery Element} xblockElement The xblock element to be duplicated.
* @param {jquery Element} parentElement Parent element of the xblock element to be duplicated,
* new duplicated xblock would be placed under this xblock.
* @returns {jQuery promise} A promise representing the duplication of the xblock.
*/
duplicateXBlock = function(xblockElement, parentElement) {
return ViewUtils.runOperationShowingMessage(gettext('Duplicating'),
function() {
var duplicationOperation = $.Deferred();
$.postJSON(ModuleUtils.getUpdateUrl(), {
duplicate_source_locator: xblockElement.data('locator'),
parent_locator: parentElement.data('locator')
}, function(data) {
duplicationOperation.resolve(data);
})
.fail(function() {
duplicationOperation.reject();
});
return duplicationOperation.promise();
});
};
/**
* Deletes the specified xblock.
* @param xblockInfo The model for the xblock to be deleted.
@@ -87,9 +113,9 @@ define(['jquery', 'underscore', 'gettext', 'common/js/components/utils/view_util
);
},
messageBody;
xblockType = xblockType || 'component';
messageBody = interpolate(
gettext('Deleting this %(xblock_type)s is permanent and cannot be undone.'),
xblockType = xblockType || 'component'; // eslint-disable-line no-param-reassign
messageBody = StringUtils.interpolate(
gettext('Deleting this {xblock_type} is permanent and cannot be undone.'),
{xblock_type: xblockType},
true
);
@@ -97,14 +123,14 @@ define(['jquery', 'underscore', 'gettext', 'common/js/components/utils/view_util
if (xblockInfo.get('is_prereq')) {
messageBody += ' ' + gettext('Any content that has listed this content as a prerequisite will also have access limitations removed.'); // eslint-disable-line max-len
ViewUtils.confirmThenRunOperation(
interpolate(
gettext('Delete this %(xblock_type)s (and prerequisite)?'),
StringUtils.interpolate(
gettext('Delete this {xblock_type} (and prerequisite)?'),
{xblock_type: xblockType},
true
),
messageBody,
interpolate(
gettext('Yes, delete this %(xblock_type)s'),
StringUtils.interpolate(
gettext('Yes, delete this {xblock_type}'),
{xblock_type: xblockType},
true
),
@@ -112,14 +138,14 @@ define(['jquery', 'underscore', 'gettext', 'common/js/components/utils/view_util
);
} else {
ViewUtils.confirmThenRunOperation(
interpolate(
gettext('Delete this %(xblock_type)s?'),
StringUtils.interpolate(
gettext('Delete this {xblock_type}?'),
{xblock_type: xblockType},
true
),
messageBody,
interpolate(
gettext('Yes, delete this %(xblock_type)s'),
StringUtils.interpolate(
gettext('Yes, delete this {xblock_type}'),
{xblock_type: xblockType},
true
),
@@ -217,6 +243,7 @@ define(['jquery', 'underscore', 'gettext', 'common/js/components/utils/view_util
return {
'VisibilityState': VisibilityState,
'addXBlock': addXBlock,
duplicateXBlock: duplicateXBlock,
'deleteXBlock': deleteXBlock,
'updateXBlockField': updateXBlockField,
'getXBlockVisibilityClass': getXBlockVisibilityClass,