MDL-61133 core_question: add new question tags modal
[moodle.git] / question / amd / build / edit_tags.min.js
blob859ba137d2881ce94d442e5e8e618dec526dd2f6
1 define(["jquery","core/fragment","core/str","core/modal_events","core/modal_factory","core/notification","core/custom_interaction_events","core_question/repository"],function(a,b,c,d,e,f,g,h){var i={TAGS_LINK:'[data-action="edittags"]',SAVE_BUTTON:'[data-action="save"]',LOADING_ICON:'[data-region="overlay-icon-container"]'},j=function(a){a.find(i.SAVE_BUTTON).prop("disabled",!1)},k=function(a){a.find(i.SAVE_BUTTON).prop("disabled",!0)},l=function(a){return a.getBody().find("form").serialize()},m=function(a){var b=a.find(i.LOADING_ICON);b.removeClass("hidden")},n=function(a){var b=a.find(i.LOADING_ICON);b.addClass("hidden")},o=function(h){var l=e.create({type:e.types.SAVE_CANCEL,large:!1},[h,i.TAGS_LINK]).then(function(a){return c.get_string("questiontags","question").then(function(b){return a.setTitle(b),b}).fail(f.exception),a.getRoot().on(d.save,function(b){var c=a.getBody().find("form");c.submit(),b.preventDefault()}),a.getRoot().on("submit","form",function(b){p(a,h).then(function(){a.hide()}).fail(f.exception),b.preventDefault(),b.stopPropagation()}),a});h.on(g.events.activate,i.TAGS_LINK,function(c){var d=a(c.currentTarget),e=d.data("questionid"),g=!!d.data("canedit"),o=d.data("contextid");l.then(function(a){k(h),m(h);var c={id:e},d=b.loadFragment("question","tags_form",o,c);return a.setBody(d),d.then(function(){j(h)}).always(function(){n(h)}).fail(f.exception),g?a.getRoot().find(i.SAVE_BUTTON).show():a.getRoot().find(i.SAVE_BUTTON).hide(),a}).fail(f.exception),c.preventDefault()})},p=function(a,b){k(b),m(b);var c=l(a);return h.submitTagCreateUpdateForm(c).always(function(){n(b),j(b)}).fail(f.exception)};return{init:function(b){b=a(b),o(b)}}});