Exemplo n.º 1
0
    /**
     * Generate html form based on Entity @Input annotated params
     * @param \entity\BaseEntity $entity
     * @param $customKeys
     * @throws AnnotationException
     * @return
     */
    protected function extractFormAnnotationsFromEntity(\entity\BaseEntity $entity, $customKeys = null, $showNeedsConfirmation = true) {
        $className = get_class($entity);
        $listAnnotations = Annotation::extractAnnotations($className);

        if (!$listAnnotations) {
            throw new AnnotationException(\core\Messages::CLASS_HAS_NO_ANNOTATIONS);
        }

        $elements = array();

        $listFormBehavior = array(Annotation::T_INPUT);

        foreach ($listAnnotations[Annotation::PROPERTIES] as $key=>$propertiesAnnotations) {
            if ($customKeys && is_array($customKeys) && !in_array($key, $customKeys)) {
                continue;
            }
            foreach ($propertiesAnnotations as $annotation) {
                if (in_array($annotation[Annotation::BEHAVIOR], $listFormBehavior)) {
                    $label = '';
                    $format = '';
                    foreach ($propertiesAnnotations as $subAnnotation) {
                        if ($subAnnotation[Annotation::BEHAVIOR] == Annotation::T_LABEL) {
                            $label = $subAnnotation[Annotation::VALUES][Annotation::O_VALUE];
                        } else if ($subAnnotation[Annotation::BEHAVIOR] == Annotation::T_FORMAT) {
                            $format = $subAnnotation[Annotation::VALUES];
                        }
                    }
                    $value = \helper\ReflectionHelper::getMethodResultFromInstance($entity, 'get'.ucfirst($key));
                    $elements[] = array(
                            Annotation::O_REFERS_TO => $key,
                            Annotation::O_VALUE => $value,
                            Annotation::T_LABEL => $label,
                            Annotation::VALUES => $annotation[Annotation::VALUES],
                            Annotation::T_FORMAT => $format
                    );
                    if ($showNeedsConfirmation) {
                        foreach ($propertiesAnnotations as $subAnnotation) {
                            if ($subAnnotation[Annotation::BEHAVIOR] == Annotation::T_NEEDS_CONFIRMATION) {
                                $tmpKey = 'confirm'.$key;
                                $values = $annotation[Annotation::VALUES];
                                $values[Annotation::T_NEEDS_CONFIRMATION] = $tmpKey;
                                $elements[] = array(
                                        Annotation::O_REFERS_TO => 'confirm-'.$key,
                                        Annotation::O_VALUE => isset($entity->$tmpKey) ? $entity->$tmpKey : null,
                                        Annotation::T_LABEL => $subAnnotation[Annotation::VALUES][Annotation::O_VALUE],
                                        Annotation::VALUES => $values
                                );
                                JavascriptManager::getInstance()->putCommand(JavascriptHelper::createPreventCutCopyPaste(strtolower(get_class($entity)).'-'.$key));
                                JavascriptManager::getInstance()->putCommand(JavascriptHelper::createPreventCutCopyPaste(strtolower(get_class($entity)).'-confirm-'.$key));
                                break;
                            }
                        }
                    }
                }
            }
        }

        return $elements;
    }
Exemplo n.º 2
0
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="<?=\App::getInstance()->getWebDir()?>/css/custom/site-ie.css" />
<![endif]-->
</head>
<body>

<? require("/../../includes/core/app.messages.php"); ?>

<?
if (isset($c[presentation\BasePresentation::TEMPLATE_INNER_FILE])) {
    if (is_array($c[presentation\BasePresentation::TEMPLATE_INNER_FILE])) {
        foreach ($c[presentation\BasePresentation::TEMPLATE_INNER_FILE] as $file) {
            require($file);
        }
    } else {
        require($c[presentation\BasePresentation::TEMPLATE_INNER_FILE]);
    }
}
?>

<script type="text/javascript" src="<?=\App::getInstance()->getWebDir()?>/javascript/core/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="<?=\App::getInstance()->getWebDir()?>/javascript/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="<?=\App::getInstance()->getWebDir()?>/javascript/core/jquery.maskedinput-1.2.2.min.js"></script>
<script type="text/javascript" src="<?=\App::getInstance()->getWebDir()?>/javascript/core/jquery.meio.mask.min.js"></script>
<script type="text/javascript" src="<?=\App::getInstance()->getWebDir()?>/javascript/jquery.blockUI.js"></script>
<script type="text/javascript" src="<?=\App::getInstance()->getWebDir()?>/javascript/default.js"></script>
<script type="text/javascript">
<?=\core\JavascriptManager::getInstance()->windowLoad();?>
</script>
</body>
</html>
Exemplo n.º 3
0
    /**
     * Generate HTML form
     * @param $className
     * @param $formAnnotations
     * @param $operationName
     * @param $formAction
     * @param $disabled
     * @param $submitCallback
     */
    protected function generateHtmlForm($className, $formAnnotations, $operationName, $formAction, $disabled = false, $submitCallback = null, $isJson = false) {
        $htmlForm = array();
        $className = strtolower($className);

        // FORM_ELEMENTS
        if ($formAnnotations) {
            $formElements = array();
            foreach ($formAnnotations as $formAnnotation) {
                $inputId = $className.'-'.$formAnnotation[Annotation::O_REFERS_TO];
                $label = '';
                $input = '';
                if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::SELECT) {
                    $fetchList = explode('.', $formAnnotation[Annotation::VALUES][Annotation::O_FETCH_LIST]);
                    $list = ReflectionHelper::getMethodResultFromName($fetchList[0], $fetchList[1]);
                    $optionList = array();
                    if (count($list) > 1) {
                        $optionList = array(0=>'Selecione');
                    }
                    foreach ($list as $item) {
                        $key = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_ID]));
                        $value = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_VALUE]));
                        $optionList[$key] = $value;
                    }
                    if (!$disabled) {
                        $input = HtmlHelper::createSelect($inputId, $inputId, $optionList, $formAnnotation[Annotation::O_VALUE]);
                    } else {
                        $input = HtmlHelper::createSelectDisabled($inputId, $inputId, $optionList, $formAnnotation[Annotation::O_VALUE]);
                    }

                } else if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::RADIO) {
                    $fetchList = explode('.', $formAnnotation[Annotation::VALUES][Annotation::O_FETCH_LIST]);
                    $list = ReflectionHelper::getMethodResultFromName($fetchList[0], $fetchList[1]);
                    $optionList = array();
                    foreach ($list as $item) {
                        $key = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_ID]));
                        $value = ReflectionHelper::getMethodResultFromInstance($item, 'get'.ucfirst($formAnnotation[Annotation::VALUES][Annotation::O_VALUE]));
                        $optionList[$key] = $value;
                    }
                    if (!$disabled) {
                        $input = HtmlHelper::createRadioList($inputId, $inputId, $optionList, $formAnnotation[Annotation::O_VALUE]);
                    } else {
                        p($optionList);
                    }

                } else if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::TEXTAREA) {
                    $value = $formAnnotation[Annotation::O_VALUE];
                    $input = HtmlHelper::createTextArea(
                            $inputId,
                            $inputId,
                            $formAnnotation[Annotation::VALUES][Annotation::O_COLS],
                            $formAnnotation[Annotation::VALUES][Annotation::O_ROWS],
                            $value
                    );

                } else {
                    $value = $formAnnotation[Annotation::O_VALUE];
                    $style = '';
                    if (isset($formAnnotation[Annotation::T_FORMAT]) && isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE])) {
                        if ($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE] == HtmlHelper::INPUT_FORMAT_DATE) {
                            $style = 'formDate';
                            $pattern = '';
                            if (isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_JS])) {
                                $pattern = $formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_JS];
                            }
                            if (isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_PHP]) && \helper\StringHelper::isNotNull($value)) {
                                $value = DateHelper::getAsString($value, $formAnnotation[Annotation::T_FORMAT][Annotation::O_PATTERN_PHP]);
                            }
                            JavascriptManager::getInstance()->putCommand(JavascriptHelper::createDatePicker($inputId, $pattern));
                        } else if ($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE] == HtmlHelper::INPUT_FORMAT_NUMBER) {
                            $style = 'formNumber';
                        }
                        if (isset($formAnnotation[Annotation::T_FORMAT][Annotation::O_MASK])) {
                            if ($formAnnotation[Annotation::T_FORMAT][Annotation::O_TYPE] == HtmlHelper::INPUT_FORMAT_DECIMAL) {
                                $style = 'formDecimal';
                                $mask = strrev($formAnnotation[Annotation::T_FORMAT][Annotation::O_MASK]);
                                $mask = preg_replace('/[.]/', ',', $mask, 1);
                                JavascriptManager::getInstance()->putCommand(JavascriptHelper::createMask($inputId, $mask, true));
                            } else {
                                JavascriptManager::getInstance()->putCommand(JavascriptHelper::createMask($inputId, $formAnnotation[Annotation::T_FORMAT][Annotation::O_MASK]));
                            }
                        }
                    }
                    if (!$disabled) {
                        $input = HtmlHelper::createInput(
                                $formAnnotation[Annotation::VALUES][Annotation::O_TYPE],
                                $inputId,
                                $inputId,
                                $value,
                                isset($formAnnotation[Annotation::VALUES][Annotation::O_MAX_LENGTH]) ? $formAnnotation[Annotation::VALUES][Annotation::O_MAX_LENGTH] : null,
                                null,
                                $style
                        );
                    } else {
                        $input = HtmlHelper::createInputDisabled(
                                $formAnnotation[Annotation::VALUES][Annotation::O_TYPE],
                                $value
                        );
                    }
                }
                if ($formAnnotation[Annotation::T_LABEL]) {
                    $label = HtmlHelper::createLabel(
                            $formAnnotation[Annotation::T_LABEL],
                            $inputId
                    );
                }
                if ($formAnnotation[Annotation::VALUES][Annotation::O_TYPE] == HtmlHelper::INPUT_TYPE_CHECKBOX) {
                    $formElements[$inputId] = array(self::FORM_INPUT => $label, self::FORM_LABEL => $input);

                } else {
                    $formElements[$inputId] = array(self::FORM_INPUT => $input, self::FORM_LABEL => $label);
                }
            }
            $htmlForm[self::FORM_ELEMENTS] = $formElements;
        }

        // FORM_PARAMS
        $formId = 'form-'.$className.'-'.strtolower($operationName);
        $htmlForm[self::FORM_PARAMS] = HtmlHelper::createFormParameters($formId, $formAction, 'POST', $submitCallback);

        // FORM SUBMIT
        $submitId = $formId.'-'.HtmlHelper::INPUT_TYPE_SUBMIT;
        if (!$isJson) {
            $htmlForm[self::FORM_SUBMIT] = HtmlHelper::createInput(HtmlHelper::INPUT_TYPE_SUBMIT, $submitId, $submitId, ucfirst($operationName));
        } else {
            $htmlForm[self::FORM_SUBMIT] = HtmlHelper::createInput(HtmlHelper::INPUT_TYPE_BUTTON, $submitId, $submitId, ucfirst($operationName));
            JavascriptManager::getInstance()->putCommand(JavascriptHelper::bindAjaxPostInClick($submitId, $formId));
        }

        // FORM CANCEL
        $cancelOperation = 'cancelar';
        $cancelId = $formId.'-'.$cancelOperation;
        $cancelCallback = JavascriptHelper::createLocationHrefChange(\App::getInstance()->getURIPrevious());
        $htmlForm[self::FORM_CANCEL] = HtmlHelper::createInput(HtmlHelper::INPUT_TYPE_BUTTON, $cancelId, $cancelId, ucfirst($cancelOperation), null, $cancelCallback);

        return $htmlForm;
    }