if (typeof Prototype == 'undefined') { warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>)."; alert(warning); } if (Prototype.Version.substring(0, 3) != '1.6') { warning = "ActiveScaffold Error: Prototype version 1.6.x is required. Please update prototype.js (rake rails:update:javascripts)."; alert(warning); } if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); /* * Simple utility methods */ var ActiveScaffold = { records_for: function(tbody_id) { var rows = []; var child = $(tbody_id).down('.record'); while (child) { rows.push(child); child = child.next('.record'); } return rows; }, stripe: function(tbody_id) { var even = false; var rows = this.records_for(tbody_id); for (var i = 0; i < rows.length; i++) { var child = rows[i]; //Make sure to skip rows that are create or edit rows or messages if (child.tagName != 'SCRIPT' && !child.hasClassName("create") && !child.hasClassName("update") && !child.hasClassName("inline-adapter") && !child.hasClassName("active-scaffold-calculations")) { if (even) child.addClassName("even-record"); else child.removeClassName("even-record"); even = !even; } } }, hide_empty_message: function(tbody, empty_message_id) { if (this.records_for(tbody).length != 0) { $(empty_message_id).hide(); } }, reload_if_empty: function(tbody, url) { if (this.records_for(tbody).length == 0) { new Ajax.Request(url, { method: 'get', asynchronous: true, evalScripts: true }); } }, removeSortClasses: function(scaffold_id) { $$('#' + scaffold_id + ' td.sorted').each(function(element) { element.removeClassName("sorted"); }); $$('#' + scaffold_id + ' th.sorted').each(function(element) { element.removeClassName("sorted"); element.removeClassName("asc"); element.removeClassName("desc"); }); }, decrement_record_count: function(scaffold_id) { // decrement the last record count, firsts record count are in nested lists count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); if (count) count.update(parseInt(count.innerHTML, 10) - 1); }, increment_record_count: function(scaffold_id) { // increment the last record count, firsts record count are in nested lists count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); if (count) count.update(parseInt(count.innerHTML, 10) + 1); }, update_row: function(row, html) { row = $(row); Element.replace(row, html); var new_row = $(row.id); if (row.hasClassName('even-record')) new_row.addClassName('even-record'); new_row.highlight(); }, server_error_response: '', report_500_response: function(active_scaffold_id) { messages_container = $(active_scaffold_id).down('td.messages-container'); new Insertion.Top(messages_container, this.server_error_response); } } /* * DHTML history tie-in */ function addActiveScaffoldPageToHistory(url, active_scaffold_id) { if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded var array = url.split('?'); var qs = new Querystring(array[1]); var sort = qs.get('sort') var dir = qs.get('sort_direction') var page = qs.get('page') if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url); } /* * Add-ons/Patches to Prototype */ /* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */ Element.replace = function(element, html) { element = $(element); if (element.outerHTML) { try { element.outerHTML = html.stripScripts(); } catch (e) { var tn = element.tagName; if(tn=='TBODY' || tn=='TR' || tn=='TD') { var tempDiv = document.createElement("div"); tempDiv.innerHTML = '
'; element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element); } else throw e; } } else { var range = element.ownerDocument.createRange(); /* patch to fix