Properly implemented new search
authorAlexander Ebert <ebert@woltlab.com>
Fri, 20 May 2016 13:20:16 +0000 (15:20 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 20 May 2016 13:20:26 +0000 (15:20 +0200)
com.woltlab.wcf/templates/pageHeaderSearch.tpl
wcfsetup/install/files/js/WoltLab/WCF/Ui/Search/Page.js

index 07403e5e07a19b61b43ab1873ceb85a34fa7ee7a..1dfe96def0e3bf29547b6bf299fa7b4b29fd96f3 100644 (file)
@@ -1,19 +1,19 @@
-{capture assign='__searchFormLink'}{link controller='Search'}{/link}{/capture}
+{capture assign='__searchLink'}{link controller='Search'}{/link}{/capture}
 
 {event name='settings'}
 
 <div id="pageHeaderSearch" class="pageHeaderSearch">
-       <form method="post" action="{@$__searchFormLink}">
+       <form method="post" action="{@$__searchLink}">
                <div id="pageHeaderSearchInputContainer" class="pageHeaderSearchInputContainer">
                        <div class="pageHeaderSearchType dropdown">
-                               <a href="#" class="button dropdownToggle">{lang}wcf.search.type.{if !$searchObjectTypeName|empty}{@$searchObjectTypeName}{else}everywhere{/if}{/lang}</a>
+                               <a href="#" class="button dropdownToggle">{lang}wcf.search.type.{if !$__searchObjectTypeName|empty}{@$__searchObjectTypeName}{else}everywhere{/if}{/lang}</a>
                                <ul class="dropdownMenu">
-                                       <li><a href="#" data-object-type="">{lang}wcf.search.type.everywhere{/lang}</a></li>
+                                       <li><a href="#" data-object-type="everywhere">{lang}wcf.search.type.everywhere{/lang}</a></li>
                                        <li class="dropdownDivider"></li>
                                        
                                        {hascontent}
                                                {content}
-                                                       {event name='searchTypesScoped'}
+                                                       {if !$__searchTypesScoped|empty}{@$__searchTypesScoped}{/if}
                                                {/content}
                                                
                                                <li class="dropdownDivider"></li>
@@ -26,7 +26,7 @@
                                        {/foreach}
                                        
                                        <li class="dropdownDivider"></li>
-                                       <li><a href="{@$__searchFormLink}">{lang}wcf.search.extended{/lang}</a></li>
+                                       <li><a href="{@$__searchLink}">{lang}wcf.search.extended{/lang}</a></li>
                                </ul>
                        </div>
                        
                                <span class="icon icon16 fa-search pointer" title="{lang}wcf.global.search{/lang}"></span>
                        </button>
                        
-                       {if !$searchObjectTypeName|empty}<input type="hidden" name="types[]" value="{$searchObjectTypeName}">{/if}
+                       <div id="pageHeaderSearchParameters"></div>
                        
                        {@SECURITY_TOKEN_INPUT_TAG}
                </div>
                
                <label for="pageHeaderSearchInput" class="pageHeaderSearchLabel"></label>
-               
-               {if !$searchObjectTypeName|empty}<input type="hidden" name="types[]" value="{$searchObjectTypeName}">{/if}
-               
-               {@SECURITY_TOKEN_INPUT_TAG}
        </form>
 </div>
 
 {if !OFFLINE || $__wcf->session->getPermission('admin.general.canViewPageDuringOfflineMode')}
        <script data-relocate="true">
                require(['WoltLab/WCF/Ui/Search/Page'], function(UiSearchPage) {
-                       UiSearchPage.init();
+                       UiSearchPage.init('{if !$__searchObjectTypeName|empty}{@$__searchObjectTypeName}{else}everywhere{/if}');
                });
        </script>
 {/if}
\ No newline at end of file
index 11e846efc0aee6bf6892c299ca7f4529af8e9cdc..522352a289df3955290cb139314062f3ccdab905 100644 (file)
@@ -1,10 +1,8 @@
-define(['Dom/Util', './Input'], function(DomUtil, UiSearchInput) {
+define(['Core', 'Dom/Util', 'Ui/SimpleDropdown', './Input'], function(Core, DomUtil, UiSimpleDropdown, UiSearchInput) {
        "use strict";
        
-       var _dropdownMenu = null;
-       
        return {
-               init: function () {
+               init: function (objectType) {
                        var searchInput = elById('pageHeaderSearchInput');
                        
                        new UiSearchInput(searchInput, {
@@ -26,6 +24,49 @@ define(['Dom/Util', './Input'], function(DomUtil, UiSearchInput) {
                                        dropdownMenu.style.setProperty('transform', 'translateX(-' + Math.ceil(offsetRight) + 'px) translateY(-' + offsetTop + 'px)', '');
                                }
                        });
+                       
+                       var dropdownMenu = UiSimpleDropdown.getDropdownMenu(DomUtil.identify(elBySel('.pageHeaderSearchType')));
+                       var callback = this._click.bind(this);
+                       elBySelAll('a[data-object-type]', dropdownMenu, function(link) {
+                               link.addEventListener(WCF_CLICK_EVENT, callback);
+                       });
+                       
+                       // trigger click on init
+                       var link = elBySel('a[data-object-type="' + objectType + '"]', dropdownMenu);
+                       Core.triggerEvent(link, WCF_CLICK_EVENT);
+               },
+               
+               _click: function(event) {
+                       event.preventDefault();
+                       
+                       var objectType = elData(event.currentTarget, 'object-type');
+                       
+                       var container = elById('pageHeaderSearchParameters');
+                       container.innerHTML = '';
+                       
+                       var parameters = elData(event.currentTarget, 'parameters');
+                       if (parameters) {
+                               parameters = JSON.parse(parameters);
+                       }
+                       else {
+                               parameters = {};
+                       }
+                       
+                       if (objectType) parameters['types[]'] = objectType;
+                       
+                       for (var key in parameters) {
+                               if (parameters.hasOwnProperty(key)) {
+                                       var input = elCreate('input');
+                                       input.type = 'hidden';
+                                       input.name = key;
+                                       input.value = parameters[key];
+                                       container.appendChild(input);
+                               }
+                       }
+                       
+                       // update label
+                       var button = elBySel('.pageHeaderSearchType > .button', elById('pageHeaderSearchInputContainer'));
+                       button.textContent = event.currentTarget.textContent;
                }
        };
 });