You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
5.0 KiB
1 line
5.0 KiB
2 years ago
|
define(["jquery","core/templates","core/ajax","core/str","core/notification","core/config"],function(a,b,c,d,e,f){"use strict";var g,h={pickAnIcon:""},i=[],j=[],k=function(b,d){var e=c.call([{methodname:"format_tiles_get_icon_set",args:{courseid:b}}]);e[0].done(function(b){b.photos&&(j=JSON.parse(b.photos));var c=JSON.parse(b.icons);Object.keys(c).forEach(function(a){i.push({filename:a,displayname:c[a]})}),i.length<=0&&require(["core/log"],function(a){a.error("Error empty icon set"),a.debug(b)}),"function"==typeof d&&d();var e=j.map(function(a){return a.filename});a("#iconpickerphotos").find(".photo").each(function(b,c){c=a(c),e.indexOf(c.attr("data-filename"))===-1&&c.fadeOut(500)}),b.status!==!0&&require(["core/log"],function(a){a.error("Non true status response when getting icon set"),a.debug(b)})}),e[0].fail(function(a){require(["core/log"],function(b){b.error("Fail when getting icon set"),b.debug(a)})})},l=function(a,b){return f.wwwroot+"/course/format/tiles/editimage.php?courseid="+a+"§ionid="+b},m=function(f,g,h,i,j,m,n,o,p){var q=a("#selectedicon"),r=function(c,d,e){var i="",n={tileicon:h,tileid:g,secid:f,isediting:1};switch(e){case"tileicon":i="tileicon";break;case"tilephoto":i="tilebarphoto",n.phototileurl=d,n.phototileediturl=l(m,f),n.iamgetype=e,c.closest(".tileiconcontainer").addClass("hasphoto"),setTimeout(function(){k(m)},3e3);break;case"draftfile":i="tilebarphoto",n.phototileurl=d,n.phototileediturl=l(m,f),n.iamgetype=e;break;default:throw new Error("Invalid image type "+e)}var o="course-view-tiles"===j?c:q;o.animate({opacity:0},500,function(){b.render("format_tiles/"+i,n).done(function(a){o.html(a).animate({opacity:1},500)})}),"course-editsection"===j&&"tilephoto"===e&&a("input[name=tilephoto]").val(h)},s={image:h,courseid:m,sectionid:f,imagetype:n,sourcecontextid:void 0===o?0:o,sourceitemid:void 0===p?0:p},t=c.call([{methodname:"format_tiles_set_image",args:s}]);t[0].done(function(c){if(c.status===!0)if("course-view-tiles"===j)r(a("#tileicon_"+g),c.imageurl,n);else if("course-edit"===j||"course-editsection"===j){var f=a("#id_defaulttileicon");"course-editsection"===j&&(f=a("#id_tileicon")),f.val(h),"tileicon"===n?(b.renderPix("tileicon/"+h,"format_tiles",i).done(function(a){q.html(a),"course-editsection"===j&&d.get_strings([{key:"tip",component:"format_tiles"},{key:"tileselecttip",component:"format_tiles"}]).done(function(a){e.alert(a[0],a[1])})}),"course-editsection"===j&&a("input[name=tilephoto]").val("")):"tilephoto"===n&&r(a("#tileicon_"+g),c.imageurl,n)}}).fail(function(a){require(["core/log"],function(b){b.error("Fail setting icon"),b.debug(a)})})},n=function(c,d,e,n,o,p){var q=function(b,e,f){var g=a("#iconpickerphotos");g.html(b);var h=2e5,i=[];g.find("img").each(function(b,g){g=a(g),g.attr("data-filesize")<h?setTimeout(function(){g.attr("src",g.attr("data-url"))},20*b):i.push(g),g.click(function(b){var g=a(b.currentTarget);m(e.attr("data-sectionid"),e.attr("data-section"),g.attr("data-filename"),g.attr("data-filename"),c,d,g.attr("data-imagetype"),g.attr("data-contextid"),g.attr("data-itemid")),f.hide()})}),setTimeout(function(){i.forEach(function(a){a.attr("src",a.attr("data-url"))})},1e3)};if("object"!=typeof g){var r=function(){b.render("format_tiles/icon_picker_modal_body",{icon_picker_icons:i,photosallowed:o,wwwroot:f.wwwroot,documentationurl:p}).done(function(i){require(["core/modal_factory"],function(k){k.create({type:k.types.DEFAULT,title:h.pickAnIcon,body:i}).done(function(h){g=h,h.setLarge(),h.show();var i=a(h.root);i.attr("id","icon_picker_modal"),i.attr("data-sectionid",e),i.attr("data-section",n),i.addClass("icon_picker_modal"),i.on("click",".pickericon",function(b){var f=a(b.currentTarget);m(e,n,f.attr("data-icon"),f.attr("title"),c,d,"tileicon",f.attr("data-contextid"),f.attr("data-itemid")),h.hide()}),i.on("input","input.iconsearch",function(b){var c=b.currentTarget.value.toLowerCase();i.find(".pickericon").show(),c.length>=3&&i.find(".pickericon").filter(function(b,d){return a(d).attr("data-original-title").toLowerCase().indexOf(c)<0}).hide()});try{a(".pickericon").tooltip
|