on-demand release 4.0dev+
[moodle.git] / contentbank / amd / build / actions.min.js
CommitLineData
3776fbaf 1define ("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 l={DELETE_CONTENT:"[data-action=\"deletecontent\"]",RENAME_CONTENT:"[data-action=\"renamecontent\"]",SET_CONTENT_VISIBILITY:"[data-action=\"setcontentvisibility\"]"},m=function(){this.registerEvents()};m.prototype.registerEvents=function(){a(l.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(l.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)});a(l.SET_CONTENT_VISIBILITY).click(function(b){b.preventDefault();var c=a(this).data("contentid"),d=a(this).data("visibility");k(c,d)})};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)}function k(a,d){var e="success";b.call([{methodname:"core_contentbank_set_content_visibility",args:{contentid:a,visibility:d}}])[0].then(function(a){if(a.result){return"contentvisibilitychanged"}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 m}}});
45192e9a 2//# sourceMappingURL=actions.min.js.map