The new reset button doesnt seem to work properly. I hit reset and then ok it showed the block, i hit f5 its hidden again "display:none". I am logged in as admin.

Comments

marcoka’s picture

well. i reset it. visit the page, block shows, i hit f5, settings are written to the db (without hitting the close button)
http://www.root.artwaves.de/screensnapr/1352842558-rrHUJ9.jpg

so no wonder it just sets the db value (that it should be closed) without hitting the close button.

marcoka’s picture

the same is for anonymous users, hit f5 and block is gone.

it just calls closeblock_ajax_callback() on f5 and there is closeblock_closing_info_set($params); called.
this function should only be called by the CLOSE button right?

marcoka’s picture

Priority: Normal » Major

tested with a clean install and garland. hit f5 block gone. this makes the module non-functional.

marcoka’s picture

i did some debugging

if (info.save) {
            var
             _path = Drupal.settings.basePath + ['closeblock', info.module, info.delta].join('/');
            $.post(_path);
          }

info.save is always true if you enabled "saving stat for the user" and so it will trigger the callback  $items['closeblock/%/%'] = array( .... 
which runs 
function closeblock_ajax_callback($module, $delta) {... and that runs
closeblock_closing_info_set($params) and soithe state is set to CLOSED after a reload of the page.

disabling the "save state" option. module works as expected. so the save state logic is broken.

marcoka’s picture

problem is that the callback is called on page request and not by clicking the button.
well i found the error and pulled me the 7.x from git as i wanted to patch this, as i see you fixed it there. could you please set the correct version to stable as the current 1.4 is broken.

marcoka’s picture

Status: Active » Needs review

well the master and 7.x do not seem to have the save function,so no patch with git. here is the fix, you want the ajax post that triggers the ajax callback INSIDE the click button function

CURRENTLY, the ajax callback is called on pageload, thats wrong. clicking the buttn should trigger it.

(function($) {

  Drupal.behaviors.closeblock = {

    attach: function (context, settings) {
      
      if (settings.closeblock == undefined) {
        return;
      }
      
      $.each(settings.closeblock, function(id, info) {
        $('#'+ id  + ':not(.closeblock-processed)', context).addClass('closeblock-processed').each(function() {
          var
            $block = $(this);
            
          if (info.closed) {
            $block.hide();
            return;
          }
          
          var
            $close_buttton = $('<span />').addClass('closeblock-button').html('close'),
            $close_contaier = $('<div />').addClass('closeblock').append($close_buttton);
          
          $block.prepend($close_contaier);
          
          $close_buttton.click(function() {
            if (info.type) {
              $block[info.type](info.speed);
            }
            else {
              $block.hide();
            }
          });
          
          if (info.save) {
            var
             _path = Drupal.settings.basePath + ['closeblock', info.module, info.delta].join('/');
            $.post(_path);
          }
        });
      });
      
    }

  };
  
})(jQuery);

CHANGE TO THIS, putting the ajax callback INSIDE the click function.

(function($) {

  Drupal.behaviors.closeblock = {

    attach: function (context, settings) {
      
      if (settings.closeblock == undefined) {
        return;
      }
      
      $.each(settings.closeblock, function(id, info) {
        $('#'+ id  + ':not(.closeblock-processed)', context).addClass('closeblock-processed').each(function() {
          var
            $block = $(this);
            
          if (info.closed) {
            $block.hide();
            return;
          }
          
          var
            $close_buttton = $('<span />').addClass('closeblock-button').html('close'),
            $close_contaier = $('<div />').addClass('closeblock').append($close_buttton);
          
          $block.prepend($close_contaier);
          
          $close_buttton.click(function() {
            if (info.type) {
              $block[info.type](info.speed);
            }
            else {
              $block.hide();
            }

          if (info.save) {
              var
                  _path = Drupal.settings.basePath + ['closeblock', info.module, info.delta].join('/');
              $.post(_path);
          }
          });
          
       
        });
      });
      
    }

  };
  
})(jQuery);

skifdesu’s picture

Status: Needs review » Closed (fixed)

Fixed. Please check for new release.

marcoka’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review

tested the module again today. reset is still not working, block stays hidden. can anyone confirm this?

marcoka’s picture

i actually found the problem:

/**
 * Form submission handler for Reset button.
 *
 * @see closeblock_settings_elements()
 */
function closeblock_reset_submit($form, &$form_state) {
  switch ($form['#id']) {
    case 'system-theme-settings':
      $params = array(
        'theme' => $form_state['values']['theme'],
      );
      break;
    case 'block-admin-configure':
      $params = array(
        'module' => $form_state['values']['module'],
        'delta' => $form_state['values']['delta'],
      );
      break;
  }
  if (!empty($params)) {
    closeblock_db_delete($params);
  }
}

This will not work if you use a subteheme like omega/zen or adaptive theme because then there is no $form_state['values']['theme']
so basically rest will not work if done on admin/appearance/settings but it will work if you hit the reset button in the block settings.

  • hoter committed 7494e13 on 7.x-1.x
    Issue #1839804 by marcoka: fix reset function
    
  • hoter committed 93dd918 on 7.x-1.x
    Issue #1839804 by marcoka: fix reset function
    
hoter’s picture

Status: Needs review » Closed (fixed)

Please have a look at the latest version of the module (7.x-1.6).