/* * This file is part of HOAM, copyright (C) 2002-2009 Robert D Butler Jr. * * HOAM is free software; you can redistribute it and/or modify it under the * terms of the GNU Affero General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) * any later version. * * HOAM is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with HOAM; if not, see http://www.gnu.org/licenses or write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 * * Questions specific to HOAM should be directed to HOA Management. Please see * the HOAM web site at http://hoam.hoa-management.com/ * * Some portions of HOAM incorporate ideas and/or code from other sources, and * those portions are explicitly mentioned and attributed in the relevant * section of HOAM source code. Questions about that code should be directed to * the original authors. * */ function HOAM_formInit () { // Look for LABELs and append help text, if any found. HOAM_formHelpLookup (); HOAM_formFieldTags (); } function HOAM_formFieldTags () { if ($('article')) { // 'article' is the old content id used, once all of the code has // been migrated then this check can safely be removed. var input_fields = $('article').getElementsByTagName ('INPUT'); var textarea_fields = $('article').getElementsByTagName ('TEXTAREA'); } else { var input_fields = $('page_content').getElementsByTagName ('INPUT'); var textarea_fields = $('page_content').getElementsByTagName ('TEXTAREA'); } // Check input tags for any special cases. if (input_fields.length > 0) { for (var i = 0; i < input_fields.length; i++) { field_type = input_fields[i].getAttribute ('field'); // Look for specific fields and apply validation where applicable switch (field_type) { case 'date': // This still uses Matt Kruse's calendar function, so we // need to work within those constraints. var calendar = new CalendarPopup(); calendar.showNavigationDropdowns(); var button = document.createElement ('IMG'); button.id = input_fields[i].name + '_button'; button.setAttribute ('src', '/hoam/images/icons/calendar.png'); button.setAttribute ('title', HOAM_languageLookup ('field_names|calendar|show')); button.style.cursor = 'pointer'; input_fields[i].parentNode.insertBefore (button, input_fields[i].nextSibling); Event.observe (button, 'click', function () { calendar.select (this.previousSibling, this.id, 'MM/dd/yyyy') }); break; case 'enable': var enable_checkbox = document.createElement ('INPUT'); enable_checkbox.id = input_fields[i].id + '_enable'; enable_checkbox.name = input_fields[i].id + '_enable'; enable_checkbox.setAttribute ('title', HOAM_languageLookup ('field_names|admin|enable')); enable_checkbox.type = 'checkbox'; enable_checkbox.value = 1; input_fields[i].parentNode.insertBefore (enable_checkbox, input_fields[i].nextSibling); Element.observe (enable_checkbox, 'click', function (event) { var input_name = Event.element(event).id.replace (/_enable/, ''); $(input_name)[$(input_name).disabled ? 'enable' : 'disable'](); }); break; default: // No default action. break; } } } // Run through the same routine for textareas. if (textarea_fields.length > 0) { for (var i = 0; i < textarea_fields.length; i++) { field_type = textarea_fields[i].getAttribute ('field'); // Look for specific fields and apply validation where applicable switch (field_type) { case 'enable': var enable_checkbox = document.createElement ('INPUT'); enable_checkbox.id = textarea_fields[i].id + '_enable'; enable_checkbox.name = textarea_fields[i].id + '_enable'; enable_checkbox.setAttribute ('title', HOAM_languageLookup ('field_names|admin|enable')); enable_checkbox.type = 'checkbox'; enable_checkbox.value = 1; var preview = document.createElement ('IMG'); preview.id = textarea_fields[i].name + '_preview'; preview.setAttribute ('src', '/hoam/images/icons/layout.png'); preview.setAttribute ('title', HOAM_languageLookup ('field_names|admin|preview')); preview.style.cursor = 'pointer'; textarea_fields[i].parentNode.insertBefore (enable_checkbox, textarea_fields[i]); textarea_fields[i].disabled = 1; textarea_fields[i].parentNode.insertBefore (preview, textarea_fields[i]); Element.observe ($(enable_checkbox), 'click', function (event) { var textarea_name = Event.element(event).id.replace (/_enable/, ''); // $(textarea_name)[$(textarea_name).disabled ? 'enable' : 'disable'](); }); Element.observe ($(preview), 'click', function (event) { var textarea_name = Event.element(event).id.replace (/_preview/, ''); HOAM_formPreview ($F(textarea_name)); }); break; default: // No default action. break; } } } } function HOAM_formPreview (html) { var div = document.createElement ('DIV'); div.setAttribute ('style', 'background: white; border: 1px solid black; font-size: 50%; margin: 0 auto; padding: 5px; position: absolute; width: 50%'); div.innerHTML = html; $('page_content').appendChild (div); // Element.observe (div, 'click', function (event) { // document.removeChild (Event.element(event)); // Event.stopObserving (Event.element(event), 'click'); // }); } function HOAM_formErrorMessage (label_for, message) { // Display the given message in a child span of the specified label if ($('article')) { // 'article' is the old content id used, once all of the code has // been migrated then this check can safely be removed. var labels = $('article').getElementsByTagName ('LABEL'); } else { var labels = $('page_content').getElementsByTagName ('LABEL'); } if (labels.length > 0) { var i = 0; var label_found = false; while (i < labels.length && !label_found) { if (labels[i].getAttribute ('for') == label_for) { label_found = true; } else { i++; } } if (label_found) { var spans = $(labels[i]).getElementsByTagName ('SPAN'); if (spans.length > 1) { // we don't know which span to modify / overwrite. // just skip doing anything. } else if (spans.length == 1) { spans[0].className = 'error_img'; spans[0].innerHTML = message; } else { span = document.createElement ('SPAN'); span.className = 'error_img'; span.innerHTML = message; labels[i].appendChild (span); } } else { alert (HOAM_languageLookup ('errors|hoam|form|label-not-found', label_for, message)); } } else { alert (HOAM_languageLookup ('errors|hoam|form|label-not-found', label_for, message)); } } function HOAM_formErrorClear (label_for) { // Remove any existing error message span. if ($('article')) { // 'article' is the old content id used, once all of the code has // been migrated then this check can safely be removed. var labels = $('article').getElementsByTagName ('LABEL'); } else { var labels = $('page_content').getElementsByTagName ('LABEL'); } if (labels.length > 0) { var i = 0; var label_found = false; while (i < labels.length && !label_found) { if (labels[i].getAttribute ('for') == label_for) { label_found = true; } else { i++; } } if (label_found) { var spans = $(labels[i]).getElementsByClassName ('error_img'); if (spans.length > 1) { // we don't know which span to modify / overwrite. // just skip doing anything. } else if (spans.length == 1) { labels[i].removeChild (spans[0]); } else { // No spans, so nothing to remove. } } } } function HOAM_formHelpLookup () { // Find all