Пример #1
0
    /**
     * Returns the HTML for the record selector that will appear in a pop-up window.
     *
     * @param string $fieldname  The hidden HTML form field in the parent to pass values back to.
     * @param array  $lookupOIDs An optional array of related look-up OIDs, only required for rendering MANY-TO-MANY rels
     *
     * @since 1.0
     *
     * @return string
     */
    public function renderSelector($fieldname, $lookupOIDs = array())
    {
        self::$logger->debug('>>renderSelector(fieldname=[' . $fieldname . '], lookupOIDs=[' . var_export($lookupOIDs, true) . '])');
        $config = ConfigProvider::getInstance();
        $html = '<script language="JavaScript">
            var selectedOIDs = new Object();

            function toggelOID(oid, displayValue, isSelected) {
                if(isSelected)
                    selectedOIDs[oid] = displayValue;
                else
                    delete selectedOIDs[oid];
            }

            function setParentFieldValues() {
                var OIDs;
                var displayValues;

                for(key in selectedOIDs) {
                    if(OIDs == null)
                        OIDs = key;
                    else
                        OIDs = OIDs + \',\' + key;

                    if(displayValues == null)
                        displayValues = selectedOIDs[key];
                    else
                        displayValues = displayValues + \'\\n\' + selectedOIDs[key];
                }

                if(OIDs == null) {
                    document.getElementById(\'' . $fieldname . '\').value = "00000000000";
                    document.getElementById(\'' . $fieldname . '_display\').value = "";
                }else{
                    document.getElementById(\'' . $fieldname . '\').value = OIDs;
                    document.getElementById(\'' . $fieldname . '_display\').value = displayValues;
                }
            }

            </script>';
        if ($this->relationObject->getRelationType() == 'MANY-TO-MANY') {
            $classNameLeft = $this->relationObject->getRelatedClass('left');
            $classNameRight = $this->relationObject->getRelatedClass('right');
            if ($this->accessingClassName == $classNameLeft) {
                $tmpObject = new $classNameRight();
                $fieldName = $this->relationObject->getRelatedClassDisplayField('right');
                $fieldLabel = $tmpObject->getDataLabel($fieldName);
                $oidLabel = $tmpObject->getDataLabel('OID');
                $objects = $tmpObject->loadAll(0, 0, 'OID', 'ASC', true);
                self::$logger->debug('[' . count($objects) . '] related [' . $classNameLeft . '] objects loaded');
            } else {
                $tmpObject = new $classNameLeft();
                $fieldName = $this->relationObject->getRelatedClassDisplayField('left');
                $fieldLabel = $tmpObject->getDataLabel($fieldName);
                $oidLabel = $tmpObject->getDataLabel('OID');
                $objects = $tmpObject->loadAll(0, 0, 'OID', 'ASC', true);
                self::$logger->debug('[' . count($objects) . '] related [' . $classNameLeft . '] objects loaded');
            }
            $html .= '<table cols="3" class="table table-bordered">';
            $html .= '<tr>';
            $html .= '<th>' . $oidLabel . '</th>';
            $html .= '<th>' . $fieldLabel . '</th>';
            $html .= '<th>Connect?</th>';
            $html .= '</tr>';
            foreach ($objects as $obj) {
                $html .= '<tr>';
                $html .= '<td width="20%">';
                $html .= $obj->getOID();
                $html .= '</td>';
                $html .= '<td width="60%">';
                $html .= $obj->get($fieldName);
                $html .= '</td>';
                $html .= '<td width="20%">';
                if (in_array($obj->getOID(), $lookupOIDs)) {
                    $this->onloadJS .= 'toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',true);';
                    $html .= '<input name = "' . $obj->getOID() . '" type="checkbox" checked onclick="toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',this.checked);"/>';
                } else {
                    $html .= '<input name = "' . $obj->getOID() . '" type="checkbox" onclick="toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',this.checked);"/>';
                }
                $html .= '</td>';
                $html .= '</tr>';
            }
            $html .= '</table>';
        } else {
            $className = $this->relationObject->getRelatedClass();
            $tmpObject = new $className();
            $label = $tmpObject->getDataLabel($this->relationObject->getRelatedClassDisplayField());
            $oidLabel = $tmpObject->getDataLabel('OID');
            $objects = $tmpObject->loadAll(0, 0, 'OID', 'DESC');
            $html = '<table cols="3" width="100%" class="bordered">';
            $html .= '<tr>';
            $html .= '<th>' . $oidLabel . '</th>';
            $html .= '<th>' . $label . '</th>';
            $html .= '<th>Connect?</th>';
            $html .= '</tr>';
            foreach ($objects as $obj) {
                $html .= '<tr>';
                $html .= '<td width="20%">';
                $html .= $obj->getOID();
                $html .= '</td>';
                $html .= '<td width="60%">';
                $html .= $obj->get($this->relationObject->getRelatedClassDisplayField());
                $html .= '</td>';
                $html .= '<td width="20%">';
                if ($obj->getOID() == $this->relationObject->getValue()) {
                    $html .= '<img src="' . $config->get('app.url') . '/images/icons/accept_ghost.png"/>';
                } else {
                    $tmp = new Button("document.getElementById('" . $fieldname . "').value = '" . $obj->getOID() . "'; document.getElementById('" . $fieldname . "_display').value = '" . $obj->get($this->relationObject->getRelatedClassDisplayField()) . "'; \$('[Id=" . $fieldname . "_display]').blur(); window.jQuery.dialog.close();", '', 'selBut', $config->get('app.url') . '/images/icons/accept.png');
                    $html .= $tmp->render();
                }
                $html .= '</td>';
                $html .= '</tr>';
            }
            $html .= '</table>';
        }
        $html .= '<script type="text/javascript">' . '$(document).ready(function() {';
        $html .= $this->onloadJS;
        $html .= '});</script>';
        self::$logger->debug('<<renderSelector[html]');
        return $html;
    }