CMS Tree Page View - Version 1.1

Version Description

  • Added "Add new"-link next to headline, to better match the regular post overview page + it makes it possible to add new pages/posts when there are no pages/posts added (previously there needed to be at least one post added to be able to add new posts)
  • Added post count in parenthesis after each post status. Also makes the page match the regular post overview page a it more. Works for both built in post types and custom post types + if WPML is installed it will show post count for each language too.
  • Fixed a bug with sortables (well, I kinda forgot to load that script at all!) that made the plugin only work on the dashboard.
  • Fixed some IE-bugs
Download this release

Release Info

Developer eskapism
Plugin Icon wp plugin CMS Tree Page View
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

Files changed (5) hide show
  1. functions.php +128 -9
  2. index.php +2 -2
  3. readme.txt +10 -1
  4. scripts/cms_tree_page_view.js +34 -11
  5. styles/styles.css +9 -1
functions.php CHANGED
@@ -244,7 +244,9 @@ function cms_admin_enqueue_scripts() {
244
 
245
  if (cms_tpv_is_one_of_our_pages()) {
246
 
247
- wp_enqueue_script( "jquery-cookie", CMS_TPV_URL . "scripts/jquery.biscuit.js", array("jquery")); // renamed from cookie to fix problems with mod_security
 
 
248
  wp_enqueue_script( "jquery-jstree", CMS_TPV_URL . "scripts/jquery.jstree.js", false, CMS_TPV_VERSION);
249
  wp_enqueue_script( "jquery-alerts", CMS_TPV_URL . "scripts/jquery.alerts.js", false, CMS_TPV_VERSION);
250
  // wp_enqueue_script( "hoverIntent");
@@ -481,12 +483,54 @@ function cms_tpv_is_post_type_hierarchical($post_type_object) {
481
  return $is_hierarchical;
482
  }
483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  /**
485
  * Print tree stuff that is common for both dashboard and page
486
  */
487
  function cms_tpv_print_common_tree_stuff($post_type = "") {
488
 
489
- global $sitepress, $cms_tpv_view;
490
 
491
  if (!$post_type) {
492
  $post_type = cms_tpv_get_selected_post_type();
@@ -510,6 +554,37 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
510
 
511
  }
512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
  // output js for the root/top level
514
  // function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) {
515
  // @todo: make into function since used at other places
@@ -551,7 +626,15 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
551
  $wpml_active_lang = $one_lang;
552
  $selected = "current";
553
  }
554
- $lang_out .= "<li><a class='cms_tvp_switch_lang $selected cms_tpv_switch_language_code_{$one_lang["language_code"]}' href='#'>$one_lang_details[display_name]</a> | </li>";
 
 
 
 
 
 
 
 
555
  }
556
  $lang_out = preg_replace('/ \| <\/li>$/', "</li>", $lang_out);
557
  $lang_out .= "</ul>";
@@ -561,15 +644,35 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
561
  }
562
 
563
  if (empty($pages)) {
 
564
  echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>';
565
- } else {
 
 
 
 
566
  // start the party!
 
567
  ?>
568
-
569
- <ul class="cms-tpv-subsubsub">
570
- <li><a class="cms_tvp_view_all <?php echo ($cms_tpv_view=="all") ? "current" : "" ?>" href="#"><?php _e("All", 'cms-tree-page-view') ?></a> |</li>
571
- <li><a class="cms_tvp_view_public <?php echo ($cms_tpv_view=="public") ? "current" : "" ?>" href="#"><?php _e("Public", 'cms-tree-page-view') ?></a> |</li>
572
- <li><a class="cms_tvp_view_trash <?php echo ($cms_tpv_view=="trash") ? "current" : "" ?>" href="#"><?php _e("Trash", 'cms-tree-page-view') ?></a></li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
573
 
574
  <?php
575
  if (cms_tpv_is_post_type_hierarchical($post_type_object)) {
@@ -589,6 +692,7 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
589
  <span class="cms_tree_view_search_form_no_hits"><?php _e("Nothing found.", 'cms-tree-page-view') ?></span>
590
  </form>
591
  </li>
 
592
  </ul>
593
 
594
  <div class="cms_tpv_working">
@@ -710,6 +814,12 @@ function cms_tpv_pages_page() {
710
 
711
  $post_type = cms_tpv_get_selected_post_type();
712
  $post_type_object = get_post_type_object($post_type);
 
 
 
 
 
 
713
 
714
  ?>
715
  <div class="wrap">
@@ -717,6 +827,15 @@ function cms_tpv_pages_page() {
717
  <h2><?php
718
  $page_title = _x(sprintf('%1$s Tree View', $post_type_object->labels->name), "headline of page with tree", "cms-tree-page-view");
719
  echo $page_title;
 
 
 
 
 
 
 
 
 
720
  ?></h2>
721
 
722
  <?php
244
 
245
  if (cms_tpv_is_one_of_our_pages()) {
246
 
247
+ // renamed from cookie to fix problems with mod_security
248
+ wp_enqueue_script( "jquery-cookie", CMS_TPV_URL . "scripts/jquery.biscuit.js", array("jquery"));
249
+ wp_enqueue_script( "jquery-ui-sortable");
250
  wp_enqueue_script( "jquery-jstree", CMS_TPV_URL . "scripts/jquery.jstree.js", false, CMS_TPV_VERSION);
251
  wp_enqueue_script( "jquery-alerts", CMS_TPV_URL . "scripts/jquery.alerts.js", false, CMS_TPV_VERSION);
252
  // wp_enqueue_script( "hoverIntent");
483
  return $is_hierarchical;
484
  }
485
 
486
+
487
+ function cms_tpv_get_wpml_post_counts($post_type) {
488
+
489
+ global $wpdb;
490
+
491
+ $arr_statuses = array("publish", "draft", "trash");
492
+ $arr_counts = array();
493
+
494
+ foreach ($arr_statuses as $post_status) {
495
+
496
+ $extra_cond = "";
497
+ if ($post_status){
498
+ $extra_cond .= " AND post_status = '" . $post_status . "'";
499
+ }
500
+ if ($post_status != 'trash'){
501
+ $extra_cond .= " AND post_status <> 'trash'";
502
+ }
503
+ $extra_cond .= " AND post_status <> 'auto-draft'";
504
+ $sql = "
505
+ SELECT language_code, COUNT(p.ID) AS c FROM {$wpdb->prefix}icl_translations t
506
+ JOIN {$wpdb->posts} p ON t.element_id=p.ID
507
+ JOIN {$wpdb->prefix}icl_languages l ON t.language_code=l.code AND l.active = 1
508
+ WHERE p.post_type='{$post_type}' AND t.element_type='post_{$post_type}' {$extra_cond}
509
+ GROUP BY language_code
510
+ ";
511
+ $res = $wpdb->get_results($sql);
512
+
513
+ $langs['all'] = 0;
514
+ foreach($res as $r) {
515
+ $langs[$r->language_code] = $r->c;
516
+ $langs['all'] += $r->c;
517
+ }
518
+
519
+ $arr_counts[$post_status] = $langs;
520
+
521
+ }
522
+
523
+ return $arr_counts;
524
+
525
+ }
526
+
527
+
528
  /**
529
  * Print tree stuff that is common for both dashboard and page
530
  */
531
  function cms_tpv_print_common_tree_stuff($post_type = "") {
532
 
533
+ global $sitepress, $cms_tpv_view, $wpdb;
534
 
535
  if (!$post_type) {
536
  $post_type = cms_tpv_get_selected_post_type();
554
 
555
  }
556
 
557
+ $status_data_attributes = array("all" => "", "publish" => "", "trash" => "");
558
+
559
+ // Calculate post counts
560
+ if ($wpml_current_lang) {
561
+
562
+ // Count code for WPML, mostly taken/inspired from WPML Multilingual CMS, sitepress.class.php
563
+ $langs = array();
564
+
565
+ $wpml_post_counts = cms_tpv_get_wpml_post_counts($post_type);
566
+
567
+ $post_count_all = @$wpml_post_counts["publish"][$wpml_current_lang] + @$wpml_post_counts["draft"][$wpml_current_lang];
568
+ $post_count_publish = @$wpml_post_counts["publish"][$wpml_current_lang];
569
+ $post_count_trash = @$wpml_post_counts["trash"][$wpml_current_lang];
570
+
571
+ foreach ($wpml_post_counts["publish"] as $one_wpml_lang => $one_wpml_lang_count) {
572
+ if ("all" === $one_wpml_lang) continue;
573
+ $lang_post_count_all = $wpml_post_counts["publish"][$one_wpml_lang] + $wpml_post_counts["draft"][$one_wpml_lang];
574
+ $lang_post_count_publish = $wpml_post_counts["publish"][$one_wpml_lang];
575
+ $lang_post_count_trash = $wpml_post_counts["trash"][$one_wpml_lang];
576
+ $status_data_attributes["all"] .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_all}' ";
577
+ $status_data_attributes["publish"] .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_publish}' ";
578
+ $status_data_attributes["trash"] .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_trash}' ";
579
+ }
580
+
581
+ } else {
582
+ $post_count = wp_count_posts($post_type);
583
+ $post_count_all = $post_count->publish + $post_count->future + $post_count->draft + $post_count->pending + $post_count->private;
584
+ $post_count_publish = $post_count->publish;
585
+ $post_count_trash = $post_count->trash;
586
+ }
587
+
588
  // output js for the root/top level
589
  // function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) {
590
  // @todo: make into function since used at other places
626
  $wpml_active_lang = $one_lang;
627
  $selected = "current";
628
  }
629
+
630
+ $lang_count = @$wpml_post_counts["publish"][$one_lang["language_code"]] + @$wpml_post_counts["draft"][$one_lang["language_code"]];
631
+
632
+ $lang_out .= "
633
+ <li>
634
+ <a class='cms_tvp_switch_lang $selected cms_tpv_switch_language_code_{$one_lang["language_code"]}' href='#'>
635
+ $one_lang_details[display_name]
636
+ <span class='count'>(" . $lang_count . ")</span>
637
+ </a> | </li>";
638
  }
639
  $lang_out = preg_replace('/ \| <\/li>$/', "</li>", $lang_out);
640
  $lang_out .= "</ul>";
644
  }
645
 
646
  if (empty($pages)) {
647
+
648
  echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>';
649
+
650
+ }
651
+
652
+ if (true) {
653
+
654
  // start the party!
655
+
656
  ?>
657
+ <ul class="cms-tpv-subsubsub cms-tpv-subsubsub-select-view">
658
+ <li class="cms_tvp_view_is_status_view">
659
+ <a class="cms_tvp_view_all <?php echo ($cms_tpv_view=="all") ? "current" : "" ?>" href="#" <?php echo $status_data_attributes["all"] ?>>
660
+ <?php _e("All", 'cms-tree-page-view') ?>
661
+ <span class="count">(<?php echo $post_count_all ?>)</span>
662
+ </a> |
663
+ </li>
664
+ <li class="cms_tvp_view_is_status_view">
665
+ <a class="cms_tvp_view_public <?php echo ($cms_tpv_view=="public") ? "current" : "" ?>" href="#" <?php echo $status_data_attributes["publish"] ?>>
666
+ <?php _e("Public", 'cms-tree-page-view') ?>
667
+ <span class="count">(<?php echo $post_count_publish ?>)</span>
668
+ </a> |
669
+ </li>
670
+ <li class="cms_tvp_view_is_status_view">
671
+ <a class="cms_tvp_view_trash <?php echo ($cms_tpv_view=="trash") ? "current" : "" ?>" href="#" <?php echo $status_data_attributes["trash"] ?>>
672
+ <?php _e("Trash", 'cms-tree-page-view') ?>
673
+ <span class="count">(<?php echo $post_count_trash ?>)</span>
674
+ </a>
675
+ </li>
676
 
677
  <?php
678
  if (cms_tpv_is_post_type_hierarchical($post_type_object)) {
692
  <span class="cms_tree_view_search_form_no_hits"><?php _e("Nothing found.", 'cms-tree-page-view') ?></span>
693
  </form>
694
  </li>
695
+
696
  </ul>
697
 
698
  <div class="cms_tpv_working">
814
 
815
  $post_type = cms_tpv_get_selected_post_type();
816
  $post_type_object = get_post_type_object($post_type);
817
+
818
+ if ( 'post' != $post_type ) {
819
+ $post_new_file = "post-new.php?post_type=$post_type";
820
+ } else {
821
+ $post_new_file = 'post-new.php';
822
+ }
823
 
824
  ?>
825
  <div class="wrap">
827
  <h2><?php
828
  $page_title = _x(sprintf('%1$s Tree View', $post_type_object->labels->name), "headline of page with tree", "cms-tree-page-view");
829
  echo $page_title;
830
+
831
+ // Add "add new" link the same way as the regular post page has
832
+ if ( current_user_can( $post_type_object->cap->create_posts ) ) {
833
+ echo ' <a href="' . esc_url( $post_new_file ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
834
+ }
835
+
836
+
837
+
838
+
839
  ?></h2>
840
 
841
  <?php
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. Use the tree view to edit, view, add pages and search pages (very useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
- Version: 1.0
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
@@ -27,7 +27,7 @@ License: GPL2
27
 
28
  #require("functions.php");
29
 
30
- define( "CMS_TPV_VERSION", "1.0");
31
  define( "CMS_TPV_NAME", "CMS Tree Page View");
32
 
33
  require(dirname(__FILE__)."/functions.php");
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. Use the tree view to edit, view, add pages and search pages (very useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
+ Version: 1.1
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
27
 
28
  #require("functions.php");
29
 
30
+ define( "CMS_TPV_VERSION", "1.1");
31
  define( "CMS_TPV_NAME", "CMS Tree Page View");
32
 
33
  require(dirname(__FILE__)."/functions.php");
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://eskapism.se/sida/donate/
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
5
  Requires at least: 3.0
6
  Tested up to: 3.5
7
- Stable tag: 1.0
8
 
9
  Adds a tree of all your pages or custom posts. Use drag & drop to reorder your pages, and edit, view, add, and search your pages.
10
 
@@ -23,11 +23,14 @@ Page management in WordPress won't get any easier than this!
23
  * View your pages & posts in a tree-view, like you view files in Windows Explorer or the Finder in OS X
24
  * Drag and drop to rearrange/order your pages
25
  * Add pages after or inside a page
 
26
  * Edit pages
27
  * View pages
28
  * Search pages
29
  * Available for both regular pages and custom posts
 
30
  * View your site hierarchy directly from the WordPress dashboard
 
31
  * Support for translation plugin [WPML](http://wordpress.org/extend/plugins/sitepress-multilingual-cms/), so you can manage all the languages of your site
32
 
33
  #### Screencast
@@ -88,6 +91,12 @@ Now the tree with the pages will be visible both on the dashboard and in the men
88
 
89
  == Changelog ==
90
 
 
 
 
 
 
 
91
  = 1.0 =
92
  - New: create multiple pages at once! Add multiple pages faster than ever before! You can ever select if the new pages should be drafts or published. And ever drag and drop the pages to get the correct order even before adding them. I know - it's awesome!
93
  - Fixed: adds new pages with the correct and selected WPML-language
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
5
  Requires at least: 3.0
6
  Tested up to: 3.5
7
+ Stable tag: 1.1
8
 
9
  Adds a tree of all your pages or custom posts. Use drag & drop to reorder your pages, and edit, view, add, and search your pages.
10
 
23
  * View your pages & posts in a tree-view, like you view files in Windows Explorer or the Finder in OS X
24
  * Drag and drop to rearrange/order your pages
25
  * Add pages after or inside a page
26
+ * Add multiple pages at once - perfect for setting up a new site structure
27
  * Edit pages
28
  * View pages
29
  * Search pages
30
  * Available for both regular pages and custom posts
31
+ * Works with both hierarchical and non-hierarchical post types
32
  * View your site hierarchy directly from the WordPress dashboard
33
+ * Drag and drop between trees with different post types to change to post type of the draged item, i.e. change a regular page to became any custom post type
34
  * Support for translation plugin [WPML](http://wordpress.org/extend/plugins/sitepress-multilingual-cms/), so you can manage all the languages of your site
35
 
36
  #### Screencast
91
 
92
  == Changelog ==
93
 
94
+ = 1.1 =
95
+ - Added "Add new"-link next to headline, to better match the regular post overview page + it makes it possible to add new pages/posts when there are no pages/posts added (previously there needed to be at least one post added to be able to add new posts)
96
+ - Added post count in parenthesis after each post status. Also makes the page match the regular post overview page a it more. Works for both built in post types and custom post types + if WPML is installed it will show post count for each language too.
97
+ - Fixed a bug with sortables (well, I kinda forgot to load that script at all!) that made the plugin only work on the dashboard.
98
+ - Fixed some IE-bugs
99
+
100
  = 1.0 =
101
  - New: create multiple pages at once! Add multiple pages faster than ever before! You can ever select if the new pages should be drafts or published. And ever drag and drop the pages to get the correct order even before adding them. I know - it's awesome!
102
  - Fixed: adds new pages with the correct and selected WPML-language
scripts/cms_tree_page_view.js CHANGED
@@ -51,7 +51,7 @@ var cms_tree_page_view = (function ($) {
51
  // When something has been written in one of the page titles: show another row
52
  // Also: if more than one row are empty at the end, remove all but the last
53
  $(document).on("keyup", "ul.cms_tpv_action_add_doit_pages li:last-child input", function(e) {
54
- my.log(123);
55
  var $t = $(this);
56
  var $li = $t.closest("li");
57
 
@@ -327,16 +327,14 @@ function cms_tpv_tree_loaded(event, data) {
327
 
328
  if ( ! actions_div_doit.is(":visible") ) {
329
 
330
- var timeoutID = setTimeout(function(e) {
331
  cms_tpv_mouseover_li(e);
332
- }, 500, e);
333
-
334
- console.log("timer added");
335
 
336
  $container.data("cmstpv_global_link_timer", timeoutID);
337
 
338
  } else {
339
- console.log("timer not added because doit visible");
340
  }
341
 
342
  });
@@ -387,8 +385,6 @@ function cms_tpv_get_wrapper(elm) {
387
  }
388
 
389
 
390
-
391
-
392
  // check if tree is beging dragged
393
  function cms_tpv_is_dragging() {
394
  var eDrag = jQuery("#vakata-dragged");
@@ -546,7 +542,7 @@ jQuery(document).on("mouseenter", "div.cms_tpv_page_actions", function(e) {
546
  var $wrapper = $this.closest("div.cms_tpv_wrapper");
547
  var $container = $wrapper.find("div.cms_tpv_container");
548
  var timer = $container.data("cmstpv_global_link_timer");
549
- // console.log("back to action div");
550
  clearTimeout(timer);
551
 
552
  });
@@ -736,18 +732,38 @@ jQuery(document).on("click", "a.cms_tvp_view_trash", function() {
736
  });
737
 
738
 
739
- // change lang
740
  jQuery(document).on("click", "a.cms_tvp_switch_lang", function(e) {
741
 
742
  $wrapper = cms_tpv_get_wrapper(this);
 
 
743
  $wrapper.find("ul.cms_tvp_switch_langs a").removeClass("current");
744
  jQuery(this).addClass("current");
745
 
 
746
  var re = /cms_tpv_switch_language_code_([\w-]+)/;
747
  var matches = re.exec( jQuery(this).attr("class") );
748
  var lang_code = matches[1];
 
 
749
  $wrapper.find("[name=cms_tpv_meta_wpml_language]").val(lang_code);
750
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
751
  var current_view = cms_tpv_get_current_view(this);
752
  cms_tvp_set_view(current_view, this);
753
 
@@ -774,19 +790,25 @@ function cms_tpv_get_current_view(elm) {
774
 
775
  }
776
 
 
 
 
 
 
777
  function cms_tvp_set_view(view, elm) {
778
 
779
  var $wrapper = jQuery(elm).closest(".cms_tpv_wrapper");
780
 
781
  var div_actions_for_post_type = cms_tpv_get_page_actions_div(elm);
 
782
  $wrapper.append(div_actions_for_post_type);
783
  $wrapper.find(".cms_tvp_view_all, .cms_tvp_view_public, .cms_tvp_view_trash").removeClass("current");
784
  $wrapper.find(".cms_tpv_container").jstree("destroy").html("");
785
-
786
  $wrapper.find("div.cms_tpv_page_actions").removeClass("cms_tpv_page_actions_visible");
787
 
788
  cms_tpv_bind_clean_node();
789
 
 
790
  if (view == "all") {
791
  $wrapper.find(".cms_tvp_view_all").addClass("current");
792
  } else if (view == "public") {
@@ -797,6 +819,7 @@ function cms_tvp_set_view(view, elm) {
797
 
798
  }
799
 
 
800
  var treeOptionsTmp = jQuery.extend(true, {}, treeOptions);
801
  treeOptionsTmp.json_data.ajax.url = ajaxurl + CMS_TPV_AJAXURL + view + "&post_type=" + cms_tpv_get_post_type(elm) + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
802
 
51
  // When something has been written in one of the page titles: show another row
52
  // Also: if more than one row are empty at the end, remove all but the last
53
  $(document).on("keyup", "ul.cms_tpv_action_add_doit_pages li:last-child input", function(e) {
54
+
55
  var $t = $(this);
56
  var $li = $t.closest("li");
57
 
327
 
328
  if ( ! actions_div_doit.is(":visible") ) {
329
 
330
+ var timeoutID = setTimeout((function() {
331
  cms_tpv_mouseover_li(e);
332
+ }), 500, e);
 
 
333
 
334
  $container.data("cmstpv_global_link_timer", timeoutID);
335
 
336
  } else {
337
+ //console.log("timer not added because doit visible");
338
  }
339
 
340
  });
385
  }
386
 
387
 
 
 
388
  // check if tree is beging dragged
389
  function cms_tpv_is_dragging() {
390
  var eDrag = jQuery("#vakata-dragged");
542
  var $wrapper = $this.closest("div.cms_tpv_wrapper");
543
  var $container = $wrapper.find("div.cms_tpv_container");
544
  var timer = $container.data("cmstpv_global_link_timer");
545
+
546
  clearTimeout(timer);
547
 
548
  });
732
  });
733
 
734
 
735
+ // click on link to change WPML-language
736
  jQuery(document).on("click", "a.cms_tvp_switch_lang", function(e) {
737
 
738
  $wrapper = cms_tpv_get_wrapper(this);
739
+
740
+ // Mark clicked link as selected
741
  $wrapper.find("ul.cms_tvp_switch_langs a").removeClass("current");
742
  jQuery(this).addClass("current");
743
 
744
+ // Determine selected language, based on classes on the link
745
  var re = /cms_tpv_switch_language_code_([\w-]+)/;
746
  var matches = re.exec( jQuery(this).attr("class") );
747
  var lang_code = matches[1];
748
+
749
+ // Add seleted lang to hidden input
750
  $wrapper.find("[name=cms_tpv_meta_wpml_language]").val(lang_code);
751
 
752
+ // Update post count
753
+ // Post counts are stored on the links for all | public | trash
754
+ var $ul_select_view = $wrapper.find(".cms-tpv-subsubsub-select-view");
755
+ $ul_select_view.find("li.cms_tvp_view_is_status_view a").each(function(i, a_tag) {
756
+
757
+ // check if this link has a data attr with count for the selected lang
758
+ var $a = jQuery(a_tag);
759
+ var link_count = $a.data("post-count-" + lang_code);
760
+ if ("undefined" === typeof(link_count)) return;
761
+
762
+ $a.find(".count").text("(" + link_count + ")");
763
+
764
+ });
765
+
766
+ // Set the view = reload the tree
767
  var current_view = cms_tpv_get_current_view(this);
768
  cms_tvp_set_view(current_view, this);
769
 
790
 
791
  }
792
 
793
+ /**
794
+ * Sets the view; load pages for the current lang + post type + status
795
+ * @param view all | public | trash
796
+ * @elm element
797
+ */
798
  function cms_tvp_set_view(view, elm) {
799
 
800
  var $wrapper = jQuery(elm).closest(".cms_tpv_wrapper");
801
 
802
  var div_actions_for_post_type = cms_tpv_get_page_actions_div(elm);
803
+
804
  $wrapper.append(div_actions_for_post_type);
805
  $wrapper.find(".cms_tvp_view_all, .cms_tvp_view_public, .cms_tvp_view_trash").removeClass("current");
806
  $wrapper.find(".cms_tpv_container").jstree("destroy").html("");
 
807
  $wrapper.find("div.cms_tpv_page_actions").removeClass("cms_tpv_page_actions_visible");
808
 
809
  cms_tpv_bind_clean_node();
810
 
811
+ // Mark selected link
812
  if (view == "all") {
813
  $wrapper.find(".cms_tvp_view_all").addClass("current");
814
  } else if (view == "public") {
819
 
820
  }
821
 
822
+ // Reload tree
823
  var treeOptionsTmp = jQuery.extend(true, {}, treeOptions);
824
  treeOptionsTmp.json_data.ajax.url = ajaxurl + CMS_TPV_AJAXURL + view + "&post_type=" + cms_tpv_get_post_type(elm) + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
825
 
styles/styles.css CHANGED
@@ -40,12 +40,20 @@
40
  display: inline;
41
  }
42
 
 
 
 
 
43
  .cms-tpv-subsubsub li a.current {
44
  font-weight: bold;
45
- text-decoration: none;
46
  color: black;
47
  }
48
 
 
 
 
 
 
49
  .pages_page_cms-tpv-pages-page .cms-tpv-subsubsub li {
50
  zoom: 1; /* weird ie-problems otherwise, like li-items that disappear on search. */
51
  }
40
  display: inline;
41
  }
42
 
43
+ .cms-tpv-subsubsub li a {
44
+ text-decoration: none;
45
+ }
46
+
47
  .cms-tpv-subsubsub li a.current {
48
  font-weight: bold;
 
49
  color: black;
50
  }
51
 
52
+ .cms-tpv-subsubsub li a.current .count {
53
+ font-weight: normal;
54
+ color: #999x;
55
+ }
56
+
57
  .pages_page_cms-tpv-pages-page .cms-tpv-subsubsub li {
58
  zoom: 1; /* weird ie-problems otherwise, like li-items that disappear on search. */
59
  }