Skip to content

Commit 6b2ee46

Browse files
feat: Add message for template and page save
Add a message when saving a grapes template and grapes page. Improve messages when errors occur.
1 parent bb43397 commit 6b2ee46

File tree

3 files changed

+100
-38
lines changed

3 files changed

+100
-38
lines changed

code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,19 @@
108108
}),
109109
contentType: "application/json",
110110
success: function (response) {
111-
console.log('Saved as Template');
111+
if (response.success) {
112+
AspenDiscovery.showMessage('Success', response.message);
113+
} else {
114+
AspenDiscovery.showMessage('Error', response.message || 'Failed to save template.');
115+
}
112116
},
113117
error: function (xhr, status, error) {
114118
console.error('Error saving template: ', error);
119+
let errorMessage = 'Failed to save template. Please try again.';
120+
if (xhr.responseJSON && xhr.responseJSON.message) {
121+
errorMessage = xhr.responseJSON.message;
122+
}
123+
AspenDiscovery.showMessage('Error', errorMessage);
115124
}
116125
});
117126
}

code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,19 @@
106106
}),
107107
contentType: "application/json",
108108
success: function (response) {
109-
console.log('Saved as Grapes Page');
109+
if (response.success) {
110+
AspenDiscovery.showMessage('Success', response.message);
111+
} else {
112+
AspenDiscovery.showMessage('Error', response.message || 'Failed to save page.');
113+
}
110114
},
111115
error: function (xhr, status, error) {
112116
console.error('Error saving page: ', error);
117+
let errorMessage = 'Failed to save page. Please try again.';
118+
if (xhr.responseJSON && xhr.responseJSON.message){
119+
errorMessage = xhr.responseJSON.message;
120+
}
121+
AspenDiscovery.showMessage('Error', errorMessage);
113122
}
114123
});
115124
}

code/web/services/WebBuilder/AJAX.php

Lines changed: 80 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -972,43 +972,87 @@ function trackWebResourceUsage() {
972972
}
973973
function saveAsTemplate(){
974974
require_once ROOT_DIR . '/sys/WebBuilder/GrapesTemplate.php';
975-
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
976-
$templateId = $newGrapesPageContent['templateId'];
977-
$html = $newGrapesPageContent['html'];
978-
$css = $newGrapesPageContent['css'];
979-
$projectData = json_encode($newGrapesPageContent['projectData']);
980-
981-
$template = new GrapesTemplate();
982-
$template->id = $templateId;
983-
984-
if ($template->find(true)) {
985-
$template->templateContent = $projectData;
986-
$template->htmlData = $html;
987-
$template->cssData = $css;
988-
}
989-
$template->update();
990-
}
991-
992-
function saveAsPage() {
993-
require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php';
994-
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
995-
$grapesPageId = $newGrapesPageContent['grapesPageId'];
996-
$grapesGenId = $newGrapesPageContent['grapesGenId'];
997-
$templateId = $newGrapesPageContent['templateId'];
998-
$html = $newGrapesPageContent['html'];
999-
$css = $newGrapesPageContent['css'];
1000-
$grapesPage = new GrapesPage();
1001-
$grapesPage->id = $grapesPageId;
1002-
$projectData = json_encode($newGrapesPageContent['projectData']);
975+
976+
try {
977+
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
978+
$templateId = $newGrapesPageContent['templateId'];
979+
$html = $newGrapesPageContent['html'];
980+
$css = $newGrapesPageContent['css'];
981+
$projectData = json_encode($newGrapesPageContent['projectData']);
982+
983+
$template = new GrapesTemplate();
984+
$template->id = $templateId;
985+
986+
if (!$template->find(true)) {
987+
return [
988+
'success' => false,
989+
'message' => "Template with ID $templateId not found. Unable to update."
990+
];
991+
}
992+
$template->templateContent = $projectData;
993+
$template->htmlData = $html;
994+
$template->cssData = $css;
995+
996+
if(!$template->update()) {
997+
return [
998+
'success' => false,
999+
'message' => 'Failed to update the template.'
1000+
];
1001+
}
1002+
return [
1003+
'success' => true,
1004+
'message' => 'Template saved successfully.'
1005+
];
1006+
} catch (Exception $e) {
1007+
return [
1008+
'success' => false,
1009+
'message' => 'an unexpected error occurred: ' . $e->getMessage()
1010+
];
1011+
}
1012+
}
10031013

1004-
if ($grapesPage->find(true)) {
1005-
$grapesPage->grapesGenId = $grapesGenId;
1006-
$grapesPage->templateContent = $projectData;
1007-
$grapesPage->htmlData = $html;
1008-
$grapesPage->cssData = $css;
1009-
}
1010-
$grapesPage->update();
1011-
}
1014+
function saveAsPage() {
1015+
require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php';
1016+
1017+
try {
1018+
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
1019+
$grapesPageId = $newGrapesPageContent['grapesPageId'];
1020+
$grapesGenId = $newGrapesPageContent['grapesGenId'];
1021+
$templateId = $newGrapesPageContent['templateId'];
1022+
$html = $newGrapesPageContent['html'];
1023+
$css = $newGrapesPageContent['css'];
1024+
$grapesPage = new GrapesPage();
1025+
$grapesPage->id = $grapesPageId;
1026+
$projectData = json_encode($newGrapesPageContent['projectData']);
1027+
1028+
if (!$grapesPage->find(true)) {
1029+
return [
1030+
'success' =>false,
1031+
'message' => "Page with ID $grapesPageId not found. Unable to update."
1032+
];
1033+
}
1034+
$grapesPage->grapesGenId = $grapesGenId;
1035+
$grapesPage->templateContent = $projectData;
1036+
$grapesPage->htmlData = $html;
1037+
$grapesPage->cssData = $css;
1038+
1039+
if (!$grapesPage->update()) {
1040+
return [
1041+
'success ' => false,
1042+
'message' => 'Failed to update the page.'
1043+
];
1044+
}
1045+
return [
1046+
'success' => true,
1047+
'message' => 'Page saved successfully.'
1048+
];
1049+
} catch (Exception $e) {
1050+
return [
1051+
'success' => false,
1052+
'message' => 'An unexpected error occurred: ' . $e->getMessage()
1053+
];
1054+
}
1055+
}
10121056

10131057
function loadGrapesPage() {
10141058
require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php';

0 commit comments

Comments
 (0)