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