Permalink
Browse files

Further Moodle integration polishing.

- Fixed the config JSON files. Now PaintWeb loads in Safari 4, once again.
Thanks to Dan Poltawski for his bug report and his time for testing.

- The Moodle extension now displays a quickform validation error when the user
tries to submit a form while editing an image with unsaved changes, as suggested
by Martin Langhoff.

- The Moodle extension now hides the textarea[format] selection drop-down while
PaintWeb is visible.

--HG--
extra : convert_revision : svn%3Afc1ba2b4-ac28-11dd-a772-7fcde58d38e6/trunk%40117
  • Loading branch information...
1 parent c3bd1fc commit 4169ee42fbac072edf1e61a57364afd635179ab3 mihai.sucan committed Aug 23, 2009
Showing with 121 additions and 18 deletions.
  1. +13 −0 CHANGES
  2. +2 −2 ext/moodle/config.json
  3. +6 −5 ext/tinymce-plugin/paintweb/editor_plugin_src.js
  4. +2 −2 src/config-example.json
  5. +95 −7 src/extensions/moodle.js
  6. +3 −2 src/lang/en.json
View
13 CHANGES
@@ -1,3 +1,16 @@
+2009-08-23:
+===========
+
+- Fixed the config JSON files. Now PaintWeb loads in Safari 4, once again.
+Thanks to Dan Poltawski for his bug report and his time for testing.
+
+- The Moodle extension now displays a quickform validation error when the user
+tries to submit a form while editing an image with unsaved changes, as suggested
+by Martin Langhoff.
+
+- The Moodle extension now hides the textarea[format] selection drop-down while
+PaintWeb is visible.
+
2009-08-20:
===========
View
@@ -1,5 +1,5 @@
{
- // $Date: 2009-08-13 20:22:44 +0300 $
+ // $Date: 2009-08-23 16:28:45 +0300 $
/**
* The list of available languages. This associated language IDs to their
@@ -645,7 +645,7 @@
// Miscellaneous commands.
"X": { "command": "swapFillStroke" },
- "F1": { "command": "about" },
+ "F1": { "command": "about" }
},
/**
@@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
- * $Date: 2009-08-20 20:03:26 +0300 $
+ * $Date: 2009-08-23 16:30:16 +0300 $
*/
/**
@@ -951,10 +951,7 @@ tinymce.create('tinymce.plugins.paintweb', {
// The image is not saved, thus we prevent form submission.
ev.preventDefault();
- if (typeof paintwebConfig.tinymce.onSubmitUnsaved === 'function') {
- paintwebConfig.tinymce.onSubmitUnsaved(ev, ed, paintwebInstance);
-
- } else {
+ if (pluginBar) {
var str = ed.getLang('paintweb.submitUnsaved',
'The image is not saved! You cannot submit the form. Please save ' +
'the image changes, or cancel image editing, then try again.');
@@ -971,6 +968,10 @@ tinymce.create('tinymce.plugins.paintweb', {
pluginBar.focus();
pluginBar.tabIndex = -1;
}
+
+ if (typeof paintwebConfig.tinymce.onSubmitUnsaved === 'function') {
+ paintwebConfig.tinymce.onSubmitUnsaved(ev, ed, paintwebInstance);
+ }
},
/**
View
@@ -1,5 +1,5 @@
{
- // $Date: 2009-08-13 19:23:55 +0300 $
+ // $Date: 2009-08-22 12:05:52 +0300 $
// TODO: try jsdoc-toolkit on this json (!)
/**
@@ -641,7 +641,7 @@
// Miscellaneous commands.
"X": { "command": "swapFillStroke" },
- "F1": { "command": "about" },
+ "F1": { "command": "about" }
}
// vim:set spell spl=en fo=wan1croql tw=80 ts=2 sw=2 sts=2 sta et ai cin fenc=utf-8 ff=unix ft=javascript:
View
@@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
- * $Date: 2009-08-12 17:51:51 +0300 $
+ * $Date: 2009-08-23 17:36:33 +0300 $
*/
/**
@@ -42,7 +42,8 @@ pwlib.extensions.moodle = function (app) {
gui = app.gui,
lang = app.lang.moodle,
moodleServer = config.moodleServer,
- tinymceEditor = null;
+ tinymceEditor = null,
+ qfErrorShown = false;
// Holds information related to Moodle.
var moodleInfo = {
@@ -71,7 +72,8 @@ pwlib.extensions.moodle = function (app) {
};
/**
- * The <code>extensionRegister</code> event handler.
+ * The <code>extensionRegister</code> event handler. Setup event listeners,
+ * determine Moodle version, and more.
*
* @returns {Boolean} True if the extension initialized successfully, or false
* if not.
@@ -89,10 +91,47 @@ pwlib.extensions.moodle = function (app) {
}
}
+ if (moodleInfo.release >= 2 && typeof window.qf_errorHandler === 'function'
+ && config.tinymce && !config.tinymce.onSubmitUnsaved) {
+ config.tinymce.onSubmitUnsaved = this.onSubmitUnsaved;
+ }
+
return true;
};
/**
+ * The <code>submit</code> event handler for the form to which the PaintWeb
+ * instance is attached to. This method is invoked by the TinyMCE plugin when
+ * the form is submitted while the user edits an image with unsaved changes.
+ * @private
+ */
+ this.onSubmitUnsaved = function () {
+ var tmce = config.tinymceEditor,
+ textarea = tmce ? tmce.getElement() : null,
+ guiPlaceholder = config.guiPlaceholder,
+ prevSibling = guiPlaceholder.previousSibling;
+
+ if (tmce && textarea && window.qf_errorHandler) {
+ try {
+ qf_errorHandler(textarea, "\n - " + lang.errorSubmitUnsaved);
+ } catch (err) {
+ return;
+ }
+
+ qfErrorShown = true;
+
+ // Due to the styling of the error shown by Moodle, PaintWeb must have
+ // clear:right.
+ if (prevSibling && prevSibling.className &&
+ prevSibling.className.indexOf('paintweb_tinymce_status') !== -1) {
+ prevSibling.style.clear = 'right';
+ } else {
+ guiPlaceholder.style.clear = 'right';
+ }
+ }
+ };
+
+ /**
* The <code>imageSave</code> application event handler. When the user
* attempts to save an image, this extension handles the event by sending the
* image data to the Moodle server, to perform the actual save operation.
@@ -226,6 +265,8 @@ pwlib.extensions.moodle = function (app) {
elem.style.display = 'none';
}
+ qfErrorShown = false;
+
// For Moodle 2.0 we must determine the draft item ID in order to properly
// perform the image save operation into the current draft area.
if (moodleInfo.release < 2) {
@@ -240,16 +281,25 @@ pwlib.extensions.moodle = function (app) {
textarea = tmce ? tmce.getElement() : null,
frm = textarea ? textarea.form : null;
- if (!textarea || !textarea.name || !frm) {
+ if (!tmce || !textarea || !textarea.name || !frm) {
+ return;
+ }
+
+ var fieldname = textarea.name.replace(/\[text\]$/, '');
+ if (!fieldname) {
return;
}
- var tname = textarea.name.replace(/\[text\]$/, ''),
- draftitemid = tname ? frm.elements.namedItem(tname + '[itemid]') : null;
+ var draftitemid = frm.elements.namedItem(fieldname + '[itemid]'),
+ format = frm.elements.namedItem(fieldname + '[format]');
if (draftitemid) {
moodleInfo.draftitemid = draftitemid.value;
}
+
+ if (format) {
+ format.style.display = 'none';
+ }
};
/**
@@ -259,12 +309,50 @@ pwlib.extensions.moodle = function (app) {
* @private
*/
this.guiHide = function () {
- var pNode = config.guiPlaceholder.parentNode,
+ var guiPlaceholder = config.guiPlaceholder,
+ prevSibling = guiPlaceholder.previousSibling;
+ pNode = guiPlaceholder.parentNode,
elem = pNode.getElementsByClassName(moodleInfo.textareaButtons)[0];
if (elem) {
elem.style.display = '';
}
+
+ if (moodleInfo.release < 2) {
+ return;
+ }
+
+ var tmce = config.tinymceEditor,
+ textarea = tmce ? tmce.getElement() : null,
+ frm = textarea ? textarea.form : null;
+
+ if (!tmce || !textarea || !textarea.name || !frm) {
+ return;
+ }
+
+ if (qfErrorShown) {
+ if (window.qf_errorHandler) {
+ qf_errorHandler(textarea, '');
+ }
+
+ if (prevSibling && prevSibling.className &&
+ prevSibling.className.indexOf('paintweb_tinymce_status') !== -1) {
+ prevSibling.style.clear = '';
+ } else {
+ guiPlaceholder.style.clear = '';
+ }
+ }
+
+ var fieldname = textarea.name.replace(/\[text\]$/, '');
+ if (!fieldname) {
+ return;
+ }
+
+ var format = frm.elements.namedItem(fieldname + '[format]');
+
+ if (format) {
+ format.style.display = '';
+ }
};
};
View
@@ -1,5 +1,5 @@
{
- // $Date: 2009-08-13 19:04:48 +0300 $
+ // $Date: 2009-08-23 16:53:28 +0300 $
"errorInitBufferCanvas": "Error: adding the new buffer canvas element failed.",
"errorInitContext": "Error while initializing the canvas context.",
@@ -244,7 +244,8 @@
"xhrRequestFailed": "The image save request failed.",
"jsonParseFailed": "Parsing the JSON result from the server failed!",
"imageSaveFailed": "The image save operation failed.",
- "urlMismatch": "Image address mismatch!\nThe current image is {url}.\nThe server replied a successful save for {urlServer}."
+ "urlMismatch": "Image address mismatch!\nThe current image is {url}.\nThe server replied a successful save for {urlServer}.",
+ "errorSubmitUnsaved": "This image is not saved!"
},
"moodleServer": {
"permissionDenied": "Permission denied.",

0 comments on commit 4169ee4

Please sign in to comment.