i added this code as php code in a basic page, but the page does not show the availability calendar of node 1?

<?php
  // Add js script and settings for the viewport and the buttons
  $node = node_load(1);
  $viewport_settings = array(
    'settings' => array(
      'month' => array('width' => 231, 'height' => 247),
      'viewport' => array('cols' => 3, 'rows' => 2),
      'step' => array('cols' => 0, 'rows' => 1)
    ),
    'backwardSelector' => '#ac-up',
    'forwardSelector' => '#ac-down',
  );
  availability_calendars_add_js($node, $viewport_settings, 'viewport');
?>

Comments

fietserwin’s picture

Status: Active » Closed (works as designed)

The viewport only wraps some div's around the calendar, and attaches some js functionality to that. It does not render the calendar itself. That should be done by rendering the node or by calling the theme function yourself.

ronajon’s picture

i added the script to the node.tpl.php of my template, but still the calendar does not show?

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
  <?php print render($title_prefix); ?>
  <?php if (!$page): ?>
    <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
  <?php endif; ?>
  <?php print render($title_suffix); ?>

  <div class="content"<?php print $content_attributes; ?>>
    <?php
      // We hide the comments and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
      print render($content);
    ?>
  </div>

  <?php print render($content['links']); ?>

  <?php print render($content['comments']); ?>

<?php

  // Add js script and settings for the viewport and the buttons
  $viewport_settings = array(
    'settings' => array(
      'month' => array('width' => 231, 'height' => 247),
      'viewport' => array('cols' => 3, 'rows' => 2),
      'step' => array('cols' => 0, 'rows' => 1)
    ),
    'backwardSelector' => '#ac-up',
    'forwardSelector' => '#ac-down',
  );
  availability_calendars_add_js($node, $viewport_settings, 'viewport');
?>
</div>
fietserwin’s picture

Status: Closed (works as designed) » Postponed (maintainer needs more info)

It works with me (I even moved the code to the node.tpl.php), so I need more information. Are you using the latest dev version? What browser? Did you debug the code, are these lines executed before the js is emitted? ...

ronajon’s picture

the version i'm using is 7.x-2.x-dev

in my previous post the whole node.tpl.php is shown. i just tried adding print theme('availability_calendars_node'); as a last line but that didn't work. instead it gave the message
Notice: Trying to get property of non-object in theme_availability_calendars_node() (line 54 of /var/www/hongarijetours/sites/all/modules/availability_calendars/availability_calendars.page.inc).

before the of my page source is

  <script type="text/javascript">
<!--//--><![CDATA[//><!--
Drupal.behaviors.availabilityCalendarsViewport0 = {
        attach: function(context, settings) {
          Drupal.availabilityCalendars.viewport0 = new Drupal.availabilityCalendars.Viewport(
            Drupal.availabilityCalendars.get(settings.availabilityCalendars.viewport0.nid,
              settings.availabilityCalendars.viewport0.settings),
            settings.availabilityCalendars.viewport0.viewport.settings,
            settings.availabilityCalendars.viewport0.viewport.backwardSelector,
            settings.availabilityCalendars.viewport0.viewport.forwardSelector
          );
        }
      };
//--><!]]>
</script>

moving the code to page.tpl.php didn't work either

fietserwin’s picture

Back to the basics:
- the calendar is not showing. The viewport only adds wrappers around it, so without that code the calendar is still not showing: am I correct?
[- the print(theme(...)) line will certainly fail as the required information is not passed in.]
- there is an option to disable automatic rendering/theming of the calendar on the node. What is its value?
[- Dev versions are running targets: so a dev version only becomes defined by its download date]
- Do all content types have calendar enabled? Because I don't see any checking on the content type of the node in the template file.

ronajon’s picture

in order of your questions / remarks
- i disabled the calendar through the configuration pages for all content types, the calendar doesn't show (figures)
then i re-enabled the calendar on my custom content page. The calendar now is shown, but the viewport wrapper not (see #2)
- the setting 'Show automatically on node page' is enabled
- the setting 'Allow to override settings per node' is disabled
- only the custom content type has the calendar, i have also a nodd--custom_contenttype.tpl.php file for that contenttype (code of #2)

fietserwin’s picture

I'm sorry, but it is very hard for me, from a distance, to guess what could go wrong. Can you please debug the html and javascript using firebug or any other inspect tool?

To be sure: do you have the latest dev version? That is the dev version from july 8? If changelog.txt contains the message: "Issue #1211782: Multiple errors with calendars on multilingual sites by fietserwin: errors with multilingual calendars. Partly solved: cache and delete are still open." near the top you have the latest dev version. if not and your site is multilingual, that may well be the source of your problem.

If that is not the case:
- Do you have any idea why the node now shows but did not do so before you disabled and re-enabled the calendar for the given type?
- Can you have a look with an html inspector to see if there are divs with a class like "availability-calendars-viewport" or "availability-calendars-viewport-inner" around the calendar?
- Can you set set a breakpoint on the javascript code in file availability_calendars.view.js, at line 87 to see what settings are passed in?
- What browser version are you using?

ronajon’s picture

hi,
just checked your questions

- my dev version if of july 8th
- i have no multilanguage site
- the node always showed, with and without the calendar enabled
- i have two div's

<div class="availability-calendars-viewport" style="width: 693px; height: 494px;"><div class="availability-calendars-viewport-inner">

-here's the debugging info from the settings variable in the js

settings
	Object { month={...}, viewport={...}, step={...}}
	
month
	Object { width=231, height=247}
	
height
	247
	
width
	231
	
step
	Object { cols=0, rows=1}
	
cols
	0
	
rows
	1
	
viewport
	Object { cols=3, rows=2}
	
cols
	3
	
rows
	2
	
viewport
	undefined
fietserwin’s picture

(Sorry, i meant "- Do you have any idea why the calendar now shows but did not do so before you disabled and re-enabled the calendar for the given type?")

- The div's are there: so the viewport is there!
- The outer div has a style attribute: thus the js code is executing correctly at least up to line 123!

So the viewport is showing. Apparently you are expecting some other result than what you see. This is probably because it is a very recent feature which is not very well documented, except the description in the js file.

For an impression of what the viewport does, please visit the "Try out a demonstration" site (I updated the project page yesterday): http://www.maisonnera.eu/en/holiday-home/les-camelias and go to the "Prices & reservations" tab. Click "next 3 months" and "previous 3 months" to see how only 6 out of 12 months are shown while the other months are hidden by the outer viewport div.

for this to work:
- You need to define the buttons yourself, that's why you have to pass them in. (I'm thinking of a way to incorporate them, but that would mean other options,something like "button placement").
- These settings in availability_calendars.base.css must not be overruled by cascading styles:

.availability-calendars-viewport {
  position: relative;
  overflow: hidden;
}

.availability-calendars-viewport-inner {
  position: relative;
  top: 0;
  left: 0;
  overflow: visible;
}

- The width and height setting must be the actual width and height of the months (including margin and padding). Because the months may be hidden initially, because they are on a closed tab or in a collapsed fieldset. I cannot use jQuery to ask for the width and height. So they need to be passed in by you.

I hope this further explains the situation and that you can now see what else you have to do to really see the viewport in action.

ronajon’s picture

i now see i'm missing the buttons.
i added

<div class="ac-move"><a id="ac-up" disabled="disabled">Voorgaande 3 maanden</a><a id="ac-down">Volgende 3 maanden</a></div>

to my tpl.php file.

The buttons now show, the source code of my page now shows the buttons, but both are disabled? how to enable the click-event to it? Does it activate automatically or do i need to add some extra html and/or javascript?

ronajon’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

got it working. I had the maximum number of months to display set to 5 in the availability calendar configuration. That was why the scrolling didn't work, because i set the viewport number of cols / rows to 6 (3*2)

i modified the configuration to 12 maximum months and now the calendar viewports scrolls like on the maisonnera.eu site

now i'm up to styling the calendars and buttons

great looking functionality, thanks for all the support and patience.

fietserwin’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

If you pass in the selectors, it should work without further action form your site. Thus no need to set one to disabled. Note however that if you don't provide an href attribute on an a-tag, it will be seen as defining an anchor, not as a link and thus the cursor will not change when hovering over it. However, I guess that the click event should still be working.

fietserwin’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

cross posted ...