- $$('.requires').each(function(element) {
- var eventObj = {
- 'element': Element.extend(element),
- 'requires': [],
- 'callback': function(required) {},
- checkRequirements: function() {
- var scopeElement = adminSystemConfig.getScopeElement(eventObj.element);
- if (!scopeElement || !scopeElement.checked) {
- eventObj.element.enable();
- eventObj.requires.each(function(required) {
- adminSystemConfig.checkRequired.call(Element.extend(required), eventObj.element, eventObj.callback);
- }.bind(this));
- }
- },
- keydownCheckRequirements: function() {
- window.setTimeout(eventObj.checkRequirements, 1);
- },
- bindCheckingObserver: function(element) {
- if (element.tagName.toLowerCase() == 'fieldset') {
- Element.extend(element).select('input,select').each(function(subElement) {
- eventObj.bindCheckingObserver(subElement);
- })
- } else {
- var scopeElement = adminSystemConfig.getScopeElement(element);
- if (scopeElement) {
- Event.observe(scopeElement, 'click', eventObj.checkRequirements);
- }
- Event.observe(element, 'change', eventObj.checkRequirements);
- Event.observe(element, 'keydown', eventObj.keydownCheckRequirements);
- }
- },
- indicateEnabled: function() {
- var labelElement = adminSystemConfig.getUpTr(eventObj.element).select('td.label label')[0];
- if (typeof labelElement != 'undefined') {
- if (eventObj.element.value == 1) {
- labelElement.addClassName('enabled');
- } else {
- labelElement.removeClassName('enabled');
- }
- }
- }
- };
-
- // fill eventObj with required elements
- adminSystemConfig.mapClasses(element, false, function(className) {
- var requiredElement = Element.extend(document.getElementById(className.substr(9)));
- if (requiredElement) {
- eventObj.requires.push(requiredElement);
- }
- }, 'requires');
- Element.extend(element).requiresObj = eventObj;
-
- // replacing "Use Default" action with checking requirements
- var scopeElement = adminSystemConfig.getScopeElement(element);
- if (scopeElement) {
- Event.stopObserving(scopeElement, 'click');
- Event.observe(scopeElement, 'click', function(event) {
- toggleValueElements(scopeElement, Element.previous(scopeElement.parentNode));
- eventObj.checkRequirements();
- });
- }
-
- // binding events
- eventObj.requires.each(function(required) {
- eventObj.bindCheckingObserver(required);
- });
- Event.observe(eventObj.element, 'change', eventObj.indicateEnabled);
- eventObj.checkRequirements();
- eventObj.indicateEnabled();
- });