Skip to content
Snippets Groups Projects
Verified Commit 19dda409 authored by Damien's avatar Damien
Browse files

FEAT #9685 Notes Templates

parent b633bcb5
No related branches found
No related tags found
No related merge requests found
......@@ -126,30 +126,31 @@ class NoteController
return ['encodedDocument' => base64_encode($fileContent)];
}
public static function getTemplatesByResId(Request $request, Response $response, array $aArgs)
public static function getTemplates(Request $request, Response $response)
{
if (!Validator::intVal()->notEmpty()->validate($aArgs['resId'])) {
return $response->withStatus(400)->withJson(['errors' => 'Route resId is not an integer']);
}
if (!ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$query = $request->getQueryParams();
$resource = ResModel::getById(['resId' => $aArgs['resId'], 'select' => ['destination']]);
if (!empty($resource['destination'])) {
$templates = TemplateModel::getWithAssociation(['select' => ['DISTINCT(templates.template_id), template_label', 'template_content'], 'where' => ['template_target = ?', 'value_field = ?', 'templates.template_id = templates_association.template_id'], 'data' => ['notes', $resource['destination']], 'orderBy' => ['template_label']]);
if (!empty($query['resId']) && is_numeric($query['resId'])) {
if (!ResController::hasRightByResId(['resId' => $query['resId'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$resource = ResModel::getById(['resId' => $query['resId'], 'select' => ['destination']]);
if (!empty($resource['destination'])) {
$templates = TemplateModel::getWithAssociation([
'select' => ['DISTINCT(templates.template_id), template_label', 'template_content'],
'where' => ['template_target = ?', 'value_field = ?', 'templates.template_id = templates_association.template_id'],
'data' => ['notes', $resource['destination']],
'orderBy' => ['template_label']
]);
} else {
$templates = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]);
}
} else {
$templates = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]);
}
return $response->withJson(['templates' => $templates]);
}
public static function getTemplates(Request $request, Response $response)
{
$templates = TemplateModel::getByTarget(['template_target' => 'notes', 'select' => ['template_label', 'template_content']]);
return $response->withJson(['templates' => $templates]);
}
}
......@@ -49,18 +49,15 @@ export class NoteEditorComponent implements AfterViewInit {
getTemplatesNote() {
if (this.templatesNote.length == 0) {
let params = {};
if (this.resIds.length == 1) {
this.http.get("../../rest/res/" + this.resIds[0] + "/notes/templates")
.subscribe((data: any) => {
this.templatesNote = data['templates'];
});
} else {
this.http.get("../../rest/notes/templates")
.subscribe((data: any) => {
this.templatesNote = data['templates'];
});
params['resId'] = this.resIds[0];
}
this.http.get("../../rest/notes/templates", {params: params})
.subscribe((data: any) => {
this.templatesNote = data['templates'];
});
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment