WIP Edit and Add forms
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 24 Feb 2017 22:00:54 +0000 (17:00 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 24 Feb 2017 22:00:54 +0000 (17:00 -0500)
Edit and Add page is working. Have to go over some fields like
contact_id and the member reference with Chuck though.

models/admin/registrations/accounts.php
views/admin/registrations/account.html
views/admin/registrations/edit.html

index c294731..2f8d2d5 100644 (file)
@@ -87,22 +87,26 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
 
     public function modelAction($actionData = false)
     {
-        $option         = 'list';
-        $numbAccounts   = 0;
-        $hasAccounts    = false;
-        $paging         = true;
-        $prevStart      = false;
-        $nextStart      = false;
-        $start          = 1;
-        $limit          = 20;        // Set to the number of listings per page
-        $fromDate       = false;
-        $toDate         = false;
-        $filterArchived = false;
-        $filterPending  = false;
-        $accounts       = false;
-        $view           = 'account.html';
-        $account        = false;
-        $haveAccount    = false;
+        $option             = 'list';
+        $numbAccounts       = 0;
+        $hasAccounts        = false;
+        $paging             = true;
+        $prevStart          = false;
+        $nextStart          = false;
+        $start              = 1;
+        $limit              = 20;        // Set to the number of listings per page
+        $fromDate           = false;
+        $toDate             = false;
+        $filterArchived     = false;
+        $filterPending      = false;
+        $accounts           = false;
+        $view               = 'account';
+        $account            = false;
+        $haveAccount        = false;
+        $accountUpdated     = false;
+        $accountUpdateError = false;
+        $accountAdded       = false;
+        $accountAddError    = false;
 
         // Get any provided option
         if (isset($_REQUEST['option'])) {
@@ -123,15 +127,22 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
 
         switch ( $option ) {
         case 'add':
-            $view = 'edit.html';
+            $view    = 'edit';
             $account = $this->newEntry();
             break;
 
         case 'insert':
+            $view    = 'edit';
+            $account = $this->insertEntry();
+            if ( $account['status'] ) {
+                $accountAdded = true;
+            } else {
+                $accountAddError = true;
+            }
             break;
 
         case 'edit':
-            $view    = 'edit.html';
+            $view    = 'edit';
             $account = $this->editEntry( $this->accountID );
             if ( $account['status'] ) {
                 $haveAccount = true;
@@ -140,6 +151,20 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
             break;
 
         case 'update':
+            $account = $this->updateEntry( $this->accountID );
+
+            if ( $account['status'] ) {
+                $accountUpdated = true;
+                // Retrieve the Edit Entry again
+                $account = $this->editEntry( $this->accountID );
+                if ( $account['status'] ) {
+                    $haveAccount = true;
+                }
+            } else {
+                $accountUpdateError = true;
+            }
+
+            $view   = 'edit';
             break;
 
         case 'delete':
@@ -148,32 +173,37 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
         default:
             $accounts    = $this->getList();
             $hasAccounts = ( $accounts !== false && count( $accounts > 0 ) ) ? true: false;
-            $view        = 'account.html';
+            $view        = 'account';
             break;
         }
 
         // Compile template data
         $templateData = array(
-            'hasAccounts'    => $hasAccounts,
-            'numAccounts'    => count($accounts),
-            'accounts'       => $accounts,
-            'account'        => $account,
-            'limit'          => $limit,
-            'prevStart'      => $prevStart,
-            'nextStart'      => $nextStart,
-            'paging'         => $paging,
-            'fromDate'       => $fromDate,
-            'toDate'         => $toDate,
-            'filterArchived' => $filterArchived,
-            'filterPending'  => $filterPending,
-            'accountID'      => $this->accountID,
-            'haveAccount'    => $haveAccount,
+            'hasAccounts'        => $hasAccounts,
+            'numAccounts'        => count($accounts),
+            'accounts'           => $accounts,
+            'account'            => $account,
+            'limit'              => $limit,
+            'prevStart'          => $prevStart,
+            'nextStart'          => $nextStart,
+            'paging'             => $paging,
+            'fromDate'           => $fromDate,
+            'toDate'             => $toDate,
+            'filterArchived'     => $filterArchived,
+            'filterPending'      => $filterPending,
+            'accountID'          => $this->accountID,
+            'haveAccount'        => $haveAccount,
+            'accountUpdated'     => $accountUpdated,
+            'accountUpdateError' => $accountUpdateError,
+            'option'             => $option,
+            'accountAdded'       => $accountAdded,
+            'accountAddError'    => $accountAddError,
         );
              // Return status, any suggested view, and any data to controller
         return array(
             'status'        => true,
             'modelRedirect' => false,
-            'view'          => 'admin/registrations/' . $view,
+            'view'          => 'admin/registrations/' . $view . '.html',
             'data'          => $templateData
         );
 
index e1d0f51..96524b0 100644 (file)
@@ -2,6 +2,8 @@
 
 <h3>Account List Page</h3>
 
+    <a href="{$thisUrl}?page=glm-members-admin-menu-registrations-accounts&glm_action=accounts&option=add" class="button button-secondary glm-button glm-right">Add A New Account</a>
+
     <form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
 
         <input type="hidden" name="prevStart" value="{$prevStart}">
index 3708596..87287f6 100644 (file)
@@ -1,8 +1,31 @@
 {include file='admin/registrations/header.html'}
 
-<h3>Account Edit Page</h3>
+    <a href="{$thisUrl}?page={$thisPage}&glm_action=accounts" class="button button-secondary glm-button glm-right">Return to Account List</a>
+
+  {if $option == 'edit' || $option == 'update'}
+    <a id="deleteAccountButton" class="button button-secondary glm-button glm-right">Delete this Account</a>
+    <h2>Edit Account
+  {else}
+    <h2>Add new Account
+  {/if}
+        &nbsp;&nbsp;&nbsp;
+        {if $accountUpdated}<span class="glm-notice glm-flash-updated">Account Updated</span>{/if}
+        {if $accountUpdateError}<span class="glm-error glm-flash-updated">Account Update Error</span>{/if}
+        {if $accountAdded}<span class="glm-notice glm-flash-updated">Account Added</span>{/if}
+        {if $accountAddError}<span class="glm-error glm-flash-updated">Account Add Error</span>{/if}
+    </h2>
+
 
     <form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
+        <input type="hidden" name="glm_action" value="accounts">
+    {if $haveAccount}
+        <input type="hidden" name="option" value="update">
+        <input type="hidden" name="account" value="{$account.fieldData.id}">
+    {else}
+        <input type="hidden" name="option" value="insert">
+    {/if}
+        <input type="hidden" name="contact_id" value="0">
+        <input type="hidden" name="registered_by" value="0">
         <table id="glm-table-account" class="glm-admin-table glm-account-table">
             {if $haveAccount} <input type="hidden" name="account" value="{$accountID}"> {/if}
 
         </tr>
 
         </table>
+
+        <input id="updateAccount" type="submit" value="{if $haveAccount}Update Account{else}Save New Account{/if}">
+
     </form>
+    <script>
+        jQuery(document).ready(function($) {
+            $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+        });
+
+    </script>
 
 {include file='admin/footer.html'}