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 lines
3.6 KiB

define(["jquery","core/templates","core/config","format_tiles/completion"],function(a,b,c){"use strict";var d,e={},f={cmid:"data-cmid",numberComplete:"data-numcomplete",numberOutOf:"data-numoutof",section:"data-section"},g={launchModuleModal:'[data-action="launch-tiles-module-modal"]',launchResourceModal:'[data-action="launch-tiles-resource-modal"]',pageContent:"#page-content",regionMain:"#region-main",resourceModule:".activity.resource",completeonevent:".completeonevent",completeonview:".completeonview",activity:"li.activity",section:"li.section.main",togglecompletion:"form.togglecompletion"},h={completionYes:"completion-icon-y",completionNo:"completion-icon-n"},i=[],j=function(a,b,c,d){var e={tileid:a,numComplete:b,numOutOf:c,showAsPercent:d,percent:Math.round(b/c*100),percentCircumf:106.8,percentOffset:Math.round((c-b)/c*106.8),isComplete:!1,isSingleDigit:!1};return 0===a?e.isOverall=1:e.isOverall=0,b>=c&&(e.isComplete=!0),e.percent<10&&(e.isSingleDigit=!0),e},k=function(c,d,e){if(!(0===d.attr(f.numberComplete)&&e<0)){var g=Math.min(parseInt(d.attr(f.numberComplete))+e,d.attr(f.numberOutOf)),h=a("#tileprogress-0"),i=Math.min(parseInt(h.attr(f.numberComplete))+e,h.attr(f.numberOutOf));b.render("format_tiles/progress",j(c,g,d.attr(f.numberOutOf),d.hasClass("percent"))).done(function(b){d.replaceWith(b),a("#tileprogress-"+c).tooltip()}),b.render("format_tiles/progress",j(0,i,h.attr(f.numberOutOf),!0)).done(function(b){a("#tileprogress-0").replaceWith(b).fadeOut(0).animate({opacity:1},500)})}},l=function(b){var e=b.attr(f.cmid),j=a("#completionstate_"+e),l={id:e,completionstate:parseInt(j.attr("value")),fromajax:1,sesskey:c.sesskey};b.tooltip("hide");var m=c.wwwroot+"/course/togglecompletion.php";a.post(m,l,function(c,l){if("success"===l&&"OK"===c){var m,n=a(".completion_img_"+e);"1"===j.attr("value")?(a("#completion_dynamic_change").attr("value",0),j.attr("value",0),m=1,n.addClass(h.completionYes).removeClass(h.completionNo),a(".complete-y-"+e).fadeIn(200).fadeOut(1e3)):(a("#completion_dynamic_change").attr("value",1),j.attr("value",1),m=-1,a(".complete-n-"+e).fadeIn(200).fadeOut(1e3),n.addClass(h.completionNo).removeClass(h.completionYes)),j.closest(g.activity).is(i.map(function(a){return"."+a}).join(","))||(k(b.attr(f.section),a("#tileprogress-"+b.attr(f.section)),m),require(["format_tiles/browser_storage"],function(a){a.storeCourseContent(d,b.attr("data-section"),"")}))}}).fail(function(){throw new Error("Failed to register completion change with server")})},m=function(b){var c=b.closest(g.section).attr("data-section");if(b.hasClass("completeonview")){var f=b.find(".completion-icon"),i=f.closest(".completioncheckbox");"0"===i.attr("data-ismanual")&&"0"===i.attr("data-completionstate")&&(f.addClass(h.completionYes).removeClass(h.completionNo),i.attr("data-completionstate",1),i.attr("data-original-title",e.completeauto),i.tooltip(),k(c,a("#tileprogress-"+c),1))}require(["format_tiles/browser_storage"],function(a){a.storeCourseContent(d,c,"")})};return{init:function(b,c,f){d=b,a(document).ready(function(){i=JSON.parse(f),e.completeauto=c,a("body").on("click",g.togglecompletion,function(b){b.preventDefault(),l(a(b.currentTarget))});var b=a("#page-content");0===b.length&&(b=a("#region-main")),b.on("click",g.launchModuleModal+", "+g.launchResourceModal,function(b){var c=a(b.currentTarget).closest(g.activity);c.hasClass("completeonview")&&m(c)}),a(g.pageContent).on("click",g.completeonevent+", "+g.completeonview,function(b){var c=a(b.currentTarget).closest(g.section).attr("data-section");require(["format_tiles/browser_storage"],function(a){a.storeCourseContent(d,c,"")})})})},markAsAutoCompleteInUI:function(a,b){d=a,m(b)}}});