Block updates for edit page
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 23 Jul 2015 19:48:42 +0000 (15:48 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 23 Jul 2015 19:48:42 +0000 (15:48 -0400)
Call in a script to hide elements on edit and add pages.
Add jquery calls to the change events for the page selector or url
field, so it selects the correct radio button.
Update label for the fields.

controllers/admin.php
glm-blocks.php
js/glm-blocks.js [new file with mode: 0644]
models/block.php
views/admin/metaBoxes.php

index f16304c..cf09a3c 100644 (file)
@@ -19,7 +19,6 @@ class glm_blocks_admin
     {
         $this->pluginDirName = $path;
         $jobs = new glm_models_block($path);
-        add_action('admin_init', array($this, 'remove_elements'));
     }
 
     /**
@@ -30,25 +29,4 @@ class glm_blocks_admin
         $this->pluginDirName = $dir;
     }
 
-
-    /**
-     * Hide certain elements from the normal post edit page. 
-     */
-    function remove_elements()
-    {
-        if(    isset($_GET['post']) && $_GET['post']
-            || (isset($_GET['post_type']) && $_GET['post_type'] == GLM_BLOCK_POST_TYPE)
-        ) {
-            $post_type = (isset($_GET['post']))
-                ? get_post_type($_GET['post'])
-                : $_GET['post_type'];
-            if($post_type == GLM_BLOCK_POST_TYPE) {
-                echo '<style>
-                    #edit-slug-box, #postbox-container-2 .inside p {display:none;}
-                    #set-ngg-post-thumbnail {display: none;}
-                    </style>';
-            }
-        }
-    }
-
 }
index dab2668..00bc25f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
 Plugin Name: GLM Blocks
-Version: 1.2.0
+Version: 1.2.1
 Description: Displays blocks of content managed from the admin under Blocks.
 Author: Steve Sutton <steve@gaslightmedia.com>
 Author URI: http://www.gaslightmedia.com
diff --git a/js/glm-blocks.js b/js/glm-blocks.js
new file mode 100644 (file)
index 0000000..23392a6
--- /dev/null
@@ -0,0 +1,19 @@
+jQuery(function($){
+
+    $("#edit-slug-box").hide();
+    $("#set-ngg-post-thumbnail").hide();
+    $("#glm_block_page").change(function(){
+        if($("#glm_block_page").val()) {
+            $("input[name=glm_block_url]").filter('input[value=page]').attr('checked', true);
+        } else {
+            $("input[name=glm_block_url]").filter('input[value=page]').attr('checked', false);
+        }
+    });
+    $("#glm_block_ext_url").change(function(){
+        if($("#glm_block_ext_url").val()) {
+            $("input[name=glm_block_url]").filter('input[value=url]').attr('checked', true);
+        } else {
+            $("input[name=glm_block_url]").filter('input[value=url]').attr('checked', false);
+        }
+    });
+});
index efaebf3..e171f89 100644 (file)
@@ -31,6 +31,7 @@ class glm_models_block
     {
         $this->pluginDirName = $path;
         add_action('init', array($this, 'addPostTypes'));
+        add_action('admin_enqueue_scripts', array($this, 'load_admin_scripts'));
         add_action('add_meta_boxes', array($this, 'addMetaBoxes'));
         add_action('save_post', array($this, 'saveMetaBox'));
         add_action('manage_edit-glm_blocks_columns', array($this, 'addOrderColumn'));
@@ -39,6 +40,21 @@ class glm_models_block
         add_action('pre_get_posts', array($this, 'sortQuery'));
     }
 
+    public function load_admin_scripts()
+    {
+        $current_screen = get_current_screen();
+        //var_dump($current_screen);
+
+        if ($current_screen->post_type == 'glm_blocks') {
+            wp_enqueue_script('jquery');
+            wp_enqueue_script(
+                'glm_blocks_js',
+                plugins_url('../js/glm-blocks.js', __FILE__),
+                array('jquery')
+            );
+        }
+    }
+
     /**
      * sortQuery
      *
@@ -107,7 +123,7 @@ class glm_models_block
     {
         add_meta_box(
             'glm_blocks_url',
-            __('URL', 'glm_blocks_textdomain'),
+            __('Destination', 'glm_blocks_textdomain'),
             array($this, 'metaBoxCallBack'),
             GLM_BLOCK_POST_TYPE,
             'normal'
index 7ebce57..7631d4f 100644 (file)
@@ -6,7 +6,7 @@
            echo 'checked';
        }; ?>>
 <label>
-<?php echo _e('External URL', 'glm_blocks_textdomain'); ?>
+<?php echo _e('External URL (with http://)', 'glm_blocks_textdomain'); ?>
     <input
         type="text"
         id="glm_block_ext_url"
@@ -19,7 +19,7 @@
 <?php if ($glm_block_url == 'page') {
     echo 'checked';
 }; ?>>
-<label for="my_meta_box_post_type">Post type: </label>
+<label for="my_meta_box_post_type">Internal link: </label>
 <?php
 wp_dropdown_pages(
     array(
@@ -33,4 +33,4 @@ wp_dropdown_pages(
     )
 );
 ?>
-</select>
\ No newline at end of file
+</select>