I'm unsure if this had been discussed, I have not found it in the issue queue.

Like with many other calendar systems, often when you're viewing a calendar which you can edit, you should be able to generally click on one of the dates in that calendar to create a new event node with the corresponding date field prefilled to the date clicked. I am aware of the 'Add event' link that you can put at the top of the display, but in that case you still have to fill in the date manually.

Is this feature possible? Is it planned?

Thanks for your valuable time.

Comments

apoc1’s picture

I've been searching for a solution to this for a long time now, anyone who knows how to get this function working?

tmsimont’s picture

I'm actually currently working on this very feature as a stand-alone module. What I've been working on is much more complex, but as part of my effort I spent a lot of time making the calendar plugin style more extensible.

If you use this patch:
http://drupal.org/node/1908018#comment-7035384

and then create a new module that implements hook_views_plugins (I used a module called "pattern"):


/**
 * @file
 *
 * Creates pattern displays of Views results.
 */
/**
 * Implementation of hook_views_plugins
 */
function pattern_views_plugins() {
  $views_path = drupal_get_path('module', 'views');
  $calendar_path = drupal_get_path('module', 'calendar');
  $module_path = drupal_get_path('module', 'pattern');
  $theme_path = $module_path;
  module_load_include('inc', 'pattern', 'theme/theme');

  // Limit these plugins to base tables that represent entities.
  $base = array_keys(date_views_base_tables());

  $data = array(
    'module' => 'pattern', // This just tells our themes are elsewhere.

    'style' => array(
      'pattern_calendar_style' => array(
        'title' => t('Calendar manager'),
        'help' => t('Present view results as a manageable Calendar.'),
        'handler' => 'pattern_plugin_style',
        'path' => "$module_path/includes",
        'theme' => 'calendar_style',
        'theme file' => 'theme.inc',
        'theme path' => "$calendar_path/theme",
        'additional themes' => array(
          'calendar_mini' => 'style',
          'calendar_day' => 'style',
          'calendar_week' => 'style',
          'calendar_month' => 'style',
          'calendar_year' => 'style',
          'calendar_day_overlap' => 'style',
          'calendar_week_overlap' => 'style',
        ),
        'uses fields' => TRUE,
        'uses grouping' => FALSE,
        'uses row plugin' => TRUE,
        'uses options' => TRUE,
        'type' => 'normal',
        'even empty' => TRUE,
        'base' => $base,
      ),
    ),
  );
  return $data;
}

Then in a file called "includes/pattern_style_plugin.inc" you can use something like this code:

class pattern_plugin_style extends calendar_plugin_style {
  function get_builder() {
    $builder_type = 'pattern_builder_' . $this->options['calendar_type'];
    return new $builder_type($this);
  }
}

class pattern_builder_month extends calendar_builder_month {
  function get_week_builder() {
    return new pattern_builder_week($this->plugin);
  }
}

class pattern_builder_week extends calendar_builder_week {
  function get_day_builder($wday) {
    return new pattern_builder_day_weekday($this, $wday);
  }
}

class pattern_builder_day_weekday extends calendar_builder_day_weekday {
  function calendar_build_day() {
    parent::calendar_build_day();
    $this->week->add_singleday_bucket($this->wday, "BUCKET!");
  }
}

Notice in that last part, I'm injecting the text "BUCKET!" into the calendar at each day of a month. This will only work on a month view, I haven't get it set up for year/week/day yet.

There's a property of the "weekday" called $this->plugin. You can use $this->plugin->curday to get the current date and replace the text "BUCKET" with a link to add a date. You'll have to pass the date with a query string or a special arugment or something... still a lot to do between the code I've got and what you need but hopefully that's helpful

I'll post back anything I put up online regarding that stand-alone module I'm building.

apoc1’s picture

Interesting code you got there! I didn't think that far (maybe as my php knowledge is little..). Will you submit your stand-alone module to the community? Otherwise, I just wait till you post it, before I get messing in php..

tmsimont’s picture

Ya i re-read that and it's pretty intense haha - I definitely plan on posting the stand-alone. I'm hoping to do so soon, but i should warn that its a bit complex

hazah’s picture

Is there a link yet? Chances are we could make use of it and contribute back based on use cases.

tmsimont’s picture

I will try to put up a sandbox today, but it might not be ready until early next week

tmsimont’s picture

in the mean time, you could create a simple module that uses hook_form_alter on your date-containing entity to look for a query string -- then the calendar td with a "single-day" class already has "data-date" attribute. You could use jQuery to write in a link to each td:

$(".single-day").each(function() {
  var date = $(this).data("date");
  var link = "<a href='/node/add/type?date=" + date + "'>Add</a>";
  $(this).append(link);
});
hazah’s picture

I don't like query strings :). I'm sure a path would do fine. Thanks!

tmsimont’s picture

ok here it is:
http://drupal.org/sandbox/tmsimont/1917664

please take a look and let me know. i'd love some help with this thing.

hazah’s picture

Cool, will do.

adamtong’s picture

I also want the feature to click on calendar date to create events!!

Thank you!

tictac42’s picture

Assigned: Unassigned » tictac42
Category: feature » support

I am currently in dev, and trying to click events on my calendar to view nodes that I have already established (logged in as Admin). Is there a way to toggle between clicking the calendar to add events, and clicking the titles to view the nodes, I imagine somewhere in configuration? I am pretty new to Drupal...
thanks!

dmadruga’s picture

+1

Alcaparra’s picture

+1

adityaj’s picture

var link = "Add"; doesn't open the date content type with the date , it rather open "Add Content Page". Wonder where i am going wrong!

bleeuwen’s picture

Issue summary: View changes

In addition to #7

(function($){
$(document).ready(function(){
$(".single-day").each(function() {
var date = $(this).data("date");
if (date) {
var link = "+";
$(this).append(link);}
});
});
})(jQuery)

Randeep.Singh’s picture

I am looking for this functionality. It is still under development. Is there any other way to achieve this functionality? if possible please provide information in this regard.

Neslee Canil Pinto’s picture

Status: Active » Closed (outdated)