Page 1 of 1

Weird Request..

PostPosted: Thu Dec 16, 2010 8:10 am
by digital1
I know this may be a bit weird, but is there a way in the Event's calendar to have the link go directly to the edit screen instead of the right side panel view that shows the event details? I have a client that wants the linked event on the calendar to just go to the edit form.

Re: Weird Request..

PostPosted: Thu Dec 16, 2010 11:46 am
by shannah
You should be able to do this by overriding the Dataface.Calendar.Event.prototype.getDescription function.

e.g.

Create a javascript file "calendar-override.js":
Code: Select all
jQuery(document).ready(function($){
    Dataface.Calendar.Event.prototype.getDescription = function(){
        window.location.href=DATAFACE_SITE_HREF+'?-action=edit&-recordid='+encodeURIComponent(this.record_id);
    };
});


Then Add appropriate javascript files to the head of the document by adding the following to your application delegate class:
Code: Select all
function beforeHandleRequest(){
    $app = Dataface_Application::getInstance();
    $query =& $app->getQuery();
    if ( $query['-action'] == 'calendar' ){
         $app->addHeadContent('<script src="'.DATAFACE_URL.'/js/jquery.packed.js"></script>');
         $app->addHeadContent('<script src="'.DATAFACE_SITE_URL.'/calendar-override.js"></script>');
    }
}



(Note this snippet hasn't been tested so undoubtedly contains a few bugs... but this is the right idea).

-Steve

Re: Weird Request..

PostPosted: Mon Dec 20, 2010 9:22 am
by digital1
Greetings Steve,

Thanks for the quick response. I have been trying to get it to work, this is what I have so far:

This is the Application delegate
Code: Select all
   if ( $query['-table'] == 'show' and $app->_conf['using_default_action'] ){
            $query['-action'] = 'calendar';
         $app->addHeadContent('<script src="'.DATAFACE_URL.'/js/jquery.packed.js"></script>');
          $app->addHeadContent('<script src="'.DATAFACE_SITE_URL.'/calendar-override.js"></script>');
       
       }






Here is my JS

Code: Select all
jQuery(document).ready(function($){
        //window.location.href=DATAFACE_SITE_HREF+'?-action=edit&-recordid='+encodeURIComponent(this.record_id);
       
        Dataface.Calendar.prototype.drawMonth = function () {
    var firstDay = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth(), 1);
    var out = '<table class="Dataface-Calendar-month" cellspacing="0"><thead><tr><th>' + Date.daysOfWeek.join('</th><th>') + '</th></tr></thead>';
    out += '<tbody>';
    var day = -1;
    for (var i = 0; i < 5; i++) {
        out += '<tr>';
        for (var j = 0; j < 7; j++) {
            if ((day == -1) && (firstDay.getDay() == j)) {
                day = 0;
            }
            if (day == this.selectedDate.daysInMonth()) {
                day = -1;
            }
            var cls = '';
            if (day >= 0) cls = 'Dataface-Calendar-day';
            else cls = 'Dataface-Calendar-empty-day';
            out += '<td class="' + cls + '"><div class="day-wrapper"';
            if (day >= 0) {
                var currDay = this.selectedDate.clone();
                currDay.setDate(day + 1);
                out += '<div class="day-number"><a href="javascript:Dataface.Calendar.getInstance(\'' + this.id + '\').handleSelectDay(\'' + currDay.toString() + '\')">' + (day + 1) + '</a></div>';
                var events = this.events.day(currDay);
                for (var k = 0; k < events.length; k++) {
                      var link=DATAFACE_SITE_HREF+'?-action=edit&-recordid='+encodeURIComponent(this.record_id);
                    out += '<div class="Dataface-Calendar-event" id="event-preview-' + events[k].id + '"><a href="'+link+'">' + events[k].title + '</a></div>';
                }
                day++;
            }
            out += '</div></td>';
        }
        out += '</tr>';
    }
       out += '</tbody></table>';
    return out;
       
       
       
    };
});



Am I doing something wrong here? I am not seeing the change happen in the calendar. I did notice that some interesting path info got set in the generated HTML.

Re: Weird Request..

PostPosted: Fri Jan 14, 2011 12:30 pm
by shannah
Hard to say what is going wrong... overriding the entire drawMonth method may be more extreme than necessary. Is overriding just the description not sufficient?