From 7e1d4186adda764a6262e72020ede9c689a6e023 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Mon, 14 Jun 2010 19:22:49 +0000 Subject: [PATCH] NIHVIVO-646 Move custom form utilities to a separate js file and add utility mixin methods to mix them in to specific custom forms. Make paths to css and js files in formPrefix.jsp and formSuffix.jsp absolute instead of relative. --- webapp/web/edit/formPrefix.jsp | 6 +++--- webapp/web/edit/formSuffix.jsp | 14 ++++++------- webapp/web/js/customFormUtils.js | 27 ++++++++++++++++++++++++ webapp/web/js/utils.js | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 webapp/web/js/customFormUtils.js create mode 100644 webapp/web/js/utils.js diff --git a/webapp/web/edit/formPrefix.jsp b/webapp/web/edit/formPrefix.jsp index 036a9e447..9cee407d8 100644 --- a/webapp/web/edit/formPrefix.jsp +++ b/webapp/web/edit/formPrefix.jsp @@ -64,15 +64,15 @@ <% String useAutoComplete = (useAutoComplete=request.getParameter("useAutoComplete")) != null && !(useAutoComplete.equals("")) ? useAutoComplete : "false"; if (useAutoComplete.equalsIgnoreCase("true")) { %> - + " /> <% } %> - + " media="screen"/> - + " /> " media="screen"/> " media="screen"/> diff --git a/webapp/web/edit/formSuffix.jsp b/webapp/web/edit/formSuffix.jsp index 4fb07c412..70aad6851 100644 --- a/webapp/web/edit/formSuffix.jsp +++ b/webapp/web/edit/formSuffix.jsp @@ -13,15 +13,15 @@ - - - - - - + > + + + + + - + diff --git a/webapp/web/js/customFormUtils.js b/webapp/web/js/customFormUtils.js new file mode 100644 index 000000000..29e9bade7 --- /dev/null +++ b/webapp/web/js/customFormUtils.js @@ -0,0 +1,27 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var vitro; +if (!vitro) { + vitro = {}; +} + +vitro.customFormUtils = { + + // This method should always be called instead of calling hide() directly on any + // element containing form fields. + hideFields: function(el) { + // Clear any input and error message, so if we re-show the element it won't still be there. + this.clearFields(el); + el.hide(); + }, + + // Clear data from form elements in element el + clearFields: function(el) { + el.find(':input[type!="hidden"][type!="submit"][type!="button"]').val(''); + + // For now we can remove the error elements. Later we may include them in + // the markup, for customized positioning, in which case we will empty them + // but not remove them here. See findValidationErrors(). + el.find('.validationError').remove(); + } +} \ No newline at end of file diff --git a/webapp/web/js/utils.js b/webapp/web/js/utils.js new file mode 100644 index 000000000..d62fa4e42 --- /dev/null +++ b/webapp/web/js/utils.js @@ -0,0 +1,35 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var vitro; +if (!vitro) { + vitro = {}; +} +/* From "JavaScript: The Definitive Guide," 5th edition, by David Flanagan + * Copyright 2006 O'Reilly Media, Inc. + * ISBN 978-0-596-10199-2 + */ + +vitro.utils = { + + // Borrow methods from one class for use by another. + // The arguments should be the constructor functions for the classes. + // Methods of built-in types such as Object, Array, Date, and RegExp are + // not enumerable and cannot be borrowed from with this method. + borrowPrototypeMethods: function(borrowFrom, addTo) { + var from = borrowFrom.prototype; // prototype object to borrow from + var to = addTo.prototype; // prototype object to extend + + for (m in from) { // loop through all properties of the prototype + if (typeof from[m] != "function") { continue; } // ignore non-functions + to[m] = from[m]; + } + }, + + borrowMethods: function(borrowFrom, addTo) { + for (m in borrowFrom) { // loop through all properties of the prototype + if (typeof borrowFrom[m] != "function") { continue; } // ignore non-functions + addTo[m] = borrowFrom[m]; + } + } + +}; \ No newline at end of file