Add page filter for ads at global location
authorMatthias Schmidt <gravatronics@live.com>
Sat, 9 Feb 2019 14:35:58 +0000 (15:35 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 9 Feb 2019 14:35:58 +0000 (15:35 +0100)
Close #2653

wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/adAdd.tpl

index cd09681e2e1aa7e8cd8d5cba11385fcbe2835935..9dae6aad5fe2c61fd34226616eec2d93e3b71e7c 100644 (file)
@@ -2473,11 +2473,17 @@ WCF.ACP.Ad.LocationHandler = Class.extend({
        _pageConditions: null,
        
        /**
-        * select element for the page controller condition
+        * select elements for the page controller condition
         * @var jQuery[]
         */
        _pageInputs: [],
        
+       /**
+        * page controller condition container
+        * @var jQuery[]
+        */
+       _pageSelectionContainer: null,
+       
        /**
         * Initializes a new WCF.ACP.Ad.LocationHandler object.
         * 
@@ -2491,42 +2497,71 @@ WCF.ACP.Ad.LocationHandler = Class.extend({
                
                this._variablesDescriptionsList = $('#ad').next('small').children('ul');
                
-               var dl = $(this._pageInputs[0]).parents('dl:eq(0)');
+               this._pageSelectionContainer = $(this._pageInputs[0]).parents('dl:eq(0)');
                
                // hide the page controller elements
-               dl.prev('dl').hide();
-               dl.hide();
+               this._hidePageSelection(true);
+               
+               $('#objectTypeID').on('change', $.proxy(this._setPageController, this));
+               
+               this._setPageController();
+               
+               $('#adForm').submit($.proxy(this._submit, this));
+       },
+       
+       /**
+        * Hides the page selection form field.
+        * 
+        * @since       5.2
+        */
+       _hidePageSelection: function(addEventListeners) {
+               this._pageSelectionContainer.prev('dl').hide();
+               this._pageSelectionContainer.hide();
+               
+               // fix the margin of a potentially next page condition element
+               this._pageSelectionContainer.next('dl').css('margin-top', 0);
                
-               var section = dl.parent('section');
+               var section = this._pageSelectionContainer.parent('section');
                if (!section.children('dl:visible').length) {
                        section.hide();
+                       
+                       var nextSection = section.next('section');
+                       if (nextSection) {
+                               nextSection.css('margin-top', 0);
+                               
+                               if (addEventListeners) {
+                                       require(['EventHandler'], function(EventHandler) {
+                                               EventHandler.add('com.woltlab.wcf.pageConditionDependence', 'checkVisivility', function() {
+                                                       if (section.is(':visible')) {
+                                                               nextSection.css('margin-top', '40px');
+                                                       }
+                                                       else {
+                                                               nextSection.css('margin-top', 0);
+                                                       }
+                                               });
+                                       });
+                               }
+                       }
                }
+       },
+       
+       /**
+        * Shows the page selection form field.
+        * 
+        * @since       5.2
+        */
+       _showPageSelection: function() {
+               this._pageSelectionContainer.prev('dl').show();
+               this._pageSelectionContainer.show();
+               this._pageSelectionContainer.next('dl').css('margin-top', '40px');
+               
+               var section = this._pageSelectionContainer.parent('section');
+               section.show();
                
                var nextSection = section.next('section');
                if (nextSection) {
-                       var marginTop = nextSection.css('margin-top');
-                       nextSection.css('margin-top', 0);
-                       
-                       require(['EventHandler'], function(EventHandler) {
-                               EventHandler.add('com.woltlab.wcf.pageConditionDependence', 'checkVisivility', function() {
-                                       if (section.is(':visible')) {
-                                               nextSection.css('margin-top', marginTop);
-                                       }
-                                       else {
-                                               nextSection.css('margin-top', 0);
-                                       }
-                               });
-                       });
+                       nextSection.css('margin-top', '40px');
                }
-               
-               // fix the margin of a potentially next page condition element
-               dl.next('dl').css('margin-top', 0);
-               
-               $('#objectTypeID').on('change', $.proxy(this._setPageController, this));
-               
-               this._setPageController();
-               
-               $('#adForm').submit($.proxy(this._submit, this));
        },
        
        /**
@@ -2534,29 +2569,38 @@ WCF.ACP.Ad.LocationHandler = Class.extend({
         */
        _setPageController: function() {
                var option = $('#objectTypeID').find('option:checked');
+               var parent = option.parent();
                
-               require(['Core'], function(Core) {
-                       var input, triggerEvent;
+               // the page controller can be explicitly set for global positions
+               if (parent.is('optgroup') && parent.data('categoryName') === 'com.woltlab.wcf.global') {
+                       this._showPageSelection();
+               }
+               else {
+                       this._hidePageSelection();
                        
-                       // select the related page
-                       for (var i = 0, length = this._pageInputs.length; i < length; i++) {
-                               input = this._pageInputs[i];
-                               triggerEvent = false;
+                       require(['Core'], function(Core) {
+                               var input, triggerEvent;
                                
-                               if (option.data('page') && elData(input, 'identifier') === option.data('page')) {
-                                       if (!input.checked) triggerEvent = true;
+                               // select the related page
+                               for (var i = 0, length = this._pageInputs.length; i < length; i++) {
+                                       input = this._pageInputs[i];
+                                       triggerEvent = false;
                                        
-                                       input.checked = true;
-                               }
-                               else {
-                                       if (input.checked) triggerEvent = true;
+                                       if (option.data('page') && elData(input, 'identifier') === option.data('page')) {
+                                               if (!input.checked) triggerEvent = true;
+                                               
+                                               input.checked = true;
+                                       }
+                                       else {
+                                               if (input.checked) triggerEvent = true;
+                                               
+                                               input.checked = false;
+                                       }
                                        
-                                       input.checked = false;
+                                       if (triggerEvent) Core.triggerEvent(this._pageInputs[i], 'change');
                                }
-                               
-                               if (triggerEvent) Core.triggerEvent(this._pageInputs[i], 'change');
-                       }
-               }.bind(this));
+                       }.bind(this));
+               }
                
                this._variablesDescriptionsList.children(':not(.jsDefaultItem)').remove();
                
@@ -2575,7 +2619,7 @@ WCF.ACP.Ad.LocationHandler = Class.extend({
                        // of these conditions
                        this._pageConditions.find('select, input').remove();
                }
-               else {
+               else if (this._pageSelectionContainer.is(':hidden')) {
                        // reset page controller conditions to avoid creation of
                        // unnecessary conditions
                        for (var i = 0, length = this._pageInputs.length; i < length; i++) {
index d583b758113225361ee3bcff3fc1d4eb33c721c4..c0e121044667e38d5eb211cc697942e40a98218f 100644 (file)
@@ -76,7 +76,8 @@
                                <select name="objectTypeID" id="objectTypeID">
                                        <option value="0"{if !$objectTypeID} selected{/if}>{lang}wcf.global.noSelection{/lang}</option>
                                        {foreach from=$locations key='locationGroupLabel' item='locationGroup'}
-                                               <optgroup label="{$locationGroupLabel}">
+                                               {assign var='__firstLocationID' value=$locationGroup|key}
+                                               <optgroup label="{$locationGroupLabel}" data-category-name="{@$locationObjectTypes[$__firstLocationID]->categoryname}">
                                                        {foreach from=$locationGroup key='locationID' item='location'}
                                                                <option value="{@$locationID}"{if $locationObjectTypes[$locationID]->page} data-page="{$locationObjectTypes[$locationID]->page}"{/if}{if $objectTypeID == $locationID} selected{/if}>{$location}</option>
                                                        {/foreach}