* add edit role template method.
This commit is contained in:
@@ -571,6 +571,9 @@ class ai extends control
|
||||
case 'delete':
|
||||
$this->ai->deleteRoleTemplate($data->id);
|
||||
break;
|
||||
case 'edit':
|
||||
$this->ai->updateRoleTemplate($data->id, $data->role, $data->characterization);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ $lang->ai->prompts->charPlaceholder = 'Detailed characterization of this role';
|
||||
$lang->ai->prompts->roleTemplate = 'Role Template';
|
||||
$lang->ai->prompts->roleTemplateTip = 'After a template is referenced, modifying the role or role description does not affect the template.';
|
||||
$lang->ai->prompts->addRoleTemplate = 'Add Role Template';
|
||||
$lang->ai->prompts->editRoleTemplate = 'Edit Role Template';
|
||||
$lang->ai->prompts->roleAddedSuccess = 'Role added successfully.';
|
||||
$lang->ai->prompts->roleDelConfirm = 'Deleting the role does not affect the role that is already in the prompt. Do you want to delete it?';
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ $lang->ai->prompts->charPlaceholder = '该角色的具体描述信息';
|
||||
$lang->ai->prompts->roleTemplate = '角色模版';
|
||||
$lang->ai->prompts->roleTemplateTip = '引用模板后,修改角色、角色描述不会对模板造成影响。';
|
||||
$lang->ai->prompts->addRoleTemplate = '添加角色模板';
|
||||
$lang->ai->prompts->editRoleTemplate = '编辑角色模板';
|
||||
$lang->ai->prompts->roleAddedSuccess = '角色模版保存成功';
|
||||
$lang->ai->prompts->roleDelConfirm = '删除不会影响已用角色模版的提词,是否删除?';
|
||||
|
||||
|
||||
@@ -81,8 +81,7 @@
|
||||
</div>
|
||||
<div class='content-row'>
|
||||
<div class='input-label'><span><?php echo $lang->ai->prompts->characterization;?></span></div>
|
||||
<div class='input'><?php echo html::textarea('characterization',
|
||||
'', "class='form-control' rows='4' placeholder='{$lang->ai->prompts->charPlaceholder}'");?></div>
|
||||
<div class='input'><?php echo html::textarea('characterization', '', "class='form-control' rows='4' placeholder='{$lang->ai->prompts->charPlaceholder}'");?></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -93,6 +92,33 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="editRoleTemplateModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only"><?php echo $lang->close; ?></span></button>
|
||||
<h4 class="modal-title"><?php echo $lang->ai->prompts->editRoleTemplate; ?> <i class='icon icon-help'></i> <span class="text-gray">本次编辑不会影响已用模版的提词</span></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="editRoleForm">
|
||||
<div class='content-row'>
|
||||
<div class='input-label'><span><?php echo $lang->ai->prompts->role;?></span></div>
|
||||
<div class='input mw-400px'><?php echo html::input('role', '', "class='form-control' placeholder='{$lang->ai->prompts->rolePlaceholder}'");?></div>
|
||||
</div>
|
||||
<div class='content-row'>
|
||||
<div class='input-label'><span><?php echo $lang->ai->prompts->characterization;?></span></div>
|
||||
<div class='input'><?php echo html::textarea('characterization','', "class='form-control' rows='4' placeholder='{$lang->ai->prompts->charPlaceholder}'");?></div>
|
||||
</div>
|
||||
<input type="hidden" name="id">
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="editRoleButton" type="button" class="btn btn-primary" data-dismiss="modal"><?php echo $lang->save; ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function validateForm()
|
||||
{
|
||||
@@ -134,13 +160,33 @@ $('#createRoleButton').on('click', function(e)
|
||||
});
|
||||
});
|
||||
|
||||
$('#editRoleButton').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
const formData = new FormData(document.getElementById('editRoleForm'));
|
||||
$.ajax({
|
||||
url: createLink('ai', 'roleTemplates'),
|
||||
type: 'POST',
|
||||
data: {method: 'edit', id: formData.get('id'), role: formData.get('role'), characterization: formData.get('characterization')},
|
||||
dataType: 'html',
|
||||
success: function(response)
|
||||
{
|
||||
new $.zui.Messager('<?php echo $lang->ai->prompts->roleAddedSuccess; ?>', {type: 'success'}).show();
|
||||
$('#roleList').html($($.parseHTML(response)).filter('#roleList').html());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#roleListContainer').on('click', function (e)
|
||||
{
|
||||
const button = e.target.closest('#roleListContainer button');
|
||||
if(!button) return;
|
||||
if(!'id' in button.dataset || !'action' in button.dataset) return;
|
||||
const card = button.closest('.role-template-card');
|
||||
if(!card) return;
|
||||
if(!'id' in card.dataset || !'action' in button.dataset) return;
|
||||
e.preventDefault();
|
||||
const id = button.dataset.id;
|
||||
|
||||
const id = card.dataset.id;
|
||||
|
||||
if(button.dataset.action === 'del')
|
||||
{
|
||||
@@ -158,6 +204,14 @@ $('#roleListContainer').on('click', function (e)
|
||||
});
|
||||
}
|
||||
}
|
||||
else if(button.dataset.action === 'edit')
|
||||
{
|
||||
const model = $('#editRoleTemplateModal');
|
||||
model.find('input[name="id"]').val(id);
|
||||
model.find('#role').val(card.querySelector('#role').innerText);
|
||||
model.find('#characterization').val(card.querySelector('#characterization').innerText);
|
||||
model.modal('toggle');
|
||||
}
|
||||
});
|
||||
|
||||
(function()
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
<div id="roleList" style="display: flex; flex-direction: column; gap:8px;">
|
||||
<?php foreach($roleTemplates as $role)
|
||||
{ ?>
|
||||
<div class="role-template-card" style="border: 1px solid #D8DBDE; border-radius: 4px; padding: 12px; width: 100%;">
|
||||
<div class="role-template-card" data-id="<?php echo $role->id; ?>" style="border: 1px solid #D8DBDE; border-radius: 4px; padding: 12px; width: 100%;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; gap: 16px;">
|
||||
<p id="role" class="clip"><?php echo $role->role; ?></p>
|
||||
<div style="display: flex; gap: 2px;">
|
||||
<?php echo html::commonButton("<span class='text-primary'>{$lang->app->common}</span>", '', 'btn btn-link'); ?>
|
||||
<?php echo html::commonButton("<i class='icon icon-edit icon-sm text-primary'></i>", "data-id=$role->id data-action='edit'", 'btn btn-link'); ?>
|
||||
<?php echo html::commonButton("<i class='icon icon-trash icon-sm text-primary'></i>", "data-id=$role->id data-action='del'", 'btn btn-link'); ?>
|
||||
<?php echo html::commonButton("<span class='text-primary'>{$lang->app->common}</span>", "data-action='apply'", 'btn btn-link'); ?>
|
||||
<?php echo html::commonButton("<i class='icon icon-edit icon-sm text-primary'></i>", "data-action='edit'", 'btn btn-link'); ?>
|
||||
<?php echo html::commonButton("<i class='icon icon-trash icon-sm text-primary'></i>", "data-action='del'", 'btn btn-link'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<p id="characterization" class="text-gray clip"><?php echo $role->characterization; ?></p>
|
||||
|
||||
Reference in New Issue
Block a user