From dbdec73b0f122369ba748a7380c05be0d7b3adc0 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 4 Dec 2017 12:42:37 -0500 Subject: [PATCH] Update the edit form so it shows errors Show update or insert errors or success messages. --- models/admin/settings/notificationTypes.php | 71 ++++++++++++------- .../admin/settings/editNotificationType.html | 65 ++++++++++------- 2 files changed, 85 insertions(+), 51 deletions(-) diff --git a/models/admin/settings/notificationTypes.php b/models/admin/settings/notificationTypes.php index fa07c07..521ee6f 100644 --- a/models/admin/settings/notificationTypes.php +++ b/models/admin/settings/notificationTypes.php @@ -99,14 +99,19 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType public function modelAction ($actionData = false) { - $id = 0; - $option = 'list'; - $view = 'notificationTypes'; - $success = true; - $haveNotificationTypes = false; - $notificationTypes = false; - $error = false; - $enable_members = $this->config['settings']['enable_members']; + $id = 0; + $option = 'list'; + $view = 'notificationTypes'; + $success = true; + $notificationUpdated = false; + $notificationUpdateError = false; + $notificationAdded = false; + $notificationInsertError = false; + $haveNotificationTypes = false; + $notificationTypes = false; + $notification = false; + $error = false; + $enable_members = $this->config['settings']['enable_members']; // Check for region id $id = 0; @@ -139,34 +144,45 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType switch($_REQUEST['option']) { case 'add': - $notificationTypes = $this->newEntry(); + $notification = $this->newEntry(); $view = 'editNotificationType'; break; case 'insert': $view = 'editNotificationType'; - $test = $this->insertEntry(); - echo '
$test: ' . print_r($test, true) . '
'; - $notificationTypes = $this->getList(); + $notification = $this->insertEntry(); + if ( $notification['status'] ) { + $notificationAdded = true; + $id = $notification['fieldData']['id']; + $notification = $this->editEntry( $id ); + } else { + $notificationInsertError = true; + } break; case 'edit': - $notificationTypes = $this->editEntry( $id ); + $notification = $this->editEntry( $id ); $view = 'editNotificationType'; break; case 'update': if ($id > 0) { - $this->updateEntry($id); + $notification = $this->updateEntry($id); + if ( $notification['status'] ) { + $notificationUpdated = true; + $notification = $this->editEntry( $id ); + } else { + $notificationUpdateError = true; + } + $view = 'editNotificationType'; } - $notificationTypes = $this->getList(); + break; case 'delete': if ($id > 0) { $this->deleteEntry($id, true); } - case 'list': default: // Get a current list of members @@ -175,8 +191,6 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType } - // echo '
$notificationTypes: ' . print_r( $notificationTypes, true ) . '
'; - // If we have list entries - even if it's an empty list $success = true; $haveNotificationTypes = false; @@ -203,14 +217,19 @@ class GlmMembersAdmin_settings_notificationTypes extends GlmDataNotificationType // Compile template data $templateData = array( - 'notification_id' => $id, - 'action' => $_REQUEST['glm_action'], - 'enable_members' => $enable_members, - 'haveNotificationTypes' => $haveNotificationTypes, - 'notificationTypes' => $notificationTypes, - 'send_date_period' => $this->config['send_date_period'], - 'send_date_when' => $this->config['send_date_when'], - 'send_action' => $this->config['send_action'], + 'notification_id' => $id, + 'action' => $_REQUEST['glm_action'], + 'enable_members' => $enable_members, + 'haveNotificationTypes' => $haveNotificationTypes, + 'notificationTypes' => $notificationTypes, + 'notification' => $notification, + 'notificationUpdated' => $notificationUpdated, + 'notificationUpdateError' => $notificationUpdateError, + 'notificationAdded' => $notificationAdded, + 'notificationInsertError' => $notificationInsertError, + 'send_date_period' => $this->config['send_date_period'], + 'send_date_when' => $this->config['send_date_when'], + 'send_action' => $this->config['send_action'], ); // Return status, suggested view, and data to controller diff --git a/views/admin/settings/editNotificationType.html b/views/admin/settings/editNotificationType.html index 77ee708..305975a 100644 --- a/views/admin/settings/editNotificationType.html +++ b/views/admin/settings/editNotificationType.html @@ -2,7 +2,10 @@ {include file='admin/settings/subHeader.html'} -Show error header here +{if $notificationUpdated}Notification Updated{/if} +{if $notificationUpdateError}Notification Update Error{/if} +{if $notificationInsertError}Notification Insert Error{/if} +{if $notificationAdded}Notification Added{/if}
{if $notification_id} @@ -15,21 +18,23 @@ Show error header here - - + + + - + + + - + - - + - - + - - + - - + @@ -112,5 +120,12 @@ Show error header here
Name - - {if $notificationTypes.fieldFail.name}

{$notificationTypes.fieldFail.name}

{/if}
+
Name + + {if $notification.fieldFail.name}

{$notification.fieldFail.name}

{/if}
Send Notification based on
Due Date
Immediate Action
Subject - - {if $notificationTypes.fieldFail.subject}

{$notificationTypes.fieldFail.subject}

{/if}
+
Subject + + {if $notification.fieldFail.subject}

{$notification.fieldFail.subject}

{/if}
From - - {if $notificationTypes.fieldFail.from_header}

{$notificationTypes.fieldFail.from_header}

{/if}
+
From + + {if $notification.fieldFail.from_header}

{$notification.fieldFail.from_header}

{/if}
Reply-To - - {if $notificationTypes.fieldFail.replyto}

{$notificationTypes.fieldFail.replyto}

{/if}
+
Reply-To + + {if $notification.fieldFail.replyto}

{$notification.fieldFail.replyto}

{/if}
Message: + Message: {php} - wp_editor('{$notificationTypes.fieldData.message|escape:quotes}', 'glm_descr', array( + wp_editor('{$notification.fieldData.message|escape:quotes}', 'glm_descr', array( 'media_buttons' => false, 'textarea_name' => 'message', 'editor_height' => 200, )); {/php} - {if $notificationTypes.fieldFail.message}

{$notificationTypes.fieldFail.message}

{/if} + {if $notification.fieldFail.message}

{$notification.fieldFail.message}

{/if}
+ {include file='admin/footer.html'} -- 2.17.1