diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 435dec20308..97abc709d9f 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -3987,6 +3987,7 @@ EOD; 'page' => $this->page ) ); + $this->page->requires->string_for_js('changesmadereallygoaway', 'moodle'); } } diff --git a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-debug.js b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-debug.js index 868751f1160..6fbee86da65 100644 --- a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-debug.js +++ b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-debug.js @@ -178,6 +178,14 @@ M.core_formchangechecker.get_form_dirty_state = function() { return 0; }; +/* + * Reset the form state + */ +M.core_formchangechecker.reset_form_dirty_state = function() { + M.core_formchangechecker.stateinformation.formsubmitted = false; + M.core_formchangechecker.stateinformation.formchanged = false; +}; + /* * Return a suitable message if changes have been made to a form */ diff --git a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-min.js b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-min.js index 505dbe80d20..af2f3e2249d 100644 --- a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-min.js +++ b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker-min.js @@ -1 +1 @@ -YUI.add("moodle-core-formchangechecker",function(e,t){var n="core-formchangechecker",r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{initialvaluelisteners:[],initializer:function(){var t="form#"+this.get("formid"),n=e.one(t);if(!n)return;n.delegate("change",M.core_formchangechecker.set_form_changed,"input",this),n.delegate("change",M.core_formchangechecker.set_form_changed,"textarea",this),n.delegate("change",M.core_formchangechecker.set_form_changed,"select",this),this.initialvaluelisteners.push(n.delegate("focus",this.store_initial_value,"input",this)),this.initialvaluelisteners.push(n.delegate("focus",this.store_initial_value,"textarea",this)),this.initialvaluelisteners.push(n.delegate("focus",this.store_initial_value,"select",this)),e.one(t).on("submit",M.core_formchangechecker.set_form_submitted,this),window.onbeforeunload=M.core_formchangechecker.report_form_dirty_state},store_initial_value:function(e){var t;if(e.target.hasClass("ignoredirty"))return;if(M.core_formchangechecker.get_form_dirty_state()){while(this.initialvaluelisteners.length)t=this.initialvaluelisteners.shift(),t.detach();return}M.core_formchangechecker.stateinformation.focused_element={element:e.target,initial_value:e.target.get("value")}}},{NAME:n,ATTRS:{formid:{value:""}}}),M.core_formchangechecker=M.core_formchangechecker||{},M.core_formchangechecker.instances=M.core_formchangechecker.instances||[],M.core_formchangechecker.init=function(e){var t=new r(e);return M.core_formchangechecker.instances.push(t),t},M.core_formchangechecker.stateinformation=[],M.core_formchangechecker.set_form_changed=function(e){if(e&&e.target&&e.target.hasClass("ignoredirty"))return;M.core_formchangechecker.stateinformation.formchanged=1,delete M.core_formchangechecker.stateinformation.focused_element},M.core_formchangechecker.set_form_submitted=function(){M.core_formchangechecker.stateinformation.formsubmitted=1},M.core_formchangechecker.get_form_dirty_state=function(){var e=M.core_formchangechecker.stateinformation,t;if(e.formsubmitted)return 0;if(e.formchanged)return 1;if(e.focused_element&&e.focused_element.element.get("value")!==e.focused_element.initial_value)return 1;if(typeof window.tinyMCE!="undefined")for(t in window.tinyMCE.editors)if(window.tinyMCE.editors[t].isDirty())return 1;return 0},M.core_formchangechecker.report_form_dirty_state=function(e){if(!M.core_formchangechecker.get_form_dirty_state())return;var t=M.util.get_string("changesmadereallygoaway","moodle");if(M.cfg.behatsiterunning)return;return e&&(e.returnValue=t),t}},"@VERSION@",{requires:["base","event-focus"]}); +YUI.add("moodle-core-formchangechecker",function(e,t){var n="core-formchangechecker",r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{initialvaluelisteners:[],initializer:function(){var t="form#"+this.get("formid"),n=e.one(t);if(!n)return;n.delegate("change",M.core_formchangechecker.set_form_changed,"input",this),n.delegate("change",M.core_formchangechecker.set_form_changed,"textarea",this),n.delegate("change",M.core_formchangechecker.set_form_changed,"select",this),this.initialvaluelisteners.push(n.delegate("focus",this.store_initial_value,"input",this)),this.initialvaluelisteners.push(n.delegate("focus",this.store_initial_value,"textarea",this)),this.initialvaluelisteners.push(n.delegate("focus",this.store_initial_value,"select",this)),e.one(t).on("submit",M.core_formchangechecker.set_form_submitted,this),window.onbeforeunload=M.core_formchangechecker.report_form_dirty_state},store_initial_value:function(e){var t;if(e.target.hasClass("ignoredirty"))return;if(M.core_formchangechecker.get_form_dirty_state()){while(this.initialvaluelisteners.length)t=this.initialvaluelisteners.shift(),t.detach();return}M.core_formchangechecker.stateinformation.focused_element={element:e.target,initial_value:e.target.get("value")}}},{NAME:n,ATTRS:{formid:{value:""}}}),M.core_formchangechecker=M.core_formchangechecker||{},M.core_formchangechecker.instances=M.core_formchangechecker.instances||[],M.core_formchangechecker.init=function(e){var t=new r(e);return M.core_formchangechecker.instances.push(t),t},M.core_formchangechecker.stateinformation=[],M.core_formchangechecker.set_form_changed=function(e){if(e&&e.target&&e.target.hasClass("ignoredirty"))return;M.core_formchangechecker.stateinformation.formchanged=1,delete M.core_formchangechecker.stateinformation.focused_element},M.core_formchangechecker.set_form_submitted=function(){M.core_formchangechecker.stateinformation.formsubmitted=1},M.core_formchangechecker.get_form_dirty_state=function(){var e=M.core_formchangechecker.stateinformation,t;if(e.formsubmitted)return 0;if(e.formchanged)return 1;if(e.focused_element&&e.focused_element.element.get("value")!==e.focused_element.initial_value)return 1;if(typeof window.tinyMCE!="undefined")for(t in window.tinyMCE.editors)if(window.tinyMCE.editors[t].isDirty())return 1;return 0},M.core_formchangechecker.reset_form_dirty_state=function(){M.core_formchangechecker.stateinformation.formsubmitted=!1,M.core_formchangechecker.stateinformation.formchanged=!1},M.core_formchangechecker.report_form_dirty_state=function(e){if(!M.core_formchangechecker.get_form_dirty_state())return;var t=M.util.get_string("changesmadereallygoaway","moodle");if(M.cfg.behatsiterunning)return;return e&&(e.returnValue=t),t}},"@VERSION@",{requires:["base","event-focus"]}); diff --git a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker.js b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker.js index 868751f1160..6fbee86da65 100644 --- a/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker.js +++ b/lib/yui/build/moodle-core-formchangechecker/moodle-core-formchangechecker.js @@ -178,6 +178,14 @@ M.core_formchangechecker.get_form_dirty_state = function() { return 0; }; +/* + * Reset the form state + */ +M.core_formchangechecker.reset_form_dirty_state = function() { + M.core_formchangechecker.stateinformation.formsubmitted = false; + M.core_formchangechecker.stateinformation.formchanged = false; +}; + /* * Return a suitable message if changes have been made to a form */ diff --git a/lib/yui/src/formchangechecker/js/formchangechecker.js b/lib/yui/src/formchangechecker/js/formchangechecker.js index ae0d8099268..db1023f2cb4 100644 --- a/lib/yui/src/formchangechecker/js/formchangechecker.js +++ b/lib/yui/src/formchangechecker/js/formchangechecker.js @@ -176,6 +176,14 @@ M.core_formchangechecker.get_form_dirty_state = function() { return 0; }; +/* + * Reset the form state + */ +M.core_formchangechecker.reset_form_dirty_state = function() { + M.core_formchangechecker.stateinformation.formsubmitted = false; + M.core_formchangechecker.stateinformation.formchanged = false; +}; + /* * Return a suitable message if changes have been made to a form */ diff --git a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-debug.js b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-debug.js index 1c604a86d5e..3d73d5df9a9 100644 --- a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-debug.js +++ b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-debug.js @@ -225,7 +225,7 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. _bb: null, _sendLock: false, - + _hide: null, /** * Initializer. * @@ -236,10 +236,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. content; this._bb = this.get('boundingBox'); + this._hide = this.hide; // Prepare the content area. tpl = Y.Handlebars.compile( - '
' + + '' + '
' + '' + '' + @@ -296,6 +297,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. // Set the content as empty and lock send. this._bb.one(SELECTORS.SENDMSGDIALOG.INPUT).set('value', ''); + + // Register form with formchangechecker + Y.use('moodle-core-formchangechecker', function() { + M.core_formchangechecker.init({formid: "messageform"}); + }); }, /** @@ -369,6 +375,33 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. }); }, + /** + * Override the default hide function. + * @method hide + */ + hide: function() { + var self = this; + + if (!M.core_formchangechecker.get_form_dirty_state()) { + return SENDMSGDIALOG.superclass.hide.call(this, arguments); + } + + Y.use('moodle-core-notification-confirm', function() { + var confirm = new M.core.confirm({ + title : M.util.get_string('confirm', 'moodle'), + question : M.util.get_string('changesmadereallygoaway', 'moodle'), + yesLabel : M.util.get_string('confirm', 'moodle'), + noLabel : M.util.get_string('cancel', 'moodle') + }); + confirm.on('complete-yes', function() { + M.core_formchangechecker.reset_form_dirty_state(); + confirm.hide(); + confirm.destroy(); + return SENDMSGDIALOG.superclass.hide.call(this, arguments); + }, self); + }); + }, + /** * Show a notice. * diff --git a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-min.js b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-min.js index 82fe4150380..8f60a305e4c 100644 --- a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-min.js +++ b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger-min.js @@ -1 +1,2 @@ -YUI.add("moodle-core_message-messenger",function(e,t){var n={},r={};r.MANAGER={SENDMESSAGE:'[data-trigger="core_message-messenger::sendmessage"]'};var i=function(){i.superclass.constructor.apply(this,arguments)};e.namespace("M.core_message.messenger").Manager=e.extend(i,e.Base,{_sendMessageDialog:null,_events:[],initializer:function(){this._setEvents()},sendMessage:function(t,n,r){var i;this._sendMessageDialog||(i=e.namespace("M.core_message.messenger.sendMessage"),this._sendMessageDialog=new i({url:this.get("url")})),this._sendMessageDialog.prepareForUser(t,n),this._sendMessageDialog.show(r)},_setEvents:function(){var t=function(e){var t=e.currentTarget,n=parseInt(t.getData("userid"),10),r=t.getData("fullname");if(!n||!r)return;e.preventDefault(),this.sendMessage(n,r,e)};this._events.push(e.delegate("click",t,"body",r.MANAGER.SENDMESSAGE,this)),this._events.push(e.one(e.config.doc).delegate("key",t,"space",r.MANAGER.SENDMESSAGE,this))}},{NAME:"core_message-messenger-manager",ATTRS:{url:{readonly:!0,value:M.cfg.wwwroot+"/message/ajax.php"}}});var s;e.namespace("M.core_message.messenger").init=function(e){return s||(s=new i(e)),s},n.SENDMSGDIALOG={ACCESSHIDE:"accesshide",ACTIONS:"message-actions",FOOTER:"message-footer",HIDDEN:"hidden",HISTORYLINK:"message-history",INPUT:"message-input",INPUTAREA:"message-area",NOTICE:"message-notice",NOTICEAREA:"message-notice-area",PREFIX:"core_message-messenger-sendmessage",SENDBTN:"message-send",WRAPPER:"message-wrapper"},r.SENDMSGDIALOG={FORM:"form",HISTORYLINK:".message-history",INPUT:".message-input",NOTICE:".message-notice div",NOTICEAREA:".message-notice-area",SENDBTN:".message-send"};var o=function(){o.superclass.constructor.apply(this,arguments)};e.namespace("M.core_message.messenger").sendMessage=e.extend(o,M.core.dialogue,{_bb:null,_sendLock:!1,initializer:function(){var t,r;this._bb=this.get("boundingBox"),t=e.Handlebars.compile('
'),r=e.Node.create(t({CSSR:n.SENDMSGDIALOG,id:e.guid(),labelStr:M.util.get_string("messagetosend","core_message"),loadingIcon:M.util.image_url("i/loading","moodle"),sendStr:M.util.get_string("sendmessage","core_message"),viewHistoryStr:M.util.get_string("viewconversation","core_message")})),this.setStdModContent(e.WidgetStdMod.BODY,r,e.WidgetStdMod.REPLACE),this._bb.one(".moodle-dialogue-wrap").addClass("moodle-dialogue-content"),this._setEvents()},prepareForUser:function(t,n){var i;this.set("userid",t),this.set("fullname",n),i=e.Node.create("

"+e.Escape.html(n)+"

"),this.setStdModContent(e.WidgetStdMod.HEADER,i,e.WidgetStdMod.REPLACE),this._bb.one(r.SENDMSGDIALOG.HISTORYLINK).set("href",M.cfg.wwwroot+"/message/index.php?id="+this.get("userid")),this._bb.one(r.SENDMSGDIALOG.INPUT).set("value","")},sendMessage:function(t){if(this._sendLock)return;if(!t||!this._validateMessage(t))return;this._ioSend=e.io(this.get("url"),{method:"POST",data:{sesskey:M.cfg.sesskey,action:"sendmessage",userid:this.get("userid"),message:t},on:{start:function(){var e='';this.setSendLock(!0),this.showNotice(e+" "+M.util.get_string("sendingmessage","core_message"))},success:function(t,n){var r=null;try{r=e.JSON.parse(n.responseText);if(r.error){this.hideNotice(),new M.core.ajaxException(r);return}}catch(i){this.hideNotice(),new M.core.exception(i);return}this.showNotice(M.util.get_string("messagesent","core_message")),e.later(1300,this,function(){this.setSendLock(!1),this.hideNotice(),this.hide()})},failure:function(){this.setSendLock(!1),this.hideNotice(),new M.core.alert({title:M.util.get_string("error","core"),message:M.util.get_string("errorwhilesendingmessage","core_message")})}},context:this})},hideNotice:function(){this._bb.one(r.SENDMSGDIALOG.NOTICEAREA).hide()},showNotice:function(e){this._bb.one(r.SENDMSGDIALOG.NOTICE).setHTML(e),this._bb.one(r.SENDMSGDIALOG.NOTICEAREA).show()},setSendLock:function(e){e?this._sendLock=!0:this._sendLock=!1},_setEvents:function(){this._bb.one(r.SENDMSGDIALOG.FORM).on("submit",function(e){var t=this._bb.one(r.SENDMSGDIALOG.INPUT).get("value");e.preventDefault(),this.sendMessage(t)},this)},_validateMessage:function(e){var t;return e?(t=e.replace(" ","").replace(" ","").replace(/((<\/br\s*\/?>)?)+/,"").trim(),t.length>1):!1}},{NAME:"core_message-messenger-sendmessage",CSS_PREFIX:n.SENDMSGDIALOG.PREFIX,ATTRS:{fullname:{validator:e.Lang.isString,value:""},url:{validator:e.Lang.isString,value:null},userid:{validator:e.Lang.isNumber,value:0}}}),e.Base.modifyAttrs(e.namespace("M.core_message.messenger.sendMessage"),{extraClasses:{value:["core_message-messenger-sendmessage"]},focusOnPreviousTargetAfterHide:{value:!0},width:{value:"360px"},visible:{value:!1},modal:{value:!0},draggable:{value:!1},center:{value:!0}})},"@VERSION@",{requires:["escape","handlebars","io-base","moodle-core-notification-ajaxexception","moodle-core-notification-alert","moodle-core-notification-dialogue","moodle-core-notification-exception"]}); +YUI.add("moodle-core_message-messenger",function(e,t){var n={},r={};r.MANAGER={SENDMESSAGE:'[data-trigger="core_message-messenger::sendmessage"]'};var i=function(){i.superclass.constructor.apply(this,arguments)};e.namespace("M.core_message.messenger").Manager=e.extend(i,e.Base,{_sendMessageDialog:null,_events:[],initializer:function(){this._setEvents()},sendMessage:function(t,n,r){var i;this._sendMessageDialog||(i=e.namespace("M.core_message.messenger.sendMessage"),this._sendMessageDialog=new i({url:this.get("url")})),this._sendMessageDialog.prepareForUser(t,n),this._sendMessageDialog.show(r)},_setEvents:function(){var t=function(e){var t=e.currentTarget,n=parseInt(t.getData("userid"),10),r=t.getData("fullname");if(!n||!r)return;e.preventDefault(),this.sendMessage(n,r,e)};this._events.push(e.delegate("click",t,"body",r.MANAGER.SENDMESSAGE,this)),this._events.push(e.one(e.config.doc).delegate("key",t,"space",r.MANAGER.SENDMESSAGE,this))}},{NAME:"core_message-messenger-manager",ATTRS:{url:{readonly:!0,value:M.cfg.wwwroot+"/message/ajax.php"}}});var s;e.namespace("M.core_message.messenger").init=function(e){return s||(s=new i(e)),s},n.SENDMSGDIALOG={ACCESSHIDE:"accesshide",ACTIONS:"message-actions",FOOTER:"message-footer",HIDDEN:"hidden",HISTORYLINK:"message-history",INPUT:"message-input",INPUTAREA:"message-area",NOTICE:"message-notice",NOTICEAREA:"message-notice-area",PREFIX:"core_message-messenger-sendmessage",SENDBTN:"message-send",WRAPPER:"message-wrapper"},r.SENDMSGDIALOG={FORM:"form",HISTORYLINK:".message-history",INPUT:".message-input",NOTICE:".message-notice div",NOTICEAREA:".message-notice-area",SENDBTN:".message-send"};var o=function(){o.superclass.constructor.apply(this,arguments)};e.namespace("M.core_message.messenger").sendMessage=e.extend(o,M.core.dialogue,{_bb:null,_sendLock:!1,_hide:null,initializer:function(){var t,r;this._bb=this.get("boundingBox"),this._hide=this.hide,t=e.Handlebars.compile('
'),r=e.Node.create(t({CSSR:n.SENDMSGDIALOG,id:e.guid(),labelStr:M.util.get_string("messagetosend","core_message"),loadingIcon:M.util.image_url("i/loading","moodle"),sendStr:M.util.get_string("sendmessage","core_message"),viewHistoryStr:M.util.get_string("viewconversation","core_message")})),this.setStdModContent(e.WidgetStdMod.BODY,r,e.WidgetStdMod.REPLACE),this._bb.one(".moodle-dialogue-wrap").addClass("moodle-dialogue-content"),this._setEvents()},prepareForUser:function(t,n){var i;this.set("userid",t),this.set("fullname",n),i=e.Node.create("

"+e.Escape.html(n)+"

"),this.setStdModContent(e.WidgetStdMod.HEADER,i,e.WidgetStdMod.REPLACE),this._bb.one(r.SENDMSGDIALOG.HISTORYLINK).set("href",M.cfg.wwwroot+"/message/index.php?id="+this.get("userid")),this._bb.one(r.SENDMSGDIALOG.INPUT).set("value",""),e.use("moodle-core-formchangechecker",function(){M.core_formchangechecker.init({formid:"messageform"})})},sendMessage:function(t){if(this._sendLock)return;if(!t||!this._validateMessage(t))return;this._ioSend=e.io(this.get("url"),{method:"POST",data:{sesskey:M.cfg.sesskey,action:"sendmessage",userid:this.get("userid"),message:t},on:{start:function(){var e='';this.setSendLock(!0),this.showNotice(e+" "+M.util.get_string("sendingmessage","core_message"))},success:function(t,n){var r=null;try{r=e.JSON.parse(n.responseText);if(r.error){this.hideNotice(),new M.core.ajaxException(r);return}}catch(i){this.hideNotice(),new M.core.exception(i);return}this.showNotice(M.util.get_string("messagesent","core_message")),e.later(1300,this,function(){this.setSendLock(!1),this.hideNotice(),this.hide()})},failure:function(){this.setSendLock(!1),this.hideNotice(),new M.core.alert({title:M.util.get_string("error","core"),message:M.util.get_string("errorwhilesendingmessage","core_message")})}},context:this})},hide:function(){var t=this;if(!M.core_formchangechecker.get_form_dirty_state())return o.superclass.hide.call(this,arguments);e.use("moodle-core-notification-confirm",function(){var e=new M.core.confirm({title:M.util.get_string("confirm","moodle"),question:M.util.get_string("changesmadereallygoaway","moodle"),yesLabel:M.util.get_string("confirm","moodle"),noLabel:M.util.get_string("cancel","moodle")});e.on("complete-yes",function(){return M.core_formchangechecker.reset_form_dirty_state(),e.hide(),e.destroy(),o.superclass.hide.call(this,arguments)},t)})},hideNotice:function(){this._bb.one(r.SENDMSGDIALOG.NOTICEAREA).hide()},showNotice:function(e){this._bb.one(r.SENDMSGDIALOG.NOTICE).setHTML(e),this._bb.one(r.SENDMSGDIALOG.NOTICEAREA).show()},setSendLock:function(e){e?this._sendLock=!0:this._sendLock=!1},_setEvents:function(){this._bb.one(r.SENDMSGDIALOG.FORM).on("submit",function(e){var t=this._bb.one(r.SENDMSGDIALOG.INPUT).get("value");e.preventDefault(),this.sendMessage(t)},this)},_validateMessage:function(e){var t;return e?(t=e.replace(" ","").replace(" ","").replace(/((<\/br\s*\/?>)?)+/,"").trim(),t.length>1):!1}},{NAME:"core_message-messenger-sendmessage",CSS_PREFIX:n.SENDMSGDIALOG.PREFIX,ATTRS:{fullname:{validator:e.Lang.isString,value:""},url:{validator:e.Lang.isString,value:null},userid:{validator:e.Lang.isNumber,value:0}}}),e.Base.modifyAttrs(e.namespace("M.core_message.messenger.sendMessage"),{extraClasses:{value:["core_message-messenger-sendmessage"]},focusOnPreviousTargetAfterHide:{value:!0},width:{value:"360px"},visible:{value:!1},modal:{value:!0},draggable:{value:!1},center +:{value:!0}})},"@VERSION@",{requires:["escape","handlebars","io-base","moodle-core-notification-ajaxexception","moodle-core-notification-alert","moodle-core-notification-dialogue","moodle-core-notification-exception"]}); diff --git a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger.js b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger.js index 1c604a86d5e..3d73d5df9a9 100644 --- a/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger.js +++ b/message/yui/build/moodle-core_message-messenger/moodle-core_message-messenger.js @@ -225,7 +225,7 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. _bb: null, _sendLock: false, - + _hide: null, /** * Initializer. * @@ -236,10 +236,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. content; this._bb = this.get('boundingBox'); + this._hide = this.hide; // Prepare the content area. tpl = Y.Handlebars.compile( - '
' + + '' + '
' + '' + '' + @@ -296,6 +297,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. // Set the content as empty and lock send. this._bb.one(SELECTORS.SENDMSGDIALOG.INPUT).set('value', ''); + + // Register form with formchangechecker + Y.use('moodle-core-formchangechecker', function() { + M.core_formchangechecker.init({formid: "messageform"}); + }); }, /** @@ -369,6 +375,33 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. }); }, + /** + * Override the default hide function. + * @method hide + */ + hide: function() { + var self = this; + + if (!M.core_formchangechecker.get_form_dirty_state()) { + return SENDMSGDIALOG.superclass.hide.call(this, arguments); + } + + Y.use('moodle-core-notification-confirm', function() { + var confirm = new M.core.confirm({ + title : M.util.get_string('confirm', 'moodle'), + question : M.util.get_string('changesmadereallygoaway', 'moodle'), + yesLabel : M.util.get_string('confirm', 'moodle'), + noLabel : M.util.get_string('cancel', 'moodle') + }); + confirm.on('complete-yes', function() { + M.core_formchangechecker.reset_form_dirty_state(); + confirm.hide(); + confirm.destroy(); + return SENDMSGDIALOG.superclass.hide.call(this, arguments); + }, self); + }); + }, + /** * Show a notice. * diff --git a/message/yui/src/messenger/js/sendmessage.js b/message/yui/src/messenger/js/sendmessage.js index 51d81eb73c5..8998638f9dd 100644 --- a/message/yui/src/messenger/js/sendmessage.js +++ b/message/yui/src/messenger/js/sendmessage.js @@ -60,7 +60,7 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. _bb: null, _sendLock: false, - + _hide: null, /** * Initializer. * @@ -71,10 +71,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. content; this._bb = this.get('boundingBox'); + this._hide = this.hide; // Prepare the content area. tpl = Y.Handlebars.compile( - '' + + '' + '
' + '' + '' + @@ -131,6 +132,11 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. // Set the content as empty and lock send. this._bb.one(SELECTORS.SENDMSGDIALOG.INPUT).set('value', ''); + + // Register form with formchangechecker + Y.use('moodle-core-formchangechecker', function() { + M.core_formchangechecker.init({formid: "messageform"}); + }); }, /** @@ -204,6 +210,33 @@ Y.namespace('M.core_message.messenger').sendMessage = Y.extend(SENDMSGDIALOG, M. }); }, + /** + * Override the default hide function. + * @method hide + */ + hide: function() { + var self = this; + + if (!M.core_formchangechecker.get_form_dirty_state()) { + return SENDMSGDIALOG.superclass.hide.call(this, arguments); + } + + Y.use('moodle-core-notification-confirm', function() { + var confirm = new M.core.confirm({ + title : M.util.get_string('confirm', 'moodle'), + question : M.util.get_string('changesmadereallygoaway', 'moodle'), + yesLabel : M.util.get_string('confirm', 'moodle'), + noLabel : M.util.get_string('cancel', 'moodle') + }); + confirm.on('complete-yes', function() { + M.core_formchangechecker.reset_form_dirty_state(); + confirm.hide(); + confirm.destroy(); + return SENDMSGDIALOG.superclass.hide.call(this, arguments); + }, self); + }); + }, + /** * Show a notice. *