* @package ai * @link https://www.zentao.net */ namespace zin; h::css(" .detail-view > .detail-body > .detail-main > .detail-sections:first-child > .detail-section {position: relative; z-index: 1;} .detail-view > .detail-body > .detail-main > .detail-sections:first-child > .detail-section:first-child {z-index: 2;} "); $promptMenuInject = function() { if(isInModal()) return; $this->loadModel('ai'); if(!$this->ai->hasModelsAvailable() || !commonModel::hasPriv('ai', 'promptExecute')) return; $this->app->loadLang('ai'); $this->app->loadConfig('ai'); $module = $this->app->getModuleName(); $method = $this->app->getMethodName(); if(!isset($this->config->ai->menuPrint->locations[$module][$method])) return; $menuOptions = $this->config->ai->menuPrint->locations[$module][$method]; $prompts = $this->ai->getPromptsForUser($menuOptions->module); $prompts = $this->ai->filterPromptsForExecution($prompts, true); if(empty($prompts)) return; $html = ''; $objectVarName = empty($menuOptions->objectVarName) ? $menuOptions->module : $menuOptions->objectVarName; $currentObjectId = !empty($this->view->$objectVarName) ? $this->view->$objectVarName->id : 0; if(count($prompts) > 1) { $html .= '
'; } else { $prompt = current($prompts); $html .= html::linkButton($prompt->name . ($prompt->status != 'active' ? '' . $this->lang->ai->prompts->statuses[$prompt->status] . '' : ''), helper::createLink('ai', 'promptExecute', "promptId=$prompt->id&objectId=$currentObjectId"), 'self', (empty($prompt->unauthorized) ? '' : 'disabled') . (empty($prompt->desc) ? '' : " data-toggle='popover' data-container='body' data-trigger='hover' data-content='$prompt->desc' data-title='$prompt->name' data-placement='bottom'"), 'prompt btn ghost size-sm font-medium' . ((isset($menuOptions->class) ? ' ' . $menuOptions->class : '') . (isset($menuOptions->buttonClass) ? ' ' . $menuOptions->buttonClass : ''))); } /* Assemble injector script. */ $script = <<< JAVASCRIPT (() => { const container = window.frameElement?.closest('.load-indicator'); if(container && container.dataset.loading) { delete container.dataset.loading; container.classList.remove('loading'); container.classList.remove('no-delay'); } JAVASCRIPT; $script .= "$(`$menuOptions->targetContainer`).first()." . (!empty($menuOptions->injectMethod) ? $menuOptions->injectMethod : 'append') . "(`$html`).css('z-index', 2);\n"; $script .= <<< JAVASCRIPT $('[data-toggle="popover"]').popover({template: '