MDL-70438 contentbank: Display content uses before removal

This commit is contained in:
Sara Arjona 2020-12-09 14:42:39 +01:00
parent 890d0690d4
commit deeadc98d6
6 changed files with 40 additions and 8 deletions

View File

@ -1,2 +1,2 @@
define ("core_contentbank/actions",["jquery","core/ajax","core/notification","core/str","core/templates","core/url","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g,h){var k={DELETE_CONTENT:"[data-action=\"deletecontent\"]",RENAME_CONTENT:"[data-action=\"renamecontent\"]"},l=function(){this.registerEvents()};l.prototype.registerEvents=function(){a(k.DELETE_CONTENT).click(function(b){b.preventDefault();var e=a(this).data("contentname"),f=a(this).data("contentid"),j=a(this).data("contextid"),k="";d.get_strings([{key:"deletecontent",component:"core_contentbank"},{key:"deletecontentconfirm",component:"core_contentbank",param:{name:e}},{key:"delete",component:"core"}]).then(function(a){var b=a[0],c=a[1];k=a[2];return g.create({title:b,body:c,type:g.types.SAVE_CANCEL,large:!0})}).done(function(a){a.setSaveButtonText(k);a.getRoot().on(h.save,function(){return i(f,j)});a.getRoot().on(h.hidden,function(){a.destroy()});a.show()}).catch(c.exception)});a(k.RENAME_CONTENT).click(function(b){b.preventDefault();var f=a(this).data("contentname"),i=a(this).data("contentid"),k="";d.get_strings([{key:"renamecontent",component:"core_contentbank"},{key:"rename",component:"core_contentbank"}]).then(function(a){var b=a[0];k=a[1];return g.create({title:b,body:e.render("core_contentbank/renamecontent",{contentid:i,name:f}),type:g.types.SAVE_CANCEL})}).then(function(b){b.setSaveButtonText(k);b.getRoot().on(h.save,function(b){var e=a("#newname").val().trim();if(e){j(i,e)}else{d.get_strings([{key:"error"},{key:"emptynamenotallowed",component:"core_contentbank"}]).then(function(a){c.alert(a[0],a[1])}).catch(c.exception);b.preventDefault()}});b.getRoot().on(h.hidden,function(){b.destroy()});b.show()}).catch(c.exception)})};function i(a,d){var e="success";b.call([{methodname:"core_contentbank_delete_content",args:{contentids:{contentid:a}}}])[0].then(function(a){if(a.result){return"contentdeleted"}e="error";return"contentnotdeleted"}).done(function(a){var b={contextid:d};if("success"==e){b.statusmsg=a}else{b.errormsg=a}window.location.href=f.relativeUrl("contentbank/index.php",b,!1)}).fail(c.exception)}function j(a,d){var e="success";b.call([{methodname:"core_contentbank_rename_content",args:{contentid:a,name:d}}])[0].then(function(a){if(a.result){return"contentrenamed"}e="error";return a.warnings[0].message}).then(function(b){var d=null;if("success"==e){d={id:a,statusmsg:b};window.location.href=f.relativeUrl("contentbank/view.php",d,!1)}else{c.addNotification({message:b,type:"error"});c.fetchNotifications()}}).catch(c.exception)}return{init:function init(){return new l}}});
define ("core_contentbank/actions",["jquery","core/ajax","core/notification","core/str","core/templates","core/url","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g,h){var k={DELETE_CONTENT:"[data-action=\"deletecontent\"]",RENAME_CONTENT:"[data-action=\"renamecontent\"]"},l=function(){this.registerEvents()};l.prototype.registerEvents=function(){a(k.DELETE_CONTENT).click(function(b){b.preventDefault();var e=a(this).data("contentname"),f=a(this).data("uses"),j=a(this).data("contentid"),k=a(this).data("contextid"),l="";d.get_strings([{key:"deletecontent",component:"core_contentbank"},{key:"deletecontentconfirm",component:"core_contentbank",param:{name:e}},{key:"deletecontentconfirmlinked",component:"core_contentbank"},{key:"delete",component:"core"}]).then(function(a){var b=a[0],c=a[1];if(0<f){c+=" "+a[2]}l=a[3];return g.create({title:b,body:c,type:g.types.SAVE_CANCEL,large:!0})}).done(function(a){a.setSaveButtonText(l);a.getRoot().on(h.save,function(){return i(j,k)});a.getRoot().on(h.hidden,function(){a.destroy()});a.show()}).catch(c.exception)});a(k.RENAME_CONTENT).click(function(b){b.preventDefault();var f=a(this).data("contentname"),i=a(this).data("contentid"),k="";d.get_strings([{key:"renamecontent",component:"core_contentbank"},{key:"rename",component:"core_contentbank"}]).then(function(a){var b=a[0];k=a[1];return g.create({title:b,body:e.render("core_contentbank/renamecontent",{contentid:i,name:f}),type:g.types.SAVE_CANCEL})}).then(function(b){b.setSaveButtonText(k);b.getRoot().on(h.save,function(b){var e=a("#newname").val().trim();if(e){j(i,e)}else{d.get_strings([{key:"error"},{key:"emptynamenotallowed",component:"core_contentbank"}]).then(function(a){c.alert(a[0],a[1])}).catch(c.exception);b.preventDefault()}});b.getRoot().on(h.hidden,function(){b.destroy()});b.show()}).catch(c.exception)})};function i(a,d){var e="success";b.call([{methodname:"core_contentbank_delete_content",args:{contentids:{contentid:a}}}])[0].then(function(a){if(a.result){return"contentdeleted"}e="error";return"contentnotdeleted"}).done(function(a){var b={contextid:d};if("success"==e){b.statusmsg=a}else{b.errormsg=a}window.location.href=f.relativeUrl("contentbank/index.php",b,!1)}).fail(c.exception)}function j(a,d){var e="success";b.call([{methodname:"core_contentbank_rename_content",args:{contentid:a,name:d}}])[0].then(function(a){if(a.result){return"contentrenamed"}e="error";return a.warnings[0].message}).then(function(b){var d=null;if("success"==e){d={id:a,statusmsg:b};window.location.href=f.relativeUrl("contentbank/view.php",d,!1)}else{c.addNotification({message:b,type:"error"});c.fetchNotifications()}}).catch(c.exception)}return{init:function init(){return new l}}});
//# sourceMappingURL=actions.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,7 @@ function($, Ajax, Notification, Str, Templates, Url, ModalFactory, ModalEvents)
e.preventDefault();
var contentname = $(this).data('contentname');
var contentuses = $(this).data('uses');
var contentid = $(this).data('contentid');
var contextid = $(this).data('contextid');
@ -72,6 +73,10 @@ function($, Ajax, Notification, Str, Templates, Url, ModalFactory, ModalEvents)
name: contentname,
}
},
{
key: 'deletecontentconfirmlinked',
component: 'core_contentbank',
},
{
key: 'delete',
component: 'core'
@ -82,7 +87,10 @@ function($, Ajax, Notification, Str, Templates, Url, ModalFactory, ModalEvents)
Str.get_strings(strings).then(function(langStrings) {
var modalTitle = langStrings[0];
var modalContent = langStrings[1];
deleteButtonText = langStrings[2];
if (contentuses > 0) {
modalContent += ' ' + langStrings[2];
}
deleteButtonText = langStrings[3];
return ModalFactory.create({
title: modalTitle,

View File

@ -22,6 +22,7 @@ Feature: Delete H5P file from the content bank
And I click on "Choose a file..." "button"
And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "filltheblanks.h5p" "link"
And I set the field "Save as" to "content2delete.h5p"
And I click on "Select this file" "button"
And I click on "Save changes" "button"
@ -29,15 +30,16 @@ Feature: Delete H5P file from the content bank
Given I open the action menu in "region-main-settings-menu" "region"
And I should see "Delete"
When I choose "Delete" in the open action menu
And I should see "Are you sure you want to delete the content 'filltheblanks.h5p'"
And I should see "Are you sure you want to delete the content 'content2delete.h5p'"
And I should not see "The content will only be deleted from the content bank"
And I click on "Cancel" "button" in the "Delete content" "dialogue"
Then I should see "filltheblanks.h5p"
Then I should see "content2delete.h5p"
And I open the action menu in "region-main-settings-menu" "region"
And I choose "Delete" in the open action menu
And I click on "Delete" "button" in the "Delete content" "dialogue"
And I wait until the page is ready
And I should see "The content has been deleted."
And I should not see "filltheblanks.h5p"
And I should not see "content2delete.h5p"
Scenario: Users without the required capability can only delete their own content
Given the following "permission overrides" exist:
@ -56,8 +58,8 @@ Feature: Delete H5P file from the content bank
And I click on "Save changes" "button"
When I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Content bank" "link" in the "Navigation" "block"
And I should see "filltheblanks.h5p"
And I follow "filltheblanks.h5p"
And I should see "content2delete.h5p"
And I follow "content2delete.h5p"
Then ".header-actions-container" "css_element" should not exist
And I click on "Content bank" "link"
And I click on "Upload" "link"
@ -68,3 +70,23 @@ Feature: Delete H5P file from the content bank
And I click on "Save changes" "button"
And I open the action menu in "region-main-settings-menu" "region"
And I should see "Delete"
Scenario: The number of times a content is used is displayed before removing it
Given I follow "Dashboard" in the user menu
And I follow "Manage private files..."
And I click on "Add..." "button"
And I select "Content bank" repository in file picker
And I click on "content2delete.h5p" "file" in repository content area
And I click on "Link to the file" "radio"
And I click on "Select this file" "button"
And I click on "Save changes" "button"
When I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Content bank" "link" in the "Navigation" "block"
And I follow "content2delete.h5p"
And I open the action menu in "region-main-settings-menu" "region"
And I choose "Delete" in the open action menu
Then I should see "Are you sure you want to delete the content 'content2delete.h5p'"
And I should see "The content will only be deleted from the content bank"
And I click on "Delete" "button" in the "Delete content" "dialogue"
And I should see "The content has been deleted."
And I should not see "content2delete.h5p"

View File

@ -103,6 +103,7 @@ if ($contenttype->can_delete($content)) {
$attributes = [
'data-action' => 'deletecontent',
'data-contentname' => $content->get_name(),
'data-uses' => count($content->get_uses()),
'data-contentid' => $content->get_id(),
'data-contextid' => $context->id,
];

View File

@ -45,6 +45,7 @@ $string['errordeletingcontentfromcategory'] = 'Error deleting content from categ
$string['errornofile'] = 'A compatible file is needed to create content.';
$string['deletecontent'] = 'Delete content';
$string['deletecontentconfirm'] = 'Are you sure you want to delete the content <em>\'{$a->name}\'</em> and all associated files? This action cannot be undone.';
$string['deletecontentconfirmlinked'] = 'The content will only be deleted from the content bank. Any places which currently link to it will be automatically updated to use a copy of the content instead.';
$string['displaydetails'] = 'Display content bank with file details';
$string['displayicons'] = 'Display content bank with icons';
$string['file'] = 'Upload content';