private function _getComponentSetupCommands(__IComponent &$component) { $return_value = array(); //update client end-point with current component state: $component->updateClient(); //get all commands from client end-points $binding_codes = $component->getBindingCodes(); foreach ($binding_codes as $binding_code) { $ui_binding = __UIBindingManager::getInstance()->getUIBinding($binding_code); if ($ui_binding != null) { $command = $ui_binding->getClientEndPoint()->getSetupCommand(); if ($command != null) { $return_value[] = $command; } } } $handled_events = __EventHandlerManager::getInstance()->getEventHandler($component->getViewCode())->getComponentHandledEvents($component->getName()); foreach ($handled_events as $handled_event) { if ($handled_event != 'submit') { $command = new __AsyncMessageCommand(); $command->setClass('__RegisterEventListenerCommand'); $command->setData(array('element' => $component->getId(), 'event' => $handled_event)); $return_value[] = $command; } } return $return_value; }
/** * This method process an AJAX request * */ public function processRequest(__IRequest &$request, __IResponse &$response) { $ui_event = __EventResolver::getInstance()->resolveEvent(); if ($ui_event != null) { $view_code = $ui_event->getComponent()->getViewCode(); $event_handler = __EventHandlerManager::getInstance()->getEventHandler($view_code); $event_handler->handleEvent($ui_event); } }
/** * Delete a component handler and all his components from the component pool. * It also removes the associated event handler if any * * @param string $view_code */ public function freeComponentHandler($view_code) { $upper_case_view_code = strtoupper($view_code); if (key_exists($upper_case_view_code, $this->_component_handlers)) { $component_handler = $this->_component_handlers[$upper_case_view_code]; $component_handler->freeComponents(); unset($this->_component_handlers[$upper_case_view_code]); __EventHandlerManager::getInstance()->removesEventHandler($view_code); } }
public function raiseEvent($event_name, $extra_info = array()) { if ($this->_composite_component != null) { $view_code = $this->_composite_component->getViewCode(); $event_handler = __EventHandlerManager::getInstance()->getEventHandler($view_code); if ($event_handler != null) { $event = new __UIEvent($event_name, $extra_info, $this->_composite_component); $event_handler->handleEvent($event); } } }
public function restoreView() { if ($this->_component_handler != null) { __ComponentHandlerManager::getInstance()->addComponentHandler($this->_component_handler); __EventHandlerManager::getInstance()->addEventHandler($this->_event_handler); $component_pool = __ComponentPool::getInstance(); foreach ($this->_components as $component) { $component_pool->registerComponent($component); unset($component); } } }
/** * Unregister a given component * * @param __IComponent $component The component to unregister from */ public function unregisterComponent($component_id) { if (key_exists($component_id, $this->_components)) { $component = $this->_components[$component_id]; if ($component instanceof __ICompositeComponent && __EventHandlerManager::getInstance()->hasEventHandler($component_id)) { __EventHandlerManager::getInstance()->getEventHandler($component_id)->free(); } if ($component->hasContainer()) { $container = $component->getContainer(); $container->removeComponent($component_id); } unset($this->_components[$component_id]); unset($component); } }
public final function __construct($view_code) { $this->_view_code = $view_code; $this->_renderers_stack = new __Stack(); $this->_properties_stack = new __Stack(); if (__ComponentHandlerManager::getInstance()->hasComponentHandler($view_code)) { $this->_first_time_execution = false; $this->_component_handler = __ComponentHandlerManager::getInstance()->getComponentHandler($view_code); } else { $this->_component_handler = __ComponentHandlerManager::getInstance()->createComponentHandler($view_code); } $this->_event_handler = __EventHandlerManager::getInstance()->getEventHandler($view_code); $request = __ActionDispatcher::getInstance()->getRequest(); if ($request != null) { if ($request->hasParameter('PARENT_VIEW_CODE')) { $this->_event_handler->setParentViewCode($request->getParameter('PARENT_VIEW_CODE')); } if ($request->hasParameter('ACTIONBOX_ID')) { $this->_event_handler->setContainerActionBoxId($request->getParameter('ACTIONBOX_ID')); } } }
public function startRender(__IComponent &$component) { if ($component instanceof __ICompositeComponent) { $return_value = null; $component_id = $component->getId(); $view = $this->createView(); if ($view instanceof __IView) { //set the view code as the component identifier: $view->setCode($component_id); $event_handler = null; if (!__EventHandlerManager::getInstance()->hasEventHandler($component_id)) { $event_handler_class = $view->getEventHandlerClass(); if ($event_handler_class != null) { $event_handler = new $event_handler_class(); if ($event_handler instanceof __ICompositeComponentEventHandler) { //set the view code: $event_handler->setViewCode($component_id); //relate the component with the event handler: $event_handler->setCompositeComponent($component); $component->setEventHandler($event_handler); __EventHandlerManager::getInstance()->addEventHandler($event_handler); } else { throw __ExceptionFactory::getInstance()->createException('Event handler associated to a composite components must implement __ICompositeComponentEventHandler. ' . get_class($event_handler) . ' class does not implement this interface'); } } } //assign the component to the view: $this->_assignComponentToView($view, $component); //execute the view to render the component: $return_value = $view->execute(); } $component->setContent($return_value); return '<span id="' . $component_id . '">' . $return_value . '</span>'; } else { throw __ExceptionFactory::getInstance()->createException(get_class($component) . ' class not expected, but an instance of a class implementing __ICompositeComponent.'); } }
public function startRender(__IComponent &$component) { $component_id = $component->getId(); $event_handler = __EventHandlerManager::getInstance()->getEventHandler($component->getViewCode()); $component_to_validate = $component->getComponentToValidate(); $component_to_validate_id = $component_to_validate->getId(); if (__ResponseWriterManager::getInstance()->hasResponseWriter('livevalidation')) { $jod_response_writer = __ResponseWriterManager::getInstance()->getResponseWriter('livevalidation'); } else { $jod_response_writer = new __JavascriptOnDemandResponseWriter('livevalidation'); $jod_response_writer->addJsFileRef('livevalidation/livevalidation_1.3.1.js'); $jod_response_writer->addLoadCheckingVariable('Validate'); $javascript_rw = __ResponseWriterManager::getInstance()->getResponseWriter('javascript'); $javascript_rw->addResponseWriter($jod_response_writer); } $configuration = array('validMessage : ""'); if ($component->getValidateOnlyOnBlur()) { $configuration[] = 'onlyOnBlur: true'; } else { if ($component->getValidateOnlyOnSubmit()) { $configuration[] = 'onlyOnSubmit: true'; } else { $configuration[] = 'wait: ' . $component->getWait(); } } $report_after_component = $component->getComponentForErrorReporting(); $report_after_element = $component->getReportAfterElement(); if ($report_after_component != null) { $configuration[] = 'insertAfterWhatNode: "' . $report_after_component->getId() . '"'; } else { if ($report_after_element != null) { $configuration[] = 'insertAfterWhatNode: "' . $report_after_element . '"'; } } if ($event_handler->isEventHandled('validate', $component_to_validate->getName())) { $configuration[] = 'onValid: function() { (__ClientEventHandler.getInstance()).sendEvent("validate", { validationRule : "' . $component_id . '"}, "' . $component_to_validate_id . '", true); }'; } else { if ($event_handler->isEventHandled('validate', $component->getName())) { $configuration[] = 'onValid: function() { (__ClientEventHandler.getInstance()).sendEvent("validate", { validationRule : "' . $component_id . '"}, "' . $component_id . '", true); }'; } } $on_invalid = $component->getOnInvalid(); if (!empty($on_invalid)) { $configuration[] = 'onInvalid: ' . $on_invalid; } $js_code = "if(\$(\"{$component_to_validate_id}\")) {\n"; $js_code .= "if(!window['{$component_id}']) {\n"; $js_code .= ' window[\'' . $component_id . '\'] = new LiveValidation("' . $component_to_validate_id . '", {' . join(', ', $configuration) . '});' . "\n"; $js_code .= "} else {\n"; $js_code .= ' ' . $component_id . '.initialize("' . $component_to_validate_id . '", {' . join(', ', $configuration) . '});' . "\n"; $js_code .= "}\n"; $js_code .= $this->_getValidLengthJsPart($component); $js_code .= $this->_getValidFormatJsPart($component); $js_code .= $this->_getComponentMatchJsPart($component); $js_code .= $this->_getMandatoryJsPart($component); $js_code .= $this->_getAcceptanceJsPart($component); $js_code .= $this->_getShowMessageJsPart($component); $js_code .= $this->_getAllowedExtensionsJsPart($component); $js_code .= $this->_getNumericalityJsPart($component); $js_code .= $this->_getListenValidateEvent($component); $js_code .= "}\n"; $jod_response_writer->addJsCode($js_code); }
protected function _doValidation(__IComponent &$component) { $this->_validation_result = true; if ($component instanceof __IValueHolder && $component->getEnabled() && $component->getVisible()) { $value = $component->getValue(); $trimmed_value = trim($value); $component_to_match = $this->getComponentToMatch(); //check file size (if applicable): $error_file_size = false; $max_file_size = $this->getMaxFileSize(); if ($max_file_size !== null) { if ($component instanceof __IUploaderComponent) { $size = $component->getSize(); if ($size !== null && $max_file_size < $size) { $error_file_size = true; } } else { throw __ExceptionFactory::getInstance()->createException('Can not validate file size on a non uploader component (not implementing the __IUploaderComponent): ' . get_class($component)); } } if ($error_file_size) { $component->setStatus(__IUploaderComponent::UPLOAD_STATUS_ERROR); $exceded_size = $size - $max_file_size; $this->setErrorMessage('Maximum file size (' . $this->_getPrintableSize($max_file_size) . ') exceded by ' . $this->_getPrintableSize($exceded_size)); $this->_validation_result = false; } else { if ($component_to_match instanceof __IValueHolder && trim($component_to_match->getValue()) !== $trimmed_value) { print "[" . trim($component_to_match->getValue()) . "] - [" . $trimmed_value . ']'; $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_FIELD_MUST_MATCH')->setParameters(array($component->getAlias(), $component_to_match->getAlias()))->getValue()); $this->_validation_result = false; } else { if (strlen($trimmed_value) == 0 && $this->getMandatory()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_REQUIRED_FIELD')->setParameters(array($component->getAlias()))->getValue()); $this->_validation_result = false; } else { if ($this->getValidLength() != null && strlen($value) != $this->getValidLength()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_INVALID_LENGTH')->setParameters(array($component->getAlias(), $this->getValidLength()))->getValue()); $this->_validation_result = false; } else { if ($this->getMinLength() != null && strlen($value) < $this->getMinLength()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_TOO_SHORT_VALUE')->setParameters(array($component->getAlias(), $this->getMinLength()))->getValue()); $this->_validation_result = false; } else { if ($this->getMaxLength() != null && strlen($value) > $this->getMaxLength()) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_TOO_LONG_VALUE')->setParameters(array($component->getAlias(), $this->getMaxLength()))->getValue()); $this->_validation_result = false; } else { if (!empty($value) && $this->getPattern() != null && !preg_match("/" . $this->getPattern() . "/i", $value)) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_INVALID_VALUE')->setParameters(array($component->getAlias()))->getValue()); $this->_validation_result = false; } else { if ($this->getAcceptance() && !$value) { $this->setErrorMessage(__ResourceManager::getInstance()->getResource('ERR_MUST_BE_ACCEPTED')); $this->_validation_result = false; } else { if (!empty($value) && $this->getOnlyInteger() && !is_numeric($value)) { $this->setErrorMessage('Must be integer'); $this->_validation_result = false; } else { if (!empty($value) && $this->getSpecificNumber() !== null && $value != $this->getSpecificNumber()) { $this->setErrorMessage('Must be ' . $this->getSpecificNumber()); $this->_validation_result = false; } else { if (!empty($value) && $this->getMinimumNumber() !== null && $value < $this->getMinimumNumber()) { $this->setErrorMessage('Must not be less than ' . $this->getMinimumNumber()); $this->_validation_result = false; } else { if (!empty($value) && $this->getMaximumNumber() !== null && $value > $this->getMaximumNumber()) { $this->setErrorMessage('Must not be more than ' . $this->getMaximumNumber()); $this->_validation_result = false; } else { if (!empty($value) && $this->getAllowedExtensions() != null && !preg_match('/\\.(' . join('|', $this->getAllowedExtensions()) . ')$/i', $value)) { $component->setStatus(__IUploaderComponent::UPLOAD_STATUS_ERROR); $this->setErrorMessage('Invalid file type. Expected extensions: ' . join(', ', $this->getAllowedExtensions())); $this->_validation_result = false; } else { $event_handler = __EventHandlerManager::getInstance()->getEventHandler($this->_view_code); if ($event_handler->isEventHandled('validate', $this->_component)) { $ui_event = new __UIEvent('validate', array('validationRule' => $this->getId()), $component); if ($event_handler->handleEvent($ui_event) === false) { $this->_validation_result = false; } } } } } } } } } } } } } } } } if ($this->_validation_result == true) { $this->_error_message = null; } return $this->_validation_result; }
/** * Get the event handler correponding to the parent view (if applicable) * * @return __IEventHandler * */ public function getParentEventHandler() { $return_value = null; if ($this->_parent_view_code != null && __EventHandlerManager::getInstance()->hasEventHandler($this->_parent_view_code)) { $return_value = __EventHandlerManager::getInstance()->getEventHandler($this->_parent_view_code); } }
public final function handleCallback(__IRequest &$request) { $event_handler = __EventHandlerManager::getInstance()->getEventHandler($this->_view_code); if ($event_handler->isEventHandled('callback', $this->getName())) { $validate_event = new __UIEvent('callback', $request, $this); $event_handler->handleEvent($validate_event); } }
public function execute(&$parameters = null) { if ($parameters == null) { $parameters = array(); } else { if (!is_array($parameters)) { $parameters = array($parameters); } } $return_value = null; $event_handler = __EventHandlerManager::getInstance()->getEventHandler($this->_view_code); $event_handler_method = $this->getEventHandlerMethod(); if (method_exists($event_handler, $event_handler_method)) { $return_value = call_user_func_array(array($event_handler, $event_handler_method), $parameters); } return $return_value; }