Selective Updating of the Scheduler

I realise that [color=red]scheduler.config.readonly = true; stops anyone updating the scheduler, but that is not very practical. What I would like is to allow anyone who is in a particular ASP.NET role, say User.IsInRole(”EventEditor”);, to be able to update the scheduler, barring all others. I don’t normally use JavaScript so I am having problems putting a test around the scheduler.config.readonly = true; statement so that it is usually true, but false for users within the particular role. Can you please help?

Hello,

scheduler.config.readonly is very simple flag and it’s either true or false, you can’t build logic around it. But what it does is quite simple too and you can implement it yourself (with your own logic) - it blocks several events which could lead to event modification, e.g. onBeforeEventChanged, onClick, onDblClick, onBeforeDrag.

Best regards,
Ilya

Hi Ilya

I am thinking of using the ActionResult Save routine on Postback to try and limit updating to a particular role, as follows:-

[code]public ActionResult Save( Event changedEvent, FormCollection actionValues )
{
String action_type = “Refresh”;

if (User.IsInRole( "EditEvent" ))
{
	action_type = actionValues["!nativeeditor_status"];
	Int64 source_id = Int64.Parse( actionValues["id"] );
	Int64 target_id = source_id;

	SchedulerTestDb eventData = new SchedulerTestDb();
	try
	{
		....
	}
	catch
	{
		....
	}

  return View( new CalendarActionResponseModel( action_type, source_id,
               target_id ) );
}
else
{
	return ????????;
};

}[/code]
For return ???; I would like to just refresh the screen, thus removing any changes a non-editor has made. I have tried re-opening the event calendar again, but for some reason that gives me an XML error. I can’t see why it should because it should just be running function init() again. A call to ActionResult Data() rereads the existing data from App-Data but I don’t think it is completing the cycle because the changed event is still being displayed.

I was wondering therefore if action_type had a value that could be used with return View( new CalendarActionResponseModel( action_type, source_id, target_id ) ); to just refresh the screen with the original data.

Hi

what do you want to do can not be done entirely
on the server side, try this way:
before each event, you can back them up,
and when the server returns a message that action was rejected, restore their values

on the client side that can be done by the following code


 scheduler.deep_copy = function (source) {//helper function
            if (typeof (source) == "object") {
                if (source instanceof Array)
                    var target = new Array();
                else
                    var target = new Object();
                if (source instanceof Date)
                    return new Date(source.getTime());
                for (var i in source) {
                    target[i] = scheduler.deep_copy(source[i]);
                }
            }
            else
                var target = source;
            return target;

        };
        scheduler._backup_event = function (event_id) {
            if (!scheduler.event_backups)
                scheduler.event_backups = {};
            scheduler.event_backups[event_id] = {};
            if (scheduler._events[event_id])
                scheduler.event_backups[event_id] = scheduler.deep_copy(scheduler._events[event_id]);
        };
        scheduler.attachEvent("onEventAdded", function (event_id) {
            if (!scheduler.event_backups)
                scheduler.event_backups = {};
            scheduler.event_backups[event_id] = false;
            return true;
        });
        scheduler.attachEvent("onBeforeEventDelete", function (event_id) {
            scheduler._backup_event(event_id);
            return true;
        });
        scheduler.attachEvent("onEventSave", function (event_id) {
            scheduler._backup_event(event_id);
            return true;
        });

        
        var dp = new dataProcessor(...);
        dp.attachEvent("onAfterUpdate", function (id, status) {
            if (status == "error") {

                for (var i in scheduler.event_backups) {
                    if (scheduler.event_backups[i] === false && scheduler._events[i]) {
                        delete scheduler._events[i];
                    }
                    else {
                        scheduler._events[i] = scheduler.deep_copy(scheduler.event_backups[i]);                          
                    }

                }
                scheduler.render_view_data()
            }
            if (scheduler.event_backups && scheduler.event_backups[id])
                delete scheduler.event_backups[id];

        });

for users without needed permissions on the server side you can use connector which will block
any update operations

public override IdhtmlxConnector CreateConnector(HttpContext context)
        {
            var connector =  new dhtmlxSchedulerConnector(
                ....
            );
//event fired before create/update/delete operations
            connector.BeforeDataActionProcessing += new EventHandler<DataActionProcessingEventArgs>(connector_BeforeDataActionProcessing);
            return connector;
        }

        void connector_BeforeDataActionProcessing(object sender, DataActionProcessingEventArgs e)
        {
            e.DataAction.SetFailed("Do not have permissions");
        }

I have found the following code works perfectly

<% if ( User.IsInRole("EventEditor") ) { %> scheduler.config.readonly = false; <% } else { %> scheduler.config.readonly = true; <% }; %>
I have included this in the function init() {…} routine.