morning mate,

I've included the Js Calendar code successfully in a few applications.
You might be able to use the method I have employed.

1. Structure
- Put the `jscalendar` dir in your `vendors` directory (at the same
level as your Cake dir).
- Put the `jscalendar` dir in your `js` directory (within your webroot)
- NOTE: you probably only need the calendar.php file in part 1 of this
step, but for now just drop the whole thing in there

2. Component
- I've put my calendar code in a component as I use it quite often
- Create a calendar component (or I've created a general form
component) and include the following function

   /**
    *
    * Allows a form to include calendar elements
    *
    * @return boolean success
    */
   function initCalendar()
   {
       // include required vendors
       vendor('jscalendar/calendar');
       $calendar_lang = 'en';
       $calendar = new DHTML_Calendar($this->controller->base .
'/js/jscalendar/', $calendar_lang, 'calendar-win2k-2', false);
       $this->controller->set('calendar', $calendar);

       // set any header elements that may be required
       if (isset($this->controller->Header))
       {
           
$this->controller->Header->addHeader($calendar->get_load_files_code());
       }
       else
       {
        $this->controller->set('headers', $calendar->get_load_files_code());
       }

   }

- NOTE: I use an additional Header component in the above code, you
will need to remove reference to it.

3. Controller
- Now we have this code wrapped up nicely you can call it wherever you like
- e.g.

       // init calendar
       $this->ExtForm->initCalendar();

- NOTE: My component is called ExtForm
- NOTE: don't forget to include your component in the controller that
calls it using the $components variable.

4. Layout
- In your layout you need to include the headers required for the calendar
- we set these in our component earlier
- NOTE: I'm using a helper again, you'll need to remove that code and
just output the $headers value

<?php if (isset($headers)) $header->generateHeaders($headers); ?>

5. View / Helper
- Again, I've packaged my code so I can reuse it all the time.
- My method of doing this is fairly cumbersome and has quickly become
outdated since the release of CakePHP v1.2 so I will try and summarize
with some code snippets.
- Basically, have a look at the calendar.php file and you can see how
it goes about outputting a calendar field. I also created a function
called get_input_field that returned the rendered input field as a
string as opposed to outputting it.

           $calendarOptions = array(
               'firstDay'       => 1, // show Monday first
               'showsTime'      => false,
               'showOthers'     => true,
               'ifFormat'       => '%Y-%m-%d',
               'daFormat'       => '%Y-%m-%d',
               'timeFormat'     => '12',
               'align'          => 'cR'
           );

          $calendar->get_input_field($calendarOptions,$calendarFieldAttributes);

- NOTE: set $calendarFieldAttributes to represent the attributes of
the text field to go along side the calendar.

I think that about covers it. I may have forgotten something, and the
instructions get a bit patchy towards the end - my apologies. The way
I've done it (in total) is too bulky to include here. I need to
streamline my code a lot more. Hope to do this when I venture in to
1.2.

Good luck,
mikee

On 06/01/07, keymaster <[EMAIL PROTECTED]> wrote:

Can someone please offer some instruction on how to get my javascript
popup menu working within cake?

The calendar javascript files are contained in:
----------------------------------------------------------------
webroot/js/jscalendar-1.0/


In the header of my views/layout, I have:
----------------------------------------------------------

<link rel="stylesheet" type="text/css" media="all"
href="calendar-win2k-cold-1.css" title="win2k-cold-1" />

<script type="text/javascript" src="<?php echo
$html->url('/js/jscalendar-1.0/calendar.js'); ?>"></script>

<script type="text/javascript" src="<?php echo
$html->url('/js/jscalendar-1.0/lang/calendar-en.js'); ?>"></script>

<script type="text/javascript" src="<?php echo
$html->url('/js/jscalendar-1.0/calendar-setup.js'); ?>"></script>


To invoke the calendar I do:
----------------------------------------

<script type="text/javascript">
Calendar.setup({
    inputField     :    "f_date_b",
    ifFormat       :    "%m/%d/%Y %I:%M %p",
    showsTime      :    true,
    button         :    "f_trigger_b",
    singleClick    :    false,
    step           :    1   });
</script>


I am not at the stage where I want to get back the parameters from the
dates selected. Just want the javascript invoked (so I  can see the
popup calendar).

Any help will be appreciated. Thx.


>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to