Dynamically updating calendar fields if not part of store

Plugins and extensions for Extensible components, usage examples, links to applications using Extensible, etc.

Dynamically updating calendar fields if not part of store

Postby rmasud » Fri Apr 20, 2012 4:56 am

Hi All;

In case you have a db which does not support kep calendar fields, we can create/update data on fly for calendar fields like..id, cid, startDate, endDate etc
In the code below, we did not have calender id, event id, startDate, endDate, Title... using conver:function(), you can utilize available data coming from db to create necessary info for creating events and calendar..

Code: Select all
 
Extensible.calendar.data.EventMappings = {
            EventId: {
                name: 'ID',
                mapping: 'evt_id',
                type: 'string',
                convert: function(newValue, model) {
                    return Ext.Date.format(model.data.TransDate, 'Ymd').toString() + '-' + model.data.TimeFrom.toString() + '-' + model.data.TimeTo.toString();
                }
            },
            CalendarId: {
                name: 'CalID',
                mapping: 'cal_id',
                type: 'string',
                convert: function(newValue, model) {
                    return '1';
                }
            },
            Title: {
                name: 'EvtTitle',
                mapping: 'evt_title',
                convert: function(newValue, model) {
                    return 'Normal Hours';
                }
            },
            StartDate: {
                name: 'StartDt',
                mapping: 'start_dt',
                type: 'date',
                dateFormat: 'c',
                convert: function(newValue, model) {
                    debugger;
                    var timeFrom = model.data.TimeFrom.toString();
                    var hours;
                    if (timeFrom.length == 3)
                        hours = timeFrom.substr(0, 1);
                    else
                        hours = timeFrom.substr(0, 2);

                    var mins = model.data.TimeFrom.toString().substr(2, 3);
                    var date = Ext.Date.clearTime(new Date());
                    return Ext.Date.add(date, Ext.Date.SECOND, parseInt(hours) * 3600 + parseInt(mins) * 60);
                }
            },
            EndDate: {
                name: 'EndDt',
                mapping: 'end_dt',
                type: 'date',
                dateFormat: 'c',
                convert: function(newValue, model) {
                    debugger;
                    var timeTo = model.data.TimeTo.toString();
                    var hours;
                    if (timeTo.length == 3)
                        hours = timeTo.substr(0, 1);
                    else
                        hours = timeTo.substr(0, 2);

                    var mins = timeTo.substr(2, 3);

                    var date = Ext.Date.clearTime(new Date());
                    return Ext.Date.add(date, Ext.Date.SECOND, parseInt(hours) * 3600 + parseInt(mins) * 60);
                }
            },
            RRule: { name: 'RecurRule', mapping: 'recur_rule' },
            Location: { name: 'Location', mapping: 'location' },
            Notes: {
                name: 'Desc',
                mapping: 'full_desc',
                convert: function(newValue, model) {
                    return 'Normal Hours';
                }
            },
            Url: { name: 'LinkUrl', mapping: 'link_url' },
            IsAllDay: { name: 'AllDay', mapping: 'all_day', type: 'boolean' },
            Reminder: { name: 'Reminder', mapping: 'reminder' },

            // We can also add some new fields that do not exist in the standard EventRecord:
            CreatedBy: { name: 'CreatedBy', mapping: 'created_by' },
            IsPrivate: { name: 'Private', mapping: 'private', type: 'boolean' },
            Client: { name: 'Client', mapping: 'client', type: 'string' },
            ResourceId: { name: 'ResourceId', mapping: 'resourceId', type: 'string' },
            PostId: { name: 'PostId', mapping: 'postId', type: 'string' },
            TransDate: { name: 'TransDate', mapping: 'transDate', type: 'date' },
            TimeFrom: { name: 'TimeFrom', mapping: 'timeFrom', type: 'int' },
            TimeTo: { name: 'TimeTo', mapping: 'timeTo', type: 'int' },
            NormalHours: { name: 'NormalHours', mapping: 'normalHours', type: 'double' }
        };
Extensible.calendar.data.EventModel.reconfigure();
rmasud
Premium Member
Premium Member
 
Posts: 19
Joined: Mon Apr 16, 2012 6:49 am

Re: Dynamically updating calendar fields if not part of stor

Postby brian.moeskau » Tue Apr 24, 2012 8:01 pm

Thanks for sharing this example (I've moved it into the Examples forum).
Personal Blog: Extraneous / Twitter: @bmoeskau / Meetup: Austin Bleeding Edge Web
User avatar
brian.moeskau
Site Admin
Site Admin
 
Posts: 1344
Joined: Sat Sep 18, 2010 5:00 pm
Location: Austin, Texas


Return to Plugins, Examples & Extras

Who is online

Users browsing this forum: No registered users and 1 guest

cron