Started work on Events list calendar, Added formatting to phone input
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 18 May 2016 18:02:47 +0000 (14:02 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 18 May 2016 18:02:47 +0000 (14:02 -0400)
classes/glmPluginSupport.php
controllers/admin.php
defines.php
js/jquery.maskedinput-1.2.2.js [new file with mode: 0644]
models/front/members/list.php
setup/frontHooks.php
setup/standardTemplateParams.php
views/admin/member/memberInfo.html
views/front/members/list.html

index 634816a..23bd731 100644 (file)
@@ -434,6 +434,8 @@ class GlmPluginSupport
      */
     function glmMembersGitNotice() {
 
+return; // Off for now ** Need to make this switchable in management
+
         echo '<div class="error"><h3 class="glm-error">Plugin Git Branch Warning:</h3><table>';
         foreach ($this->gitBranch as $b) {
 
index 51f82ce..bd1964d 100644 (file)
@@ -221,27 +221,24 @@ class glmMembersAdmin extends GlmPluginSupport
      * Acccepts all AJAX requests for member db admin.
      *
      * Requests are submitted to the WordPress AJAX processor with "action" specified
-     * as "glm_members_admin_ajax". The AJAX call must also specify the target table
-     * the image entry will point to and the target table record ID of the record with
-     * which image will be associated. Only valid tables are accepted according to the
-     *
+     * as "glm_members_admin_ajax".
      *
      * @return void
      * @access public
      */
     public function  glmMembersAdminAjax()
     {
+
         // Get the model action
         if (isset($_REQUEST['glm_action']) && $_REQUEST['glm_action'] != '') {
-            $a = sanitize_text_field($_REQUEST['glm_action']);
-            if ($a != '') {
-                $glmAction = $a;
-            } else {
+            $glmAction = sanitize_text_field($_REQUEST['glm_action']);
+            if ($glmAction == '') {
                 // No menu provided - terminating
                 trigger_error ( 'ERROR: No "glm_action" string provided in POST array.', E_USER_ERROR);
             }
 
         } else {
+
             trigger_error ( 'ERROR: No "glm_action" itme in POST array.', E_USER_ERROR);
         }
 
@@ -273,6 +270,7 @@ class glmMembersAdmin extends GlmPluginSupport
 
                 // Instantiate the model and ask it to perform the work
                 $model = new $className($this->wpdb, $this->config);
+
                 $model->modelAction();
 
             }
@@ -440,6 +438,16 @@ class glmMembersAdmin extends GlmPluginSupport
         );
         wp_enqueue_style('glm-members-admin-fullcalendar-css');
 
+        wp_register_script(
+            'glm-members-admin-maskedinput',
+            GLM_MEMBERS_PLUGIN_URL . 'js/jquery.maskedinput-1.2.2.js',
+            array(
+                    'jquery'
+            ),
+            GLM_MEMBERS_PLUGIN_VERSION
+        );
+        wp_enqueue_script('glm-members-admin-maskedinput');
+
     }
 
     /**
index 7660cb7..0b9f7a3 100644 (file)
@@ -40,6 +40,7 @@ $WPUploadDir = wp_upload_dir();
 define('GLM_MEMBERS_SITE_BASE_URL', home_url('/') );
 define('GLM_MEMBERS_PLUGIN_URL', plugin_dir_url(__FILE__));
 define('GLM_MEMBERS_PLUGIN_ADMIN_URL', admin_url('admin.php'));
+define('GLM_MEMBERS_PLUGIN_ADMIN_AJAX_URL', admin_url('admin-ajax.php'));
 define('GLM_MEMBERS_PLUGIN_ASSETS_URL', GLM_MEMBERS_PLUGIN_URL.'/assets');
 define('GLM_MEMBERS_PLUGIN_BASE_URL', WP_PLUGIN_URL.'/'.GLM_MEMBERS_PLUGIN_SLUG);
 define('GLM_MEMBERS_PLUGIN_CURRENT_URL', $urlParts['scheme'].'://'.$urlParts['host'].$pageUri[0]);
diff --git a/js/jquery.maskedinput-1.2.2.js b/js/jquery.maskedinput-1.2.2.js
new file mode 100644 (file)
index 0000000..1b9077d
--- /dev/null
@@ -0,0 +1,252 @@
+/// <reference path="../../../lib/jquery-1.2.6.js" />
+/*
+    Masked Input plugin for jQuery
+    Copyright (c) 2007-2009 Josh Bush (digitalbush.com)
+    Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) 
+    Version: 1.2.2 (03/09/2009 22:39:06)
+*/
+(function($) {
+    var pasteEventName = ($.browser.msie ? 'paste' : 'input') + ".mask";
+    var iPhone = (window.orientation != undefined);
+
+    $.mask = {
+        //Predefined character definitions
+        definitions: {
+            '9': "[0-9]",
+            'a': "[A-Za-z]",
+            '*': "[A-Za-z0-9]"
+        }
+    };
+
+    $.fn.extend({
+        //Helper Function for Caret positioning
+        caret: function(begin, end) {
+            if (this.length == 0) return;
+            if (typeof begin == 'number') {
+                end = (typeof end == 'number') ? end : begin;
+                return this.each(function() {
+                    if (this.setSelectionRange) {
+                        this.focus();
+                        this.setSelectionRange(begin, end);
+                    } else if (this.createTextRange) {
+                        var range = this.createTextRange();
+                        range.collapse(true);
+                        range.moveEnd('character', end);
+                        range.moveStart('character', begin);
+                        range.select();
+                    }
+                });
+            } else {
+                if (this[0].setSelectionRange) {
+                    begin = this[0].selectionStart;
+                    end = this[0].selectionEnd;
+                } else if (document.selection && document.selection.createRange) {
+                    var range = document.selection.createRange();
+                    begin = 0 - range.duplicate().moveStart('character', -100000);
+                    end = begin + range.text.length;
+                }
+                return { begin: begin, end: end };
+            }
+        },
+        unmask: function() { return this.trigger("unmask"); },
+        mask: function(mask, settings) {
+            if (!mask && this.length > 0) {
+                var input = $(this[0]);
+                var tests = input.data("tests");
+                return $.map(input.data("buffer"), function(c, i) {
+                    return tests[i] ? c : null;
+                }).join('');
+            }
+            settings = $.extend({
+                placeholder: "_",
+                completed: null
+            }, settings);
+
+            var defs = $.mask.definitions;
+            var tests = [];
+            var partialPosition = mask.length;
+            var firstNonMaskPos = null;
+            var len = mask.length;
+
+            $.each(mask.split(""), function(i, c) {
+                if (c == '?') {
+                    len--;
+                    partialPosition = i;
+                } else if (defs[c]) {
+                    tests.push(new RegExp(defs[c]));
+                    if(firstNonMaskPos==null)
+                        firstNonMaskPos =  tests.length - 1;
+                } else {
+                    tests.push(null);
+                }
+            });
+
+            return this.each(function() {
+                var input = $(this);
+                var buffer = $.map(mask.split(""), function(c, i) { if (c != '?') return defs[c] ? settings.placeholder : c });
+                var ignore = false;             //Variable for ignoring control keys
+                var focusText = input.val();
+
+                input.data("buffer", buffer).data("tests", tests);
+
+                function seekNext(pos) {
+                    while (++pos <= len && !tests[pos]);
+                    return pos;
+                };
+
+                function shiftL(pos) {
+                    while (!tests[pos] && --pos >= 0);
+                    for (var i = pos; i < len; i++) {
+                        if (tests[i]) {
+                            buffer[i] = settings.placeholder;
+                            var j = seekNext(i);
+                            if (j < len && tests[i].test(buffer[j])) {
+                                buffer[i] = buffer[j];
+                            } else
+                                break;
+                        }
+                    }
+                    writeBuffer();
+                    input.caret(Math.max(firstNonMaskPos, pos));
+                };
+
+                function shiftR(pos) {
+                    for (var i = pos, c = settings.placeholder; i < len; i++) {
+                        if (tests[i]) {
+                            var j = seekNext(i);
+                            var t = buffer[i];
+                            buffer[i] = c;
+                            if (j < len && tests[j].test(t))
+                                c = t;
+                            else
+                                break;
+                        }
+                    }
+                };
+
+                function keydownEvent(e) {
+                    var pos = $(this).caret();
+                    var k = e.keyCode;
+                    ignore = (k < 16 || (k > 16 && k < 32) || (k > 32 && k < 41));
+
+                    //delete selection before proceeding
+                    if ((pos.begin - pos.end) != 0 && (!ignore || k == 8 || k == 46))
+                        clearBuffer(pos.begin, pos.end);
+
+                    //backspace, delete, and escape get special treatment
+                    if (k == 8 || k == 46 || (iPhone && k == 127)) {//backspace/delete
+                        shiftL(pos.begin + (k == 46 ? 0 : -1));
+                        return false;
+                    } else if (k == 27) {//escape
+                        input.val(focusText);
+                        input.caret(0, checkVal());
+                        return false;
+                    }
+                };
+
+                function keypressEvent(e) {
+                    if (ignore) {
+                        ignore = false;
+                        //Fixes Mac FF bug on backspace
+                        return (e.keyCode == 8) ? false : null;
+                    }
+                    e = e || window.event;
+                    var k = e.charCode || e.keyCode || e.which;
+                    var pos = $(this).caret();
+
+                    if (e.ctrlKey || e.altKey || e.metaKey) {//Ignore
+                        return true;
+                    } else if ((k >= 32 && k <= 125) || k > 186) {//typeable characters
+                        var p = seekNext(pos.begin - 1);
+                        if (p < len) {
+                            var c = String.fromCharCode(k);
+                            if (tests[p].test(c)) {
+                                shiftR(p);
+                                buffer[p] = c;
+                                writeBuffer();
+                                var next = seekNext(p);
+                                $(this).caret(next);
+                                if (settings.completed && next == len)
+                                    settings.completed.call(input);
+                            }
+                        }
+                    }
+                    return false;
+                };
+
+                function clearBuffer(start, end) {
+                    for (var i = start; i < end && i < len; i++) {
+                        if (tests[i])
+                            buffer[i] = settings.placeholder;
+                    }
+                };
+
+                function writeBuffer() { return input.val(buffer.join('')).val(); };
+
+                function checkVal(allow) {
+                    //try to place characters where they belong
+                    var test = input.val();
+                    var lastMatch = -1;
+                    for (var i = 0, pos = 0; i < len; i++) {
+                        if (tests[i]) {
+                            buffer[i] = settings.placeholder;
+                            while (pos++ < test.length) {
+                                var c = test.charAt(pos - 1);
+                                if (tests[i].test(c)) {
+                                    buffer[i] = c;
+                                    lastMatch = i;
+                                    break;
+                                }
+                            }
+                            if (pos > test.length)
+                                break;
+                        } else if (buffer[i] == test[pos] && i!=partialPosition) {
+                            pos++;
+                            lastMatch = i;
+                        } 
+                    }
+                    if (!allow && lastMatch + 1 < partialPosition) {
+                        input.val("");
+                        clearBuffer(0, len);
+                    } else if (allow || lastMatch + 1 >= partialPosition) {
+                        writeBuffer();
+                        if (!allow) input.val(input.val().substring(0, lastMatch + 1));
+                    }
+                    return (partialPosition ? i : firstNonMaskPos);
+                };
+
+                if (!input.attr("readonly"))
+                    input
+                    .one("unmask", function() {
+                        input
+                            .unbind(".mask")
+                            .removeData("buffer")
+                            .removeData("tests");
+                    })
+                    .bind("focus.mask", function() {
+                        focusText = input.val();
+                        var pos = checkVal();
+                        writeBuffer();
+                        setTimeout(function() {
+                            if (pos == mask.length)
+                                input.caret(0, pos);
+                            else
+                                input.caret(pos);
+                        }, 0);
+                    })
+                    .bind("blur.mask", function() {
+                        checkVal();
+                        if (input.val() != focusText)
+                            input.change();
+                    })
+                    .bind("keydown.mask", keydownEvent)
+                    .bind("keypress.mask", keypressEvent)
+                    .bind(pasteEventName, function() {
+                        setTimeout(function() { input.caret(checkVal(true)); }, 0);
+                    });
+
+                checkVal(); //Perform initial check for existing values
+            });
+        }
+    });
+})(jQuery);
\ No newline at end of file
index 2eaec5f..35f6e4e 100644 (file)
@@ -154,6 +154,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         $haveFilter = false;
         $textSearch = '';
         $blankStart = false;
+        $membersFound = false;
 
         // Check for "show" shortcode parameter (what elements to show on the page)
         $settings = array();
@@ -441,7 +442,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             strtolower($actionData['request']['view']) == "grid") {
             $view = "front/members/grid.html";
         }
-      
+
         /*
          * Check for a blank start - No members selected, just search form
          */
@@ -457,7 +458,10 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
          */
         if (!$blankStart) {
 
-                // Get member list and sort
+            // Get stats for the current selection
+            $membersFound = $this->getStats(str_replace('T.', '', $where));
+
+            // Get member list and sort
             $list = $this->getList($where.$alphaWhere, 'member_name');
 
             if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
@@ -489,6 +493,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         $templateData = array(
             'haveMembers' => $haveMembers,
             'members' => $list,
+            'membersFound' => $membersFound,
             'haveFilter' => $haveFilter,
             'filterArchived' => $filterArchived,
             'filterPending' => $filterPending,
index 310ed04..74b2d7d 100644 (file)
@@ -129,7 +129,7 @@ function glm_members_only_template( $template ) {
         return $newTemplate;
         /* Uncomment this if you want every child page of the members only page to be given the members only template
          *  (i.e. changed in the database) and not just using them on the front-end
-         */ 
+         */
          // global $post;
          // update_post_meta($post->ID, '_wp_page_template', $templateName);
     }
index f2dde16..9bbffd6 100644 (file)
@@ -28,6 +28,7 @@ $smarty->templateAssign('siteBaseUrl', GLM_MEMBERS_SITE_BASE_URL);
 $smarty->templateAssign('assetsUrl', GLM_MEMBERS_PLUGIN_ASSETS_URL);
 $smarty->templateAssign('baseUrl', GLM_MEMBERS_PLUGIN_BASE_URL);
 $smarty->templateAssign('thisUrl', GLM_MEMBERS_PLUGIN_CURRENT_URL );
+$smarty->templateAssign('ajaxUrl', GLM_MEMBERS_PLUGIN_ADMIN_AJAX_URL );
 $smarty->templateAssign('glmPluginMediaUrl', GLM_MEMBERS_PLUGIN_MEDIA_URL );
 $smarty->templateAssign('thisPage', (isset($_REQUEST['page']) ? $_REQUEST['page']: '') );
 $smarty->templateAssign('glmWordpresBasePluginPath', GLM_MEMBERS_WORDPRESS_PLUGIN_PATH );
index 3d839b8..51aa478 100644 (file)
             <tr>
                 <th {if $memberInfo.fieldRequired.phone}class="glm-required"{/if}>Phone #:</th>
                 <td {if $memberInfo.fieldFail.phone}class="glm-form-bad-input" data-tabid="glm-member-info-contact"{/if}>
-                    <input type="text" name="phone" value="{$memberInfo.fieldData.phone}" class="glm-form-text-input-short" placeholder="ex: 123-456-7890 ext 123">
+                    <input type="text" name="phone" value="{$memberInfo.fieldData.phone}" class="glm-form-text-input-short glm-phone-input" placeholder="ex: 123-456-7890 [ext 123]">
                     {if $memberInfo.fieldFail.phone}<p>{$memberInfo.fieldFail.phone}</p>{/if}
                 </td>
             </tr>
             <tr>
                 <th {if $memberInfo.fieldRequired.toll_free}class="glm-required"{/if}>Toll Free #:</th>
                 <td {if $memberInfo.fieldFail.toll_free}class="glm-form-bad-input" data-tabid="glm-member-info-contact"{/if}>
-                    <input type="text" name="toll_free" value="{$memberInfo.fieldData.toll_free}" class="glm-form-text-input-short" placeholder="ex: 800-123-4567">
+                    <input type="text" name="toll_free" value="{$memberInfo.fieldData.toll_free}" class="glm-form-text-input-short glm-phone-input" placeholder="ex: 800-123-4567 [ext 123]">
                     {if $memberInfo.fieldFail.toll_free}<p>{$memberInfo.fieldFail.toll_free}</p>{/if}
                 </td>
             </tr>
                 </td>
             </tr>
             <tr>
-                <th {if $memberInfo.fieldRequired.logo}class="glm-required"{/if}>Logo:</th>
+                <th {if $memberInfo.fieldRequired.logo}class="glm-required"{/if}>Profile Image:</th>
                 <td {if $memberInfo.fieldFail.logo}class="glm-form-bad-input" data-tabid="glm-member-info-images"{/if}>
                     <table class="glm-admin-image-edit-table">
         {if $memberInfo.fieldData.logo}
                     return false;
                     
                 });
+                
+                // Set masking for phone number fields - see http://digitalbush.com/projects/masked-input-plugin/
+                $.mask.definitions['e'] = "[A-Za-z0-9: ]";
+                $(".glm-phone-input").mask("999-999-9999? eeeeeeeeeee");
                                 
             });
             
index 9e6d43f..6f7c0ec 100644 (file)
@@ -78,6 +78,8 @@
         <h3>List of {$terms.term_member_plur_cap}</h3>
   {if $haveMembers}
 
+    {$terms.term_member_plur_cap} found: {$membersFound}<br>
+    
     {if $settings.list_show_search_alpha}
         <div class="glm-alpha-links">
             <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSelected}" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>