diff --git a/amd/build/custom.min.js b/amd/build/custom.min.js index 3d36733..0fe6e1b 100644 --- a/amd/build/custom.min.js +++ b/amd/build/custom.min.js @@ -1,2 +1,2 @@ -define(["jquery"],function(l){return{initialise:function(){l(document).ready(function(){var e=l("#region-main"),t=l("#add_notification_wrapper_id"),s={save:"Save",update:"Update",req:"Required...",preview:"Preview",title:"Title",message:"Message"};e.on("click",".notifications_table tr > td > form > button[type=submit]",function(e){e.preventDefault();var n={call:"ajax",purpose:"",tableaction:"",blockid:""},i=l(this).closest("form").attr("data-edit"),e=l(this).closest("form").attr("data-delete");n.blockid=l(this).closest("form").find("[name=blockid]")[0].value,d(),void 0!==i&&!1!==i?(n.purpose="edit",n.tableaction=i,(i=l("#add_notification_save")).addClass("update"),i.val(s.update)):void 0!==e&&!1!==e&&(n.purpose="delete",n.tableaction=e);e=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;l.post(e,n).fail(function(){console.error("No 'manage' response received.")}).done(function(e){if(e=JSON.parse(e),0'),l("#add_notification_purpose").val("update")),t=l("#add_notification_wrapper_id").find("#add_notification_"+i),"enabled"!==i&&"global"!==i&&"dismissible"!==i&&"aicon"!==i||1!=e[i]?"enabled"!==i&&"global"!==i&&"dismissible"!==i&&"aicon"!==i||0!=e[i]?t.val(e[i]):t.prop("checked",!1):t.prop("checked",!0))}o()}})}),e.on("click",".notifications_restore_table tr > td > form > button[type=submit]",function(e){e.preventDefault();var i={call:"ajax",purpose:"",tableaction:"",blockid:""},t=l(this).closest("form").attr("data-restore"),e=l(this).closest("form").attr("data-permdelete");i.blockid=l(this).closest("form").find("[name=blockid]")[0].value,void 0!==t&&!1!==t?(i.purpose="restore",i.tableaction=t):void 0!==e&&!1!==e&&(i.purpose="permdelete",i.tableaction=e);e=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;l.post(e,i).fail(function(){console.error("No 'restore/permdelete' response received.")}).done(function(e){e=JSON.parse(e),0'+s.req+"").insertAfter(t[0].nextSibling));o.hide()}).done(function(){o.find(".saving").hide(),o.find(".done").show(),c(),setTimeout(function(){o.fadeOut(function(){o.find(".done").hide(),o.find(".saving").show()})},1500),l("#advnotifications_table_wrapper").load("# #advnotifications_table_wrapper > *")}))}),t.on("input propertychange paste","#add_notification_title, #add_notification_message",function(){o()}),l("#add_notification_type").on("change",function(){o()}),l("#add_notification_dismissible").on("change",function(){o()}),l("#add_notification_aicon").on("change",function(){o()});var i,n,o=function(){var e=t.find("#add_notification_title");0 img").attr("src",M.util.image_url(e,"block_advnotifications")),l("#add_notification_dismissible")[0].checked?(l(".preview-alert-dismissible").show(),i.addClass("dismissible")):(l(".preview-alert-dismissible").hide(),i.removeClass("dismissible")),l("#add_notification_aicon")[0].checked?(l(".preview-aicon").show(),i.addClass("aicon")):(l(".preview-aicon").hide(),i.removeClass("aicon"))},a=function(){var e=l("#notification_preview_wrapper"),i='
'+s.preview+'
'+s.title+'
'+s.message+'
';0'+s.req+"").insertAfter(l(i[e]).closest("select")[0].nextSibling),!1;return!0},d=function(){l("select.requiredfield").removeClass("requiredfield"),l("strong.requiredfield").remove()},c=function(){l("#add_notification_form")[0].reset(),d(),a();var e=l("#add_notification_save");e.removeClass("update"),l("#add_notification_id").remove(),l("#add_notification_purpose").val("add"),e.val(s.save)};i={call:"ajax",purpose:"strings"},n=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey,l.post(n,i).fail(function(){console.error("No 'strings' response received.")}).done(function(e){s=e}).always(function(){a()}),l("#add_notification_form").append('')})}}}); -//# sourceMappingURL=custom.min.js.map \ No newline at end of file +function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("block_advnotifications/custom",["jquery"],function(a){return{initialise:function initialise(){a(document).ready(function(){var b=a("#region-main"),c=a("#add_notification_wrapper_id"),d={save:"Save",update:"Update",req:"Required...",preview:"Preview",title:"Title",message:"Message"};b.on("click",".notifications_table tr > td > form > button[type=submit]",function(b){b.preventDefault();var c={call:"ajax",purpose:"",tableaction:"",blockid:""},g=a(this).closest("form").attr("data-edit"),j=a(this).closest("form").attr("data-delete");c.blockid=a(this).closest("form").find("[name=blockid]")[0].value;h();if(_typeof(g)!=="undefined"&&!1!==g){c.purpose="edit";c.tableaction=g;var k=a("#add_notification_save");k.addClass("update");k.val(d.update)}else if(_typeof(j)!=="undefined"&&!1!==j){c.purpose="delete";c.tableaction=j}var l=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;a.post(l,c).fail(function(){console.error("No 'manage' response received.")}).done(function(b){b=JSON.parse(b);if(0");a("#add_notification_purpose").val("update")}var h=a("#add_notification_wrapper_id").find("#add_notification_"+d);if(("enabled"===d||"global"===d||"dismissible"===d||"aicon"===d||"sendnotifications"===d)&&1==b[d]){h.prop("checked",!0)}else if(("enabled"===d||"global"===d||"dismissible"===d||"aicon"===d||"sendnotifications"===d)&&0==b[d]){h.prop("checked",!1)}else{h.val(b[d])}}}e()}})});b.on("click",".notifications_restore_table tr > td > form > button[type=submit]",function(b){b.preventDefault();var c={call:"ajax",purpose:"",tableaction:"",blockid:""},d=a(this).closest("form").attr("data-restore"),e=a(this).closest("form").attr("data-permdelete");c.blockid=a(this).closest("form").find("[name=blockid]")[0].value;if(_typeof(d)!=="undefined"&&!1!==d){c.purpose="restore";c.tableaction=d}else if(_typeof(e)!=="undefined"&&!1!==e){c.purpose="permdelete";c.tableaction=e}var f=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;a.post(f,c).fail(function(){console.error("No 'restore/permdelete' response received.")}).done(function(b){b=JSON.parse(b);if(0"+d.req+"").insertAfter(h[0].nextSibling)}}c.hide()}).done(function(){c.find(".saving").hide();c.find(".done").show();i();setTimeout(function(){c.fadeOut(function(){c.find(".done").hide();c.find(".saving").show()})},1500);a("#advnotifications_table_wrapper").load("# #advnotifications_table_wrapper > *")})});c.on("input propertychange paste","#add_notification_title, #add_notification_message",function(){e()});a("#add_notification_type").on("change",function(){e()});a("#add_notification_dismissible").on("change",function(){e()});a("#add_notification_aicon").on("change",function(){e()});var e=function(){var b=c.find("#add_notification_title");if(0 img").attr("src",M.util.image_url(f,"block_advnotifications"));if(!a("#add_notification_dismissible")[0].checked){a(".preview-alert-dismissible").hide();g.removeClass("dismissible")}else{a(".preview-alert-dismissible").show();g.addClass("dismissible")}if(!a("#add_notification_aicon")[0].checked){a(".preview-aicon").hide();g.removeClass("aicon")}else{a(".preview-aicon").show();g.addClass("aicon")}},f=function(){var b=a("#notification_preview_wrapper"),e="
"+d.preview+"
"+d.title+"
"+d.message+"
×
";if(0"+d.req+"").insertAfter(a(b[c]).closest("select")[0].nextSibling);return!1}}}return!0},h=function(){a("select.requiredfield").removeClass("requiredfield");a("strong.requiredfield").remove()},i=function(){a("#add_notification_form")[0].reset();h();f();var b=a("#add_notification_save");b.removeClass("update");a("#add_notification_id").remove();a("#add_notification_purpose").val("add");b.val(d.save)};(function init(){var b=M.cfg.wwwroot+"/blocks/advnotifications/pages/process.php?sesskey="+M.cfg.sesskey;a.post(b,{call:"ajax",purpose:"strings"}).fail(function(){console.error("No 'strings' response received.")}).done(function(a){d=a}).always(function(){f()});a("#add_notification_form").append("")})()})}}}); +//# sourceMappingURL=custom.min.js.map diff --git a/amd/build/custom.min.js.map b/amd/build/custom.min.js.map index 8a1cb0a..33af344 100644 --- a/amd/build/custom.min.js.map +++ b/amd/build/custom.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/custom.js"],"names":["define","$","initialise","document","ready","mainregion","addregion","strings","save","update","req","preview","title","message","on","e","preventDefault","senddata","call","purpose","tableaction","blockid","eattr","closest","attr","dattr","find","value","refreshRequired","savebutton","addClass","val","callpath","M","cfg","wwwroot","sesskey","post","fail","console","error","done","data","JSON","parse","parseInt","fadeOut","remove","clearForm","refreshPreview","i","hasOwnProperty","form","prepend","affectelement","prop","reloadPreview","rattr","pdattr","status","checkRequired","show","serialize","responseJSON","sfield","insertAfter","nextSibling","hide","setTimeout","load","length","innerHTML","alerttype","previewalert","removeClass","util","image_url","checked","previewelem","previewdom","prependTo","slideDown","disselopt","opt","reset","init","always","append"],"mappings":"mSAWAA,OAAM,iCAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,CAG3B,MAAO,CACHC,UAAU,CAAE,qBAAW,CAEnBD,CAAC,CAACE,QAAD,CAAD,CAAYC,KAAZ,CAAkB,UAAW,IAErBC,CAAAA,CAAU,CAAGJ,CAAC,CAAC,cAAD,CAFO,CAGrBK,CAAS,CAAGL,CAAC,CAAC,8BAAD,CAHQ,CAIrBM,CAAO,CAAG,CACVC,IAAI,CAAE,MADI,CAEVC,MAAM,CAAE,QAFE,CAGVC,GAAG,CAAE,aAHK,CAIVC,OAAO,CAAE,SAJC,CAKVC,KAAK,CAAE,OALG,CAMVC,OAAO,CAAE,SANC,CAJW,CAczBR,CAAU,CAACS,EAAX,CAAc,OAAd,CAAuB,2DAAvB,CAAoF,SAASC,CAAT,CAAY,CAC5FA,CAAC,CAACC,cAAF,GAD4F,GAExFC,CAAAA,CAAQ,CAAG,CACNC,IADM,CACC,MADD,CAENC,OAFM,CAEI,EAFJ,CAGNC,WAHM,CAGQ,EAHR,CAINC,OAJM,CAII,EAJJ,CAF6E,CASxFC,CAAK,CAAGrB,CAAC,CAAC,IAAD,CAAD,CAAQsB,OAAR,CAAgB,MAAhB,EAAwBC,IAAxB,CAA6B,WAA7B,CATgF,CAUxFC,CAAK,CAAGxB,CAAC,CAAC,IAAD,CAAD,CAAQsB,OAAR,CAAgB,MAAhB,EAAwBC,IAAxB,CAA6B,aAA7B,CAVgF,CAW5FP,CAAQ,CAACI,OAAT,CAAmBpB,CAAC,CAAC,IAAD,CAAD,CAAQsB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8B,GAA/B,CAAmC,KAAnC,EAEAF,CAAU,CAACE,GAAX,CAAexB,CAAO,CAACC,IAAvB,CACH,CAnXwB,CAqXzB,CAxFW,QAAP6E,CAAAA,IAAO,EAAW,IAMdrD,CAAAA,CAAQ,CAAGC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,qDAAhB,CAAwEF,CAAC,CAACC,GAAF,CAAME,OAN3E,CAQlBnC,CAAC,CAACoC,IAAF,CAAOL,CAAP,CANe,CACNd,IADM,CACC,MADD,CAENC,OAFM,CAEI,SAFJ,CAMf,EAA2BmB,IAA3B,CAAgC,UAAW,CACvCC,OAAO,CAACC,KAAR,CAAc,iCAAd,CACH,CAFD,EAEGC,IAFH,CAEQ,SAASC,CAAT,CAAe,CAGnBnC,CAAO,CAAGmC,CACb,CAND,EAMG4C,MANH,CAMU,UAAW,CAEjBrC,CAAc,EACjB,CATD,EAYAhD,CAAC,CAAC,wBAAD,CAAD,CAA4BsF,MAA5B,CACI,oFADJ,CAGH,CAiED,GACH,CAtXD,CAuXH,CA1XE,CA4XV,CA/XK,CAAN","sourcesContent":["/* eslint no-console: [\"error\", { allow: [\"error\"] }], max-nested-callbacks: [\"error\", 7] */\n/**\n * @package block_advnotifications\n * @copyright 2019 onwards LearningWorks Ltd {@link https://learningworks.co.nz/}\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @author Zander Potgieter \n */\n\n/**\n * @module block_advnotifications/custom\n */\ndefine(['jquery'], function($) {\n // JQuery is available via $.\n\n return {\n initialise: function() {\n // Module initialised.\n $(document).ready(function() {\n // Commonly (multiple times) used elements.\n var mainregion = $('#region-main');\n var addregion = $('#add_notification_wrapper_id');\n var strings = {\n save: 'Save',\n update: 'Update',\n req: 'Required...',\n preview: 'Preview',\n title: 'Title',\n message: 'Message'\n };\n\n // MANAGING NOTIFICATIONS.\n mainregion.on('click', '.notifications_table tr > td > form > button[type=submit]', function(e) {\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to edit/delete.\n var eattr = $(this).closest('form').attr('data-edit');\n var dattr = $(this).closest('form').attr('data-delete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n refreshRequired();\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof eattr !== typeof undefined && eattr !== false) {\n senddata.purpose = 'edit';\n senddata.tableaction = eattr;\n\n var savebutton = $('#add_notification_save');\n savebutton.addClass('update');\n savebutton.val(strings.update);\n } else if (typeof dattr !== typeof undefined && dattr !== false) {\n senddata.purpose = 'delete';\n senddata.tableaction = dattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'manage' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/edited notification.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n clearForm();\n refreshPreview();\n });\n } else if (senddata.purpose === \"edit\") {\n for (var i in data) {\n if (data.hasOwnProperty(i)) {\n\n // Need this for updating.\n if (i === \"id\") {\n var form = $('#add_notification_form');\n\n // Because we're doing a standard submit, we need extra inputs to pass params.\n // But first, remove old hidden inputs.\n $('#add_notification_id').remove();\n form.prepend(\n ''\n );\n\n $('#add_notification_purpose').val('update');\n }\n\n var affectelement = $('#add_notification_wrapper_id').find('#add_notification_' + i);\n\n // Check whether checkboxes should be checked or not.\n // We also don't assign a value to checkbox input fields.\n if (\n (\n i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon'\n ) && data[i] == 1) {\n affectelement.prop('checked', true);\n } else if (\n (i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon') && data[i] == 0) {\n affectelement.prop('checked', false);\n } else {\n affectelement.val(data[i]);\n }\n }\n }\n reloadPreview();\n }\n });\n });\n\n // Restore & Permanently delete notifications.\n mainregion.on('click', '.notifications_restore_table tr > td > form > button[type=submit]', function(e) {\n\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to restore/delete.\n var rattr = $(this).closest('form').attr('data-restore');\n var pdattr = $(this).closest('form').attr('data-permdelete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof rattr !== typeof undefined && rattr !== false) {\n senddata.purpose = 'restore';\n senddata.tableaction = rattr;\n } else if (typeof pdattr !== typeof undefined && pdattr !== false) {\n senddata.purpose = 'permdelete';\n senddata.tableaction = pdattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'restore/permdelete' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/restored notification.\n // Object 'done' is returned for both restore & delete.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n });\n }\n });\n });\n\n // Clear form.\n addregion.on('click', '#add_notification_cancel', function(e) {\n e.preventDefault();\n clearForm();\n });\n\n // Managing more notifications.\n mainregion.on('submit', '#add_notification_form', function(e) {\n e.preventDefault();\n var status = $('#add_notification_status');\n var form = $('#add_notification_form');\n\n refreshRequired();\n if (!checkRequired()) {\n // Stop if required fields are not supplied.\n return;\n }\n\n status.show();\n\n var senddata = $(this).serialize(); // Data Object.\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php\";\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function(data) {\n console.error(\"No 'add' response received.\");\n\n var error = data.responseJSON.error;\n\n for (var i in error) {\n if (error.hasOwnProperty(i)) {\n var sfield = form.find('select[name=' + error[i] + ']');\n sfield.addClass('requiredfield');\n $(\n '' + strings.req + ''\n ).insertAfter(sfield[0].nextSibling);\n }\n }\n\n status.hide();\n }).done(function() {\n // User saved notification.\n status.find('.saving').hide();\n status.find('.done').show();\n\n // Clear Form.\n clearForm();\n\n setTimeout(function() {\n status.fadeOut(function() {\n status.find('.done').hide();\n status.find('.saving').show();\n });\n }, 1500);\n\n $('#advnotifications_table_wrapper').load('# #advnotifications_table_wrapper > *');\n });\n });\n\n // LIVE PREVIEW.\n // Dynamically update preview alert as user changes textbox content.\n addregion.on('input propertychange paste', '#add_notification_title, #add_notification_message', function() {\n reloadPreview();\n });\n\n // Dynamically update preview alert type.\n $('#add_notification_type').on('change', function() {\n reloadPreview();\n });\n\n $('#add_notification_dismissible').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n $('#add_notification_aicon').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n // Check if preview is displaying correct (Update it).\n var reloadPreview = function() {\n // Update title.\n var title = addregion.find('#add_notification_title');\n if (title.val().length > 0) {\n addregion.find('.preview-title')[0].innerHTML = title.val();\n } else {\n addregion.find('.preview-title')[0].innerHTML = strings.title;\n }\n\n // Update message.\n var message = addregion.find('#add_notification_message');\n if (message.val().length > 0) {\n addregion.find('.preview-message')[0].innerHTML = message.val();\n } else {\n addregion.find('.preview-message')[0].innerHTML = strings.message;\n }\n\n // Check notification type.\n var alerttype = $('#add_notification_type').val();\n var previewalert = $('#add_notification_wrapper_id .preview-alert');\n\n // Clear existing classes.\n previewalert.removeClass('alert-info alert-success alert-danger alert-warning announcement');\n\n // Special check for announcement type.\n if (alerttype === 'announcement') {\n previewalert.addClass(alerttype);\n alerttype = 'info';\n }\n\n // If anything unexpected, set to info type.\n if (alerttype !== 'info' && alerttype !== 'success' && alerttype !== 'warning' && alerttype !== 'danger') {\n alerttype = 'info';\n }\n\n // Add type of alert class.\n previewalert.addClass('alert-' + alerttype);\n\n $('.preview-aicon').find('> img').attr('src', M.util.image_url(alerttype, 'block_advnotifications'));\n\n // Check if dismissable.\n if (!$('#add_notification_dismissible')[0].checked) {\n $('.preview-alert-dismissible').hide();\n previewalert.removeClass('dismissible');\n } else {\n $('.preview-alert-dismissible').show();\n previewalert.addClass('dismissible');\n }\n\n // Check if icon should be shown.\n if (!$('#add_notification_aicon')[0].checked) {\n $('.preview-aicon').hide();\n previewalert.removeClass('aicon');\n } else {\n $('.preview-aicon').show();\n previewalert.addClass('aicon');\n }\n };\n\n var init = function() {\n // Get strings.\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = 'strings';\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'strings' response received.\");\n }).done(function(data) {\n // TODO: ONLY DO THIS IF AJAX SUCCESSFUL - don't render with English first?).\n // Store strings and update preview.\n strings = data;\n }).always(function() {\n // Always prepend live preview. Use langstrings if AJAX successful, otherwise use strings declared at top.\n refreshPreview();\n });\n\n // JS is enabled, so we can use AJAX in the new notification form.\n $('#add_notification_form').append(\n ''\n );\n };\n\n // Shiny new and fresh preview.\n var refreshPreview = function() {\n var previewelem = $('#notification_preview_wrapper');\n var previewdom =\n '
' +\n '' + strings.preview + '
' +\n '
' +\n '
' +\n '' +\n '
' +\n '' + strings.title + ' ' +\n '
' + strings.message + '
' +\n '
×
' +\n '
' +\n '
';\n\n // If it exists already, remove before adding again.\n if (previewelem.length > 0) {\n previewelem.remove();\n // Don't slide in.\n $(previewdom).prependTo($(addregion));\n } else {\n // Slide in.\n $(previewdom).prependTo($(addregion)).hide().slideDown();\n }\n };\n\n var checkRequired = function() {\n var disselopt = $('#add_notification_form select option:selected:disabled');\n\n for (var opt in disselopt) {\n if (disselopt.hasOwnProperty(opt)) {\n if ($(disselopt[opt]).prop('disabled')) {\n $(disselopt[opt]).closest('select').addClass('requiredfield');\n $('' + strings.req + '')\n .insertAfter($(disselopt[opt]).closest('select')[0].nextSibling);\n\n return false;\n }\n }\n }\n return true;\n };\n\n var refreshRequired = function() {\n $('select.requiredfield').removeClass('requiredfield');\n $('strong.requiredfield').remove();\n };\n\n var clearForm = function() {\n $('#add_notification_form')[0].reset();\n refreshRequired();\n refreshPreview();\n\n // Change save button back to normal.\n var savebutton = $('#add_notification_save');\n savebutton.removeClass('update');\n $('#add_notification_id').remove();\n $('#add_notification_purpose').val('add');\n\n savebutton.val(strings.save);\n };\n\n init();\n });\n }\n };\n});"],"file":"custom.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/custom.js"],"names":["define","$","initialise","document","ready","mainregion","addregion","strings","save","update","req","preview","title","message","on","e","preventDefault","senddata","call","purpose","tableaction","blockid","eattr","closest","attr","dattr","find","value","refreshRequired","savebutton","addClass","val","callpath","M","cfg","wwwroot","sesskey","post","fail","console","error","done","data","JSON","parse","parseInt","fadeOut","remove","clearForm","refreshPreview","i","hasOwnProperty","form","prepend","affectelement","prop","reloadPreview","rattr","pdattr","status","checkRequired","show","serialize","responseJSON","sfield","insertAfter","nextSibling","hide","setTimeout","load","length","innerHTML","alerttype","previewalert","removeClass","util","image_url","checked","previewelem","previewdom","prependTo","slideDown","disselopt","opt","reset","init","always","append"],"mappings":"mSAWAA,OAAM,iCAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,CAG3B,MAAO,CACHC,UAAU,CAAE,qBAAW,CAEnBD,CAAC,CAACE,QAAD,CAAD,CAAYC,KAAZ,CAAkB,UAAW,IAErBC,CAAAA,CAAU,CAAGJ,CAAC,CAAC,cAAD,CAFO,CAGrBK,CAAS,CAAGL,CAAC,CAAC,8BAAD,CAHQ,CAIrBM,CAAO,CAAG,CACVC,IAAI,CAAE,MADI,CAEVC,MAAM,CAAE,QAFE,CAGVC,GAAG,CAAE,aAHK,CAI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C,wBAAD,CAAD,CAA4BsF,MAA5B,CACI,oFADJ,CAGH,CAiED,GACH,CAzXD,CA0XH,CA7XE,CA+XV,CAlYK,CAAN","sourcesContent":["/* eslint no-console: [\"error\", { allow: [\"error\"] }], max-nested-callbacks: [\"error\", 7] */\n/**\n * @package block_advnotifications\n * @copyright 2019 onwards LearningWorks Ltd {@link https://learningworks.co.nz/}\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @author Zander Potgieter \n */\n\n/**\n * @module block_advnotifications/custom\n */\ndefine(['jquery'], function($) {\n // JQuery is available via $.\n\n return {\n initialise: function() {\n // Module initialised.\n $(document).ready(function() {\n // Commonly (multiple times) used elements.\n var mainregion = $('#region-main');\n var addregion = $('#add_notification_wrapper_id');\n var strings = {\n save: 'Save',\n update: 'Update',\n req: 'Required...',\n preview: 'Preview',\n title: 'Title',\n message: 'Message'\n };\n\n // MANAGING NOTIFICATIONS.\n mainregion.on('click', '.notifications_table tr > td > form > button[type=submit]', function(e) {\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to edit/delete.\n var eattr = $(this).closest('form').attr('data-edit');\n var dattr = $(this).closest('form').attr('data-delete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n refreshRequired();\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof eattr !== typeof undefined && eattr !== false) {\n senddata.purpose = 'edit';\n senddata.tableaction = eattr;\n\n var savebutton = $('#add_notification_save');\n savebutton.addClass('update');\n savebutton.val(strings.update);\n } else if (typeof dattr !== typeof undefined && dattr !== false) {\n senddata.purpose = 'delete';\n senddata.tableaction = dattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'manage' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/edited notification.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n clearForm();\n refreshPreview();\n });\n } else if (senddata.purpose === \"edit\") {\n for (var i in data) {\n if (data.hasOwnProperty(i)) {\n\n // Need this for updating.\n if (i === \"id\") {\n var form = $('#add_notification_form');\n\n // Because we're doing a standard submit, we need extra inputs to pass params.\n // But first, remove old hidden inputs.\n $('#add_notification_id').remove();\n form.prepend(\n ''\n );\n\n $('#add_notification_purpose').val('update');\n }\n\n var affectelement = $('#add_notification_wrapper_id').find('#add_notification_' + i);\n\n // Check whether checkboxes should be checked or not.\n // We also don't assign a value to checkbox input fields.\n if (\n (\n i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon' ||\n i === 'sendnotifications'\n ) && data[i] == 1) {\n affectelement.prop('checked', true);\n } else if (\n (i === 'enabled' ||\n i === 'global' ||\n i === 'dismissible' ||\n i === 'aicon' ||\n i === 'sendnotifications'\n ) && data[i] == 0) {\n affectelement.prop('checked', false);\n } else {\n affectelement.val(data[i]);\n }\n }\n }\n reloadPreview();\n }\n });\n });\n\n // Restore & Permanently delete notifications.\n mainregion.on('click', '.notifications_restore_table tr > td > form > button[type=submit]', function(e) {\n\n e.preventDefault();\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = '';\n senddata.tableaction = '';\n senddata.blockid = '';\n\n // Check if user wants to restore/delete.\n var rattr = $(this).closest('form').attr('data-restore');\n var pdattr = $(this).closest('form').attr('data-permdelete');\n senddata.blockid = $(this).closest('form').find('[name=blockid]')[0].value;\n\n // Check if anchor element has attribute, retrieved from above.\n if (typeof rattr !== typeof undefined && rattr !== false) {\n senddata.purpose = 'restore';\n senddata.tableaction = rattr;\n } else if (typeof pdattr !== typeof undefined && pdattr !== false) {\n senddata.purpose = 'permdelete';\n senddata.tableaction = pdattr;\n }\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'restore/permdelete' response received.\");\n }).done(function(data) {\n data = JSON.parse(data);\n\n // User deleted/restored notification.\n // Object 'done' is returned for both restore & delete.\n if (parseInt(data.done, 10) > 0) {\n $('#tr' + senddata.purpose + data.done).closest(\"tr\").fadeOut(250, function() {\n $(this).remove();\n });\n }\n });\n });\n\n // Clear form.\n addregion.on('click', '#add_notification_cancel', function(e) {\n e.preventDefault();\n clearForm();\n });\n\n // Managing more notifications.\n mainregion.on('submit', '#add_notification_form', function(e) {\n e.preventDefault();\n var status = $('#add_notification_status');\n var form = $('#add_notification_form');\n\n refreshRequired();\n if (!checkRequired()) {\n // Stop if required fields are not supplied.\n return;\n }\n\n status.show();\n\n var senddata = $(this).serialize(); // Data Object.\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php\";\n\n // Perform tableaction.\n $.post(callpath, senddata).fail(function(data) {\n console.error(\"No 'add' response received.\");\n\n var error = data.responseJSON.error;\n\n for (var i in error) {\n if (error.hasOwnProperty(i)) {\n var sfield = form.find('select[name=' + error[i] + ']');\n sfield.addClass('requiredfield');\n $(\n '' + strings.req + ''\n ).insertAfter(sfield[0].nextSibling);\n }\n }\n\n status.hide();\n }).done(function() {\n // User saved notification.\n status.find('.saving').hide();\n status.find('.done').show();\n\n // Clear Form.\n clearForm();\n\n setTimeout(function() {\n status.fadeOut(function() {\n status.find('.done').hide();\n status.find('.saving').show();\n });\n }, 1500);\n\n $('#advnotifications_table_wrapper').load('# #advnotifications_table_wrapper > *');\n });\n });\n\n // LIVE PREVIEW.\n // Dynamically update preview alert as user changes textbox content.\n addregion.on('input propertychange paste', '#add_notification_title, #add_notification_message', function() {\n reloadPreview();\n });\n\n // Dynamically update preview alert type.\n $('#add_notification_type').on('change', function() {\n reloadPreview();\n });\n\n $('#add_notification_dismissible').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n $('#add_notification_aicon').on('change', function() {\n // Checking specifically whether ticked/checked or not to ensure it's displayed correctly (not toggling).\n reloadPreview();\n });\n\n // Check if preview is displaying correct (Update it).\n var reloadPreview = function() {\n // Update title.\n var title = addregion.find('#add_notification_title');\n if (title.val().length > 0) {\n addregion.find('.preview-title')[0].innerHTML = title.val();\n } else {\n addregion.find('.preview-title')[0].innerHTML = strings.title;\n }\n\n // Update message.\n var message = addregion.find('#add_notification_message');\n if (message.val().length > 0) {\n addregion.find('.preview-message')[0].innerHTML = message.val();\n } else {\n addregion.find('.preview-message')[0].innerHTML = strings.message;\n }\n\n // Check notification type.\n var alerttype = $('#add_notification_type').val();\n var previewalert = $('#add_notification_wrapper_id .preview-alert');\n\n // Clear existing classes.\n previewalert.removeClass('alert-info alert-success alert-danger alert-warning announcement');\n\n // Special check for announcement type.\n if (alerttype === 'announcement') {\n previewalert.addClass(alerttype);\n alerttype = 'info';\n }\n\n // If anything unexpected, set to info type.\n if (alerttype !== 'info' && alerttype !== 'success' && alerttype !== 'warning' && alerttype !== 'danger') {\n alerttype = 'info';\n }\n\n // Add type of alert class.\n previewalert.addClass('alert-' + alerttype);\n\n $('.preview-aicon').find('> img').attr('src', M.util.image_url(alerttype, 'block_advnotifications'));\n\n // Check if dismissable.\n if (!$('#add_notification_dismissible')[0].checked) {\n $('.preview-alert-dismissible').hide();\n previewalert.removeClass('dismissible');\n } else {\n $('.preview-alert-dismissible').show();\n previewalert.addClass('dismissible');\n }\n\n // Check if icon should be shown.\n if (!$('#add_notification_aicon')[0].checked) {\n $('.preview-aicon').hide();\n previewalert.removeClass('aicon');\n } else {\n $('.preview-aicon').show();\n previewalert.addClass('aicon');\n }\n };\n\n var init = function() {\n // Get strings.\n var senddata = {}; // Data Object.\n senddata.call = 'ajax';\n senddata.purpose = 'strings';\n\n var callpath = M.cfg.wwwroot + \"/blocks/advnotifications/pages/process.php?sesskey=\" + M.cfg.sesskey;\n\n $.post(callpath, senddata).fail(function() {\n console.error(\"No 'strings' response received.\");\n }).done(function(data) {\n // TODO: ONLY DO THIS IF AJAX SUCCESSFUL - don't render with English first?).\n // Store strings and update preview.\n strings = data;\n }).always(function() {\n // Always prepend live preview. Use langstrings if AJAX successful, otherwise use strings declared at top.\n refreshPreview();\n });\n\n // JS is enabled, so we can use AJAX in the new notification form.\n $('#add_notification_form').append(\n ''\n );\n };\n\n // Shiny new and fresh preview.\n var refreshPreview = function() {\n var previewelem = $('#notification_preview_wrapper');\n var previewdom =\n '
' +\n '' + strings.preview + '
' +\n '
' +\n '
' +\n '' +\n '
' +\n '' + strings.title + ' ' +\n '
' + strings.message + '
' +\n '
×
' +\n '
' +\n '
';\n\n // If it exists already, remove before adding again.\n if (previewelem.length > 0) {\n previewelem.remove();\n // Don't slide in.\n $(previewdom).prependTo($(addregion));\n } else {\n // Slide in.\n $(previewdom).prependTo($(addregion)).hide().slideDown();\n }\n };\n\n var checkRequired = function() {\n var disselopt = $('#add_notification_form select option:selected:disabled');\n\n for (var opt in disselopt) {\n if (disselopt.hasOwnProperty(opt)) {\n if ($(disselopt[opt]).prop('disabled')) {\n $(disselopt[opt]).closest('select').addClass('requiredfield');\n $('' + strings.req + '')\n .insertAfter($(disselopt[opt]).closest('select')[0].nextSibling);\n\n return false;\n }\n }\n }\n return true;\n };\n\n var refreshRequired = function() {\n $('select.requiredfield').removeClass('requiredfield');\n $('strong.requiredfield').remove();\n };\n\n var clearForm = function() {\n $('#add_notification_form')[0].reset();\n refreshRequired();\n refreshPreview();\n\n // Change save button back to normal.\n var savebutton = $('#add_notification_save');\n savebutton.removeClass('update');\n $('#add_notification_id').remove();\n $('#add_notification_purpose').val('add');\n\n savebutton.val(strings.save);\n };\n\n init();\n });\n }\n };\n});\n"],"file":"custom.min.js"} \ No newline at end of file diff --git a/amd/src/custom.js b/amd/src/custom.js index 9be77a8..b9c7e8e 100644 --- a/amd/src/custom.js +++ b/amd/src/custom.js @@ -98,14 +98,17 @@ define(['jquery'], function($) { i === 'enabled' || i === 'global' || i === 'dismissible' || - i === 'aicon' + i === 'aicon' || + i === 'sendnotifications' ) && data[i] == 1) { affectelement.prop('checked', true); } else if ( (i === 'enabled' || i === 'global' || i === 'dismissible' || - i === 'aicon') && data[i] == 0) { + i === 'aicon' || + i === 'sendnotifications' + ) && data[i] == 0) { affectelement.prop('checked', false); } else { affectelement.val(data[i]); @@ -392,4 +395,4 @@ define(['jquery'], function($) { }); } }; -}); \ No newline at end of file +}); diff --git a/classes/base_table.php b/classes/base_table.php index 22d6e4b..0874192 100644 --- a/classes/base_table.php +++ b/classes/base_table.php @@ -64,6 +64,7 @@ public function __construct($uniqueid) { 'global', 'aicon', 'dismissible', + 'sendnotifications', 'times', 'date_from', 'date_to', @@ -80,6 +81,7 @@ public function __construct($uniqueid) { get_string('advnotifications_field_global', 'block_advnotifications'), // Global: Yes. get_string('advnotifications_field_aicon', 'block_advnotifications'), // AIcon: Yes. get_string('advnotifications_field_dismissible', 'block_advnotifications'), // Dismissible: Yes. + get_string('advnotifications_field_sendnotifications', 'block_advnotifications'), // Send notifications: Yes. get_string('advnotifications_field_times', 'block_advnotifications'), // Times: 10. get_string('advnotifications_field_date_from', 'block_advnotifications'), // Date From: dd/mm/yyyy. get_string('advnotifications_field_date_to', 'block_advnotifications'), // Date To: dd/mm/yyyy. @@ -172,6 +174,17 @@ public function col_dismissible($values) { return ($values->dismissible == 1 ? $this->yes : $this->no); } + /** + * This function is called for each data row to allow processing of the + * sendnotifications value. + * + * @param object $values Contains object with all the values of record. + * @return $string Return whether notification is sent via moodle notifications system or not. + */ + public function col_sendnotifications($values) { + return ($values->sendnotifications == 1 ? $this->yes : $this->no); + } + /** * This function is called for each data row to allow processing of the * times value. @@ -223,4 +236,4 @@ public function print_nothing_to_display() { echo '

' . get_string('advnotifications_table_empty', 'block_advnotifications') . '

'; } -} \ No newline at end of file +} diff --git a/classes/task/sendnotifications.php b/classes/task/sendnotifications.php new file mode 100644 index 0000000..55359df --- /dev/null +++ b/classes/task/sendnotifications.php @@ -0,0 +1,86 @@ +. + +/** + * Ad hoc task to send notifications. + * + * @package block_advnotifications + * @copyright 2021 Daniel Neis Araujo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_advnotifications\task; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Ad hoc task to send notifications class. + * + * @package block_advnotifications + * @copyright 2021 Daniel Neis Araujo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class sendnotifications extends \core\task\adhoc_task { + + /** + * Return the task's name as shown in admin screens. + * + * @return string + */ + public function get_name() { + return get_string('sendnotificationstask', 'block-advnotifications'); + } + + public function execute() { + global $DB; + + if (!get_config('block_advnotifications', 'enable')) { + return; + } + + $from = \core_user::get_noreply_user(); + + $notification = $DB->get_record('block_advnotifications', ['id' => $this->get_custom_data()->notificationid]); + + if (!$notification->enabled) { + return; + } + + if (!empty($notification->blockid)) { + $bcontext = \context_block::instance($notification->blockid); + } + if (isset($bcontext) && $ccontext = $bcontext->get_course_context(false)) { + $users = get_enrolled_users($ccontext, '', 0 , 'u.id'); + } else { + $users = $DB->get_records('user', ['deleted' => 0, 'suspended' => 0], '', 'id'); + } + + foreach ($users as $u) { + $eventdata = new \core\message\message(); + $eventdata->component = 'block_advnotifications'; + $eventdata->name = 'sendadvnotifications'; + $eventdata->userfrom = $from; + $eventdata->userto = $u->id; + $eventdata->subject = $notification->title; + $eventdata->fullmessage = format_text($notification->message, FORMAT_MOODLE); + $eventdata->fullmessageformat = FORMAT_MOODLE; + $eventdata->fullmessagehtml = format_text($notification->message, FORMAT_MOODLE); + $eventdata->smallmessage = ''; + $eventdata->notification = true; + message_send($eventdata); + } + } +} diff --git a/db/install.xml b/db/install.xml index 9637414..e8c2581 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,8 @@ - + @@ -8,6 +11,7 @@ + @@ -37,4 +41,4 @@
-
\ No newline at end of file +
diff --git a/db/messages.php b/db/messages.php new file mode 100644 index 0000000..7b9673b --- /dev/null +++ b/db/messages.php @@ -0,0 +1,35 @@ +. + +/** + * Message providers. + * + * @package block_advnotifications + * @copyright 2021 Daniel Neis Araujo + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$messageproviders = [ + // Send notifications to users. + 'sendadvnotifications' => [ + 'defaults' => [ + 'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN, + 'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF + ], + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 171043f..3258b0c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -102,7 +102,22 @@ function xmldb_block_advnotifications_upgrade($oldversion) { upgrade_block_savepoint(true, 2021010616, 'advnotifications'); } + if ($oldversion < 2021092000) { + + // Define field id to be added to block_advnotifications. + $table = new xmldb_table('block_advnotifications'); + $field = new xmldb_field('sendnotifications', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'aicon'); + + // Conditionally launch add field id. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Advnotifications savepoint reached. + upgrade_block_savepoint(true, 2021092000, 'advnotifications'); + } + // Add future upgrade points here. return true; -} \ No newline at end of file +} diff --git a/lang/en/block_advnotifications.php b/lang/en/block_advnotifications.php index 6196f0d..6519acc 100644 --- a/lang/en/block_advnotifications.php +++ b/lang/en/block_advnotifications.php @@ -43,6 +43,7 @@ $string['advnotifications_field_global'] = 'Global'; $string['advnotifications_field_aicon'] = 'Icon'; $string['advnotifications_field_dismissible'] = 'Dismissible'; +$string['advnotifications_field_sendnotifications'] = 'Send notifications'; $string['advnotifications_field_times'] = 'View Times'; $string['advnotifications_field_date_from'] = 'From'; $string['advnotifications_field_date_to'] = 'To'; @@ -85,6 +86,7 @@ $string['advnotifications_cancel'] = 'Cancel'; $string['advnotifications_req'] = 'Required...'; $string['advnotifications_preview'] = 'Preview'; +$string['advnotifications_sendnotifications'] = 'Send notitications via site notification system (usually will appear on the bell icon on top)'; // Renderer. $string['advnotifications_add_heading'] = 'New notification'; @@ -151,6 +153,8 @@ // Misc. $string['advnotifications_join'] = ' & '; +$string['messageprovider:sendadvnotifications'] = 'Send advanced notifications to users'; + // Privacy API. $string['privacy:metadata:block_advnotifications'] = 'Information about notifications the user has been exposed to and recorded interactions.'; $string['privacy:metadata:block_advnotifications:title'] = 'The title of the notification.'; diff --git a/pages/process.php b/pages/process.php index 77ee9a1..90764f3 100644 --- a/pages/process.php +++ b/pages/process.php @@ -61,6 +61,7 @@ $type = optional_param('type', null, PARAM_TEXT); $times = optional_param('times', null, PARAM_INT); $aicon = optional_param('aicon', null, PARAM_TEXT); +$sendnotifications = optional_param('sendnotifications', null, PARAM_TEXT); $dismissible = optional_param('dismissible', null, PARAM_TEXT); $datefrom = optional_param('date_from', null, PARAM_TEXT); $dateto = optional_param('date_to', null, PARAM_TEXT); @@ -101,6 +102,11 @@ } else { $dismissible = 0; } +if ($sendnotifications == 'on' || $sendnotifications == '1') { + $sendnotifications = 1; +} else { + $sendnotifications = 0; +} // TODO: Check if successful? // Convert dates to epoch for DB. If empty, set to 0 (forever) by default. @@ -246,6 +252,7 @@ $urow->message = $message; $urow->type = $type; $urow->aicon = $aicon; + $urow->sendnotifications = $sendnotifications; $urow->enabled = $enabled; $urow->global = $global; $urow->blockid = $blockinstance; @@ -256,6 +263,15 @@ $DB->update_record('block_advnotifications', $urow); + if ($urow->sendnotifications) { + $task = new block_advnotifications\task\sendnotifications(); + $task->set_custom_data(['notificationid' => $id]); + if ($datefrom > time()) { + $task->set_next_run_time($datefrom); + } + \core\task\manager::reschedule_or_queue_adhoc_task($task); + } + if ($ajax) { echo json_encode(array("updated" => $title)); exit(); @@ -311,6 +327,7 @@ $row->message = $message; $row->type = $type; $row->aicon = $aicon; + $row->sendnotifications = $sendnotifications; $row->enabled = $enabled; $row->global = $global; $row->blockid = $blockinstance; @@ -323,7 +340,16 @@ $row->deleted_by = -1; $row->created_by = $USER->id; - $DB->insert_record('block_advnotifications', $row); + $id = $DB->insert_record('block_advnotifications', $row); + + if ($row->sendnotifications) { + $task = new block_advnotifications\task\sendnotifications(); + $task->set_custom_data(['notificationid' => $id]); + if ($datefrom > time()) { + $task->set_next_run_time($datefrom); + } + \core\task\manager::queue_adhoc_task($task); + } // Send JSON response if AJAX call was made, otherwise simply redirect to origin page. if ($ajax) { @@ -333,4 +359,4 @@ } else { redirect(new moodle_url('/blocks/advnotifications/pages/notifications.php', $params)); } -} \ No newline at end of file +} diff --git a/renderer.php b/renderer.php index 1647aec..91b5ae4 100644 --- a/renderer.php +++ b/renderer.php @@ -189,6 +189,11 @@ class="form-check-input" +
+ + +