/** * 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); }
/** * Partial method to refresh the add/edit field for this attribute. * * @param string $mode add/edit mode * * @return string HTML the output needed to refresh the attribute. */ public function partial_refresh($mode) { $record = $this->m_ownerInstance->updateRecord(); $fieldprefix = $this->m_ownerInstance->m_postvars['atkfp']; $arr = array('fields' => array()); $defaults =& $record; $error = []; $this->addToEditArray($mode, $arr, $defaults, $error, $fieldprefix); $script = ''; foreach ($arr['fields'] as $field) { //Json::encode expect string in in ASCII or UTF-8 format, so convert data to UTF-8 $value = Tools::atk_iconv(Tools::atkGetCharset(), 'UTF-8', $field['html']); $script .= "\$('" . str_replace('.', '_', $this->m_ownerInstance->atkNodeUri() . '_' . $field['id']) . "').update(" . Json::encode($value) . ");\r\n"; } return '<script type="text/javascript">' . $script . '</script>'; }