/** * Re-render / refresh the attribute with the given name. * * @param string $name attribute name */ public function refreshAttribute($name) { if ($this->isInitial()) { return; } $offset = count($this->getNode()->getPage()->getLoadScripts()); $error = []; $editArray = array('fields' => array()); $this->m_node->getAttribute($name)->addToEditArray($this->getMode(), $editArray, $this->getRecord(), $error, $this->getFieldPrefix()); $scriptCode = ''; foreach ($editArray['fields'] as $field) { $element = str_replace('.', '_', $this->getNode()->atkNodeUri() . '_' . $field['id']); $value = Json::encode(Tools::atk_iconv(Tools::atkGetCharset(), 'UTF-8', $field['html'])); // Json::encode excepts string in UTF-8 $scriptCode .= "if (\$('{$element}')) { \$('{$element}').update({$value}); } "; } $this->getNode()->getPage()->register_loadscript($scriptCode, $offset); }
/** * Adds a node/attribute entry to the node/attribute path. * * The entry consists of the the following fields: * - nr, number in the node/attribute path (>= 0) * - node, reference to the node for this path entry * - attr, reference to the currently selected attribute for this path entry * - attrs, all searchable attributes for this node * - includeSelf, whatever the attribute list should contain a reference to ourselves or not * - selectSelf, should the self option be selected? (only valid if includeSelf is true) * * This method will modify the $path, $includeSelf and $excludes parameters to prepare * them for the next call to this method. * * @param array $path reference to the current path * @param Node $node reference to the current node * @param string $attrName currently selected attribute * @param bool $includeSelf should we include ourselves? * @param array $excludes attributes to exclude * * @return Node next node */ public function addNodeAndAttrEntry(&$path, $node, $attrName, &$includeSelf, &$excludes) { $attr = $node->getAttribute($attrName); $nr = count($path); $attrs = $this->getSearchableAttributes($node, $excludes); if (count($attrs) == 1 && !$includeSelf) { $attr = $attrs[0]; } $selectSelf = $includeSelf && $attrName == '.'; $entry = array('nr' => $nr, 'node' => $node, 'attrs' => $attrs, 'attr' => $attr, 'includeSelf' => $includeSelf, 'selectSelf' => $selectSelf); $path[] =& $entry; $includeSelf = is_a($attr, 'ManyToOneRelation'); $excludes = is_a($attr, 'OneToManyRelation') ? $attr->m_refKey : []; if (is_a($attr, 'Relation')) { $attr->createDestination(); return $attr->m_destInstance; } return; }