From 260565e305c5eae0fa3288d4e5fcde33c9073d39 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 3 Apr 2019 15:10:44 +0800 Subject: [PATCH] MDL-64573 output: ajax form event Add an event that can be fired when an mform is about to be submitted via ajax. This allows custom field types to perform an action when the form is submitted. The atto text editor will reset any autosaves when the form is submitted. --- calendar/amd/build/modal_event_form.min.js | Bin 4129 -> 4262 bytes calendar/amd/src/modal_event_form.js | 14 ++++++++- lib/amd/build/event.min.js | Bin 688 -> 966 bytes lib/amd/src/event.js | 29 ++++++++++++++++++ .../moodle-editor_atto-editor-debug.js | Bin 92808 -> 92897 bytes .../moodle-editor_atto-editor-min.js | Bin 23151 -> 23217 bytes .../moodle-editor_atto-editor.js | Bin 91618 -> 91707 bytes .../atto/yui/src/editor/js/autosave-io.js | 1 + lib/editor/tinymce/module.js | 6 ++++ lib/formslib.php | 11 +++++++ .../moodle-core-event-debug.js | Bin 3676 -> 3858 bytes .../moodle-core-event-min.js | Bin 771 -> 807 bytes .../moodle-core-event/moodle-core-event.js | Bin 3426 -> 3608 bytes lib/yui/src/event/js/event.js | 12 +++++++- mod/assign/amd/build/grading_panel.min.js | Bin 5791 -> 5770 bytes mod/assign/amd/src/grading_panel.js | 12 +++----- 16 files changed, 76 insertions(+), 9 deletions(-) diff --git a/calendar/amd/build/modal_event_form.min.js b/calendar/amd/build/modal_event_form.min.js index 79035b5623b575fb757198f7df449aa53fd4fa15..2befc260c127f8fa55c7622c02d992c847ba2d8b 100644 GIT binary patch delta 194 zcmZ3euuO5oejX;BcM8N{jLo%JMT)6q10Nii%4>n)8!Oi#0T@ zlP7=RF=R}gti)>qB*S^VIZ`#P%Myzek|(d?m1j(ze2O=ZF?q8kUk0OAl3reZNoHCl d$o}Bcq}3ahlzyyTM1{5*|hofOUL6x)=V8b!m&+Kl?@ zDQapO<(YXY`Q>`W*_j2-Ihm<>C1Hs&O`8A! delta 11 ScmX@czJYba7skn4%zFSFw*aeiCKviu4SotB~}V~`6;P-`FR??ddc}ksd}j(Q9U>RAm8}lP$yr{ Qka$Ng$B50>`#0VK00mGOhX4Qo delta 13 VcmaEOm9^t4>w*cJBPVp+0su1K2TT9} diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js index 0bb143473a14f919e8a11304d7a69003c3ba2816..2574ec4eba6f86915d4a3ef4941cbbbad46889fa 100644 GIT binary patch delta 88 zcmaFAg>mCn#tnZpbP}@?D_qM`^Gd8z_44yHeD#v^i&FJcK_Yr?{z1O+!J$sRo+0s$ pUXBr)pKBapW#pQ?TF-|`BXjaXJB7_s`W)gw5hXXz%{gw&A^_Ay9%=vp delta 40 vcmdnEmGS)+#tnZpHrs2iW1aj?&xes~vz5M<_+&W?&dGUh4nXcYH)at4Ro)I% diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js index cf12f6cb7a22350107ae3e9c13c1572d3ce605ff..fea357374aa857aac5292069c588fa6d0dc375b0 100644 GIT binary patch delta 63 zcmaEKnsxUX)(!qW28mgT6|QBec_mf~dHE@+dii-8zIw^|MX7qJAW=Ox{~+J^;7})D R&yaXWFUN?@YCU^y0stcs7+C-S delta 14 WcmdmehV{{D)(!qWn^*Kqz6k(3WC$Gq diff --git a/lib/editor/atto/yui/src/editor/js/autosave-io.js b/lib/editor/atto/yui/src/editor/js/autosave-io.js index a37352ed7e9..47e19db7519 100644 --- a/lib/editor/atto/yui/src/editor/js/autosave-io.js +++ b/lib/editor/atto/yui/src/editor/js/autosave-io.js @@ -198,6 +198,7 @@ Y.extend(EditorAutosaveIoDispatcher, Y.Base, { if (typeof this._submitEvents[node.generateID()] === 'undefined') { this._submitEvents[node.generateID()] = { event: node.on('submit', this._onSubmit, this), + ajaxEvent: node.on(M.core.event.FORM_SUBMIT_AJAX, this._onSubmit, this), ios: [] }; } diff --git a/lib/editor/tinymce/module.js b/lib/editor/tinymce/module.js index 61c56d8ab6a..ee8e4d96ae3 100644 --- a/lib/editor/tinymce/module.js +++ b/lib/editor/tinymce/module.js @@ -66,6 +66,12 @@ M.editor_tinymce.init_editor = function(Y, editorid, options) { editor.onChange.add(function(ed) { ed.save(); }); + Y.use('event', 'moodle-core-event', function(Y) { + var form = Y.one(document.getElementById(editor.id)).ancestor('form'); + form.on(M.core.event.FORM_SUBMIT_AJAX, function() { + editor.save(); + }, this) + }); }; tinyMCE.init(options); diff --git a/lib/formslib.php b/lib/formslib.php index acd0b217dfe..9e2c96f0190 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2421,6 +2421,17 @@ require(["core/event", "jquery"], function(Event, $) { return ret; } + var form = $(document.getElementById(\'' . $this->_attributes['id'] . '\')).closest(\'form\'); + form.on(M.core.event.FORM_SUBMIT_AJAX, function() { + try { + var myValidator = validate_' . $this->_formName . '; + } catch(e) { + return true; + } + if (myValidator) { + myValidator(); + } + }); document.getElementById(\'' . $this->_attributes['id'] . '\').addEventListener(\'submit\', function(ev) { try { diff --git a/lib/yui/build/moodle-core-event/moodle-core-event-debug.js b/lib/yui/build/moodle-core-event/moodle-core-event-debug.js index 1dd7edc4e2a5cc3e7fa25cdbe2d1e6e6d2279edd..1d72a163994330ebbcd1a1f396c077ff8ba19620 100644 GIT binary patch delta 157 zcmca3Gf8fPBFkn4mJFuJ3M_h?x3UQ`GU;%E*jjlCxoP=DxeA%Z3W-Vir6md_`3gy? z3dN;KxtS#;sVNF&nTZOCS&0>TlkGXhJwR%8A(FZvQ6(+~5YW;G({BDjzVX4KPQIQY d@s3`O5mpLHm>Rfht+}`+KV%o#e4o9R4FJgTFa`hs delta 26 icmbOvcSmM}BFknamUO1cN-VmYx3dW{Zm!{&#s&a#S_k_8 diff --git a/lib/yui/build/moodle-core-event/moodle-core-event-min.js b/lib/yui/build/moodle-core-event/moodle-core-event-min.js index ae188f2f68cbbf8ae3c41e1ca5ca670964393065..0a60dbdcc0fe609828e118048ba9235701dbd0d7 100644 GIT binary patch delta 46 zcmZo>Th2D&va*hwe~@o{aHx~7XGpxGmt%yLQd)jdu5NK@Qf_96Zemtq#l}m9OaN|D B5Gw!x delta 10 RcmZ3^*335H^2YB5OaK^?1atrZ diff --git a/lib/yui/build/moodle-core-event/moodle-core-event.js b/lib/yui/build/moodle-core-event/moodle-core-event.js index 847ca8f77b1efd59b3cb8f78b5da228bb845bfeb..8f6ca3b08ee79515aecf4297cbd06de8db768e69 100644 GIT binary patch delta 157 zcmaDPHA7~DBFkn4mJFuJ3M_h?x3UQ`GU;%E*jjlCxoP=DxeA%Z3W-Vir6md_`3gy? z3dN;KxtS#;sVNF&nTZOCS&0>TlkGXhJwR%8A(FZvQ6(+~5YW;G({BDjzVX4KPQIQY d@s3`O5mpLHm>Rfht+}`+KV%o#e4o9U6#&iPFcSa( delta 26 icmbOs^GIrgBFknamUO1cN-VmYx3dW{Zm!{&!wLX%F$f3% diff --git a/lib/yui/src/event/js/event.js b/lib/yui/src/event/js/event.js index 8ceff44b3ae..8d4cfaacf2e 100644 --- a/lib/yui/src/event/js/event.js +++ b/lib/yui/src/event/js/event.js @@ -29,6 +29,7 @@ var LOGNAME = 'moodle-core-event'; M.core = M.core || {}; M.core.event = M.core.event || { + /** * This event is triggered when a page has added dynamic nodes to a page * that should be processed by the filter system. An example is loading @@ -40,6 +41,7 @@ M.core.event = M.core.event || { * @param nodes {Y.NodeList} List of nodes added to the DOM. */ FILTER_CONTENT_UPDATED: "filter-content-updated", + /** * This event is triggered when an editor has recovered some draft text. * It can be used to determine let other sections know that they should reset their @@ -47,7 +49,15 @@ M.core.event = M.core.event || { * * @event "editor-content-restored" */ - EDITOR_CONTENT_RESTORED: "editor-content-restored" + EDITOR_CONTENT_RESTORED: "editor-content-restored", + + /** + * This event is triggered when an mform is about to be submitted via ajax. + * + * @event "form-submit-ajax" + */ + FORM_SUBMIT_AJAX: "form-submit-ajax" + }; M.core.globalEvents = M.core.globalEvents || { diff --git a/mod/assign/amd/build/grading_panel.min.js b/mod/assign/amd/build/grading_panel.min.js index ed1ab5c65c77666cef227db62a61f4b210c04f89..deb168518c77b0812853446f9156733269c65aa3 100644 GIT binary patch delta 231 zcmbQQ+od~U4Udjea(+>&erj22UdhDOvYa|un$=~AMGDyy&*w8{Pqt@N0Fnuel0dSG zQ4vVaVUz%p7a4^)JyUG+N^^2_Ks<4v*h|L!KyoFM>STWAIY8DL<|#5dS$cW-C7EfJ zZuv#I!KF#LnI(={i4_{@(FU=b?OFI48M8P0v&J(4m9J-?58`nA0*QHXbpol$SGeDE zXX_Od<(K4_R2HO8HsBE5{Fo<&6)5E)6bmGm2_*wbE@6Kl86_M9B-aWD1NAeC%wl56 IuGO>#0BGM#t^fc4 delta 272 zcmeCuov%A#&BUED?3&eOiA4%o6Yu3SW=-~EQ~;9sjFLdIlTpzuORu0Pza+n;vLID2 zz9=<4Ge6HZuQVq|2U#L7wW1`nIJL+#1u8fB0i!t3fFF$ef#eP*RY#@Lyp+_m%)HbT zB}H41Vfkqa<(YXY`Q>^gnR%7I&aP@|sC>PWqRjO4)S}?TvQ!OC>&bVS<^avAVxF>D zn}v^&F>A9GYdjNBWET5;5QpOzNX(S06G%