From 1f4ca1b8f4dd96550a984250579c5400322f6252 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 13 Jul 2018 11:19:26 -0400 Subject: [PATCH] Some additional adjustments to the live search, including the addition of a "help" option, which you can access just by typing "help" into the search box. Bumped version to 3.0.108 --- wire/core/Module.php | 23 +- wire/core/Modules.php | 48 +++- wire/core/ProcessWire.php | 2 +- .../AdminThemeDefault/scripts/main.js | 2 + .../AdminThemeDefault/scripts/main.min.js | 2 +- .../AdminTheme/AdminThemeReno/scripts/main.js | 2 + .../AdminThemeReno/scripts/main.min.js | 2 +- .../AdminThemeUikit/scripts/main.js | 3 + .../AdminThemeUikit/scripts/main.min.js | 2 +- .../ProcessCommentsManager.module | 15 ++ .../Process/ProcessField/ProcessField.module | 24 +- .../ProcessPageSearchLive.php | 207 ++++++++++++++++-- .../ProcessPageType/ProcessPageType.module | 15 +- .../ProcessTemplate/ProcessTemplate.module | 40 +++- 14 files changed, 335 insertions(+), 52 deletions(-) diff --git a/wire/core/Module.php b/wire/core/Module.php index d1e064d7..b9038fa3 100644 --- a/wire/core/Module.php +++ b/wire/core/Module.php @@ -534,6 +534,7 @@ interface SearchableModule { * 'title' => 'Title of these items', * 'total' => 999, // total number of items found, or omit if pagination not supported or active * 'url' => '', // optional URL to view all items, or omit for a PW-generated one + * 'properties' => array(), // optional list of supported search properties, only looked for if $options['info'] === true; * 'items' => array( * [0] => array( * 'id' => 123, // Unique ID of item (optional) @@ -549,25 +550,35 @@ interface SearchableModule { * [1] => array( * ... * ), - * ) + * ), * ); - * - * Please note: When ProcessWire calls this method, if the module is not already loaded (autoload), + * + * PLEASE NOTE: + * When ProcessWire calls this method, if the module is not already loaded (autoload), * it instantiates the module but DOES NOT call the init() or ready() methods. That’s because the * search method is generally self contained. If you need either of those methods to be called, - * and your module is not autoload, you should call the method(s) from your search() method. - * + * and your module is not autoload, you should call the method(s) from your search() method. + * + * About the optional “properties” index: + * If ProcessWire calls your search() method with $options['info'] == true; then it is likely wanting to see + * what properties are available for search. For instance, properties for a Module search might be: + * [ 'name', 'title', 'summary' ]. Implementation of the properties index is optional, and for PW’s informational + * purposes only. + * * @param string $text Text to search for * @param array $options Options array provided to search() calls: - * - `edit` (bool): True if any 'url' returned should be to edit items rather than view them + * - `edit` (bool): True if any 'url' returned should be to edit rather than view items, where access allows. (default=true) * - `multilang` (bool): If true, search all languages rather than just current (default=true). * - `start` (int): Start index (0-based), if pagination active (default=0). * - `limit` (int): Limit to this many items, or 0 for no limit. (default=0). * - `type` (string): If search should only be of a specific type, i.e. "pages", "modules", etc. then it is * specified here. This corresponds with the getModuleInfo()['searchable'] name or item 'group' property. + * Note that ProcessWire won’t call your search() method if the type cannot match this search. * - `operator` (string): Selector operator type requested, if more than one is supported (default is %=). * - `property` (string): If search should limit to a particular property/fieldj, it is named here. * - `verbose` (bool): True if output can optionally be more verbose, false if not. (default=false) + * - `debug` (bool): True if DEBUG option was specified in query. (default=false) + * - `help` (bool): True if we are just querying for help/info and are not using the search results. (default=false) * @return array * */ diff --git a/wire/core/Modules.php b/wire/core/Modules.php index d1065b2a..14ea8432 100644 --- a/wire/core/Modules.php +++ b/wire/core/Modules.php @@ -1538,7 +1538,7 @@ class Modules extends WireArray { * ~~~~~ * * @param string $prefix Specify prefix, i.e. "Process", "Fieldtype", "Inputfield", etc. - * @param bool|int $instantiate Specify one of the following: + * @param bool|int $load Specify one of the following: * - Boolean true to return array of instantiated modules. * - Boolean false to return array of module names (default). * - Integer 1 to return array of module info for each matching module. @@ -1546,16 +1546,16 @@ class Modules extends WireArray { * @return array Returns array of module class names or Module objects. In either case, array indexes are class names. * */ - public function findByPrefix($prefix, $instantiate = false) { + public function findByPrefix($prefix, $load = false) { $results = array(); foreach($this as $key => $value) { $className = wireClassName($value->className(), false); if(strpos($className, $prefix) !== 0) continue; - if($instantiate === 1) { + if($load === 1) { $results[$className] = $this->getModuleInfo($className); - } else if($instantiate === 2) { + } else if($load === 2) { $results[$className] = $this->getModuleInfoVerbose($className); - } else if($instantiate === true) { + } else if($load === true) { $results[$className] = $this->getModule($className); } else { $results[$className] = $className; @@ -1571,7 +1571,7 @@ class Modules extends WireArray { * - Selector string to match module info. * - Array of [ 'property' => 'value' ] to match in module info (this is not a selector array). * - Name of property that will match module if not empty in module info. - * @param bool|int $instantiate Specify one of the following: + * @param bool|int $load Specify one of the following: * - Boolean true to return array of instantiated modules. * - Boolean false to return array of module names (default). * - Integer 1 to return array of module info for each matching module. @@ -1579,13 +1579,13 @@ class Modules extends WireArray { * @return array Array of modules, module names or module info arrays, indexed by module name. * */ - public function findByInfo($selector, $instantiate = false) { + public function findByInfo($selector, $load = false) { $selectors = null; $infos = null; $keys = null; $results = array(); - $verbose = $instantiate === 2; + $verbose = $load === 2; $properties = array(); $has = ''; @@ -1612,7 +1612,12 @@ class Modules extends WireArray { break; } - foreach($this->getModuleInfo('*', array('verbose' => $verbose)) as $info) { + $moduleInfoOptions = array( + 'verbose' => $verbose, + 'minify' => false + ); + + foreach($this->getModuleInfo('*', $moduleInfoOptions) as $info) { $isMatch = false; if($has) { @@ -1650,9 +1655,9 @@ class Modules extends WireArray { if($isMatch) { $moduleName = $info['name']; - if(is_int($instantiate)) { + if(is_int($load)) { $results[$moduleName] = $info; - } else if($instantiate === true) { + } else if($load === true) { $results[$moduleName] = $this->getModule($moduleName); } else { $results[$moduleName] = $moduleName; @@ -3165,6 +3170,27 @@ class Modules extends WireArray { public function getModuleConfigData($className) { return $this->getConfig($className); } + + /** + * Return the URL where the module can be edited, configured or uninstalled + * + * If module is not installed, it just returns the URL to ProcessModule. + * + * #pw-group-configuration + * + * @param string|Module $className + * @param bool $collapseInfo + * @return string + * + */ + public function getModuleEditUrl($className, $collapseInfo = true) { + if(!is_string($className)) $className = $this->getModuleClass($className); + $url = $this->wire('config')->urls->admin . 'module/'; + if(empty($className) || !$this->isInstalled($className)) return $url; + $url .= "edit/?name=$className"; + if($collapseInfo) $url .= "&collapse_info=1"; + return $url; + } /** * Given a module name, return an associative array of configuration data for it diff --git a/wire/core/ProcessWire.php b/wire/core/ProcessWire.php index e1d93c2b..9e2236da 100644 --- a/wire/core/ProcessWire.php +++ b/wire/core/ProcessWire.php @@ -45,7 +45,7 @@ class ProcessWire extends Wire { * Reversion revision number * */ - const versionRevision = 107; + const versionRevision = 108; /** * Version suffix string (when applicable) diff --git a/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.js b/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.js index 9f24bbc0..5073becb 100644 --- a/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.js +++ b/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.js @@ -108,6 +108,7 @@ var ProcessWireAdminTheme = { .attr('title', item.tip) .append($label) .append($("").text(item.template)); + if(item.edit_url == '#' || !item.edit_url.length) $a.removeAttr('href'); return $("
  • ").append($a).appendTo(ul); } }); @@ -154,6 +155,7 @@ var ProcessWireAdminTheme = { // follow the link if the Enter/Return key is tapped if(typeof event.key != 'undefined') { event.preventDefault(); + if(ui.item.edit_url == '#' || !ui.item.edit_url.length) return false; window.location = ui.item.edit_url; } } diff --git a/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.min.js b/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.min.js index 4ce0f1ca..b3911007 100644 --- a/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.min.js +++ b/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.min.js @@ -1 +1 @@ -var ProcessWireAdminTheme={init:function(){var b=$("#head_button > button.pw-dropdown-toggle").hide();this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupMobile();var a=$("body");if(a.hasClass("hasWireTabs")&&$("ul.WireTabs").length==0){a.removeClass("hasWireTabs")}$("#content").removeClass("pw-fouc-fix");a.removeClass("pw-init").addClass("pw-ready");if(b.length>0){b.show()}},setupCloneButton:function(){if($("body").is(".modal")){return}var b=$("button.pw-head-button, button.head_button_clone");if(b.length==0){return}var a=$("#head_button");if(a.length==0){a=$("
    ").prependTo("#breadcrumbs .pw-container")}b.each(function(){var e=$(this);var d=e.parent("a");var c;if(d.length>0){c=e.parent("a").clone(true);a.prepend(c)}else{if(e.hasClass("pw-head-button")||e.hasClass("head_button_clone")){c=e.clone(true);c.attr("data-from_id",e.attr("id")).attr("id",e.attr("id")+"_copy");c.click(function(){$("#"+$(this).attr("data-from_id")).click();return false});a.prepend(c)}}});a.show()},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(e,c){var f=this;var d="";e.attr("id","ProcessPageSearchAutocomplete");$.each(c,function(g,h){if(h.type!=d){$("
  • "+h.type+"
  • ").addClass("ui-widget-header").appendTo(e);d=h.type}f._renderItemData(e,h)})},_renderItem:function(e,f){if(f.label==f.template){f.template=""}var c=$("").text(f.label).css("margin-right","3px");if(f.unpublished){c.css("text-decoration","line-through")}if(f.hidden){c.addClass("ui-priority-secondary")}if(typeof f.icon!="undefined"&&f.icon.length){var d=$("").addClass("fa fa-fw fa-"+f.icon).css("margin-right","2px");c.prepend(d)}var g=$("").attr("href",f.edit_url).attr("title",f.tip).append(c).append($("").text(f.template));return $("
  • ").append(g).appendTo(e)}});var b=$("#ProcessPageSearchQuery");var a=$("#ProcessPageSearchStatus");b.adminsearchautocomplete({minLength:2,position:{my:"right top",at:"right bottom"},search:function(c,d){a.html("")},open:function(c,d){$("#topnav").hide()},close:function(c,d){$("#topnav").show()},source:function(e,c){var d=b.parents("form").attr("action")+"?q="+e.term;$.getJSON(d,function(g){var f=g.matches.length;if(f50){if(!g.hasClass("collapse-topnav")){g.addClass("collapse-topnav");a=g.width()}}else{if(a>0){var f=g.width();if(g.hasClass("collapse-topnav")&&f>a){g.removeClass("collapse-topnav");a=0}}}h.children(".collapse-topnav-menu").children("a").click(function(){if($(this).is(".hover")){$(this).mouseleave()}else{$(this).mouseenter()}return false});var d=$(".WireTabs");if(d.length<1){return}d.each(function(){var j=$(this);var i=j.height();if(i>65){if(!g.hasClass("collapse-wiretabs")){g.addClass("collapse-wiretabs");c=g.width()}}else{if(c>0){var k=g.width();if(g.hasClass("collapse-wiretabs")&&k>c){g.removeClass("collapse-wiretabs");c=0}}}})};b();$(window).resize(b)}};$(document).ready(function(){ProcessWireAdminTheme.init();$("a.notice-remove","#notices").click(function(){$("#notices").slideUp("fast",function(){$(this).remove()});return false})}); \ No newline at end of file +var ProcessWireAdminTheme={init:function(){var b=$("#head_button > button.pw-dropdown-toggle").hide();this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupMobile();var a=$("body");if(a.hasClass("hasWireTabs")&&$("ul.WireTabs").length==0){a.removeClass("hasWireTabs")}$("#content").removeClass("pw-fouc-fix");a.removeClass("pw-init").addClass("pw-ready");if(b.length>0){b.show()}},setupCloneButton:function(){if($("body").is(".modal")){return}var b=$("button.pw-head-button, button.head_button_clone");if(b.length==0){return}var a=$("#head_button");if(a.length==0){a=$("
    ").prependTo("#breadcrumbs .pw-container")}b.each(function(){var e=$(this);var d=e.parent("a");var c;if(d.length>0){c=e.parent("a").clone(true);a.prepend(c)}else{if(e.hasClass("pw-head-button")||e.hasClass("head_button_clone")){c=e.clone(true);c.attr("data-from_id",e.attr("id")).attr("id",e.attr("id")+"_copy");c.click(function(){$("#"+$(this).attr("data-from_id")).click();return false});a.prepend(c)}}});a.show()},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(e,c){var f=this;var d="";e.attr("id","ProcessPageSearchAutocomplete");$.each(c,function(g,h){if(h.type!=d){$("
  • "+h.type+"
  • ").addClass("ui-widget-header").appendTo(e);d=h.type}f._renderItemData(e,h)})},_renderItem:function(e,f){if(f.label==f.template){f.template=""}var c=$("").text(f.label).css("margin-right","3px");if(f.unpublished){c.css("text-decoration","line-through")}if(f.hidden){c.addClass("ui-priority-secondary")}if(typeof f.icon!="undefined"&&f.icon.length){var d=$("").addClass("fa fa-fw fa-"+f.icon).css("margin-right","2px");c.prepend(d)}var g=$("").attr("href",f.edit_url).attr("title",f.tip).append(c).append($("").text(f.template));if(f.edit_url=="#"||!f.edit_url.length){g.removeAttr("href")}return $("
  • ").append(g).appendTo(e)}});var b=$("#ProcessPageSearchQuery");var a=$("#ProcessPageSearchStatus");b.adminsearchautocomplete({minLength:2,position:{my:"right top",at:"right bottom"},search:function(c,d){a.html("")},open:function(c,d){$("#topnav").hide()},close:function(c,d){$("#topnav").show()},source:function(e,c){var d=b.parents("form").attr("action")+"?q="+e.term;$.getJSON(d,function(g){var f=g.matches.length;if(f50){if(!g.hasClass("collapse-topnav")){g.addClass("collapse-topnav");a=g.width()}}else{if(a>0){var f=g.width();if(g.hasClass("collapse-topnav")&&f>a){g.removeClass("collapse-topnav");a=0}}}h.children(".collapse-topnav-menu").children("a").click(function(){if($(this).is(".hover")){$(this).mouseleave()}else{$(this).mouseenter()}return false});var d=$(".WireTabs");if(d.length<1){return}d.each(function(){var j=$(this);var i=j.height();if(i>65){if(!g.hasClass("collapse-wiretabs")){g.addClass("collapse-wiretabs");c=g.width()}}else{if(c>0){var k=g.width();if(g.hasClass("collapse-wiretabs")&&k>c){g.removeClass("collapse-wiretabs");c=0}}}})};b();$(window).resize(b)}};$(document).ready(function(){ProcessWireAdminTheme.init();$("a.notice-remove","#notices").click(function(){$("#notices").slideUp("fast",function(){$(this).remove()});return false})}); \ No newline at end of file diff --git a/wire/modules/AdminTheme/AdminThemeReno/scripts/main.js b/wire/modules/AdminTheme/AdminThemeReno/scripts/main.js index 151f918c..dfefd568 100644 --- a/wire/modules/AdminTheme/AdminThemeReno/scripts/main.js +++ b/wire/modules/AdminTheme/AdminThemeReno/scripts/main.js @@ -338,6 +338,7 @@ var ProcessWireAdminTheme = { .attr('title', item.tip) .append($label) .append($("").text(item.template)); + if(item.edit_url == '#' || !item.edit_url.length) $a.removeAttr('href'); return $("
  • ").append($a).appendTo(ul); } }); @@ -378,6 +379,7 @@ var ProcessWireAdminTheme = { // follow the link if the Enter/Return key is tapped if(typeof event.key != 'undefined') { event.preventDefault(); + if(ui.item.edit_url == '#' || !ui.item.edit_url.length) return false; window.location = ui.item.edit_url; } } diff --git a/wire/modules/AdminTheme/AdminThemeReno/scripts/main.min.js b/wire/modules/AdminTheme/AdminThemeReno/scripts/main.min.js index 892b813d..3f07def1 100644 --- a/wire/modules/AdminTheme/AdminThemeReno/scripts/main.min.js +++ b/wire/modules/AdminTheme/AdminThemeReno/scripts/main.min.js @@ -1 +1 @@ -var ProcessWireAdminTheme={init:function(){this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupDropdowns();this.setupSidebarNav();this.setupSideBarState();this.setupSideBarToggle();var b=$("body");var a=$("html");if(b.hasClass("hasWireTabs")&&$("ul.WireTabs").length==0){b.removeClass("hasWireTabs")}$("#content").removeClass("pw-fouc-fix");b.removeClass("pw-init").addClass("pw-ready");a.removeClass("pw-init").addClass("pw-ready");$("a.notice-remove","#notices").click(function(){$("#notices").slideUp("fast",function(){$(this).remove();return false})})},setupSidebarNav:function(){var a=window.location.toString();$(document).mouseup(function(g){var f=$("ul.quicklinks");if(!f.is(g.target)&&f.has(g.target).length===0){f.hide();$(".quicklink-open").removeClass("active");$("#main-nav .current").removeClass("no-arrow")}});$(document).keydown(function(i){var g=i.target.tagName.toLowerCase();var f=i.target.className.split(" ")[0];var h;if(g=="input"||g=="textarea"||f=="InputfieldCKEditorInline"){return}switch(i.which){case 37:h="open";break;case 39:h="closed";break;default:return}ProcessWireAdminTheme.setupSideBarState(true,h);i.preventDefault()});function e(){$("#main-nav > li > a.open:not(.hover-temp):not(.just-clicked)").each(function(){var g=$(this);var f=g.next("ul:visible");if(f.length>0){if(f.find(".quicklinks-open").length>0){f.find(".quicklink-close").click()}}})}var c=null,b=0;$("#main-nav a.parent").dblclick(function(f){f.preventDefault()}).click(function(){var f=$(this);f.addClass("just-clicked");b++;if(b===1){c=setTimeout(function(){e();f.toggleClass("open").next("ul").slideToggle(200,function(){f.removeClass("just-clicked")});b=0},200)}else{clearTimeout(c);b=0;window.location.href=f.attr("href");return true}return false});var d=null;$(".quicklink-open").click(function(j){e();var k=$(this);k.parent().addClass("quicklinks-open");k.toggleClass("active").parent().next("ul.quicklinks").toggle();k.parent().parent().siblings().find("ul.quicklinks").hide();k.parent().parent().siblings().find(".quicklink-open").removeClass("active").parent("a").removeClass("quicklinks-open");k.effect("pulsate",100);j.stopPropagation();$("#main-nav .current:not(.open)").addClass("no-arrow");var f=$(this).parent().next("ul.quicklinks");var i=f.attr("data-json");if(i.length>0&&!f.hasClass("json-loaded")){f.addClass("json-loaded");var h=f.find(".quicklinks-spinner");var g=h.attr("class");h.removeClass(g).addClass("fa fa-fw fa-spin fa-spinner");$.getJSON(i,function(l){if(l.add){var m=$("
  • "+l.add.label+"
  • ");f.append(m)}$.each(l.list,function(r){var p="";var o=this.url.indexOf("/")===0?this.url:l.url+this.url;var q=$("
  • "+p+this.label+"
  • ");if(typeof this.className!="undefined"&&this.className&&this.className.length){q.addClass(this.className)}f.append(q)});h.removeClass("fa-spin fa-spinner").addClass(g);if(l.icon.length>0){h.removeClass("fa-bolt").addClass("fa-"+l.icon)}})}return false}).mouseover(function(){var f=$(this);if(f.parent().hasClass("quicklinks-open")){return}f.addClass("hover-temp");clearTimeout(d);d=setTimeout(function(){if(f.parent().hasClass("quicklinks-open")){return}if(f.hasClass("hover-temp")){f.click()}},500)}).mouseout(function(){$(this).removeClass("hover-temp")});$(".quicklink-close").click(function(){$(this).parent().removeClass("quicklinks-open");$(this).closest("ul.quicklinks").hide().prev("a").removeClass("quicklinks-open");$(".quicklink-open").removeClass("active");$("#main-nav .current").removeClass("no-arrow");return false});$("#main-nav .parent").each(function(){var f=$(this).attr("href");if(a.match(f)){$(this).next("ul").show();$(this).addClass("open")}})},setupCloneButton:function(){if($("body").is(".modal")){return}var b=$("button.pw-head-button, button.head_button_clone");if(b.length==0||$.browser.msie){return}var a=$("
    ").prependTo("#headline").show();b.each(function(){var e=$(this);var d=e.parent("a");var c;if(d.length){c=e.parent("a").clone();a.append(c)}else{if(e.hasClass("head_button_clone")||e.hasClass("pw-head-button")){c=e.clone();c.attr("data-from_id",e.attr("id")).attr("id",e.attr("id")+"_copy");c.click(function(){$("#"+$(this).attr("data-from_id")).click();return false});a.prepend(c)}}})},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(f,d){var g=this;var e="";f.attr("id","ProcessPageSearchAutocomplete");$.each(d,function(h,i){if(i.type!=e){$("
  • "+i.type+"
  • ").addClass("ui-widget-header").appendTo(f);e=i.type}g._renderItemData(f,i)})},_renderItem:function(f,g){if(g.label==g.template){g.template=""}var d=$("").text(g.label).css("margin-right","3px");if(g.unpublished){d.css("text-decoration","line-through")}if(g.hidden){d.css("opacity",0.7)}if(g.icon.length){var e=$("").addClass("fa fa-fw fa-"+g.icon).css("margin-right","2px");d.prepend(e)}var h=$("").attr("href",g.edit_url).attr("title",g.tip).append(d).append($("").text(g.template));return $("
  • ").append(h).appendTo(f)}});var c=$("#ProcessPageSearchQuery");var a=$("#ProcessPageSearchStatus");c.adminsearchautocomplete({minLength:2,position:{my:"right top",at:"right bottom"},search:function(d,e){a.html("")},source:function(f,d){var e=c.parents("form").attr("action")+"?q="+f.term;$.getJSON(e,function(h){var g=h.matches.length;if(g a").on("click",function(a){$(this).next("ul").toggleClass("open");$(this).parent().siblings().find("ul.open").removeClass("open");return false});$("#masthead li.pw-dropdown > ul li a").on("click",function(a){a.stopPropagation()});$(document).on("click",function(){$("#masthead li.pw-dropdown ul").removeClass("open")})},setupSideBarToggle:function(){$(".main-nav-toggle").on("click",function(){ProcessWireAdminTheme.setupSideBarState(true);return false})},setupSideBarState:function(j,c){if($("body").hasClass("id-23")||$("body").hasClass("modal")){return false}var e="pw_sidebar_state";var c=c||localStorage.getItem(e);var i=$(".main-nav-toggle");var a=$("#sidebar");var h=$("#main");var d=$("#masthead");var g=$("#branding");var f=$("#NotificationBug");var b=i.add(a).add(h).add(d).add(g).add(f);if(c===null&&$(window).width()>=690){localStorage.setItem(e,"open")}if(!j&&$(window).width()<690){localStorage.setItem(e,"closed");c="closed"}if(j==true){if(c=="open"){localStorage.setItem(e,"closed");b.addClass("closed")}else{if(c=="closed"){localStorage.setItem(e,"open");b.removeClass("closed")}}a.removeClass("hide");g.removeClass("hide");h.removeClass("full");d.removeClass("full");i.removeClass("full")}else{if(c=="closed"){b.addClass("closed");a.addClass("hide");g.addClass("hide");h.addClass("full");d.addClass("full");i.addClass("full")}}},browserCheck:function(){if($.browser.msie&&$.browser.version<8){$("#content .pw-container").html("

    ProcessWire does not support IE7 and below at this time. Please try again with a newer browser.

    ").show()}}};$(document).ready(function(){ProcessWireAdminTheme.init()}); \ No newline at end of file +var ProcessWireAdminTheme={init:function(){this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupDropdowns();this.setupSidebarNav();this.setupSideBarState();this.setupSideBarToggle();var b=$("body");var a=$("html");if(b.hasClass("hasWireTabs")&&$("ul.WireTabs").length==0){b.removeClass("hasWireTabs")}$("#content").removeClass("pw-fouc-fix");b.removeClass("pw-init").addClass("pw-ready");a.removeClass("pw-init").addClass("pw-ready");$("a.notice-remove","#notices").click(function(){$("#notices").slideUp("fast",function(){$(this).remove();return false})})},setupSidebarNav:function(){var a=window.location.toString();$(document).mouseup(function(g){var f=$("ul.quicklinks");if(!f.is(g.target)&&f.has(g.target).length===0){f.hide();$(".quicklink-open").removeClass("active");$("#main-nav .current").removeClass("no-arrow")}});$(document).keydown(function(i){var g=i.target.tagName.toLowerCase();var f=i.target.className.split(" ")[0];var h;if(g=="input"||g=="textarea"||f=="InputfieldCKEditorInline"){return}switch(i.which){case 37:h="open";break;case 39:h="closed";break;default:return}ProcessWireAdminTheme.setupSideBarState(true,h);i.preventDefault()});function e(){$("#main-nav > li > a.open:not(.hover-temp):not(.just-clicked)").each(function(){var g=$(this);var f=g.next("ul:visible");if(f.length>0){if(f.find(".quicklinks-open").length>0){f.find(".quicklink-close").click()}}})}var c=null,b=0;$("#main-nav a.parent").dblclick(function(f){f.preventDefault()}).click(function(){var f=$(this);f.addClass("just-clicked");b++;if(b===1){c=setTimeout(function(){e();f.toggleClass("open").next("ul").slideToggle(200,function(){f.removeClass("just-clicked")});b=0},200)}else{clearTimeout(c);b=0;window.location.href=f.attr("href");return true}return false});var d=null;$(".quicklink-open").click(function(j){e();var k=$(this);k.parent().addClass("quicklinks-open");k.toggleClass("active").parent().next("ul.quicklinks").toggle();k.parent().parent().siblings().find("ul.quicklinks").hide();k.parent().parent().siblings().find(".quicklink-open").removeClass("active").parent("a").removeClass("quicklinks-open");k.effect("pulsate",100);j.stopPropagation();$("#main-nav .current:not(.open)").addClass("no-arrow");var f=$(this).parent().next("ul.quicklinks");var i=f.attr("data-json");if(i.length>0&&!f.hasClass("json-loaded")){f.addClass("json-loaded");var h=f.find(".quicklinks-spinner");var g=h.attr("class");h.removeClass(g).addClass("fa fa-fw fa-spin fa-spinner");$.getJSON(i,function(l){if(l.add){var m=$("
  • "+l.add.label+"
  • ");f.append(m)}$.each(l.list,function(r){var p="";var o=this.url.indexOf("/")===0?this.url:l.url+this.url;var q=$("
  • "+p+this.label+"
  • ");if(typeof this.className!="undefined"&&this.className&&this.className.length){q.addClass(this.className)}f.append(q)});h.removeClass("fa-spin fa-spinner").addClass(g);if(l.icon.length>0){h.removeClass("fa-bolt").addClass("fa-"+l.icon)}})}return false}).mouseover(function(){var f=$(this);if(f.parent().hasClass("quicklinks-open")){return}f.addClass("hover-temp");clearTimeout(d);d=setTimeout(function(){if(f.parent().hasClass("quicklinks-open")){return}if(f.hasClass("hover-temp")){f.click()}},500)}).mouseout(function(){$(this).removeClass("hover-temp")});$(".quicklink-close").click(function(){$(this).parent().removeClass("quicklinks-open");$(this).closest("ul.quicklinks").hide().prev("a").removeClass("quicklinks-open");$(".quicklink-open").removeClass("active");$("#main-nav .current").removeClass("no-arrow");return false});$("#main-nav .parent").each(function(){var f=$(this).attr("href");if(a.match(f)){$(this).next("ul").show();$(this).addClass("open")}})},setupCloneButton:function(){if($("body").is(".modal")){return}var b=$("button.pw-head-button, button.head_button_clone");if(b.length==0||$.browser.msie){return}var a=$("
    ").prependTo("#headline").show();b.each(function(){var e=$(this);var d=e.parent("a");var c;if(d.length){c=e.parent("a").clone();a.append(c)}else{if(e.hasClass("head_button_clone")||e.hasClass("pw-head-button")){c=e.clone();c.attr("data-from_id",e.attr("id")).attr("id",e.attr("id")+"_copy");c.click(function(){$("#"+$(this).attr("data-from_id")).click();return false});a.prepend(c)}}})},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(f,d){var g=this;var e="";f.attr("id","ProcessPageSearchAutocomplete");$.each(d,function(h,i){if(i.type!=e){$("
  • "+i.type+"
  • ").addClass("ui-widget-header").appendTo(f);e=i.type}g._renderItemData(f,i)})},_renderItem:function(f,g){if(g.label==g.template){g.template=""}var d=$("").text(g.label).css("margin-right","3px");if(g.unpublished){d.css("text-decoration","line-through")}if(g.hidden){d.css("opacity",0.7)}if(g.icon.length){var e=$("").addClass("fa fa-fw fa-"+g.icon).css("margin-right","2px");d.prepend(e)}var h=$("").attr("href",g.edit_url).attr("title",g.tip).append(d).append($("").text(g.template));if(g.edit_url=="#"||!g.edit_url.length){h.removeAttr("href")}return $("
  • ").append(h).appendTo(f)}});var c=$("#ProcessPageSearchQuery");var a=$("#ProcessPageSearchStatus");c.adminsearchautocomplete({minLength:2,position:{my:"right top",at:"right bottom"},search:function(d,e){a.html("")},source:function(f,d){var e=c.parents("form").attr("action")+"?q="+f.term;$.getJSON(e,function(h){var g=h.matches.length;if(g a").on("click",function(a){$(this).next("ul").toggleClass("open");$(this).parent().siblings().find("ul.open").removeClass("open");return false});$("#masthead li.pw-dropdown > ul li a").on("click",function(a){a.stopPropagation()});$(document).on("click",function(){$("#masthead li.pw-dropdown ul").removeClass("open")})},setupSideBarToggle:function(){$(".main-nav-toggle").on("click",function(){ProcessWireAdminTheme.setupSideBarState(true);return false})},setupSideBarState:function(j,c){if($("body").hasClass("id-23")||$("body").hasClass("modal")){return false}var e="pw_sidebar_state";var c=c||localStorage.getItem(e);var i=$(".main-nav-toggle");var a=$("#sidebar");var h=$("#main");var d=$("#masthead");var g=$("#branding");var f=$("#NotificationBug");var b=i.add(a).add(h).add(d).add(g).add(f);if(c===null&&$(window).width()>=690){localStorage.setItem(e,"open")}if(!j&&$(window).width()<690){localStorage.setItem(e,"closed");c="closed"}if(j==true){if(c=="open"){localStorage.setItem(e,"closed");b.addClass("closed")}else{if(c=="closed"){localStorage.setItem(e,"open");b.removeClass("closed")}}a.removeClass("hide");g.removeClass("hide");h.removeClass("full");d.removeClass("full");i.removeClass("full")}else{if(c=="closed"){b.addClass("closed");a.addClass("hide");g.addClass("hide");h.addClass("full");d.addClass("full");i.addClass("full")}}},browserCheck:function(){if($.browser.msie&&$.browser.version<8){$("#content .pw-container").html("

    ProcessWire does not support IE7 and below at this time. Please try again with a newer browser.

    ").show()}}};$(document).ready(function(){ProcessWireAdminTheme.init()}); \ No newline at end of file diff --git a/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.js b/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.js index 8503044a..0ae96f62 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.js +++ b/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.js @@ -313,6 +313,8 @@ var ProcessWireAdminTheme = { .attr('title', item.tip) .append($label) .append($("").text(item.template)); + + if(item.edit_url == '#' || !item.edit_url.length) $a.removeAttr('href'); return $("
  • ").append($a).appendTo(ul); } @@ -378,6 +380,7 @@ var ProcessWireAdminTheme = { $(this).val(''); if(typeof event.key !== 'undefined') { event.preventDefault(); + if(ui.item.edit_url === '#' || ui.item.edit_url.length < 1) return false; if(typeof parent.isPresent == "undefined") { window.location = ui.item.edit_url; } else { diff --git a/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.min.js b/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.min.js index 3eb4bc3e..46b74103 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.min.js +++ b/wire/modules/AdminTheme/AdminThemeUikit/scripts/main.min.js @@ -1 +1 @@ -var ProcessWireAdminTheme={init:function(){this.setupInputfields();this.setupTooltips();this.checkLayout()},ready:function(){this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupSideNav();var b=$("body");$(document).on("wiretabclick opened",function(c){$("body").addClass("pw-fake-resize");$(window).resize();setTimeout(function(){$("body").removeClass("pw-fake-resize")},100)});$("a.notice-remove","#notices").click(function(){$("#notices").slideUp("fast",function(){$(this).remove()});return false});$("a.pw-logo-link").click(this.logoClickEvent);$("#_ProcessPageEditView").click(function(c){c.stopPropagation()});var a=null;$(window).resize(function(){if(a){return}a=setTimeout(function(){ProcessWireAdminTheme.windowResized();a=null},250)});this.setupMasthead();this.setupWireTabs();b.removeClass("pw-init").addClass("pw-ready")},setupWireTabs:function(){var a=$(".WireTabs");if(a.length){$(document).on("wiretabclick",function(b,c){ProcessWireAdminTheme.wireTabClick(c)});setTimeout(function(){var c=a.children(".uk-active");if(c.length){var b=$(c.find("a").attr("href"));if(b.length){ProcessWireAdminTheme.wireTabClick(b)}}},500)}},wireTabClick:function(a){if(!a.length){return}var d=null;var b=null;if(a.hasClass("InputfieldWrapper")){b=a.children(".Inputfields").children(".Inputfield:eq(0)");d=b.children(".InputfieldHeader")}else{if(a.hasClass("Inputfield")){b=a;d=a.children(".InputfieldHeader")}}if(!d||!d.length){return}var i=false;var c=["InputfieldIsPrimary","InputfieldIsWarning","InputfieldIsError","InputfieldIsHighlight","InputfieldIsSuccess"];for(var f=0;f-1){a=a.replace(/([?&]layout)=[-_a-zA-Z0-9]+/,"$1=sidenav-init")}else{a+=(a.indexOf("?")>0?"&":"?")+"layout=sidenav-init"}window.location.href=a}},windowResized:function(){if($("body").hasClass("pw-fake-resize")){return}this.setupMasthead()},setupMasthead:function(){var b=$("#pw-masthead");var e=$("#pw-masthead-mobile");var c=$(window).width();var a=0;var d=0;if(c>767){d=parseInt(b.data("pw-height"));a=b.children(".pw-container").height()}else{a=999}if(b.hasClass("uk-hidden")){b.removeClass("uk-hidden")}if(a>d){if(!b.hasClass("pw-masthead-hidden")){b.addClass("pw-masthead-hidden").css({position:"absolute",top:"-9999px"});e.removeClass("uk-hidden");$("#offcanvas-toggle").removeClass("uk-hidden")}}else{if(b.hasClass("pw-masthead-hidden")){e.addClass("uk-hidden");b.removeClass("pw-masthead-hidden").css({position:"relative",top:0});$("#offcanvas-toggle").addClass("uk-hidden")}}},setupCloneButton:function(){if($("body").is(".modal")){return}var c=$("button.pw-head-button, button.head_button_clone");if(c.length==0){return}var a=$("#pw-content-head-buttons");var e=null;var h=null;var d={};c.each(function(){var m=$(this);var k=m.parent("a");var j;if(k.length>0){j=m.parent("a").clone(true);a.prepend(j)}else{if(m.hasClass("pw-head-button")||m.hasClass("head_button_clone")){j=m.clone(true);j.attr("data-from_id",m.attr("id")).attr("id",m.attr("id")+"_copy").addClass("pw-head-button");j.click(function(){$("#"+$(this).attr("data-from_id")).click();return false});if(j.hasClass("pw-button-dropdown-toggle")){var l=j.attr("id").replace("pw-dropdown-toggle-","");d[l]=j}else{if(j.hasClass("pw-button-dropdown-main")){var i=$("").addClass("pw-button-dropdown-wrap");i.append(j).addClass("uk-float-right");a.prepend(i)}else{j.addClass("uk-float-right");a.prepend(j)}}}}});for(var g in d){var b=d[g];var f=$("#"+g);f.after(b)}},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(c,a){var d=this;var b="";c.addClass("pw-dropdown-menu-shorter uk-nav uk-nav-default");c.css("z-index",9999);$.each(a,function(e,f){if(f.type!=b){if(b.length){$("
  • ").appendTo(c)}$("
  • "+f.type+"
  • ").addClass("uk-nav-header").appendTo(c);b=f.type}d._renderItemData(c,f)})},_renderItem:function(c,d){if(d.label==d.template){d.template=""}var a=$("").text(d.label).css("margin-right","3px");if(d.unpublished){a.css("text-decoration","line-through")}if(d.hidden){a.addClass("ui-priority-secondary")}if(d.icon.length){var b=$("").addClass("fa fa-fw fa-"+d.icon).css("margin-right","2px");a.prepend(b)}var e=$("").attr("href",d.edit_url).attr("title",d.tip).append(a).append($("").text(d.template));return $("
  • ").append(e).appendTo(c)}});$(".pw-search-form").each(function(){var b=$(this);var c=b.find(".pw-search-input");var a={my:"right top",at:"right bottom"};if(b.closest(".uk-offcanvas-bar").length){a.my="left top";a.at="left bottom"}c.click(function(d){d.stopPropagation()});c.adminsearchautocomplete({minLength:2,position:a,search:function(d,e){b.find(".pw-search-icon").addClass("uk-hidden");b.find(".pw-spinner-icon").removeClass("uk-hidden")},open:function(d,e){},close:function(d,e){},source:function(f,d){var e=c.parents("form").attr("data-action")+"?q="+f.term;$.getJSON(e,function(h){var g=h.matches.length;if(g");b.append(c);$.getJSON(a,function(g){var i=e.clone();var f=i.find("i");if(!f.length){f=$("");i.prepend(f)}f.attr("class","fa fa-fw fa-arrow-circle-right pw-nav-icon");i.removeAttr("data-json").removeAttr("class");i.find("small").remove();var h=$("
  • ").addClass("pw-nav-dup").append(i);b.append(h);if(g.add){var h=$("
  • "+g.add.label+"
  • ");b.append(h)}$.each(g.list,function(k){if(this.label.indexOf("-1){this.label=this.label.replace(/<\/?span[^>]*>/g,"")}var q="";var r=$("
    "+this.label+"
    ");var s=r.text();if(s.length>30){var o=r.find("small");if(o.length){o.remove()}s=r.text();s=s.substring(0,30);var k=s.lastIndexOf(" ");if(k>3){s=s.substring(0,k)+"… "}r.html(s);if(o.length){r.append(o)}}s=r.html().replace(" "," ");if(this.icon){q=""}var j=this.url.indexOf("/")===0?this.url:g.url+this.url;var l=$(""+q+s+"");var p=$("
  • ").append(l);if(this.navJSON!="undefined"&&this.navJSON){l.addClass("pw-has-items pw-has-ajax-items").attr("data-json",this.navJSON);var m=$("
      ");p.addClass("uk-parent").append(m);UIkit.nav(m,{multiple:true})}if(typeof this.className!="undefined"&&this.className&&this.className.length){p.addClass(this.className)}if(p.hasClass("pw-nav-add")||p.hasClass("pw-pagelist-show-all")){b.children(".pw-nav-dup").after(p.removeClass("separator").addClass("pw-nav-add"))}else{b.append(p)}});c.remove();b.addClass("navJSON").addClass("length"+parseInt(g.list.length)).hide();if(b.children().length){b.css("opacity",1).fadeIn("fast")}});return false})},setupInputfields:function(){var d=$("body").hasClass("AdminThemeUikitNoGrid");function e(j){$("form.uk-form-horizontal").each(function(){$(this).find(".InputfieldContent > .Inputfields").each(function(){var l=$(this);l.addClass("uk-form-vertical");l.find(".uk-form-label").removeClass("uk-form-label");l.find(".uk-form-controls").removeClass("uk-form-controls")});$(this).find(".InputfieldSubmit, .InputfieldButton").each(function(){$(this).find(".InputfieldContent").before("
       
      ")})});$(".InputfieldNoBorder.uk-card").removeClass("uk-card uk-card-default");$(".InputfieldIsOffset.InputfieldColumnWidthFirst").each(function(){var m=$(this);var l;do{l=m.next(".InputfieldColumnWidth");if(!l.length||l.hasClass("InputfieldColumnWidthFirst")){break}l.addClass("InputfieldIsOffset");m=l}while(true)});$(".Inputfields").each(function(){b($(this))});$(".ui-widget.Inputfield, .ui-widget-header.InputfieldHeader, .ui-widget-content.InputfieldContent").removeClass("ui-widget ui-widget-header ui-widget-content");$(".MarkupPagerNav:not(.uk-pagination)").each(function(){$(this).addClass("uk-pagination")});if(typeof j=="undefined"){j=$(".InputfieldForm")}var k=$("select:not([multiple]):not(.uk-select)",j);k.addClass("uk-select")}function b(j){$(".InputfieldRowFirst",j).removeClass("InputfieldRowFirst");$(".InputfieldRowLast",j).removeClass("InputfieldRowLast");var k=j.children(".Inputfield:not(.InputfieldStateHidden):eq(0)");if(!k.length){return}do{k.addClass("InputfieldRowFirst");k=k.next(".Inputfield:not(.InputfieldStateHidden)")}while(k.hasClass("InputfieldColumnWidth")&&!k.hasClass("InputfieldColumnWidthFirst"));k=j.children(".Inputfield:last-child");while(k.length&&k.hasClass("InputfieldStateHidden")){k=k.prev(".Inputfield")}do{k.addClass("InputfieldRowLast");if(!k.hasClass("InputfieldColumnWidth")||k.hasClass("InputfieldColumnWidthFirst")){break}k=k.prev(".Inputfield:not(.InputfieldStateHidden)")}while(k.hasClass("InputfieldColumnWidth"))}var i=[];function c(l,p){if(d&&typeof p!="undefined"){if(typeof l=="string"){p.addClass(l)}else{p.css("width",l+"%")}return""}var k="uk-width-1-1";var j=k;var n=false;if(typeof l=="string"&&typeof p!="undefined"){j=l;n=true}else{if(!l||l>=100){j=k}else{if(typeof i[l]!="undefined"){j="uk-width-"+i[l]}else{for(var m in ProcessWire.config.ukGridWidths){var o=ProcessWire.config.ukGridWidths[m];m=parseInt(m);if(l>=m){j=o;break}}if(j.length){i[l]=j;j="uk-width-"+j}}}}if(!n&&j&&j!=k){j+="@m"}if(typeof p!="undefined"){if(j&&p.hasClass(j)){}else{g(p);if(j){p.addClass(j)}}}return j}function g(k){var l=null;if(typeof k!="string"){l=k;k=l.attr("class")}if(k.indexOf("uk-width-")>-1){var j=k.replace(/uk-width-(\d-\d|expand)[@smxl]*\s*/g,"");if(l!==null){l.attr("class",j)}}return k}function a(j){if(!j){return}var q=j.parent().children(".Inputfield");var r=null;var l=0;var p=0;var t=0;var m=0;var k=false;function u(v,x){if(!k){return}if(typeof x=="undefined"){x=j}var w=x.attr("id");w=w.replace("wrap_Inputfield_","");console.log(w+" (combined width="+l+", w="+t+"): "+v)}function o(v){if(typeof v=="undefined"){v=r}if(v){if(d){v.addClass("InputfieldColumnWidthLast")}else{c("InputfieldColumnWidthLast uk-width-expand",v)}}}function n(){if(k){u("A: hidden",j)}m+=t;l+=t;if(r&&l>=95){m+=p;if(k){u("Updating last visible Inputfield to width="+m,r)}c(m,r);l=0;m=0;p=0;r=null}else{p+=t}}function s(){if(k){u("Skipping because full-width",j)}if(l<100&&r){o(r)}r=null;p=0;m=0;l=0}q.each(function(){j=$(this);var y=false;var x=false;var w=j.hasClass("InputfieldColumnWidth");var v=!w||j.hasClass("InputfieldColumnWidthFirst");if(v&&r&&l<100){o(r)}t=w?parseInt(j.attr("data-colwidth")):0;if(!t||t>=95){s();return}if(j.hasClass("InputfieldStateHidden")){n();return}if(!l||l>=100){l=0;x=true;y=false;if(k){u("B: starting new row",j)}}else{if(l+t>100){if(r){o(r)}l=0;x=true;if(k){u("C: start new row because width would exceed 100%",j)}}else{if(l+t==100){y=true;if(k){u("D: width is exactly 100%, so this is the last column",j)}}else{if(l+t>=95){y=true;t=100-l;if(k){u("D2: width is close enough to 100%, so this is the last column",j)}}else{if(k){u("E: not first or last column",j)}}}}}if(y){j.addClass("InputfieldColumnWidthLast")}else{j.removeClass("InputfieldColumnWidthLast")}if(x){j.addClass("InputfieldColumnWidthFirst");p=0}else{j.removeClass("InputfieldColumnWidthFirst")}if(y){r=null;l=0;m=0;if(p){t+=p}p=0}else{r=j;l+=t;m=t}c(t,j)});if(l<100&&r){o(r)}}var h=null;var f=function(l,k){var j=$(k);if(l.type=="showInputfield"){j.removeClass("uk-hidden")}else{j.show();j.addClass("uk-hidden")}a(j);if(h){return}h=setTimeout(function(){b(j.closest(".Inputfields"));var m=j.find(".Inputfields");if(m.length){m.each(function(){b($(this))})}h=null},100)};$(document).on("reloaded",function(){e($(this))});$(document).on("hideInputfield",f);$(document).on("showInputfield",f);$("body").addClass("InputfieldColumnWidthsInit");e()},setupTooltips:function(){$(".tooltip, .pw-tooltip").each(function(){$(this).removeClass("tooltip pw-tooltip");UIkit.tooltip($(this))})},linkTargetMainMouseoverEvent:function(){var b=$(this);var a=b.attr("href");if(a.length<2){return}if(b.attr("target")){return}if(b.parent("li").hasClass("PageListActionView")){b.attr("target","_top")}else{b.attr("target","main")}},logoClickEvent:function(){if($("body").hasClass("pw-layout-sidenav-init")){if($("#pw-admin-side").length){toggleSidebarPane()}else{UIkit.toggle("#offcanvas-nav").toggle()}}else{if(ProcessWire.config.adminTheme.logoAction==1){UIkit.toggle("#offcanvas-nav").toggle()}else{return true}}return false}};$(document).ready(function(){ProcessWireAdminTheme.ready()}); \ No newline at end of file +var ProcessWireAdminTheme={init:function(){this.setupInputfields();this.setupTooltips();this.checkLayout()},ready:function(){this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupSideNav();var b=$("body");$(document).on("wiretabclick opened",function(c){$("body").addClass("pw-fake-resize");$(window).resize();setTimeout(function(){$("body").removeClass("pw-fake-resize")},100)});$("a.notice-remove","#notices").click(function(){$("#notices").slideUp("fast",function(){$(this).remove()});return false});$("a.pw-logo-link").click(this.logoClickEvent);$("#_ProcessPageEditView").click(function(c){c.stopPropagation()});var a=null;$(window).resize(function(){if(a){return}a=setTimeout(function(){ProcessWireAdminTheme.windowResized();a=null},250)});this.setupMasthead();this.setupWireTabs();b.removeClass("pw-init").addClass("pw-ready")},setupWireTabs:function(){var a=$(".WireTabs");if(a.length){$(document).on("wiretabclick",function(b,c){ProcessWireAdminTheme.wireTabClick(c)});setTimeout(function(){var c=a.children(".uk-active");if(c.length){var b=$(c.find("a").attr("href"));if(b.length){ProcessWireAdminTheme.wireTabClick(b)}}},500)}},wireTabClick:function(a){if(!a.length){return}var d=null;var b=null;if(a.hasClass("InputfieldWrapper")){b=a.children(".Inputfields").children(".Inputfield:eq(0)");d=b.children(".InputfieldHeader")}else{if(a.hasClass("Inputfield")){b=a;d=a.children(".InputfieldHeader")}}if(!d||!d.length){return}var i=false;var c=["InputfieldIsPrimary","InputfieldIsWarning","InputfieldIsError","InputfieldIsHighlight","InputfieldIsSuccess"];for(var f=0;f-1){a=a.replace(/([?&]layout)=[-_a-zA-Z0-9]+/,"$1=sidenav-init")}else{a+=(a.indexOf("?")>0?"&":"?")+"layout=sidenav-init"}window.location.href=a}},windowResized:function(){if($("body").hasClass("pw-fake-resize")){return}this.setupMasthead()},setupMasthead:function(){var b=$("#pw-masthead");var e=$("#pw-masthead-mobile");var c=$(window).width();var a=0;var d=0;if(c>767){d=parseInt(b.data("pw-height"));a=b.children(".pw-container").height()}else{a=999}if(b.hasClass("uk-hidden")){b.removeClass("uk-hidden")}if(a>d){if(!b.hasClass("pw-masthead-hidden")){b.addClass("pw-masthead-hidden").css({position:"absolute",top:"-9999px"});e.removeClass("uk-hidden");$("#offcanvas-toggle").removeClass("uk-hidden")}}else{if(b.hasClass("pw-masthead-hidden")){e.addClass("uk-hidden");b.removeClass("pw-masthead-hidden").css({position:"relative",top:0});$("#offcanvas-toggle").addClass("uk-hidden")}}},setupCloneButton:function(){if($("body").is(".modal")){return}var c=$("button.pw-head-button, button.head_button_clone");if(c.length==0){return}var a=$("#pw-content-head-buttons");var e=null;var h=null;var d={};c.each(function(){var m=$(this);var k=m.parent("a");var j;if(k.length>0){j=m.parent("a").clone(true);a.prepend(j)}else{if(m.hasClass("pw-head-button")||m.hasClass("head_button_clone")){j=m.clone(true);j.attr("data-from_id",m.attr("id")).attr("id",m.attr("id")+"_copy").addClass("pw-head-button");j.click(function(){$("#"+$(this).attr("data-from_id")).click();return false});if(j.hasClass("pw-button-dropdown-toggle")){var l=j.attr("id").replace("pw-dropdown-toggle-","");d[l]=j}else{if(j.hasClass("pw-button-dropdown-main")){var i=$("").addClass("pw-button-dropdown-wrap");i.append(j).addClass("uk-float-right");a.prepend(i)}else{j.addClass("uk-float-right");a.prepend(j)}}}}});for(var g in d){var b=d[g];var f=$("#"+g);f.after(b)}},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(c,a){var d=this;var b="";c.addClass("pw-dropdown-menu-shorter uk-nav uk-nav-default");c.css("z-index",9999);$.each(a,function(e,f){if(f.type!=b){if(b.length){$("
    • ").appendTo(c)}$("
    • "+f.type+"
    • ").addClass("uk-nav-header").appendTo(c);b=f.type}d._renderItemData(c,f)})},_renderItem:function(c,d){if(d.label==d.template){d.template=""}var a=$("").text(d.label).css("margin-right","3px");if(d.unpublished){a.css("text-decoration","line-through")}if(d.hidden){a.addClass("ui-priority-secondary")}if(d.icon.length){var b=$("").addClass("fa fa-fw fa-"+d.icon).css("margin-right","2px");a.prepend(b)}var e=$("").attr("href",d.edit_url).attr("title",d.tip).append(a).append($("").text(d.template));if(d.edit_url=="#"||!d.edit_url.length){e.removeAttr("href")}return $("
    • ").append(e).appendTo(c)}});$(".pw-search-form").each(function(){var b=$(this);var c=b.find(".pw-search-input");var a={my:"right top",at:"right bottom"};if(b.closest(".uk-offcanvas-bar").length){a.my="left top";a.at="left bottom"}c.click(function(d){d.stopPropagation()});c.adminsearchautocomplete({minLength:2,position:a,search:function(d,e){b.find(".pw-search-icon").addClass("uk-hidden");b.find(".pw-spinner-icon").removeClass("uk-hidden")},open:function(d,e){},close:function(d,e){},source:function(f,d){var e=c.parents("form").attr("data-action")+"?q="+f.term;$.getJSON(e,function(h){var g=h.matches.length;if(g");b.append(c);$.getJSON(a,function(g){var i=e.clone();var f=i.find("i");if(!f.length){f=$("");i.prepend(f)}f.attr("class","fa fa-fw fa-arrow-circle-right pw-nav-icon");i.removeAttr("data-json").removeAttr("class");i.find("small").remove();var h=$("
    • ").addClass("pw-nav-dup").append(i);b.append(h);if(g.add){var h=$("
    • "+g.add.label+"
    • ");b.append(h)}$.each(g.list,function(k){if(this.label.indexOf("-1){this.label=this.label.replace(/<\/?span[^>]*>/g,"")}var q="";var r=$("
      "+this.label+"
      ");var s=r.text();if(s.length>30){var o=r.find("small");if(o.length){o.remove()}s=r.text();s=s.substring(0,30);var k=s.lastIndexOf(" ");if(k>3){s=s.substring(0,k)+"… "}r.html(s);if(o.length){r.append(o)}}s=r.html().replace(" "," ");if(this.icon){q=""}var j=this.url.indexOf("/")===0?this.url:g.url+this.url;var l=$(""+q+s+"");var p=$("
    • ").append(l);if(this.navJSON!="undefined"&&this.navJSON){l.addClass("pw-has-items pw-has-ajax-items").attr("data-json",this.navJSON);var m=$("
        ");p.addClass("uk-parent").append(m);UIkit.nav(m,{multiple:true})}if(typeof this.className!="undefined"&&this.className&&this.className.length){p.addClass(this.className)}if(p.hasClass("pw-nav-add")||p.hasClass("pw-pagelist-show-all")){b.children(".pw-nav-dup").after(p.removeClass("separator").addClass("pw-nav-add"))}else{b.append(p)}});c.remove();b.addClass("navJSON").addClass("length"+parseInt(g.list.length)).hide();if(b.children().length){b.css("opacity",1).fadeIn("fast")}});return false})},setupInputfields:function(){var d=$("body").hasClass("AdminThemeUikitNoGrid");function e(j){$("form.uk-form-horizontal").each(function(){$(this).find(".InputfieldContent > .Inputfields").each(function(){var l=$(this);l.addClass("uk-form-vertical");l.find(".uk-form-label").removeClass("uk-form-label");l.find(".uk-form-controls").removeClass("uk-form-controls")});$(this).find(".InputfieldSubmit, .InputfieldButton").each(function(){$(this).find(".InputfieldContent").before("
         
        ")})});$(".InputfieldNoBorder.uk-card").removeClass("uk-card uk-card-default");$(".InputfieldIsOffset.InputfieldColumnWidthFirst").each(function(){var m=$(this);var l;do{l=m.next(".InputfieldColumnWidth");if(!l.length||l.hasClass("InputfieldColumnWidthFirst")){break}l.addClass("InputfieldIsOffset");m=l}while(true)});$(".Inputfields").each(function(){b($(this))});$(".ui-widget.Inputfield, .ui-widget-header.InputfieldHeader, .ui-widget-content.InputfieldContent").removeClass("ui-widget ui-widget-header ui-widget-content");$(".MarkupPagerNav:not(.uk-pagination)").each(function(){$(this).addClass("uk-pagination")});if(typeof j=="undefined"){j=$(".InputfieldForm")}var k=$("select:not([multiple]):not(.uk-select)",j);k.addClass("uk-select")}function b(j){$(".InputfieldRowFirst",j).removeClass("InputfieldRowFirst");$(".InputfieldRowLast",j).removeClass("InputfieldRowLast");var k=j.children(".Inputfield:not(.InputfieldStateHidden):eq(0)");if(!k.length){return}do{k.addClass("InputfieldRowFirst");k=k.next(".Inputfield:not(.InputfieldStateHidden)")}while(k.hasClass("InputfieldColumnWidth")&&!k.hasClass("InputfieldColumnWidthFirst"));k=j.children(".Inputfield:last-child");while(k.length&&k.hasClass("InputfieldStateHidden")){k=k.prev(".Inputfield")}do{k.addClass("InputfieldRowLast");if(!k.hasClass("InputfieldColumnWidth")||k.hasClass("InputfieldColumnWidthFirst")){break}k=k.prev(".Inputfield:not(.InputfieldStateHidden)")}while(k.hasClass("InputfieldColumnWidth"))}var i=[];function c(l,p){if(d&&typeof p!="undefined"){if(typeof l=="string"){p.addClass(l)}else{p.css("width",l+"%")}return""}var k="uk-width-1-1";var j=k;var n=false;if(typeof l=="string"&&typeof p!="undefined"){j=l;n=true}else{if(!l||l>=100){j=k}else{if(typeof i[l]!="undefined"){j="uk-width-"+i[l]}else{for(var m in ProcessWire.config.ukGridWidths){var o=ProcessWire.config.ukGridWidths[m];m=parseInt(m);if(l>=m){j=o;break}}if(j.length){i[l]=j;j="uk-width-"+j}}}}if(!n&&j&&j!=k){j+="@m"}if(typeof p!="undefined"){if(j&&p.hasClass(j)){}else{g(p);if(j){p.addClass(j)}}}return j}function g(k){var l=null;if(typeof k!="string"){l=k;k=l.attr("class")}if(k.indexOf("uk-width-")>-1){var j=k.replace(/uk-width-(\d-\d|expand)[@smxl]*\s*/g,"");if(l!==null){l.attr("class",j)}}return k}function a(j){if(!j){return}var q=j.parent().children(".Inputfield");var r=null;var l=0;var p=0;var t=0;var m=0;var k=false;function u(v,x){if(!k){return}if(typeof x=="undefined"){x=j}var w=x.attr("id");w=w.replace("wrap_Inputfield_","");console.log(w+" (combined width="+l+", w="+t+"): "+v)}function o(v){if(typeof v=="undefined"){v=r}if(v){if(d){v.addClass("InputfieldColumnWidthLast")}else{c("InputfieldColumnWidthLast uk-width-expand",v)}}}function n(){if(k){u("A: hidden",j)}m+=t;l+=t;if(r&&l>=95){m+=p;if(k){u("Updating last visible Inputfield to width="+m,r)}c(m,r);l=0;m=0;p=0;r=null}else{p+=t}}function s(){if(k){u("Skipping because full-width",j)}if(l<100&&r){o(r)}r=null;p=0;m=0;l=0}q.each(function(){j=$(this);var y=false;var x=false;var w=j.hasClass("InputfieldColumnWidth");var v=!w||j.hasClass("InputfieldColumnWidthFirst");if(v&&r&&l<100){o(r)}t=w?parseInt(j.attr("data-colwidth")):0;if(!t||t>=95){s();return}if(j.hasClass("InputfieldStateHidden")){n();return}if(!l||l>=100){l=0;x=true;y=false;if(k){u("B: starting new row",j)}}else{if(l+t>100){if(r){o(r)}l=0;x=true;if(k){u("C: start new row because width would exceed 100%",j)}}else{if(l+t==100){y=true;if(k){u("D: width is exactly 100%, so this is the last column",j)}}else{if(l+t>=95){y=true;t=100-l;if(k){u("D2: width is close enough to 100%, so this is the last column",j)}}else{if(k){u("E: not first or last column",j)}}}}}if(y){j.addClass("InputfieldColumnWidthLast")}else{j.removeClass("InputfieldColumnWidthLast")}if(x){j.addClass("InputfieldColumnWidthFirst");p=0}else{j.removeClass("InputfieldColumnWidthFirst")}if(y){r=null;l=0;m=0;if(p){t+=p}p=0}else{r=j;l+=t;m=t}c(t,j)});if(l<100&&r){o(r)}}var h=null;var f=function(l,k){var j=$(k);if(l.type=="showInputfield"){j.removeClass("uk-hidden")}else{j.show();j.addClass("uk-hidden")}a(j);if(h){return}h=setTimeout(function(){b(j.closest(".Inputfields"));var m=j.find(".Inputfields");if(m.length){m.each(function(){b($(this))})}h=null},100)};$(document).on("reloaded",function(){e($(this))});$(document).on("hideInputfield",f);$(document).on("showInputfield",f);$("body").addClass("InputfieldColumnWidthsInit");e()},setupTooltips:function(){$(".tooltip, .pw-tooltip").each(function(){$(this).removeClass("tooltip pw-tooltip");UIkit.tooltip($(this))})},linkTargetMainMouseoverEvent:function(){var b=$(this);var a=b.attr("href");if(a.length<2){return}if(b.attr("target")){return}if(b.parent("li").hasClass("PageListActionView")){b.attr("target","_top")}else{b.attr("target","main")}},logoClickEvent:function(){if($("body").hasClass("pw-layout-sidenav-init")){if($("#pw-admin-side").length){toggleSidebarPane()}else{UIkit.toggle("#offcanvas-nav").toggle()}}else{if(ProcessWire.config.adminTheme.logoAction==1){UIkit.toggle("#offcanvas-nav").toggle()}else{return true}}return false}};$(document).ready(function(){ProcessWireAdminTheme.ready()}); \ No newline at end of file diff --git a/wire/modules/Process/ProcessCommentsManager/ProcessCommentsManager.module b/wire/modules/Process/ProcessCommentsManager/ProcessCommentsManager.module index 996509dc..36eaafa5 100644 --- a/wire/modules/Process/ProcessCommentsManager/ProcessCommentsManager.module +++ b/wire/modules/Process/ProcessCommentsManager/ProcessCommentsManager.module @@ -710,8 +710,23 @@ class ProcessCommentsManager extends Process { 'total' => 0, 'url' => '', 'items' => array(), + 'properties' => array( + 'text', + 'cite', + 'email', + 'status', + 'created', + 'website', + 'ip', + 'user_agent', + 'upvotes', + 'downvotes', + 'stars' + ) ); + if($options['help']) return $result; + $operator = empty($options['operator']) ? '%=' : $options['operator']; $value = $this->wire('sanitizer')->selectorValue($text); $summaryLength = $options['verbose'] ? 1024 : 200; diff --git a/wire/modules/Process/ProcessField/ProcessField.module b/wire/modules/Process/ProcessField/ProcessField.module index f27cc214..159b08c5 100644 --- a/wire/modules/Process/ProcessField/ProcessField.module +++ b/wire/modules/Process/ProcessField/ProcessField.module @@ -2625,7 +2625,20 @@ class ProcessField extends Process implements ConfigurableModule { $result = array( 'title' => $page->id ? $page->title : $this->className(), 'items' => array(), + 'total' => 0, + 'properties' => array( + 'name', + 'type', + 'label', + 'description', + 'notes', + 'settings', + 'tags', + 'icon', + ) ); + + if(!empty($options['help'])) return $result; $looseItems = array(); $exactItems = array(); @@ -2652,10 +2665,13 @@ class ProcessField extends Process implements ConfigurableModule { if($property == 'notes' || $property == 'all') $search[] = $item->notes; } - if($property == 'data') { + if($property == 'settings' || $property == 'data') { foreach($item->getArray() as $k => $v) { $search[] = (string) $v; } + } else if(!in_array($property, $result['properties'])) { + $val = $item->get($property); + if($val !== null) $search[] = $val; } $search = implode(' ', $search); @@ -2663,6 +2679,9 @@ class ProcessField extends Process implements ConfigurableModule { if($pos === false) continue; $exact = stripos($search, " $text"); + $result['total']++; + if(!empty($options['limit']) && $cnt >= $options['limit']) break; + $item = array( 'id' => $item->id, 'name' => $item->name, @@ -2680,11 +2699,10 @@ class ProcessField extends Process implements ConfigurableModule { } $cnt++; - if(!empty($options['limit']) && $cnt >= $options['limit']) break; } $result['items'] = array_merge($exactItems, $looseItems); - + return $result; } diff --git a/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php b/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php index 56e9ef40..a31665c3 100644 --- a/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php +++ b/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php @@ -52,6 +52,7 @@ class ProcessPageSearchLive extends Wire { 'limit' => 15, 'verbose' => false, 'debug' => false, + 'help' => false, ); /** @@ -370,7 +371,8 @@ class ProcessPageSearchLive extends Wire { 'multilang' => $this->wire('languages') ? true : false, 'language' => $language, 'start' => $start, - 'limit' => $limit + 'limit' => $limit, + 'help' => strtolower($q) === 'help', )); if($this->isViewAll) { @@ -463,12 +465,14 @@ class ProcessPageSearchLive extends Wire { } if($this->process) { - $headline = $this->labels['search-results']; - if($type) $headline .= " - " . ucfirst($type); - $this->process->headline($this->pagination->getPaginationString(array( - 'label' => $headline, - 'count' => count($results) - ))); + if($type) { + $this->process->headline($this->pagination->getPaginationString(array( + 'label' => $this->labels['search-results'] . " - " . ucfirst($type), + 'count' => count($results) + ))); + } else { + $this->process->headline($this->labels['search-results']); + } } $out = $this->renderList($results); @@ -517,6 +521,7 @@ class ProcessPageSearchLive extends Wire { $type = $liveSearch['type']; $foundTypes = array(); $modulesInfo = array(); + $help = $liveSearch['help']; /** @var Modules $modules */ $modules = $this->wire('modules'); @@ -536,7 +541,7 @@ class ProcessPageSearchLive extends Wire { if($type != 'pages' && $type != 'trash') { $modulesInfo = $modules->getModuleInfo('*', array('verbose' => true)); } - + foreach($modulesInfo as $info) { if(empty($info['searchable'])) continue; @@ -564,7 +569,7 @@ class ProcessPageSearchLive extends Wire { // ok } - if(!$module || empty($result['items'])) continue; + if(!$module || (empty($result['items']) && empty($liveSearch['help']))) continue; if(empty($result['total'])) $result['total'] = count($result['items']); if(!in_array($thisType, $this->searchTypesOrder)) $this->searchTypesOrder[] = $thisType; @@ -574,6 +579,14 @@ class ProcessPageSearchLive extends Wire { $title = empty($result['title']) ? $info['title'] : $result['title']; $n = $liveSearch['start']; $item = null; + + if($help) { + foreach($result['items'] as $key => $item) { + if($item['name'] != 'help') unset($result['items'][$key]); + } + $result['items'] = array_merge($this->makeHelpItems($result, $thisType), $result['items']); + } + foreach($result['items'] as $item) { $n++; $item = array_merge($this->itemTemplate, $item); @@ -582,18 +595,20 @@ class ProcessPageSearchLive extends Wire { $items[$order] = $item; $order++; } - if($n && $n < $result['total'] && !$this->isViewAll) { + + if($n && $n < $result['total'] && !$this->isViewAll && !$help) { $url = isset($result['url']) ? $result['url'] : ''; $items[$order] = $this->makeViewAllItem($liveSearch, $thisType, $item['group'], $result['total'], $url); } - if($this->isViewAll && $this->pagination && $type) { + + if($this->isViewAll && $this->pagination && $type && !$help) { $this->pagination->setTotal($result['total']); $this->pagination->setLimit($liveSearch['limit']); $this->pagination->setStart($liveSearch['start']); } } - if($type && !count($foundTypes) && !in_array($type, array('pages', 'trash', 'modules'))) { + if($type && !$help && !count($foundTypes) && !in_array($type, array('pages', 'trash', 'modules'))) { if(empty($liveSearch['template']) && !count($foundTypes)) { // if no types matched, and it’s going to skip pages, assume type is a property, and do a pages search $liveSearch = $this->init(array( @@ -635,6 +650,8 @@ class ProcessPageSearchLive extends Wire { } ksort($items); + + if($help) $items = array_merge($this->makeHelpItems(array(), 'help'), $items); return $items; } @@ -653,6 +670,13 @@ class ProcessPageSearchLive extends Wire { $superuser = $user->isSuperuser(); $pages = $this->wire('pages'); + if(!empty($liveSearch['help'])) { + $result = array('title' => 'pages', 'items' => array(), 'properties' => array('name', 'title')); + if($this->wire('fields')->get('body')) $result['properties'][] = 'body'; + $result['properties'][] = $this->_('or any field name'); + return $this->makeHelpItems($result, 'pages'); + } + // a $pages->find() search will be included in the live search $selectors = &$liveSearch['selectors']; $selectors[] = "start=$liveSearch[start], limit=$liveSearch[limit]"; @@ -766,6 +790,24 @@ class ProcessPageSearchLive extends Wire { $items = array(); $forceMatch = false; + if(!empty($liveSearch['help'])) { + $info = $this->wire('modules')->getModuleInfoVerbose('ProcessPageSearch'); + $properties = array(); + foreach(array_keys($info) as $property) { + $value = $info[$property]; + if(!is_array($value)) $properties[$property] = $property; + } + $exclude = array('id', 'file', 'versionStr', 'core'); + foreach($exclude as $key) unset($properties[$key]); + $result = array( + 'title' => 'Modules', + 'items' => array(), + 'properties' => $properties + ); + $items = $this->makeHelpItems($result, 'modules'); + return $items; + } + if($liveSearch['type'] === 'modules' && !empty($liveSearch['property'])) { // searching for custom module property $forceMatch = true; @@ -779,18 +821,20 @@ class ProcessPageSearchLive extends Wire { } foreach($infos as $info) { + $id = isset($info['id']) ? $info['id'] : 0; $name = $info['name']; $title = $info['title']; + $summary = isset($info['summary']) ? $info['summary'] : ''; if(!$forceMatch) { - $searchText = "$name $title $info[summary]"; + $searchText = "$name $title $summary"; if(stripos($searchText, $q) === false) continue; } $item = array( - 'id' => $info['id'], + 'id' => $id, 'name' => $name, 'title' => $title, 'subtitle' => $name, - 'summary' => $info['summary'], + 'summary' => $summary, 'url' => $this->wire('config')->urls->admin . "module/edit?name=$name", 'group' => $groupLabel, ); @@ -866,6 +910,129 @@ class ProcessPageSearchLive extends Wire { 'group' => 'Debug', )); } + + /** + * Make a search result item that displays property info + * + * @param array $result Result array returned by a SearchableModule::search() method + * @param string $type + * @return array + * + */ + protected function makeHelpItems(array $result, $type) { + + $items = array(); + $helloLabel = $this->_('test'); + $usage1desc = $this->wire('sanitizer')->unentities($this->_('Searches %1$s for: %2$s')); + $usage2desc = $this->wire('sanitizer')->unentities($this->_('Searches “%1$s” property of %2$s for: %3$s')); + + if($type === 'help') { + $operators = ProcessPageSearch::getOperators(); + $summary = + $this->_('Examples use the “=” equals operator.') . " \n" . + $this->_('In some cases you can also use these:') . "\n"; + foreach($operators as $op => $label) { + $summary .= "$op " . rtrim($label, '*') . "\n"; + } + $items[] = array( + 'title' => $this->_('operators:'), + 'subtitle' => implode(', ', array_keys($operators)), + 'summary' => $summary, + 'group' => 'help', + 'url' => 'https://processwire.com/api/selectors/#operators' + ); + if($this->wire('user')->isSuperuser() && $this->process) { + $items[] = array( + 'title' => $this->_('configure'), + 'subtitle' => $this->_('Click here to configure search settings'), + 'url' => $url = $this->wire('modules')->getModuleEditUrl('ProcessPageSearch'), + 'group' => 'help', + ); + } + return $items; + } + + // include any items from result that had the name "help" + foreach($result['items'] as $item) { + if($item['name'] == 'help') $items[] = $item; + } + + $items[] = array( + 'title' => "$type=$helloLabel", + 'subtitle' => sprintf($usage1desc, $type, $helloLabel), + ); + + if(!empty($result['properties'])) { + + if($type == 'pages' || $type == 'modules') { + $property = 'title'; + } else if($type == 'fields' || $type == 'templates') { + $property = 'label'; + } else { + $property = reset($result['properties']); + } + + $items[] = array( + 'title' => "$type.$property=$helloLabel", + 'subtitle' => sprintf($usage2desc, $property, $type, $helloLabel) + ); + + if($type === 'pages') { + $items[] = array( + 'title' => "$property=$helloLabel", + 'subtitle' => $this->_('Same as above (shorter syntax if no names collide)') + ); + $templateName = 'basic-page'; + $items[] = array( + 'title' => "$templateName=$helloLabel", + 'subtitle' => sprintf($this->_('Limit results to template: %s'), $templateName), + ); + $items[] = array( + 'title' => "$templateName.$property=$helloLabel", + 'subtitle' => sprintf($this->_('Limit results to %s field on template'), $property) + ); + + } else if($type === 'templates') { + $fieldName = 'images'; + $items[] = array( + 'title' => "templates.fields=$fieldName", + 'subtitle' => sprintf($this->_('Find templates that have field: %s'), $fieldName) + ); + } else if($type === 'fields') { + $items[] = array( + 'title' => "fields.settings=ckeditor", + 'subtitle' => $this->_('Find fields with “ckeditor” in settings'), + ); + } + + $properties = implode(', ', $result['properties']); + + if(strlen($properties) > 50) { + $properties = $this->wire('sanitizer')->truncate($properties, 50) . ' ' . $this->_('(hover for more)'); + } + + $summary = + sprintf($this->_('The examples use the “%s” property.'), $property) . "\n" . + $this->_('You can also use any of these properties:') . "\n • " . + implode("\n • ", $result['properties']); + + $items[] = array( + 'title' => $this->_('properties'), + 'subtitle' => $properties, + 'summary' => $summary + ); + } + + $group = sprintf($this->_('%s help'), $type); + + foreach($items as $key => $item) { + $item['name'] = 'help'; + $item['group'] = $group; + $items[$key] = array_merge($this->itemTemplate, $item); + } + + return $items; + } /** * Make a search result item that displays a “view all” link @@ -927,11 +1094,17 @@ class ProcessPageSearchLive extends Wire { $pagination = $this->pagination->renderPager(); $a = array(); + $group = ''; $out = "\n
        " . $pagination; foreach($items as $item) { - $a[] = $this->renderItem($item, $prefix); + $headline = ''; + if($item['group'] != $group) { + $group = $item['group']; + $headline = "

        " . $this->wire('sanitizer')->entities($group) . "

        "; + } + $a[] = $headline . $this->renderItem($item, $prefix); } $out .= implode('
        ', $a) . $pagination . "\n
        "; @@ -961,7 +1134,7 @@ class ProcessPageSearchLive extends Wire { } } - $title = "$item[title] "; + $title = "$item[title]"; $subtitle = empty($item['subtitle']) ? '' : "
        $item[subtitle] "; $summary = empty($item['summary']) ? '' : "
        $item[summary] "; diff --git a/wire/modules/Process/ProcessPageType/ProcessPageType.module b/wire/modules/Process/ProcessPageType/ProcessPageType.module index 0cd37685..a7c0d640 100644 --- a/wire/modules/Process/ProcessPageType/ProcessPageType.module +++ b/wire/modules/Process/ProcessPageType/ProcessPageType.module @@ -620,7 +620,8 @@ class ProcessPageType extends Process implements ConfigurableModule, WirePageEdi public function search($text, array $options = array()) { $page = $this->getProcessPage(); - $this->pages = $this->wire($page->name); + $this->pages = $this->wire($page->name); + $templates = $this->pages->getTemplates(); /** @var Languages $languages */ $page = $this->getProcessPage(); @@ -629,6 +630,18 @@ class ProcessPageType extends Process implements ConfigurableModule, WirePageEdi 'title' => $page->id ? $page->title : $this->className(), 'items' => array(), ); + + if(!empty($options['help'])) { + $result['properties'] = array('name'); + foreach($templates as $template) { + foreach($template->fieldgroup as $field) { + if($field->type instanceof FieldtypePassword) continue; + if($field->type instanceof FieldtypeFieldsetOpen) continue; + $result['properties'][] = $field->name; + } + } + return $result; + } $text = $this->wire('sanitizer')->selectorValue($text); $property = empty($options['property']) ? 'name' : $options['property']; diff --git a/wire/modules/Process/ProcessTemplate/ProcessTemplate.module b/wire/modules/Process/ProcessTemplate/ProcessTemplate.module index b77dd44c..71b623bb 100644 --- a/wire/modules/Process/ProcessTemplate/ProcessTemplate.module +++ b/wire/modules/Process/ProcessTemplate/ProcessTemplate.module @@ -3016,11 +3016,22 @@ class ProcessTemplate extends Process { /** @var Languages $languages */ $languages = $this->wire('langauges'); $page = $this->getProcessPage(); + $property = isset($options['property']) ? $options['property'] : ''; $result = array( 'title' => $page->id ? $page->title : $this->className(), 'items' => array(), + 'total' => 0, + 'properties' => array( + 'name', + 'label', + 'tags', + 'fields', + ) ); + + if(!empty($options['help'])) return $result; + if(!empty($property) && !in_array($property, $result['properties'])) return $result; $looseItems = array(); $exactItems = array(); @@ -3028,19 +3039,26 @@ class ProcessTemplate extends Process { foreach($this->wire('templates') as $item) { /** @var Template $item */ - $search = array(' ', $item->name); + $search = array(' '); + if(!$property || $property == 'name' ) $search[] = $item->name; - if(!empty($options['multilang']) && $languages) { - foreach($languages as $lang) { - $search[] = $item->getLabel($lang); + if(!$property || $property == 'label') { + if(!empty($options['multilang']) && $languages) { + foreach($languages as $lang) { + $search[] = $item->getLabel($lang); + } + } else { + $search[] = $item->getLabel(); } - } else { - $search[] = $item->getLabel(); } // when search matches field name exactly (that template has), allow template to be matched - foreach($item->fieldgroup as $field) { - if(strtolower($text) == strtolower($field->name)) $search[] = $field->name; + if($property == 'fields') { + foreach($item->fieldgroup as $field) { + if(strtolower($text) == strtolower($field->name)) $search[] = $field->name; + } + } else if($property == 'tags') { + $search[] = $item->tags; } $search = implode(' ', $search); @@ -3051,6 +3069,9 @@ class ProcessTemplate extends Process { $labelFields = sprintf($this->_n('%d field', '%d fields', $numFields), $numFields); $label = $item->getLabel(); $subtitle = $label == $item->name ? $labelFields : "$label ($labelFields)"; + + $result['total']++; + if(!empty($options['limit']) && $cnt >= $options['limit']) continue; $item = array( 'id' => $item->id, @@ -3067,9 +3088,8 @@ class ProcessTemplate extends Process { } else { $looseItems[] = $item; } - + $cnt++; - if(!empty($options['limit']) && $cnt >= $options['limit']) break; } $result['items'] = array_merge($exactItems, $looseItems);