MDL-62746 tag: Convert YUI modals to AMD modals
[moodle.git] / lib / amd / build / tag.min.js
CommitLineData
65cac800 1define(["jquery","core/ajax","core/templates","core/notification","core/str","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g){return{initTagindexPage:function(){a("body").delegate(".tagarea[data-ta] a[data-quickload=1]","click",function(d){d.preventDefault();var e=a(this),f=e[0].search.replace(/^\?/,""),g=e.closest(".tagarea[data-ta]"),h=f.split("&").reduce(function(a,b){var c=b.split("=");return a[c[0]]=decodeURIComponent(c[1]),a},{}),i=b.call([{methodname:"core_tag_get_tagindex",args:{tagindex:h}}],!0);a.when.apply(a,i).done(function(a){c.render("core_tag/index",a).done(function(a){g.replaceWith(a)})})})},initManagePage:function(){a("body").on("updated","[data-inplaceeditable]",function(b){if(e.get_string("selecttag","core_tag",b.ajaxreturn.value).then(function(c){return a('label[for="tagselect'+b.ajaxreturn.itemid+'"]').html(c)}).fail(d.exception),e.get_string("now").done(function(c){a(b.target).closest("tr").find("td.col-timemodified").html(c)}),"tagflag"===b.ajaxreturn.itemtype){var c=a(b.target).closest("tr");"0"===b.ajaxreturn.value?c.removeClass("flagged-tag"):c.addClass("flagged-tag")}}),a(".tag-management-table").delegate("a.tagdelete","click",function(b){b.preventDefault();var c=a(this).attr("href");e.get_strings([{key:"delete"},{key:"confirmdeletetag",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){window.location.href=c})})}),a("#tag-management-delete").click(function(b){var c=a(this).closest("form").get(0),f=a(c).find("input[type=checkbox]:checked").length;if(f){var g=a("<input type='hidden'/>").attr("name",this.name);b.preventDefault(),e.get_strings([{key:"delete"},{key:"confirmdeletetags",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){g.appendTo(c),c.submit()})})}}),a("#tag-management-combine").click(function(b){b.preventDefault();var h=a(this).closest("form").get(0),i=a(h).find("input[type=checkbox]:checked");if(i.length<=1)return void e.get_strings([{key:"combineselected",component:"tag"},{key:"selectmultipletags",component:"tag"},{key:"ok"}]).done(function(a){d.alert(a[0],a[1],a[2])});var j=a("<input type='hidden'/>").attr("name",this.name),k="",l=[];i.each(function(){var b=a(this).val(),c=a(".inplaceeditable[data-itemtype=tagname][data-itemid="+b+"]").attr("data-value");l.push({id:b,name:c})}),e.get_strings([{key:"combineselected",component:"tag"},{key:"continue"}]).then(function(a){var b=a[0];k=a[1];var d={tags:l};return f.create({title:b,body:c.render("core_tag/combine_tags",d),type:f.types.SAVE_CANCEL})}).then(function(b){b.setSaveButtonText(k),b.getRoot().on(g.save,function(b){b.preventDefault(),j.appendTo(h);var c=a("input[name=maintag]:checked","#combinetags_form").val();a("<input type='hidden'/>").attr("name","maintag").attr("value",c).appendTo(h),h.submit()}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.show(),a("#combinetags_form input[type=radio]").first().focus().prop("checked",!0)})["catch"](d.exception)}),a("body").on("updatefailed","[data-inplaceeditable][data-itemtype=tagname]",function(b){var c=b.exception,f=b.newvalue,g=a(b.target).attr("data-itemid");"namesalreadybeeingused"===c.errorcode&&(b.preventDefault(),e.get_strings([{key:"nameuseddocombine",component:"tag"},{key:"yes"},{key:"cancel"}]).done(function(a){d.confirm(b.message,a[0],a[1],a[2],function(){window.location.href=window.location.href+"&newname="+encodeURIComponent(f)+"&tagid="+encodeURIComponent(g)+"&action=renamecombine&sesskey="+M.cfg.sesskey})}))}),a("body").on("click","a[data-action=addstandardtag]",function(b){b.preventDefault();var h="";e.get_strings([{key:"addotags",component:"tag"},{key:"continue"}]).then(function(a){var b=a[0];h=a[1];var d={actionurl:window.location.href,sesskey:M.cfg.sesskey};return f.create({title:b,body:c.render("core_tag/add_tags",d),type:f.types.SAVE_CANCEL})}).then(function(b){b.setSaveButtonText(h),b.getRoot().on(g.save,function(b){var c=a(b.currentTarget).find("#id_tagslist"),d=c.val().trim();c.val(d);var e=a("#addtags_form");return e.on("submit",function(b){var c=a("#addtags_form");c[0].checkValidity()===!1&&(b.preventDefault(),b.stopPropagation()),c.addClass("was-validated"),a('[data-region="tagslistinput"]').addClass("error");var d=a("#id_tagslist_error_message");d.removeAttr("hidden"),d.addClass("help-block")}),e.submit(),!1}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.show()})["catch"](d.exception)})},initManageCollectionsPage:function(){a("body").on("updated","[data-inplaceeditable]",function(b){var c,d,e,f=b.ajaxreturn;"core_tag"===f.component&&"tagareaenable"===f.itemtype&&(c=a(this).attr("data-itemid"),a(".tag-collections-table ul[data-collectionid] li[data-areaid="+c+"]").hide(),e=f.value,"1"===e?(a(this).closest("tr").removeClass("dimmed_text"),d=a(this).closest("tr").find('[data-itemtype="tagareacollection"]').attr("data-value"),a(".tag-collections-table ul[data-collectionid="+d+"] li[data-areaid="+c+"]").show()):a(this).closest("tr").addClass("dimmed_text")),"core_tag"===f.component&&"tagareacollection"===f.itemtype&&(c=a(this).attr("data-itemid"),a(".tag-collections-table ul[data-collectionid] li[data-areaid="+c+"]").hide(),d=a(this).attr("data-value"),e=a(this).closest("tr").find('[data-itemtype="tagareaenable"]').attr("data-value"),"1"===e&&a(".tag-collections-table ul[data-collectionid="+d+"] li[data-areaid="+c+"]").show())}),a("body").on("click",".addtagcoll > a",function(b){b.preventDefault();var h=[{key:"addtagcoll",component:"tag"},{key:"create"}],i=a(this).attr("data-url"),j="";e.get_strings(h).then(function(a){var b=a[0];j=a[1];var d={actionurl:i,sesskey:M.cfg.sesskey};return f.create({title:b,body:c.render("core_tag/add_tag_collection",d),type:f.types.SAVE_CANCEL})}).then(function(b){b.setSaveButtonText(j),b.getRoot().on(g.save,function(b){var c=a(b.currentTarget).find("#addtagcoll_name"),d=c.val().trim();c.val(d);var e=a("#addtagcoll_form");return e.on("submit",function(b){e[0].checkValidity()===!1&&(b.preventDefault(),b.stopPropagation()),e.addClass("was-validated"),a('[data-region="addtagcoll_nameinput"]').addClass("error");var c=a("#id_addtagcoll_name_error_message");c.removeAttr("hidden"),c.addClass("help-block")}),e.submit(),!1}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.show()})["catch"](d.exception)}),a("body").on("click",".tag-collections-table .action_delete",function(b){b.preventDefault();var c=a(this).attr("data-url")+"&sesskey="+M.cfg.sesskey;e.get_strings([{key:"delete"},{key:"suredeletecoll",component:"tag",param:a(this).attr("data-collname")},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){window.location.href=c})})})}}});