Skip to content

Commit

Permalink
Item10603:
Browse files Browse the repository at this point in the history
   * removing FlexForm wiki code
   * using latest autocomplete 
   * improved integration of validation 



git-svn-id: http://svn.foswiki.org/trunk@12643 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Sep 28, 2011
1 parent 3833ee1 commit 368f86d
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 194 deletions.
2 changes: 1 addition & 1 deletion NatEditPlugin/lib/Foswiki/Plugins/NatEditPlugin.pm
Expand Up @@ -22,7 +22,7 @@ use vars qw(
);

$VERSION = '$Rev$';
$RELEASE = '4.50';
$RELEASE = '4.60';

$NO_PREFS_IN_TOPIC = 1;
$SHORTDESCRIPTION = 'A Wikiwyg Editor';
Expand Down
8 changes: 3 additions & 5 deletions NatEditPlugin/lib/Foswiki/Plugins/NatEditPlugin/NATEDIT.pm
Expand Up @@ -29,27 +29,25 @@ This is the perl stub for the jquery.natedit plugin.

=begin TML
---++ ClassMethod new( $class, $session, ... )
---++ ClassMethod new( $class, ... )
Constructor
=cut

sub new {
my $class = shift;
my $session = shift || $Foswiki::Plugins::SESSION;

my $this = bless($class->SUPER::new(
$session,
name => 'NatEdit',
version => '1.0',
version => '1.1',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Extensions/NatEditPlugin',
puburl => '%PUBURLPATH%/%SYSTEMWEB%/NatEditPlugin',
css => ['styles.css'],
documentation => "$Foswiki::cfg{SystemWebName}.NatEditPlugin",
javascript => ['edit.js', 'jquery.natedit.js'],
dependencies => ['simplemodal', 'textboxlist', 'form'],
dependencies => ['simplemodal', 'textboxlist', 'form', 'validate', 'ui'],
), $class);

return $this;
Expand Down
331 changes: 209 additions & 122 deletions NatEditPlugin/pub/System/NatEditPlugin/edit.uncompressed.js
Expand Up @@ -10,145 +10,232 @@ function fixHeightOfPane () { }
(function($) {
var editAction, $editForm;

function showErrorMessage(msg) {
$("#natEditMessageContainer").addClass("foswikiErrorMessage").html(msg).hide().fadeIn("slow");
$(window).trigger("resize");
}
function hideErrorMessage() {
$("#natEditMessageContainer").removeClass("foswikiErrorMessage").hide();
$(window).trigger("resize");
}

// add submit handler
function submitHandler() {
var topicParentField = $editForm.find("input[name=topicparent]");
$(function() {
$("form[name=EditForm]").livequery(function() {
var $editForm = $(this);

if (typeof(beforeSubmitHandler) == 'function') {
if(beforeSubmitHandler("save", editAction) === false) {
return false;
}
}
function submitHandler() {
var topicParentField = $editForm.find("input[name=topicparent]");

if (typeof(beforeSubmitHandler) == 'function') {
if(beforeSubmitHandler("save", editAction) === false) {
return false;
}
}

if (topicParentField.val() === "") {
topicParentField.val("none"); // trick in unsetting the topic parent
}

if (editAction === 'addform') {
$editForm.find("input[name='submitChangeForm']").val(editAction);
}
$editForm.find("input[name='action_preview']").val('');
$editForm.find("input[name='action_save']").val('');
$editForm.find("input[name='action_checkpoint']").val('');
$editForm.find("input[name='action_addform']").val('');
$editForm.find("input[name='action_replaceform']").val('');
$editForm.find("input[name='action_cancel']").val('');
$editForm.find("input[name='action_"+editAction+"']").val('foobar');

if (typeof(foswikiStrikeOne) != 'undefined') {
foswikiStrikeOne($editForm[0]);
}
if (topicParentField.val() === "") {
topicParentField.val("none"); // trick in unsetting the topic parent
}

if ((typeof(tinyMCE) === 'object') &&
(typeof(tinyMCE.activeEditor) === 'object') &&
(tinyMCE.activeEditor !== null)) {
tinyMCE.activeEditor.onSubmit.dispatch();
}
}
if (editAction === 'addform') {
$editForm.find("input[name='submitChangeForm']").val(editAction);
}
$editForm.find("input[name='action_preview']").val('');
$editForm.find("input[name='action_save']").val('');
$editForm.find("input[name='action_checkpoint']").val('');
$editForm.find("input[name='action_addform']").val('');
$editForm.find("input[name='action_replaceform']").val('');
$editForm.find("input[name='action_cancel']").val('');
$editForm.find("input[name='action_"+editAction+"']").val('foobar');

$(function() {
$editForm = $("#EditForm");

/* remove the second TopicTitle */
$("input[name='TopicTitle']:eq(1)").parents(".foswikiFormStep").remove();

/* remove the second Summary */
$("input[name='Summary']:eq(1)").parents(".foswikiFormStep").remove();

/* add click handler */
$("#save").click(function() {
editAction = "save";
$editForm.submit();
return false;
});
$("#checkpoint").click(function() {
editAction = "checkpoint";
if ((typeof(tinyMCE) === 'object') && typeof(tinyMCE.activeEditor === 'object')) {
// don't ajax using wysiwyg
$editForm.submit();
} else {
// only ajax using raw
submitHandler();
$editForm.ajaxSubmit({
beforeSubmit: function() {
$.blockUI({message:'<h1> Saving ... </h1>'});
},
error: function(xhr, textStatus, errorThrown) {
var message = $(xhr.response).find(".natErrorMessage").text().replace(/\s+/g, ' ').replace(/^\s+/, '') || textStatus;
$.unblockUI();
alert(message);
},
success: function(data, textStatus) {
$.unblockUI();
}
});
if (typeof(foswikiStrikeOne) != 'undefined') {
foswikiStrikeOne($editForm[0]);
}

if ((typeof(tinyMCE) === 'object') &&
(typeof(tinyMCE.activeEditor) === 'object') &&
(tinyMCE.activeEditor !== null)) {
tinyMCE.activeEditor.onSubmit.dispatch();
}

return true;
}
return false;
});
$("#preview").click(function() {
editAction = "preview";
//$editForm.submit();
submitHandler();
$editForm.ajaxSubmit({
beforeSubmit: function() {
$.blockUI({message:'<h1> Loading preview ... </h1>'});
},
error: function(xhr, textStatus, errorThrown) {
var message = $(xhr.response).find(".natErrorMessage").text().replace(/\s+/g, ' ').replace(/^\s+/, '') || textStatus;
$.unblockUI();
alert(message);
},
success: function(data, textStatus) {
var $window = $(window),
height,
width = Math.round(parseInt($window.width() * 0.6, 10));

$.unblockUI();
foswiki.openDialog(data, {
close: true,
containerCss: {
width: width

if ($editForm.is("natEditFormInited")) {
return;
}
$editForm.addClass("natEditFormInited");

/* remove the second TopicTitle */
$("input[name='TopicTitle']:eq(1)").parents(".foswikiFormStep").remove();

/* remove the second Summary */
$("input[name='Summary']:eq(1)").parents(".foswikiFormStep").remove();

/* add click handler */
$("#save").click(function() {
editAction = "save";
if (submitHandler()) {
$editForm.submit();
}
return false;
});
$("#checkpoint").click(function() {
var topicName = foswiki.getPreference("TOPIC") || '';
editAction = "checkpoint";
if ($editForm.validate().form()) {
if (!submitHandler()) {
return false;
}
if (topicName.match(/AUTOINC|XXXXXXXXXX/) || (typeof(tinyMCE) === 'object' && typeof(tinyMCE.activeEditor === 'object'))) {
// don't ajax using wysiwyg
$editForm.submit();
} else {
// only ajax using raw
$editForm.ajaxSubmit({
beforeSubmit: function() {
hideErrorMessage();
$.blockUI({message:'<h1> Saving ... </h1>'});
},
error: function(xhr, textStatus, errorThrown) {
var message = $(xhr.response).find(".natErrorMessage").text().replace(/\s+/g, ' ').replace(/^\s+/, '') || textStatus;
$.unblockUI();
showErrorMessage(message);
},
success: function(data, textStatus) {
$.unblockUI();
}
});
}
}
return false;
});
$("#preview").click(function() {
editAction = "preview";
if ($editForm.validate().form()) {
if (!submitHandler()) {
return false;
}
$editForm.ajaxSubmit({
beforeSubmit: function() {
hideErrorMessage();
$.blockUI({message:'<h1> Loading preview ... </h1>'});
},
error: function(xhr, textStatus, errorThrown) {
var message = $(xhr.response).find(".natErrorMessage").text().replace(/\s+/g, ' ').replace(/^\s+/, '') || textStatus;
$.unblockUI();
showErrorMessage(message);
},
onShow: function(dialog) {
$window.bind('resize', function() {
height = Math.round(parseInt($window.height() * 0.6, 10));
width = Math.round(parseInt($window.width() * 0.6, 10));
if (width < 640) {
width = 640;
success: function(data, textStatus) {
var $window = $(window),
height,
width = Math.round(parseInt($window.width() * 0.6, 10));

$.unblockUI();
foswiki.openDialog(data, {
close: true,
containerCss: {
width: width
},
onShow: function(dialog) {
$window.bind('resize', function() {
height = Math.round(parseInt($window.height() * 0.6, 10));
width = Math.round(parseInt($window.width() * 0.6, 10));
if (width < 640) {
width = 640;
}
dialog.container.width(width);
dialog.container.find(".foswikiPreviewArea").height(height);
});
$window.trigger('resize');
}
dialog.container.width(width);
dialog.container.find(".foswikiPreviewArea").height(height);
});
$window.trigger('resize');
}
});
}
return false;
});
$("#cancel").click(function() {
editAction = "cancel";
hideErrorMessage();
$("label.error").hide();
$("input.error").removeClass("error");
$(".jqTabGroup a.error").removeClass("error");
submitHandler();
$editForm.submit();
return false;
});
$("#replaceform").click(function() {
editAction = "replaceform";
submitHandler();
$editForm.submit();
return false;
});
$("#addform").click(function() {
editAction = "addform";
submitHandler();
$editForm.submit();
return false;
});
return false;
});
$("#cancel").click(function() {
editAction = "cancel";
$editForm.submit();
return false;
});
$("#replaceform").click(function() {
editAction = "replaceform";
$editForm.submit();
return false;
});
$("#addform").click(function() {
editAction = "addform";
$editForm.submit();
return false;
});

// fix browser back button quirks where checked radio buttons loose their state
$("input[checked=checked]").each(function() {
$(this).attr('checked', 'checked');
});
// fix browser back button quirks where checked radio buttons loose their state
$("input[checked=checked]").each(function() {
$(this).attr('checked', 'checked');
});

/* add clientside form validation */
var formRules = $.extend({}, $editForm.metadata({
type:'attr',
name:'validate'
}));

$editForm.validate({
meta: "validate",
invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids(),
$form = $(validator.currentForm);

/* ignore a cancel action */
if ($form.find("input[name*=action_][value=foobar]").attr("name") == "action_cancel") {
validator.currentForm.submit();
validator.errorList = [];
return;
}

$editForm.submit(submitHandler);
if (errors) {
var message = errors == 1
? 'There\'s an error. It has been highlighted below.'
: 'There are ' + errors + ' errors. They have been highlighted below.';
showErrorMessage(message);
$.each(validator.errorList, function() {
var $errorElem = $(this.element);
$errorElem.parents(".jqTab").each(function() {
var id = $(this).attr("id");
$("[data="+id+"]").addClass("error");
});
});
} else {
hideErrorMessage();
$form.find(".jqTabGroup a.error").removeClass("error");
}
},
rules: formRules,
ignoreTitle: true,
errorPlacement: function(error, element) {
if (element.is("[type=checkbox],[type=radio]")) {
// special placement if we are inside a table
$("<td>").appendTo(element.parents("tr:first")).append(error);
} else {
// default
error.insertAfter(element);
}
}
});
$.validator.addClassRules("foswikiMandatory", {
required: true
});
});
});

// patch in tinymce
Expand Down

0 comments on commit 368f86d

Please sign in to comment.