array(), 'leading' => array(), 'suffix' => array() ); protected function created() { $object = $this->prop('object'); if($object) { if(!$this->hasProp('id') && isset($object->id)) $this->setProp('id', $object->id); if(!$this->hasProp('title') && (isset($object->title) or isset($object->name))) $this->setProp('title', isset($object->title) ? $object->title : $object->name); if(!$this->hasProp('color') && isset($object->color)) $this->setProp('color', $object->color); if(!$this->hasProp('url') && isset($object->url)) $this->setProp('url', $object->url); if(!$this->hasProp('deleted') && isset($object->deleted)) $this->setProp('deleted', $object->deleted); if(!$this->hasProp('parent') && isset($object->parent)) $this->setProp('parent', $object->parent); } $parent = $this->prop('parent'); if($parent) { if(!$this->hasProp('parentId') && isset($parent->id)) $this->setProp('parentId', $parent->id); if(!$this->hasProp('parentTitle') && (isset($parent->title) or isset($parent->name))) $this->setProp('parentTitle', isset($parent->title) ? $parent->title : $parent->name); if(!$this->hasProp('parentUrl') && isset($parent->url)) $this->setProp('parentUrl', $parent->url); if(!$this->hasProp('parentColor') && isset($parent->color)) $this->setProp('parentColor', $parent->color); } } protected function buildTitle() { global $lang; list($id, $title, $url, $type, $color, $titleProps, $titleClass, $deleted) = $this->prop(array('id', 'title', 'url', 'type', 'color', 'titleProps', 'titleClass', 'deleted')); if($url === true && $type) $url = createLink($type, 'view', $type . 'ID={id}'); if(is_string($url) && $id) $url = str_replace('{id}', "$id", $url); return array ( $id ? idLabel::create($id, array('class' => array($this->prop('idClass'), $this->prop('inline') ? 'mr-' . $this->prop('gap', 2) : ''))) : null, $this->block('leading'), $this->buildParentTitle(), is_string($url) ? a( setClass('entity-title-link max-w-lg', $titleClass), set::href($url), set::title($title), set($titleProps), set($this->prop('linkProps')), $color ? setStyle('color', $color) : null, $title ) : span ( setClass('entity-title-text', $titleClass), set($titleProps), $color ? setStyle('color', $color) : null, $title ), $deleted ? span(setClass('label danger'), $lang->deleted) : null ); } protected function buildParentTitle() { $parentTitle = $this->prop('parentTitle'); if(!isset($parentTitle)) return null; list($parentID, $parent, $parentUrl, $parentType, $parentColor, $parentClass, $parentTitleProps, $parentTitleClass, $joiner, $joinerClass) = $this->prop(array('parentId', 'parent', 'parentUrl', 'parentType', 'parentColor', 'parentClass', 'parentTitleProps', 'parentTitleClass', 'joiner', 'joinerClass')); return array ( new entityTitle ( setClass($parentClass), set::object($parent), set::id($parentID), set::title($parentTitle), set::url($parentUrl), set::color($parentColor), set::type($parentType), set::titleProps($parentTitleProps), set::titleClass($parentTitleClass) ), $joiner ? span(setClass('entity-title-joiner', $joinerClass), $joiner) : null ); } protected function build() { /* Convert line break to space on copy. 复制时将换行转换为空格。see https://back.zcorp.cc/pms/ticket-view-1334.html */ $handleCopy = <<<'JS' const lines = document.getSelection().toString().split('\n'); event.clipboardData.setData('text/plain', lines.join(' ')); event.preventDefault(); JS; return div ( setClass('entity-title', $this->prop('inline') ? '' : 'row items-center gap-' . $this->prop('gap', 2)), set($this->getRestProps()), $this->block('prefix'), $this->buildTitle(), $this->children(), $this->block('suffix'), on::copy()->do($handleCopy) ); } }